Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkBaseDICOMReaderService.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include <mitkCustomMimeType.h>
20 #include <mitkIOMimeTypes.h>
22 #include <mitkImage.h>
23 #include <mitkDICOMFilesHelper.h>
25 #include <mitkDICOMProperty.h>
26 #include <mitkDicomSeriesReader.h>
28 #include <mitkLocaleSwitch.h>
29 #include <iostream>
30 
31 namespace mitk {
32 
33  BaseDICOMReaderService::BaseDICOMReaderService(const std::string& description)
34  : AbstractFileReader(CustomMimeType(IOMimeTypes::DICOM_MIMETYPE()), description)
35 {
36 }
37 
38 std::vector<itk::SmartPointer<BaseData> > BaseDICOMReaderService::Read()
39 {
40  std::vector<BaseData::Pointer> result;
41 
42  //special handling of Philips 3D US DICOM.
43  //Copied from DICOMSeriesReaderService
44 
45  std::string fileName = this->GetLocalFileName();
47  {
48  MITK_INFO << "it is a Philips3D US Dicom file" << std::endl;
49  mitk::LocaleSwitch localeSwitch("C");
50  std::locale previousCppLocale(std::cin.getloc());
51  std::locale l("C");
52  std::cin.imbue(l);
53 
56  stringvec.push_back(fileName);
57  if (DicomSeriesReader::LoadDicomSeries(stringvec, *node))
58  {
59  BaseData::Pointer data = node->GetData();
60  StringProperty::Pointer nameProp = StringProperty::New(itksys::SystemTools::GetFilenameName(fileName));
61  data->GetPropertyList()->SetProperty("name", nameProp);
62  result.push_back(data);
63  }
64  std::cin.imbue(previousCppLocale);
65  return result;
66  }
67 
68  //Normal DICOM handling (It wasn't a Philips 3D US)
69  mitk::StringList relevantFiles = this->GetRelevantFiles();
70 
71  if (relevantFiles.empty())
72  {
73  MITK_INFO << "DICOMReader service found no relevant files in specified location. No data is loaded. Location: "<<fileName;
74  }
75  else
76  {
77  mitk::DICOMFileReader::Pointer reader = this->GetReader(relevantFiles);
78 
79  if(reader.IsNull())
80  {
81  MITK_INFO << "DICOMReader service found no suitable reader configuration for relevant files.";
82  }
83  else
84  {
85  reader->SetAdditionalTagsOfInterest(mitk::GetCurrentDICOMTagsOfInterest());
86  reader->SetTagLookupTableToPropertyFunctor(mitk::GetDICOMPropertyForDICOMValuesFunctor);
87  reader->SetInputFiles(relevantFiles);
88 
90  scanner->AddTagPaths(reader->GetTagsOfInterest());
91  scanner->SetInputFiles(relevantFiles);
92  scanner->Scan();
93 
94  reader->SetTagCache(scanner->GetScanCache());
95  reader->AnalyzeInputFiles();
96  reader->LoadImages();
97 
98  for (unsigned int i = 0; i < reader->GetNumberOfOutputs(); ++i)
99  {
100  const mitk::DICOMImageBlockDescriptor& desc = reader->GetOutput(i);
101  mitk::BaseData::Pointer data = desc.GetMitkImage().GetPointer();
102 
103  std::string nodeName = "Unnamed_DICOM";
104 
105  std::string studyDescription = desc.GetPropertyAsString("studyDescription");
106  std::string seriesDescription = desc.GetPropertyAsString("seriesDescription");
107 
108  if (!studyDescription.empty())
109  {
110  nodeName = studyDescription;
111  }
112 
113  if (!seriesDescription.empty())
114  {
115  if (!studyDescription.empty())
116  {
117  nodeName += "/";
118  }
119  nodeName += seriesDescription;
120  }
121 
122  StringProperty::Pointer nameProp = StringProperty::New(nodeName);
123  data->SetProperty("name", nameProp);
124 
125  result.push_back(data);
126  }
127  }
128  }
129 
130  return result;
131 }
132 
134 {
135  std::string fileName = this->GetLocalFileName();
136 
137  mitk::StringList relevantFiles = mitk::GetDICOMFilesInSameDirectory(fileName);
138 
139  return relevantFiles;
140 }
141 
142 
143 }
itk::SmartPointer< Self > Pointer
The IOMimeTypes class.
DICOMTagPathMapType MITKDICOMREADER_EXPORT GetCurrentDICOMTagsOfInterest()
#define MITK_INFO
Definition: mitkLogMacros.h:22
virtual std::vector< itk::SmartPointer< BaseData > > Read() override
DICOMFilePathList GetDICOMFilesInSameDirectory(const std::string &filePath)
mitk::StringList GetRelevantFiles() const
std::vector< std::string > StringContainer
Lists of filenames.
static DataNode::Pointer LoadDicomSeries(const StringContainer &filenames, bool sort=true, bool load4D=true, bool correctGantryTilt=true, UpdateCallBackMethod callback=nullptr, itk::SmartPointer< Image > preLoadedImageBlock=nullptr)
DataCollection - Class to facilitate loading/accessing structured data.
virtual mitk::DICOMFileReader::Pointer GetReader(const mitk::StringList &relevantFiles) const =0
std::string GetLocalFileName() const
Get a local file name for reading.
MITKDICOMREADER_EXPORT mitk::BaseProperty::Pointer GetDICOMPropertyForDICOMValuesFunctor(const DICOMCachedValueLookupTable &cacheLookupTable)
BaseDICOMReaderService(const std::string &description)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
Convenience class to temporarily change the current locale.
static Pointer New()
Output descriptor for DICOMFileReader.
static bool IsPhilips3DDicom(const std::string &filename)
Checks if a specific file is a Philips3D ultrasound DICOM file.
std::vector< std::string > StringList
Image::Pointer GetMitkImage() const
the 3D mitk::Image that is loaded from the DICOM files of a DICOMImageFrameList
Base class for creating mitk::BaseData objects from files or streams.
std::string GetPropertyAsString(const std::string &) const
Convenience function around GetProperty()
static Pointer New()