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
mitkDicomSeriesReaderService.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 <mitkDicomSeriesReader.h>
21 #include <mitkIOMimeTypes.h>
22 #include <mitkImage.h>
23 #include <mitkLocaleSwitch.h>
24 #include <mitkProgressBar.h>
25 #include <mitkPropertyNameHelper.h>
26 
27 #include <iostream>
28 
29 namespace mitk
30 {
32  : AbstractFileReader(CustomMimeType(IOMimeTypes::DICOM_MIMETYPE()), "MITK DICOM Reader")
33  {
34  this->RegisterService();
35  }
36 
37  std::vector<itk::SmartPointer<BaseData>> DicomSeriesReaderService::Read()
38  {
39  std::vector<BaseData::Pointer> result;
40 
41  mitk::LocaleSwitch localeSwitch("C");
42  std::locale previousCppLocale(std::cin.getloc());
43  std::locale l("C");
44  std::cin.imbue(l);
45 
46  std::string fileName = this->GetLocalFileName();
48  {
49  MITK_INFO << "it is a Philips3D US Dicom file" << std::endl;
52  stringvec.push_back(fileName);
53  if (DicomSeriesReader::LoadDicomSeries(stringvec, *node))
54  {
55  BaseData::Pointer data = node->GetData();
56  StringProperty::Pointer nameProp = StringProperty::New(itksys::SystemTools::GetFilenameName(fileName));
57  data->GetPropertyList()->SetProperty("name", nameProp);
58  result.push_back(data);
59  }
60  std::cin.imbue(previousCppLocale);
61  return result;
62  }
63 
65  DicomSeriesReader::GetSeries(itksys::SystemTools::GetFilenamePath(fileName),
66  true); // true = group gantry tilt images
67  const unsigned int size = imageBlocks.size();
68 
71 
72  unsigned int outputIndex = 0u;
73  const DicomSeriesReader::FileNamesGrouping::const_iterator n_end = imageBlocks.end();
74 
75  for (DicomSeriesReader::FileNamesGrouping::const_iterator n_it = imageBlocks.begin(); n_it != n_end; ++n_it)
76  {
77  const std::string &uid = n_it->first;
79 
80  const DicomSeriesReader::ImageBlockDescriptor &imageBlockDescriptor(n_it->second);
81 
82  MITK_INFO << "--------------------------------------------------------------------------------";
83  MITK_INFO << "DicomSeriesReader: Loading DICOM series " << outputIndex << ": Series UID "
84  << imageBlockDescriptor.GetSeriesInstanceUID() << std::endl;
85  MITK_INFO << " " << imageBlockDescriptor.GetFilenames().size() << " '" << imageBlockDescriptor.GetModality()
86  << "' files (" << imageBlockDescriptor.GetSOPClassUIDAsString() << ") loaded into 1 mitk::Image";
87  MITK_INFO << " multi-frame: " << (imageBlockDescriptor.IsMultiFrameImage() ? "Yes" : "No");
89  imageBlockDescriptor.GetReaderImplementationLevel());
90  MITK_INFO << " pixel spacing type: "
92  MITK_INFO << " gantry tilt corrected: " << (imageBlockDescriptor.HasGantryTiltCorrected() ? "Yes" : "No");
93  MITK_INFO << " 3D+t: " << (imageBlockDescriptor.HasMultipleTimePoints() ? "Yes" : "No");
94  MITK_INFO << "--------------------------------------------------------------------------------";
95 
96  if (DicomSeriesReader::LoadDicomSeries(n_it->second.GetFilenames(), *node, true, true, true))
97  {
98  BaseData::Pointer data = node->GetData();
99  PropertyList::ConstPointer dataProps = data->GetPropertyList().GetPointer();
100 
101  std::string nodeName(uid);
102  std::string studyDescription;
103 
105  0x0008, 0x1030, "dicom.study.StudyDescription", dataProps, studyDescription))
106  {
107  nodeName = studyDescription;
108  std::string seriesDescription;
109 
111  0x0008, 0x103e, "dicom.study.SeriesDescription", dataProps, seriesDescription))
112  { // may not be a string property so use the generic access.
113  nodeName += "/" + seriesDescription;
114  }
115  }
116 
117  StringProperty::Pointer nameProp = StringProperty::New(nodeName);
118  data->SetProperty("name", nameProp);
119 
120  result.push_back(data);
121  ++outputIndex;
122  }
123  else
124  {
125  MITK_ERROR << "DicomSeriesReader: Skipping series " << outputIndex << " due to some unspecified error..."
126  << std::endl;
127  }
128 
130  }
131 
132  std::cin.imbue(previousCppLocale);
133 
134  return result;
135  }
136 
137  DicomSeriesReaderService *DicomSeriesReaderService::Clone() const { return new DicomSeriesReaderService(*this); }
138 }
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
StringContainer GetFilenames() const
List of files in this group.
The IOMimeTypes class.
Return type of GetSeries, describes a logical group of files.
bool HasGantryTiltCorrected() const
Whether or not the block contains a gantry tilt which will be "corrected" during loading.
#define MITK_INFO
Definition: mitkLogMacros.h:22
#define MITK_ERROR
Definition: mitkLogMacros.h:24
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.
std::string GetModality() const
Series Modality (CT, MR, etc.)
std::string GetLocalFileName() const
Get a local file name for reading.
static std::string ReaderImplementationLevelToString(const ReaderImplementationLevel &enumValue)
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
std::string GetSOPClassUIDAsString() const
SOP Class UID as readable string (Computed Tomography Image Storage, Secondary Capture Image Storage...
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static std::string PixelSpacingInterpretationToString(const PixelSpacingInterpretation &enumValue)
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
virtual std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
Convenience class to temporarily change the current locale.
static Pointer New()
static FileNamesGrouping GetSeries(const std::string &dir, bool groupImagesWithGantryTilt, const StringContainer &restrictions=StringContainer())
see other GetSeries().
std::string GetSeriesInstanceUID() const
The Series Instance UID.
static bool IsPhilips3DDicom(const std::string &filename)
Checks if a specific file is a Philips3D ultrasound DICOM file.
bool IsMultiFrameImage() const
Multi-frame image(s) or not.
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
Base class for creating mitk::BaseData objects from files or streams.
ReaderImplementationLevel GetReaderImplementationLevel() const
Confidence of the reader that this block can be read successfully.
std::map< std::string, ImageBlockDescriptor > FileNamesGrouping
PixelSpacingInterpretation GetPixelSpacingType() const
How the mitk::Image spacing can meaningfully be interpreted.
static Pointer New()
bool MITKCORE_EXPORT GetBackwardsCompatibleDICOMProperty(unsigned int group, unsigned int element, std::string const &backwardsCompatiblePropertyName, PropertyList const *propertyList, std::string &propertyValue)