13 #ifndef mitkDicomSeriesReader_h
14 #define mitkDicomSeriesReader_h
19 #include <itkGDCMImageIO.h>
21 #include <itkCommand.h>
22 #include <itkImageSeriesReader.h>
29 #include <gdcmConfigure.h>
38 #include <gdcmDataSet.h>
39 #include <gdcmScanner.h>
447 void AddFile(
const std::string &file);
450 void SetImageBlockUID(
const std::string &uid);
452 void SetSeriesInstanceUID(
const std::string &uid);
454 void SetModality(
const std::string &modality);
456 void SetNumberOfFrames(
const std::string &);
458 void SetSOPClassUID(
const std::string &mediaStorageSOPClassUID);
460 void SetHasGantryTiltCorrected(
bool);
462 void SetPixelSpacingInformation(
const std::string &pixelSpacing,
const std::string &imagerPixelSpacing);
464 void SetHasMultipleTimePoints(
bool);
469 std::string m_ImageBlockUID;
470 std::string m_SeriesInstanceUID;
471 std::string m_Modality;
472 std::string m_SOPClassUID;
473 bool m_HasGantryTiltCorrected;
474 std::string m_PixelSpacing;
475 std::string m_ImagerPixelSpacing;
476 bool m_HasMultipleTimePoints;
477 bool m_IsMultiFrameImage;
499 static bool IsDicom(
const std::string &filename);
515 bool groupImagesWithGantryTilt,
534 const std::string &series_uid,
535 bool groupImagesWithGantryTilt,
563 bool groupImagesWithGantryTilt,
580 bool groupImagesWithGantryTilt,
601 bool correctGantryTilt =
true,
625 bool correctGantryTilt =
true,
750 unsigned int numberOfSlicesApart);
827 const StringContainer &files,
bool groupsOfSimilarImages,
const gdcm::Scanner::MappingType &tagValueMappings_);
884 template <
typename ImageType>
885 static typename ImageType::Pointer
992 void Execute(
const itk::Object *caller,
const itk::EventObject &)
override
994 (*this->
m_Callback)(
static_cast<const itk::ProcessObject *
>(caller)->GetProgress());
998 void Execute(itk::Object *caller,
const itk::EventObject &)
override
1000 (*this->
m_Callback)(
static_cast<itk::ProcessObject *
>(caller)->GetProgress());
1059 template <
typename PixelType>
1063 DcmIoType::Pointer &io,
1071 DcmIoType::Pointer &io,
1079 DcmIoType::Pointer &io,
1087 DcmIoType::Pointer &io,
1106 template <
typename PixelType>
1111 DcmIoType::Pointer &io,
1120 DcmIoType::Pointer &io,
1129 DcmIoType::Pointer &io,
1138 DcmIoType::Pointer &io,
1163 const gdcm::Scanner::MappingType &tagValueMappings_,
1194 const gdcm::Scanner::MappingType &tagValueMappings_,
1211 const gdcm::Scanner::MappingType &tagValueMappings_,
Central node class of the MITK data tree, associating a data object with properties and mappers.
ITK command adapter for progress callbacks.
void Execute(const itk::Object *caller, const itk::EventObject &) override
Execute the callback with the progress value from a const ITK process object.
UpdateCallBackMethod m_Callback
The wrapped progress callback.
void Execute(itk::Object *caller, const itk::EventObject &) override
Execute the callback with the progress value from an ITK process object.
CallbackCommand(UpdateCallBackMethod callback)
Construct with the given callback function pointer.
Return type of GetSeries, describes a logical group of DICOM files.
ReaderImplementationLevel GetReaderImplementationLevel() const
Get the confidence level of the reader for this block.
bool IsMultiFrameImage() const
Whether this block contains multi-frame image(s).
std::string GetImageBlockUID() const
Get a unique ID describing this block (enhanced Series Instance UID).
std::string GetSOPClassUID() const
Get the SOP Class UID as a DICOM UID string.
bool PixelSpacingRelatesToDetector() const
Whether mitk::Image spacing relates to the detector surface.
bool HasMultipleTimePoints() const
Whether this block contains multiple time points (3D+t).
bool HasGantryTiltCorrected() const
Whether the block contains a gantry tilt which will be corrected during loading.
std::string GetModality() const
Get the series modality (CT, MR, etc.).
std::string GetSeriesInstanceUID() const
Get the Series Instance UID.
std::string GetSOPClassUIDAsString() const
Get the SOP Class UID as a readable string (e.g., "Computed Tomography Image Storage").
PixelSpacingInterpretation GetPixelSpacingType() const
Get the interpretation of the mitk::Image pixel spacing.
bool PixelSpacingRelatesToPatient() const
Whether mitk::Image spacing relates to the patient.
bool PixelSpacingIsUnknown() const
Whether mitk::Image spacing origin is unknown.
StringContainer GetFilenames() const
Get the list of filenames in this group.
Return type of DicomSeriesReader::AnalyzeFileForITKImageSeriesReaderSpacingAssumption.
void AddFileToUnsortedBlock(const std::string &filename)
Add a file to the unsorted (remaining) block.
StringContainer m_UnsortedFiles
Files that could not be grouped.
StringContainer GetUnsortedFilenames()
Get the remaining files which could not be grouped.
void AddFileToSortedBlock(const std::string &filename)
Add a file to the sorted (grouped) block.
bool m_GantryTilt
Whether gantry tilt was detected.
void UndoPrematureGrouping()
Undo a premature grouping decision.
bool ContainsGantryTilt()
Whether the grouped result contains a gantry tilt.
void FlagGantryTilt()
Flag this result as containing a gantry tilt.
SliceGroupingAnalysisResult()
void AddFilesToUnsortedBlock(const StringContainer &filenames)
Add multiple files to the unsorted (remaining) block.
StringContainer m_GroupedFiles
Files that form a valid image block.
StringContainer GetBlockFilenames()
Get the grouped filenames (all with same origin-to-origin distance, no gaps).
static itk::SmartPointer< Image > LoadDICOMByITK(const StringContainer &, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer< Image > preLoadedImageBlock)
Feed files into itk::ImageSeriesReader and retrieve a 3D MITK image.
static Point3D DICOMStringToPoint3D(const std::string &s, bool &successful)
Convert a DICOM string describing a 3D point to Point3D.
static std::string ConstCharStarToString(const char *s)
Safely convert a const char pointer to std::string.
std::vector< std::string > StringContainer
Container type for lists of DICOM filenames.
static std::string PixelSpacingInterpretationToString(const PixelSpacingInterpretation &enumValue)
Convert a PixelSpacingInterpretation enum value to a human-readable string.
PixelSpacingInterpretation
How the mitk::Image pixel spacing should be interpreted.
@ PixelSpacingInterpretation_SpacingInPatient
Distances are mm within a patient.
@ PixelSpacingInterpretation_SpacingUnknown
No spacing information is present; (1,1) is used as default.
@ PixelSpacingInterpretation_SpacingAtDetector
Distances are mm at detector surface.
static bool ReadPhilips3DDicom(const std::string &filename, itk::SmartPointer< Image > output_image)
Read a Philips 3D ultrasound DICOM file and load it into an mitk::Image.
static itk::SmartPointer< Image > MultiplexLoadDICOMByITK4D(std::list< StringContainer > &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer< Image > preLoadedImageBlock)
Pixel-type multiplexer for LoadDICOMByITK4D – dispatches to scalar or RGB variants.
static void FixSpacingInformation(Image *image, const ImageBlockDescriptor &imageBlockDescriptor)
Correct the pixel spacing of a loaded image based on the image block descriptor.
itk::GDCMImageIO DcmIoType
Typedef for the GDCM image IO class used internally.
static FileNamesGrouping GetSeries(const StringContainer &files, bool sortTo3DPlust, bool groupImagesWithGantryTilt, const StringContainer &restrictions=StringContainer())
PREFERRED version – scan and sort a list of DICOM files into loadable blocks.
static FileNamesGrouping GetSeries(const std::string &dir, bool groupImagesWithGantryTilt, const StringContainer &restrictions=StringContainer())
Find all series (and sub-series) in a particular directory.
static void DICOMStringToOrientationVectors(const std::string &s, Vector3D &right, Vector3D &up, bool &successful)
Convert a DICOM orientation string to two direction vectors.
static std::string IDifyTagValue(const std::string &value)
Sanitize a tag value string for use as part of a UID.
ReaderImplementationLevel
Describes how well the reader is tested for a certain file type (SOP Class).
@ ReaderImplementationLevel_Unsupported
Loader code is not working with this SOP Class.
@ ReaderImplementationLevel_PartlySupported
Loader code and tests are established for specific parts of a SOP Class.
@ ReaderImplementationLevel_Implemented
Loader code is implemented but not accompanied by tests.
@ ReaderImplementationLevel_Supported
Loader code and tests are established.
void(* UpdateCallBackMethod)(float)
Function pointer type for progress callbacks.
static void LoadDicom(const StringContainer &filenames, DataNode &node, bool sort, bool check_4d, bool correctTilt, UpdateCallBackMethod callback, itk::SmartPointer< Image > preLoadedImageBlock)
Perform the actual loading of a DICOM series.
static std::string CreateMoreUniqueSeriesIdentifier(gdcm::Scanner::TagToValue &tagValueMap)
Construct a UID that incorporates sorting criteria from GetSeries().
static std::string GetConfigurationString()
Provide the combination of preprocessor defines that was active during compilation.
static DataNode::Pointer LoadDicomSeries(const StringContainer &filenames, bool sort=true, bool load4D=true, bool correctGantryTilt=true, UpdateCallBackMethod callback=nullptr, itk::SmartPointer< Image > preLoadedImageBlock=nullptr)
Load a DICOM series into a new DataNode.
static itk::SmartPointer< Image > MultiplexLoadDICOMByITKScalar(const StringContainer &, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer< Image > preLoadedImageBlock)
Scalar pixel type multiplexer for LoadDICOMByITK.
static bool LoadDicomSeries(const StringContainer &filenames, DataNode &node, bool sort=true, bool load4D=true, bool correctGantryTilt=true, UpdateCallBackMethod callback=nullptr, itk::SmartPointer< Image > preLoadedImageBlock=nullptr)
Load a DICOM series into an existing DataNode.
static bool GdcmSortFunction(const gdcm::DataSet &ds1, const gdcm::DataSet &ds2)
Spatial sorting comparator for GDCM 2 datasets.
std::map< std::string, std::string > TagToPropertyMapType
Map type from DICOM tag strings to MITK property name strings.
static std::string CreateSeriesIdentifierPart(gdcm::Scanner::TagToValue &tagValueMap, const gdcm::Tag &tag)
Extract a single tag value as a string for use in CreateMoreUniqueSeriesIdentifier().
static std::list< StringContainer > SortIntoBlocksFor3DplusT(const StringContainer &presortedFilenames, const gdcm::Scanner::MappingType &tagValueMappings_, bool sort, bool &canLoadAs4D)
Sort files into time step blocks for 3D+t image loading.
static bool IsPhilips3DDicom(const std::string &filename)
Check if a specific file is a Philips 3D ultrasound DICOM file.
static void CopyMetaDataToImageProperties(StringContainer filenames, const gdcm::Scanner::MappingType &tagValueMappings_, DcmIoType *io, const ImageBlockDescriptor &blockInfo, Image *image)
Copy DICOM tag information to the PropertyList of an mitk::Image (single block).
static std::string ReaderImplementationLevelToString(const ReaderImplementationLevel &enumValue)
Convert a ReaderImplementationLevel enum value to a human-readable string.
static itk::SmartPointer< Image > LoadDICOMByITK4D(std::list< StringContainer > &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer< Image > preLoadedImageBlock)
Feed files into itk::ImageSeriesReader for 3D+t loading.
static FileNamesGrouping GetSeries(const StringContainer &files, bool groupImagesWithGantryTilt, const StringContainer &restrictions=StringContainer())
Scan and sort DICOM files (without explicit 3D+t control).
static StringContainer GetSeries(const std::string &dir, const std::string &series_uid, bool groupImagesWithGantryTilt, const StringContainer &restrictions=StringContainer())
Find files belonging to a specific DICOM series in a directory.
static itk::SmartPointer< Image > MultiplexLoadDICOMByITK4DScalar(std::list< StringContainer > &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer< Image > preLoadedImageBlock)
Scalar pixel type multiplexer for LoadDICOMByITK4D.
static ImageType::Pointer InPlaceFixUpTiltedGeometry(ImageType *input, const GantryTiltInformation &tiltInfo)
Correct a tilted image geometry by resampling with a shear transformation.
static StringContainer SortSeriesSlices(const StringContainer &unsortedFilenames)
static itk::SmartPointer< Image > MultiplexLoadDICOMByITK4DRGBPixel(std::list< StringContainer > &imageBlocks, ImageBlockDescriptor imageBlockDescriptor, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer< Image > preLoadedImageBlock)
RGB pixel type multiplexer for LoadDICOMByITK4D.
static const TagToPropertyMapType & GetDICOMTagsToMITKPropertyMap()
Get the mapping from DICOM tags to MITK property names.
static bool IsDicom(const std::string &filename)
Check if a specific file contains DICOM data.
std::pair< StringContainer, StringContainer > TwoStringContainers
Pair of string containers used for internal sorting operations.
static void CopyMetaDataToImageProperties(std::list< StringContainer > imageBlock, const gdcm::Scanner::MappingType &tagValueMappings_, DcmIoType *io, const ImageBlockDescriptor &blockInfo, Image *image)
Copy DICOM tag information to the PropertyList of an mitk::Image (4D blocks).
static void ScanForSliceInformation(const StringContainer &filenames, gdcm::Scanner &scanner)
Scan DICOM files for slice-relevant tag information.
static itk::SmartPointer< Image > MultiplexLoadDICOMByITKRGBPixel(const StringContainer &, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer< Image > preLoadedImageBlock)
RGB pixel type multiplexer for LoadDICOMByITK.
std::map< std::string, ImageBlockDescriptor > FileNamesGrouping
Map type from enhanced UID strings to ImageBlockDescriptor instances.
static SliceGroupingAnalysisResult AnalyzeFileForITKImageSeriesReaderSpacingAssumption(const StringContainer &files, bool groupsOfSimilarImages, const gdcm::Scanner::MappingType &tagValueMappings_)
Ensure equal z-spacing for a group of files.
static bool DICOMStringToSpacing(const std::string &s, ScalarType &spacingX, ScalarType &spacingY)
Parse a DICOM spacing string into pixel spacing X and Y values.
static itk::SmartPointer< Image > MultiplexLoadDICOMByITK(const StringContainer &, bool correctTilt, const GantryTiltInformation &tiltInfo, DcmIoType::Pointer &io, CallbackCommand *command, itk::SmartPointer< Image > preLoadedImageBlock)
Pixel-type multiplexer for LoadDICOMByITK – dispatches to scalar or RGB variants.
Image class for storing multi-dimensional medical image data.
Find image slices visible on a given plane.
double ScalarType
Scalar type used throughout MITK for geometric computations.