Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDicomSR_ImageBlockDescriptor.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 
17 #include <mitkDicomSeriesReader.h>
18 
19 #include <gdcmUIDs.h>
20 
21 namespace mitk
22 {
24  : m_HasGantryTiltCorrected(false), m_HasMultipleTimePoints(false), m_IsMultiFrameImage(false)
25  {
26  }
27 
29  {
30  // nothing
31  }
32 
34  : m_HasGantryTiltCorrected(false), m_HasMultipleTimePoints(false), m_IsMultiFrameImage(false)
35  {
36  m_Filenames = files;
37  }
38 
39  void DicomSeriesReader::ImageBlockDescriptor::AddFile(const std::string &filename)
40  {
41  m_Filenames.push_back(filename);
42  }
43 
44  void DicomSeriesReader::ImageBlockDescriptor::AddFiles(const StringContainer &files)
45  {
46  m_Filenames.insert(m_Filenames.end(), files.begin(), files.end());
47  }
48 
50  {
51  return m_Filenames;
52  }
53 
54  std::string DicomSeriesReader::ImageBlockDescriptor::GetImageBlockUID() const { return m_ImageBlockUID; }
55  std::string DicomSeriesReader::ImageBlockDescriptor::GetSeriesInstanceUID() const { return m_SeriesInstanceUID; }
56  std::string DicomSeriesReader::ImageBlockDescriptor::GetModality() const { return m_Modality; }
58  {
59  gdcm::UIDs uidKnowledge;
60  uidKnowledge.SetFromUID(m_SOPClassUID.c_str());
61  return uidKnowledge.GetName();
62  }
63 
64  std::string DicomSeriesReader::ImageBlockDescriptor::GetSOPClassUID() const { return m_SOPClassUID; }
65  bool DicomSeriesReader::ImageBlockDescriptor::IsMultiFrameImage() const { return m_IsMultiFrameImage; }
67  const
68  {
69  if (this->IsMultiFrameImage())
71 
72  gdcm::UIDs uidKnowledge;
73  uidKnowledge.SetFromUID(m_SOPClassUID.c_str());
74 
75  gdcm::UIDs::TSType uid = uidKnowledge;
76 
77  switch (uid)
78  {
79  case gdcm::UIDs::CTImageStorage:
80  case gdcm::UIDs::MRImageStorage:
81  case gdcm::UIDs::PositronEmissionTomographyImageStorage:
82  case gdcm::UIDs::ComputedRadiographyImageStorage:
83  case gdcm::UIDs::DigitalXRayImageStorageForPresentation:
84  case gdcm::UIDs::DigitalXRayImageStorageForProcessing:
86 
87  case gdcm::UIDs::NuclearMedicineImageStorage:
89 
90  case gdcm::UIDs::SecondaryCaptureImageStorage:
92 
93  default:
95  }
96  }
97 
98  bool DicomSeriesReader::ImageBlockDescriptor::HasGantryTiltCorrected() const { return m_HasGantryTiltCorrected; }
99  /*
100  PS defined IPS defined PS==IPS
101  0 0 --> UNKNOWN spacing, loader will invent
102  0 1 --> spacing as at detector surface
103  1 0 --> spacing as in patient
104  1 1 0 --> detector surface spacing CORRECTED for geometrical magnifications:
105  spacing as in patient
106  1 1 1 --> detector surface spacing NOT corrected for geometrical
107  magnifications:
108  spacing as at detector
109  */
111  {
112  if (m_PixelSpacing.empty())
113  {
114  if (m_ImagerPixelSpacing.empty())
115  {
117  }
118  else
119  {
121  }
122  }
123  else // Pixel Spacing defined
124  {
125  if (m_ImagerPixelSpacing.empty())
126  {
128  }
129  else if (m_PixelSpacing != m_ImagerPixelSpacing)
130  {
132  }
133  else
134  {
136  }
137  }
138  }
139 
141  {
142  return GetPixelSpacingType() == PixelSpacingInterpretation_SpacingInPatient;
143  }
144 
146  {
147  return GetPixelSpacingType() == PixelSpacingInterpretation_SpacingAtDetector;
148  }
149 
151  {
152  return GetPixelSpacingType() == PixelSpacingInterpretation_SpacingUnknown;
153  }
154 
155  void DicomSeriesReader::ImageBlockDescriptor::SetPixelSpacingInformation(const std::string &pixelSpacing,
156  const std::string &imagerPixelSpacing)
157  {
158  m_PixelSpacing = pixelSpacing;
159  m_ImagerPixelSpacing = imagerPixelSpacing;
160  }
161 
162  void DicomSeriesReader::ImageBlockDescriptor::GetDesiredMITKImagePixelSpacing(ScalarType &spacingX,
163  ScalarType &spacingY) const
164  {
165  // preference for "in patient" pixel spacing
166  if (!DICOMStringToSpacing(m_PixelSpacing, spacingX, spacingY))
167  {
168  // fallback to "on detector" spacing
169  if (!DICOMStringToSpacing(m_ImagerPixelSpacing, spacingX, spacingY))
170  {
171  // last resort: invent something
172  spacingX = spacingY = 1.0;
173  }
174  }
175  }
176 
177  bool DicomSeriesReader::ImageBlockDescriptor::HasMultipleTimePoints() const { return m_HasMultipleTimePoints; }
178  void DicomSeriesReader::ImageBlockDescriptor::SetImageBlockUID(const std::string &uid) { m_ImageBlockUID = uid; }
179  void DicomSeriesReader::ImageBlockDescriptor::SetSeriesInstanceUID(const std::string &uid)
180  {
181  m_SeriesInstanceUID = uid;
182  }
183 
184  void DicomSeriesReader::ImageBlockDescriptor::SetModality(const std::string &modality) { m_Modality = modality; }
185  void DicomSeriesReader::ImageBlockDescriptor::SetNumberOfFrames(const std::string &numberOfFrames)
186  {
187  m_IsMultiFrameImage = !numberOfFrames.empty();
188  }
189 
190  void DicomSeriesReader::ImageBlockDescriptor::SetSOPClassUID(const std::string &sopClassUID)
191  {
192  m_SOPClassUID = sopClassUID;
193  }
194 
195  void DicomSeriesReader::ImageBlockDescriptor::SetHasGantryTiltCorrected(bool on) { m_HasGantryTiltCorrected = on; }
196  void DicomSeriesReader::ImageBlockDescriptor::SetHasMultipleTimePoints(bool on) { m_HasMultipleTimePoints = on; }
197 } // end namespace mitk
PixelSpacingInterpretation
How the mitk::Image spacing should be interpreted.
StringContainer GetFilenames() const
List of files in this group.
static bool DICOMStringToSpacing(const std::string &s, ScalarType &spacingX, ScalarType &spacingY)
Safely convert a string into pixel spacing x and y.
bool HasGantryTiltCorrected() const
Whether or not the block contains a gantry tilt which will be "corrected" during loading.
std::string GetImageBlockUID() const
A unique ID describing this bloc (enhanced Series Instance UID).
double ScalarType
std::vector< std::string > StringContainer
Lists of filenames.
DataCollection - Class to facilitate loading/accessing structured data.
std::string GetModality() const
Series Modality (CT, MR, etc.)
std::string GetSOPClassUID() const
SOP Class UID as DICOM UID.
std::string GetSOPClassUIDAsString() const
SOP Class UID as readable string (Computed Tomography Image Storage, Secondary Capture Image Storage...
loader code is implemented but not accompanied by tests
static const std::string filename
std::string GetSeriesInstanceUID() const
The Series Instance UID.
bool IsMultiFrameImage() const
Multi-frame image(s) or not.
bool PixelSpacingRelatesToDetector() const
Whether or not mitk::Image spacing relates to the detector surface.
ReaderImplementationLevel GetReaderImplementationLevel() const
Confidence of the reader that this block can be read successfully.
bool PixelSpacingIsUnknown() const
Whether or not mitk::Image spacing is of unknown origin.
PixelSpacingInterpretation GetPixelSpacingType() const
How the mitk::Image spacing can meaningfully be interpreted.
bool PixelSpacingRelatesToPatient() const
Whether or not mitk::Image spacing relates to the patient.
ReaderImplementationLevel
Describes how well the reader is tested for a certain file type.