Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDicomSeriesReader.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,
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 #ifndef mitkDicomSeriesReader_h
18 #define mitkDicomSeriesReader_h
19 
20 #include "mitkConfig.h"
21 #include "mitkDataNode.h"
22 
23 #include <itkGDCMImageIO.h>
24 
25 #include <itkCommand.h>
26 #include <itkImageSeriesReader.h>
27 
28 #ifdef NOMINMAX
29 #define DEF_NOMINMAX
30 #undef NOMINMAX
31 #endif
32 
33 #include <gdcmConfigure.h>
34 
35 #ifdef DEF_NOMINMAX
36 #ifndef NOMINMAX
37 #define NOMINMAX
38 #endif
39 #undef DEF_NOMINMAX
40 #endif
41 
42 #include <gdcmDataSet.h>
43 #include <gdcmScanner.h>
44 
45 namespace mitk
46 {
348  class Image;
349 
351  {
352  public:
356  typedef std::vector<std::string> StringContainer;
357 
361  typedef void (*UpdateCallBackMethod)(float);
362 
373  typedef enum {
376  ReaderImplementationLevel_Implemented,
380 
386  typedef enum {
389  PixelSpacingInterpretation_SpacingUnknown
391 
400  {
401  public:
403  StringContainer GetFilenames() const;
404 
406  std::string GetImageBlockUID() const;
407 
409  std::string GetSeriesInstanceUID() const;
410 
412  std::string GetModality() const;
413 
415  std::string GetSOPClassUIDAsString() const;
416 
418  std::string GetSOPClassUID() const;
419 
421  ReaderImplementationLevel GetReaderImplementationLevel() const;
422 
424  bool HasGantryTiltCorrected() const;
425 
427  bool PixelSpacingRelatesToPatient() const;
429  bool PixelSpacingRelatesToDetector() const;
431  bool PixelSpacingIsUnknown() const;
432 
434  PixelSpacingInterpretation GetPixelSpacingType() const;
435 
437  bool HasMultipleTimePoints() const;
438 
440  bool IsMultiFrameImage() const;
441 
444 
445  private:
446  friend class DicomSeriesReader;
447 
448  ImageBlockDescriptor(const StringContainer &files);
449 
450  void AddFile(const std::string &file);
451  void AddFiles(const StringContainer &files);
452 
453  void SetImageBlockUID(const std::string &uid);
454 
455  void SetSeriesInstanceUID(const std::string &uid);
456 
457  void SetModality(const std::string &modality);
458 
459  void SetNumberOfFrames(const std::string &);
460 
461  void SetSOPClassUID(const std::string &mediaStorageSOPClassUID);
462 
463  void SetHasGantryTiltCorrected(bool);
464 
465  void SetPixelSpacingInformation(const std::string &pixelSpacing, const std::string &imagerPixelSpacing);
466 
467  void SetHasMultipleTimePoints(bool);
468 
469  void GetDesiredMITKImagePixelSpacing(ScalarType &spacingX, ScalarType &spacingY) const;
470 
471  StringContainer m_Filenames;
472  std::string m_ImageBlockUID;
473  std::string m_SeriesInstanceUID;
474  std::string m_Modality;
475  std::string m_SOPClassUID;
476  bool m_HasGantryTiltCorrected;
477  std::string m_PixelSpacing;
478  std::string m_ImagerPixelSpacing;
479  bool m_HasMultipleTimePoints;
480  bool m_IsMultiFrameImage;
481  };
482 
483  typedef std::map<std::string, ImageBlockDescriptor> FileNamesGrouping;
484 
491  static std::string GetConfigurationString();
492 
496  static bool IsDicom(const std::string &filename);
497 
503  static FileNamesGrouping GetSeries(const std::string &dir,
504  bool groupImagesWithGantryTilt,
505  const StringContainer &restrictions = StringContainer());
506 
515  static StringContainer GetSeries(const std::string &dir,
516  const std::string &series_uid,
517  bool groupImagesWithGantryTilt,
518  const StringContainer &restrictions = StringContainer());
519 
544  static FileNamesGrouping GetSeries(const StringContainer &files,
545  bool sortTo3DPlust,
546  bool groupImagesWithGantryTilt,
547  const StringContainer &restrictions = StringContainer());
548 
554  static FileNamesGrouping GetSeries(const StringContainer &files,
555  bool groupImagesWithGantryTilt,
556  const StringContainer &restrictions = StringContainer());
557 
566  static DataNode::Pointer LoadDicomSeries(const StringContainer &filenames,
567  bool sort = true,
568  bool load4D = true,
569  bool correctGantryTilt = true,
570  UpdateCallBackMethod callback = nullptr,
571  itk::SmartPointer<Image> preLoadedImageBlock = nullptr);
572 
579  static bool LoadDicomSeries(const StringContainer &filenames,
580  DataNode &node,
581  bool sort = true,
582  bool load4D = true,
583  bool correctGantryTilt = true,
584  UpdateCallBackMethod callback = nullptr,
585  itk::SmartPointer<Image> preLoadedImageBlock = nullptr);
586 
587  protected:
600  {
601  public:
603 
607  StringContainer GetBlockFilenames();
608 
612  StringContainer GetUnsortedFilenames();
613 
617  bool ContainsGantryTilt();
618 
622  void AddFileToSortedBlock(const std::string &filename);
623 
627  void AddFileToUnsortedBlock(const std::string &filename);
628  void AddFilesToUnsortedBlock(const StringContainer &filenames);
629 
634  void FlagGantryTilt();
635 
639  void UndoPrematureGrouping();
640 
641  protected:
642  StringContainer m_GroupedFiles;
643  StringContainer m_UnsortedFiles;
644 
646  };
647 
660  {
661  public:
662  // two types to avoid any rounding errors
663  typedef itk::Point<double, 3> Point3Dd;
664  typedef itk::Vector<double, 3> Vector3Dd;
665 
670 
687  GantryTiltInformation(const Point3D &origin1,
688  const Point3D &origin2,
689  const Vector3D &right,
690  const Vector3D &up,
691  unsigned int numberOfSlicesApart);
692 
698  bool IsSheared() const;
699 
709  bool IsRegularGantryTilt() const;
710 
714  double GetMatrixCoefficientForCorrectionInWorldCoordinates() const;
715 
719  double GetRealZSpacing() const;
720 
726  double GetTiltCorrectedAdditionalSize() const;
727 
731  double GetTiltAngleInDegrees() const;
732 
733  protected:
737  Point3D projectPointOnLine(Point3Dd p, Point3Dd lineOrigin, Vector3Dd lineDirection);
738 
739  double m_ShiftUp;
740  double m_ShiftRight;
743  unsigned int m_NumberOfSlicesApart;
744  };
745 
749  typedef std::pair<StringContainer, StringContainer> TwoStringContainers;
750 
754  typedef std::map<std::string, std::string> TagToPropertyMapType;
755 
771  static SliceGroupingAnalysisResult AnalyzeFileForITKImageSeriesReaderSpacingAssumption(
772  const StringContainer &files, bool groupsOfSimilarImages, const gdcm::Scanner::MappingType &tagValueMappings_);
773 
777  static std::string ConstCharStarToString(const char *s);
778 
782  static bool DICOMStringToSpacing(const std::string &s, ScalarType &spacingX, ScalarType &spacingY);
783 
792  static Point3D DICOMStringToPoint3D(const std::string &s, bool &successful);
793 
802  static void DICOMStringToOrientationVectors(const std::string &s, Vector3D &right, Vector3D &up, bool &successful);
803 
804  template <typename ImageType>
805  static typename ImageType::Pointer
806  // TODO this is NOT inplace!
807  InPlaceFixUpTiltedGeometry(ImageType *input, const GantryTiltInformation &tiltInfo);
808 
828  static StringContainer SortSeriesSlices(const StringContainer &unsortedFilenames);
829 
830  public:
834  static bool IsPhilips3DDicom(const std::string &filename);
835 
836  static std::string ReaderImplementationLevelToString(const ReaderImplementationLevel &enumValue);
837  static std::string PixelSpacingInterpretationToString(const PixelSpacingInterpretation &enumValue);
838 
839  protected:
843  static bool ReadPhilips3DDicom(const std::string &filename, itk::SmartPointer<Image> output_image);
844 
848  static std::string CreateMoreUniqueSeriesIdentifier(gdcm::Scanner::TagToValue &tagValueMap);
849 
853  static std::string CreateSeriesIdentifierPart(gdcm::Scanner::TagToValue &tagValueMap, const gdcm::Tag &tag);
854 
858  static std::string IDifyTagValue(const std::string &value);
859 
860  typedef itk::GDCMImageIO DcmIoType;
861 
865  class CallbackCommand : public itk::Command
866  {
867  public:
868  CallbackCommand(UpdateCallBackMethod callback) : m_Callback(callback) {}
869  void Execute(const itk::Object *caller, const itk::EventObject &) override
870  {
871  (*this->m_Callback)(static_cast<const itk::ProcessObject *>(caller)->GetProgress());
872  }
873 
874  void Execute(itk::Object *caller, const itk::EventObject &) override
875  {
876  (*this->m_Callback)(static_cast<itk::ProcessObject *>(caller)->GetProgress());
877  }
878 
879  protected:
880  UpdateCallBackMethod m_Callback;
881  };
882 
883  static void FixSpacingInformation(Image *image, const ImageBlockDescriptor &imageBlockDescriptor);
884 
888  static void ScanForSliceInformation(const StringContainer &filenames, gdcm::Scanner &scanner);
889 
893  static void LoadDicom(const StringContainer &filenames,
894  DataNode &node,
895  bool sort,
896  bool check_4d,
897  bool correctTilt,
898  UpdateCallBackMethod callback,
899  itk::SmartPointer<Image> preLoadedImageBlock);
900 
906  template <typename PixelType>
907  static itk::SmartPointer<Image> LoadDICOMByITK(const StringContainer &,
908  bool correctTilt,
909  const GantryTiltInformation &tiltInfo,
910  DcmIoType::Pointer &io,
911  CallbackCommand *command,
912  itk::SmartPointer<Image> preLoadedImageBlock);
913 
914  static itk::SmartPointer<Image> MultiplexLoadDICOMByITK(const StringContainer &,
915  bool correctTilt,
916  const GantryTiltInformation &tiltInfo,
917  DcmIoType::Pointer &io,
918  CallbackCommand *command,
919  itk::SmartPointer<Image> preLoadedImageBlock);
920 
921  static itk::SmartPointer<Image> MultiplexLoadDICOMByITKScalar(const StringContainer &,
922  bool correctTilt,
923  const GantryTiltInformation &tiltInfo,
924  DcmIoType::Pointer &io,
925  CallbackCommand *command,
926  itk::SmartPointer<Image> preLoadedImageBlock);
927 
928  static itk::SmartPointer<Image> MultiplexLoadDICOMByITKRGBPixel(const StringContainer &,
929  bool correctTilt,
930  const GantryTiltInformation &tiltInfo,
931  DcmIoType::Pointer &io,
932  CallbackCommand *command,
933  itk::SmartPointer<Image> preLoadedImageBlock);
934 
935  template <typename PixelType>
936  static itk::SmartPointer<Image> LoadDICOMByITK4D(std::list<StringContainer> &imageBlocks,
937  ImageBlockDescriptor imageBlockDescriptor,
938  bool correctTilt,
939  const GantryTiltInformation &tiltInfo,
940  DcmIoType::Pointer &io,
941  CallbackCommand *command,
942  itk::SmartPointer<Image> preLoadedImageBlock);
943 
944  static itk::SmartPointer<Image> MultiplexLoadDICOMByITK4D(std::list<StringContainer> &imageBlocks,
945  ImageBlockDescriptor imageBlockDescriptor,
946  bool correctTilt,
947  const GantryTiltInformation &tiltInfo,
948  DcmIoType::Pointer &io,
949  CallbackCommand *command,
950  itk::SmartPointer<Image> preLoadedImageBlock);
951 
952  static itk::SmartPointer<Image> MultiplexLoadDICOMByITK4DScalar(std::list<StringContainer> &imageBlocks,
953  ImageBlockDescriptor imageBlockDescriptor,
954  bool correctTilt,
955  const GantryTiltInformation &tiltInfo,
956  DcmIoType::Pointer &io,
957  CallbackCommand *command,
958  itk::SmartPointer<Image> preLoadedImageBlock);
959 
960  static itk::SmartPointer<Image> MultiplexLoadDICOMByITK4DRGBPixel(std::list<StringContainer> &imageBlocks,
961  ImageBlockDescriptor imageBlockDescriptor,
962  bool correctTilt,
963  const GantryTiltInformation &tiltInfo,
964  DcmIoType::Pointer &io,
965  CallbackCommand *command,
966  itk::SmartPointer<Image> preLoadedImageBlock);
967 
982  static std::list<StringContainer> SortIntoBlocksFor3DplusT(const StringContainer &presortedFilenames,
983  const gdcm::Scanner::MappingType &tagValueMappings_,
984  bool sort,
985  bool &canLoadAs4D);
986 
993  static bool GdcmSortFunction(const gdcm::DataSet &ds1, const gdcm::DataSet &ds2);
994 
1000  static void CopyMetaDataToImageProperties(StringContainer filenames,
1001  const gdcm::Scanner::MappingType &tagValueMappings_,
1002  DcmIoType *io,
1003  const ImageBlockDescriptor &blockInfo,
1004  Image *image);
1005  static void CopyMetaDataToImageProperties(std::list<StringContainer> imageBlock,
1006  const gdcm::Scanner::MappingType &tagValueMappings_,
1007  DcmIoType *io,
1008  const ImageBlockDescriptor &blockInfo,
1009  Image *image);
1010 
1019  static const TagToPropertyMapType &GetDICOMTagsToMITKPropertyMap();
1020  };
1021 }
1022 
1023 #endif /* mitkDicomSeriesReader_h */
PixelSpacingInterpretation
How the mitk::Image spacing should be interpreted.
std::map< std::string, std::string > TagToPropertyMapType
Maps DICOM tags to MITK properties.
itk::SmartPointer< Self > Pointer
#define MITKCORE_EXPORT
Return type of GetSeries, describes a logical group of files.
double ScalarType
bool DICOMStringToSpacing(const std::string &s, ScalarType &spacingX, ScalarType &spacingY)
void Execute(const itk::Object *caller, const itk::EventObject &) override
std::pair< StringContainer, StringContainer > TwoStringContainers
for internal sorting.
void DICOMStringToOrientationVectors(const std::string &s, Vector3D &right, Vector3D &up, bool &successful)
Convert DICOM string describing a point two Vector3D.
std::vector< std::string > StringContainer
Lists of filenames.
DataCollection - Class to facilitate loading/accessing structured data.
std::string ReaderImplementationLevelToString(const ReaderImplementationLevel &enumValue)
Convert mitk::ReaderImplementationLevel to a human readable string.
loader code is implemented but not accompanied by tests
ReaderImplementationLevel
Describes how well the reader is tested for a certain file type (see mitk::DICOMFileReader).
PixelSpacingInterpretation
How the mitk::Image spacing should be interpreted (see mitk::DICOMFileReader).
map::core::discrete::Elements< 3 >::InternalImageType ImageType
class ITK_EXPORT Image
static const std::string filename
void Execute(itk::Object *caller, const itk::EventObject &) override
std::string PixelSpacingInterpretationToString(const PixelSpacingInterpretation &value)
Convert mitk::PixelSpacingInterpretation to a human readable string.
Image class for storing images.
Definition: mitkImage.h:76
Progress callback for DicomSeriesReader.
Return type of DicomSeriesReader::AnalyzeFileForITKImageSeriesReaderSpacingAssumption.
CallbackCommand(UpdateCallBackMethod callback)
Point3D DICOMStringToPoint3D(const std::string &s, bool &successful)
Convert DICOM string describing a point to Point3D.
std::map< std::string, ImageBlockDescriptor > FileNamesGrouping
ReaderImplementationLevel
Describes how well the reader is tested for a certain file type.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66