Medical Imaging Interaction Toolkit  2025.12.02
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 
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:
287 
288  void InternalPrintConfiguration(std::ostream& os) const override;
289 
291  static std::string GetActiveLocale();
296  void PushLocale() const;
301  void PopLocale() const;
302 
303  const static int m_DefaultDecimalPlacesForOrientation = 5;
304  const static bool m_DefaultSimpleVolumeImport = false;
305  const static bool m_DefaultFixTiltByShearing = true;
306 
307  DICOMITKSeriesGDCMReader(unsigned int decimalPlacesForOrientation = m_DefaultDecimalPlacesForOrientation, bool simpleVolumeImport = m_DefaultSimpleVolumeImport);
309 
312 
313  using SortingBlockListItemType = std::pair<DICOMDatasetAccessingImageFrameList, IOVolumeSplitReason::Pointer>;
314  using SortingBlockList = std::vector<SortingBlockListItemType> ;
319  virtual SortingBlockList Condense3DBlocks(SortingBlockList& resultOf3DGrouping);
320 
321  virtual DICOMTagCache::Pointer GetTagCache() const;
322  void SetTagCache( const DICOMTagCache::Pointer& ) override;
323 
326  unsigned int sortingStepIndex,
327  const DICOMDatasetSorter::Pointer& sorter,
328  const SortingBlockList& input);
329 
331  virtual bool LoadMitkImageForOutput(unsigned int o);
332 
334 
336  static ReaderImplementationLevel GetReaderImplementationLevel(const std::string sopClassUID);
337  private:
338 
340  void EnsureMandatorySortersArePresent(unsigned int decimalPlacesForOrientation, bool simpleVolumeImport = false);
341 
342  protected:
343 
344  // NOT nice, made available to ThreeDnTDICOMSeriesReader due to lack of time
345  bool m_FixTiltByShearing; // could be removed by ITKDICOMSeriesReader NOT flagging tilt unless requested to fix it!
346 
348 
349  private:
350 
351  SortingBlockList m_SortingResultInProgress;
352 
353  typedef std::list<DICOMDatasetSorter::Pointer> SorterList;
354  SorterList m_Sorter;
355 
356  protected:
357 
358  // NOT nice, made available to ThreeDnTDICOMSeriesReader and ClassicDICOMSeriesReader due to lack of time
359  mitk::EquiDistantBlocksSorter::Pointer m_EquiDistantBlocksSorter;
360 
361  mitk::NormalDirectionConsistencySorter::Pointer m_NormalDirectionConsistencySorter;
362 
363  private:
364 
365  static std::mutex s_LocaleMutex;
366 
367  mutable std::stack<std::string> m_ReplacedCLocales;
368  mutable std::stack<std::locale> m_ReplacedCinLocales;
369 
370  double m_DecimalPlacesForOrientation;
371 
372  DICOMTagCache::Pointer m_TagCache;
373  bool m_ExternalCache;
374 };
375 
376 }
377 
378 #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