Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkDICOMITKSeriesGDCMReader.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkDICOMITKSeriesGDCMReader_h
14 #define mitkDICOMITKSeriesGDCMReader_h
15 
16 #include <mutex>
17 #include <stack>
18 #include <mitkDICOMFileReader.h>
19 #include <mitkDICOMDatasetSorter.h>
23 #include <MitkDICOMExports.h>
24 
25 
26 namespace itk
27 {
28  class TimeProbesCollectorBase;
29 }
30 
31 namespace mitk
32 {
33 
191 {
192  public:
193 
195  itkCloneMacro( DICOMITKSeriesGDCMReader );
196  itkFactorylessNewMacro( DICOMITKSeriesGDCMReader );
199 
204  void AnalyzeInputFiles() override;
205 
206  // void AllocateOutputImages();
210  bool LoadImages() override;
211 
212  // re-implemented from super-class
213  bool CanHandleFile(const std::string& filename) override;
214 
218  virtual void AddSortingElement(DICOMDatasetSorter* sorter, bool atFront = false);
219 
220  typedef const std::list<DICOMDatasetSorter::ConstPointer> ConstSorterList;
222 
226  void SetFixTiltByShearing(bool on);
227 
228  bool GetFixTiltByShearing() const;
229 
233  void SetAcceptTwoSlicesGroups(bool accept) const;
235 
239  void SetToleratedOriginOffsetToAdaptive(double fractionOfInterSliceDistanct = 0.3) const;
240 
244  void SetToleratedOriginOffset(double millimeters = 0.005) const;
245 
249  void SetSimpleVolumeReading(bool read)
250  {
251  m_SimpleVolumeReading = read;
252  };
253 
258  {
259  return m_SimpleVolumeReading;
260  };
261 
262  double GetToleratedOriginError() const;
264 
266 
267  bool operator==(const DICOMFileReader& other) const override;
268 
270 
272  {
273  return m_DefaultDecimalPlacesForOrientation;
274  }
275 
277  {
278  return m_DefaultSimpleVolumeImport;
279  }
280 
282  {
283  return m_DefaultFixTiltByShearing;
284  }
285 
286  protected:
288 
289  void InternalPrintConfiguration(std::ostream& os) const override;
290 
292  static std::string GetActiveLocale();
297  void PushLocale() const;
302  void PopLocale() const;
303 
304  const static int m_DefaultDecimalPlacesForOrientation = 5;
305  const static bool m_DefaultSimpleVolumeImport = false;
306  const static bool m_DefaultFixTiltByShearing = true;
307 
308  DICOMITKSeriesGDCMReader(unsigned int decimalPlacesForOrientation = m_DefaultDecimalPlacesForOrientation, bool simpleVolumeImport = m_DefaultSimpleVolumeImport);
310 
313 
314  using SortingBlockListItemType = std::pair<DICOMDatasetAccessingImageFrameList, IOVolumeSplitReason::Pointer>;
315  using SortingBlockList = std::vector<SortingBlockListItemType> ;
320  virtual SortingBlockList Condense3DBlocks(SortingBlockList& resultOf3DGrouping);
321 
322  virtual DICOMTagCache::Pointer GetTagCache() const;
323  void SetTagCache( const DICOMTagCache::Pointer& ) override;
324 
327  unsigned int sortingStepIndex,
328  const DICOMDatasetSorter::Pointer& sorter,
329  const SortingBlockList& input);
330 
332  virtual bool LoadMitkImageForOutput(unsigned int o);
333 
335 
337  static ReaderImplementationLevel GetReaderImplementationLevel(const std::string sopClassUID);
338  private:
339 
341  void EnsureMandatorySortersArePresent(unsigned int decimalPlacesForOrientation, bool simpleVolumeImport = false);
342 
343  protected:
344 
345  // NOT nice, made available to ThreeDnTDICOMSeriesReader due to lack of time
346  bool m_FixTiltByShearing; // could be removed by ITKDICOMSeriesReader NOT flagging tilt unless requested to fix it!
347 
349 
350  private:
351 
352  SortingBlockList m_SortingResultInProgress;
353 
354  typedef std::list<DICOMDatasetSorter::Pointer> SorterList;
355  SorterList m_Sorter;
356 
357  protected:
358 
359  // NOT nice, made available to ThreeDnTDICOMSeriesReader and ClassicDICOMSeriesReader due to lack of time
360  mitk::EquiDistantBlocksSorter::Pointer m_EquiDistantBlocksSorter;
361 
362  mitk::NormalDirectionConsistencySorter::Pointer m_NormalDirectionConsistencySorter;
363 
364  private:
365 
366  static std::mutex s_LocaleMutex;
367 
368  mutable std::stack<std::string> m_ReplacedCLocales;
369  mutable std::stack<std::locale> m_ReplacedCinLocales;
370 
371  double m_DecimalPlacesForOrientation;
372 
373  DICOMTagCache::Pointer m_TagCache;
374  bool m_ExternalCache;
375 };
376 
377 }
378 
379 #endif
#define MITKDICOM_EXPORT
The sorting/splitting building-block of DICOMITKSeriesGDCMReader.
Interface for DICOM readers that produce mitk::Images.
Flexible reader based on itk::ImageSeriesReader and GDCM, for single-slice modalities like CT,...
DICOMITKSeriesGDCMReader(unsigned int decimalPlacesForOrientation=m_DefaultDecimalPlacesForOrientation, bool simpleVolumeImport=m_DefaultSimpleVolumeImport)
virtual bool LoadMitkImageForOutput(unsigned int o)
Loads the mitk::Image by means of an itk::ImageSeriesReader.
static SortingBlockList InternalExecuteSortingStep(unsigned int sortingStepIndex, const DICOMDatasetSorter::Pointer &sorter, const SortingBlockList &input)
Sorting step as described in Loading strategy.
void SetTagCache(const DICOMTagCache::Pointer &) override
A way to provide external knowledge about files and tag values is appreciated.
virtual void AddSortingElement(DICOMDatasetSorter *sorter, bool atFront=false)
Add an element to the sorting procedure described in Loading strategy.
static std::string GetActiveLocale()
Return active C locale.
std::pair< DICOMDatasetAccessingImageFrameList, IOVolumeSplitReason::Pointer > SortingBlockListItemType
void PopLocale() const
Activate last remembered locale from locale stack "C" locale is required for correct parsing of numbe...
mitkNewMacro1Param(DICOMITKSeriesGDCMReader, unsigned int)
bool GetSimpleVolumeReading()
Ignore all dicom tags that are non-essential for simple 3D volume import.
DICOMTagPathList GetTagsOfInterest() const override
static ReaderImplementationLevel GetReaderImplementationLevel(const std::string sopClassUID)
Describe this reader's confidence for given SOP class UID.
void SetFixTiltByShearing(bool on)
Controls whether to "fix" tilted acquisitions by shearing the output (see Gantry tilt handling).
void SetSimpleVolumeReading(bool read)
Ignore all dicom tags that are non-essential for simple 3D volume import.
void SetToleratedOriginOffsetToAdaptive(double fractionOfInterSliceDistanct=0.3) const
See Forced Configuration.
double GetToleratedOriginError() const
mitk::NormalDirectionConsistencySorter::Pointer m_NormalDirectionConsistencySorter
void PushLocale() const
Remember current locale on stack, activate "C" locale. "C" locale is required for correct parsing of ...
virtual DICOMTagCache::Pointer GetTagCache() const
mitkNewMacro2Param(DICOMITKSeriesGDCMReader, unsigned int, bool)
bool IsToleratedOriginOffsetAbsolute() const
DICOMITKSeriesGDCMReader & operator=(const DICOMITKSeriesGDCMReader &other)
bool operator==(const DICOMFileReader &other) const override
mitkClassMacro(DICOMITKSeriesGDCMReader, DICOMFileReader)
ConstSorterList GetFreelyConfiguredSortingElements() const
virtual SortingBlockList Condense3DBlocks(SortingBlockList &resultOf3DGrouping)
"Hook" for sub-classes, see Sub-classes can condense multiple blocks into a single larger block
double GetDecimalPlacesForOrientation() const
bool LoadImages() override
Loads images using itk::ImageSeriesReader, potentially applies shearing to correct gantry tilt.
mitkCloneMacro(DICOMITKSeriesGDCMReader)
DICOMITKSeriesGDCMReader(const DICOMITKSeriesGDCMReader &other)
virtual bool LoadMitkImageForImageBlockDescriptor(DICOMImageBlockDescriptor &block) const
std::vector< SortingBlockListItemType > SortingBlockList
void SetToleratedOriginOffset(double millimeters=0.005) const
See Forced Configuration.
void AnalyzeInputFiles() override
Runs the sorting / splitting process described in Loading strategy. Method required by DICOMFileReade...
void SetAcceptTwoSlicesGroups(bool accept) const
Controls whether groups of only two images are accepted when ensuring consecutive slices via EquiDist...
bool CanHandleFile(const std::string &filename) override
Indicate whether this reader can handle given file.
mitk::EquiDistantBlocksSorter::Pointer m_EquiDistantBlocksSorter
void InternalPrintConfiguration(std::ostream &os) const override
Configuration description for human reader, to be implemented by sub-classes.
const std::list< DICOMDatasetSorter::ConstPointer > ConstSorterList
Output descriptor for DICOMFileReader.
ReaderImplementationLevel
Describes how well the reader is tested for a certain file type (see mitk::DICOMFileReader).
Find image slices visible on a given plane.
std::vector< DICOMTagPath > DICOMTagPathList
A list of DICOMTagPath instances.