MeVisLab Toolbox Reference
ml::DicomToMLTools Namespace Reference

Tool functions for the extraction and handling of information of specific DICOM frames. More...

Classes

class  DCMTreeInfo
 Small container for statistical information about a DCMTree. More...
 
class  DicomFrameSetMinMaxCalculation
 Class to collect incrementally per frame all min/max related parameters of a DICOM frame set. More...
 
struct  DICOMPixelReadAndCopyParameterResults
 Container storing parameters needed to copy data from DICOM pixel data into a SubImage. More...
 
class  DICOMPixelReadAndCopyParameters
 Small container storing and validating all input and result parameters needed to copy data from a DCMTree given by a DICOMCachedIOFileHandle into a SubImage. More...
 
struct  FrameSpecificTag
 A struct containing a information about a specific frame (position, tagId, tagPtr, and whether it's from tree root). More...
 
struct  FrameSpecificTags
 Helper structure to store a z, t, u position of a frame in a structured multi-frame tree, and a tag belonging to that frame. More...
 
struct  FrameSpecificValueTag
 A struct containing a information about a specific frame (position, tagId, tagPtr, and whether it's from tree root) as well as an associated value retrieved from the tag and the value validity. More...
 
class  NeedsSignednessCorrectionShiftingOrMasking
 Tool class to retrieve the values of HightBit, BitsAllocated, BitsStored, and PixelRepresentation from dcmTree and to set needsCorrection to true if pixel data needs post processing such as masking of retired overlay planes, sign extension, or shifting. More...
 
struct  PositionSpecificDouble
 Helper structure to store a z, t, u position with an associated double value. More...
 

Typedefs

typedef std::vector< FrameSpecificTagsFrameSpecificTagsVector
 Often used std::vector type of FrameSpecificTag elements.
 
typedef std::vector< PositionSpecificDoublePositionSpecificDoubleVector
 Often used std::vector type of PositionSpecificDouble elements.
 

Enumerations

enum  VoxelDoubleOperations { Copy = 0 , Add , Multiply }
 Defines some modes how a (voxel) value can be manipulated with a double value. More...
 
enum  { NumberOfVoxelDoubleOperations = Multiply + 1 }
 Number of available VoxelDoubleOperations. More...
 
enum  FillPageMethods {
  FILL_WITH_IMG_FILE_READER_WO_DICOM = 0 , FILL_WITH_IMG_FILE_READER , FILL_WITH_SPECTROSCOPY_DATA_TAG_DATA , FILL_WITH_PIXEL_DATA_TAG_DATA ,
  FILL_WITH_DEFAULT_FILL_VAL , FILL_DO_NOT_FILL
}
 Methods how to fill a page with data from the DICOM file or tree. More...
 
enum  OutputDataTypeSelector {
  NoChange = 0 , Automatic , UseMLuint8 , UseMLint8 ,
  UseMLuint16 , UseMLint16 , UseMLuint32 , UseMLint32 ,
  UseMLFloat , UseMLDouble
}
 Specifies whether the output voxel type shall be adopted when the data is scaled. More...
 
enum  { NumOutputDataTypeSelectors = UseMLDouble +1 }
 Number of available OutputDataTypeSelectors modes. More...
 
enum  CalculateMinMaxFromDicomModes { CalculateMinMaxAutomatic = 0 , CalculateMinMaxOnlyFromDicomTags , CalculateMinMaxMaxScanImageData , NUM__CALC_MIN_MAX_FROM_DICOM_ENUMS }
 Available selectable DPL configurations. More...
 

Functions

MLDICOM_TO_ML_TOOLS_EXPORT FrameSpecificTagsVector getFrameSpecificTagSet (const DCMTree::Const_StructuredMFPtr &smfTree, const std::vector< DCMTree::RawTagId > &tagIds)
 Returns an entry for each frame and each tag id from tagIds in which any tagId can be found and store the corresponding z, t, and u location in the entry as well as the found pointer to the tag.
 
MLDICOM_TO_ML_TOOLS_EXPORT FrameSpecificTagsVector getFrameSpecificTags (const DCMTree::Const_StructuredMFPtr &smfTree, DCMTree::RawTagId tagId)
 Returns an entry for each frame in which a tag with id tagId can be found and store the corresponding z, t, and u location in the entry as well as the found pointer to the tag.
 
MLDICOM_TO_ML_TOOLS_EXPORT size_t convertToFrameSpecificDoubles (const FrameSpecificTagsVector &frameSpecificTags, PositionSpecificDoubleVector &frameSpecificDoubles)
 Converts first entries of each entries in FrameSpecificTagsVector to a PositionSpecificDoubleVector object.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool applyFrameSpecificOperation (const VoxelDoubleOperations &operationMode, const SubImage &srcSubImage, SubImage &dstSubImage, const PositionSpecificDoubleVector &positionDoubles, const VoxelDoubleOperations dummyOperationMode=Copy, const MLdouble dummyOperationValue=0.0, PositionSpecificDoubleVector *valueFreePositions=nullptr, bool isOldMultiFrameDICOM=false)
 Copy voxels from overlapping regions of srcSubImage to dstSubImage and apply
the operationMode if for the z, t, u position of the slice an entry can be found in positionDoubles whose double value can be used for modification.
 
MLDICOM_TO_ML_TOOLS_EXPORT const FrameSpecificTagsgetFrameSpecificTagsSet (const FrameSpecificTagsVector &tagSet, MLint z, MLint t, MLint u)
 Returns pointer to the first occurrence of a FrameSpecificTags entry which has the given z, t, and u positions or nullptr if not found.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool isVolumeCovered (const PositionSpecificDoubleVector &positions, const SubImageBox &volume)
 Returns true if the (z,t,u) positions in positions cover all (z,t,u) slices in volume, otherwise false is returned.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool getPositionSpecificDoubleProperties (const PositionSpecificDoubleVector &positions, double &rangeMin, double &rangeMax, bool &hasFractionalParts)
 Returns some properties of the double values in valuePositions, the minimum / maximum range, and whether any value is a non integer one.
 
MLDICOM_TO_ML_TOOLS_EXPORT std::vector< DCMTree::RawTagIdgetOverlayTagSet ()
 Create a vector with all possible ids of type 1 and important type 3 overlay tags.
 
MLDICOM_TO_ML_TOOLS_EXPORT void setUpOverlayOutputProperties (DCMTree::Const_TreePtr dcmTree, PagedImage &overlayPagedImg, DicomToMLTools::FrameSpecificTagsVector &overlayTagSet)
 Determine DICOM overlay information from dcmTree, configures (or if necessary invalidates) the passed overlayPagedImg such that it can display these overlays correctly, and sets up overlayTagSet such that it provides all required DICOM tags to display them properly in calculateOutputSubImage.
 
MLDICOM_TO_ML_TOOLS_EXPORT std::string createOverlayBitSubImages (const FrameSpecificTagsVector &tagSet, MLint z, MLint t, MLint u, std::vector< BitImage > &bitImages)
 Create and return a BitImage in bitSubImages for each overlay for which all required type 1 tags are found in the first z,t,u frame occurrence.
 
MLDICOM_TO_ML_TOOLS_EXPORT std::string rasterOverlays (DicomToMLTools::FrameSpecificTagsVector &overlayTagSet, SubImage &outSubImg)
 Takes overlay DICOM tags from overlayTagSet matching the x/y plane of outSubImage.getBox().v1, create BitImages from them and copies them into outSubImage where the entire background it filled with 0, and valid overlay bits are set to 1.
 
void getFrameSpecificDoubleTag (const DCMTree::StructuredMF &smfTree, const unsigned int z, const unsigned int t, const unsigned int u, const DCMTree::RawTagId rawTagId, FrameSpecificValueTag< double > &valTagInfos)
 Retrieves a double tag value from a frame specific tag with id rawTagId at (z,t,u) from smfTree, and returns all result information in valTagInfos; if the value cannot be retrieved from the given frame then it is tried to get it from the tree root.
 
void getFrameSpecificStringTag (const DCMTree::StructuredMF &smfTree, const unsigned int z, const unsigned int t, const unsigned int u, const DCMTree::RawTagId rawTagId, FrameSpecificValueTag< std::string > &valTagInfos)
 Same as getFrameSpecificDoubleTag() but for std::string values.
 
MLDICOM_TO_ML_TOOLS_EXPORT MLErrorCode copyFromDCMTreeToSubImg (const DICOMCachedIOFileHandle &dcmFileHandle, DCMTree::Const_TreePtr alternativeDCMTree, SubImage &outSubImg, bool force, DicomMessageCollector &dcmMsgCollector)
 Tries to fill the given output subimage outSubImg with pixel data from the DICOM tree given by either dcmFileHandle or alternativeDCMTree.
 
MLDICOM_TO_ML_TOOLS_EXPORT MLErrorCode convertDCMTreeToSubImage (const DICOMCachedIOFileHandle &dcmFrameHandle, DCMTree::Const_TreePtr alternativeDCMTree, SubImage &subImage, DicomMessageCollector &dcmMsgCollector)
 Reads the DICOM file given by dcmFrameHandle via the MLDICOMCachedIOTreeCache (or uses alternativeDCMTree if dcmFrameHandle is empty), and updates subImage to its data content.
 
MLDICOM_TO_ML_TOOLS_EXPORT void convertToImageProperties (DCMTree::StructuredMFPtr &baseSMFPtr, const std::string &firstFileName, PagedImage &resultImgProps, FillPageMethods *fillPageMethod, const ZTUFileNameSet *setOfFileHandles, double defaultFillValue, CalculateMinMaxFromDicomModes minMaxCalcMode, const std::string &versionString, bool anonymize, bool removePrivateMultiFrameSQTag, bool forceOrthogonalWorldMatrix, bool copyPrivateTopLevelSrcTags, DicomMessageCollector &dcmMsgCollector)
 Determines as much PagedImage information from baseSMFPtr as possible and.
 
MLDICOM_TO_ML_TOOLS_EXPORT size_t getVoxelSize (DCMTree::Const_TreePtr treePtr, double &voxSizeX, double &voxSizeY, double &voxSizeZ, bool replaceOnlyIfFound, bool *isPrecise, std::vector< DCMTree::RawTagId > *usedTags, DicomMessageCollector &dcmMsgCollector)
 Determine the voxel size from the DICOM tags and returns the number of found extents.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool applyPaletteInfosToPagedImage (const DICOMTagTools::DicomPaletteInfo &paletteInfos, PagedImage &pagedImage, const bool adjustToLUTType=false)
 If possible then this function modifies pagedImage according to the settings paletteInfos.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool applySubImageColorLookUp (const SubImage &inSubImg, const DICOMTagTools::DicomPaletteInfo &paletteInfo, SubImage &outSubImg)
 Applies an intensity to color look up from valid region of inSubImg and paletteInfo to outSubImg.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool applyPhotometricInterpretationChangesToPagedImage (const DCMTree::Const_TreePtr &dcmTree, PagedImage &pagedImage)
 If possible then this function modifies pagedImage according to the photometric interpretation such that pixel values can be translated correctly.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool applyPhotometricInterpretationToSubImg (DCMTree::Const_TreePtr dcmTree, const SubImage &inSubImg, const double minVoxelValue, const double maxVoxelValue, SubImage &outSubImg)
 Applies a color format conversion from input subimage to output subimage according to the photometric interpretation tag in dcmTree.
 
MLDICOM_TO_ML_TOOLS_EXPORT void getSpectDICOMImageProperties (DCMTree::Const_TreePtr treePtr, const std::string &fileNameUTF8, PagedImage &outInfos, Vector4 &rotAxisAndRadians, Vector3 &ipp, Vector3 &relMRSPositionVector, Vector3 &mrsPositionVector, Vector3 &voiVector, Vector3 &fovVector, bool useOldWorldMatrixCalculation, DicomMessageCollector &dcmMsgCollector)
 Extract spectroscopy image properties and some other infos from the passed DICOM tree.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool copySpectData (SubImage &outSubImg, const ImageVector &outImgExtent, const DICOMTagTools::SpectComplex *mrsData, size_t spectDataSizeInBytes)
 Copies the complex spectroscopy data from mrsData to the output subimage assuming appropriate sizes of mrsData which must have been calculated successfully with getSpectDICOMImageProperties and which must match the PagedImage properties calculated in the same routine.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool isImageFrameNotOfBits (DCMTree::Const_TreePtr treePtr)
 Returns true if the DICOM tree seems to describe a sensible image with column and row extents > 1 as well as pixels with more than one bit per pixel, otherwise false.
 
MLDICOM_TO_ML_TOOLS_EXPORT void setWorldMatrixFromDcmTree (DCMTree::Const_TreePtr treePtr, PagedImage &outInfos, DicomMessageCollector &dcmMsgCollector)
 If possible all image properties from the DcmTree needed to set up the world matrix are searched and converted to a world matrix and voxel size and set in outInfos.
 
MLDICOM_TO_ML_TOOLS_EXPORT MLDataType getMLDataTypeFromDCMTree (DCMTree::Const_TreePtr treePtr, DicomMessageCollector &dcmMsgCollector)
 Determines the ML data type of pixel data in the given DICOM tree treePtr.
 
MLDICOM_TO_ML_TOOLS_EXPORT void checkAndCorrectImageExtentAccordingToPixelData (DCMTree::Const_TreePtr treePtr, size_t pixelDataSizeInBytes, ImageVector &imgExt, DicomMessageCollector &dcmMsgCollector)
 Check especially whether the extent of the image given in imgExt is larger by a multiple than the pixel data where the multiple is the same as imgExt.z, imgExt.t or imgExt.z*imgExt.t.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool determineImageExtentsFromDCMTree (DCMTree::Const_TreePtr treePtr, ImageVector &imgExt, std::vector< std::string > *cDimInfos, bool overrideBadTagInfos, DicomMessageCollector &dcmMsgCollector)
 Update imgExt and - if non nullptr - cDimInfos from treePtr if possible, otherwise they are left unchanged.
 
MLDICOM_TO_ML_TOOLS_EXPORT void getAnyDICOMImageProperties (DCMTree::Const_TreePtr treePtr, PagedImage &outInfos, bool overrideBadTagInfos, DicomMessageCollector &dcmMsgCollector)
 Extract as many PagedImage properties from the passed DICOM treePtr as possible.
 
MLDICOM_TO_ML_TOOLS_EXPORT std::string determineBasicREGProperties (DCMTree::Const_TreePtr treePtr, size_t extent[3], double voxelSize[3], MLErrorCode &errCode, DicomMessageCollector &dcmMsgCollector)
 Extract basic image properties from a DICOM tree of REG modality and SOP Class UID "1.2.840.10008.5.1.4.1.1.66.3" (Deformable Registration Storage).
 
MLDICOM_TO_ML_TOOLS_EXPORT std::string determineREGProperties (DCMTree::Const_TreePtr treePtr, ImageVector &extent, Vector3 &voxelSize, SubImage *subImage, MLErrorCode *errCode, DicomMessageCollector &dcmMsgCollector)
 Extract image properties and deformable vector field from a DICOM tree of REG modality and SOP Class UID "1.2.840.10008.5.1.4.1.1.66.3" (Deformable Registration Storage) Spatial registration storage with SOP Class UID "1.2.840.10008.5.1.4.1.1.66.1" will result to empty return string, ML_RESULT_OK (if errCode is provided), (0,...,0) extent, voxel size (1,1,1), subImage with empty box, nullptr data, and MLuint8Type.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool hasValidNonImageModality (DCMTree::Const_TreePtr treePtr)
 Returns true only if the passed string is a known, non-empty and valid modality string which is a non image modality (RTSTRUCT, RTPLAN, RTRECORD, AU, SR, HD, ECG, FID...) and the DCMTree is not a Secondary Capture IOD.
 
MLDICOM_TO_ML_TOOLS_EXPORT MLDataType determineOutputVoxelType (DCMTree::StructuredMFPtr &srcVolumeSMFTree, const MLDataType inVoxDataType, const SubImageBox &volumeBox, const double inDataRangeMin, const double inDataRangeMax, const OutputDataTypeSelector voxelTypeSelector, const VoxelDoubleOperations operationMode, const PositionSpecificDoubleVector &posDbls, const VoxelDoubleOperations defaultOperationMode, const double defaultOperationDouble, double &resultRangeMin, double &resultRangeMax)
 Determines a voxel type for an ML output image from some properties of an input image and a set of double values applied to different slices of the input image.
 
MLDICOM_TO_ML_TOOLS_EXPORT void determineDCMTreeInfo (DCMTree::Const_TreePtr dcmTree, DCMTreeInfo &dcmTreeInfo)
 Stores some statistical information from dcmTree in dcmTreeInfo.
 
MLDICOM_TO_ML_TOOLS_EXPORT DCMTree::Const_StructuredMFPtr getSMFTreeFromPagedImage (const PagedImage &pImg)
 Tries to get the first DICOM image property extension and returns its DCMTree wrapped as Structured MF Tree if possible; otherwise nullptr is returned.
 
MLDICOM_TO_ML_TOOLS_EXPORT void setUpMinMaxVoxelValues (std::string &errStr, DCMTree::Const_DictPtr dcmTreeDictPtr, double smallestPixelValue, double largestPixelValue, DCMTree::TreePtr dcmTree)
 Set up DCMTree_SmallestImagePixelValue and DCMTree_LargestImagePixelValue tags in dcmTree; requires that DCMTree_PixelRepresentation, DCMTree_SmallestImagePixelValue, or DCMTree_LargestImagePixelValue tags exist from which the value representation of the DCMTree_SmallestImagePixelValue and DCMTree_LargestImagePixelValue can be determined.
 
MLDICOM_TO_ML_TOOLS_EXPORT bool guessMinMaxRangeFromDICOMTags (DCMTree::Const_TreePtr treePtr, MLdouble &minPixVal, MLdouble &maxPixVal, DicomMessageCollector &dcmMsgCollector)
 Try to guess a min/max range from DICOM tags for the case that they cannot be determined in another way.
 
MLDICOM_TO_ML_TOOLS_EXPORT void calcImageDataMinMaxFromTag (DCMTree::Const_TreePtr &treePtr, MLint64 &minValInt64, MLint64 &maxValInt64, MLdouble &minValDbl, MLdouble &maxValDbl, DicomMessageCollector &dcmMsgCollector)
 Traverse all pixel values in the first found pixel data tag in the tree given by treePtr and returns their minimum and maximum values in minValDbl and maxValDbl as well as in minValInt64 and maxValint64.
 
MLDICOM_TO_ML_TOOLS_EXPORT void determineMinMaxValues (DCMTree::Const_TreePtr treePtr, PagedImage &pagedImg)
 Update min/max voxel values of pagedImg from tags in treePtr if possible, otherwise these settings are left unchanged.
 
MLMULTI_FILE_VOLUME_EXPORT DCMTree::Const_TreePtr getInputDCMTree (Module &moduleWithInFields, const std::string &inputSourceName, const std::string &fileName, Base *basePtr, const MLint volIdx, size_t *numVolumes, bool allowEmptyFileNames, DicomMessageCollector &dcmMsgCollector)
 Gets a DCMTree from an input which is selected via a string name.
 
MLMULTI_FILE_VOLUME_EXPORT void getDCMTreeFromAnyFileType (const std::string &fileName, bool postError, DCMTree::Const_TreePtr &treePtr, size_t &numVols, DicomMessageCollector &dcmMsgCollector)
 Loads a Const_TreePtr from a file given by the absolute file path fileName if possible (currently .dcm and .mlimage files are supported); this function implements a subfunctionality of getInputDCMTree() and needs no Base or Module.
 

Variables

MLDICOM_TO_ML_TOOLS_EXPORT const char *const VoxelDoubleOperationsStrings [NumberOfVoxelDoubleOperations]
 Strings according to VoxelDoubleOperations.
 
MLDICOM_TO_ML_TOOLS_EXPORT const char *const OutputDataTypeSelectorsStrings [NumOutputDataTypeSelectors]
 Strings according to OutputDataTypeSelector.
 
MLDICOM_TO_ML_TOOLS_EXPORT const char *const CalculateMinMaxFromDicomModesEnumStrings [NUM__CALC_MIN_MAX_FROM_DICOM_ENUMS]
 Strings names corresponding to the selectable DplMinMaxEnums.
 

Detailed Description

Tool functions for the extraction and handling of information of specific DICOM frames.

A collection of DICOM tool functions.

Tool functions for the extraction and handling of information of specific single DICOM frames.

Tool function namespace with many tool functions for the conversion of DICOM information and tag values to comparable ML information objects.

Typedef Documentation

◆ FrameSpecificTagsVector

Often used std::vector type of FrameSpecificTag elements.

Definition at line 67 of file mlDicomFrameSelectionTools.h.

◆ PositionSpecificDoubleVector

Often used std::vector type of PositionSpecificDouble elements.

Definition at line 89 of file mlDicomFrameSelectionTools.h.

Enumeration Type Documentation

◆ anonymous enum

Number of available VoxelDoubleOperations.

Enumerator
NumberOfVoxelDoubleOperations 

Definition at line 38 of file mlDicomFrameSelectionTools.h.

◆ anonymous enum

Number of available OutputDataTypeSelectors modes.

Enumerator
NumOutputDataTypeSelectors 

Definition at line 458 of file mlDicomToMLTools.h.

◆ CalculateMinMaxFromDicomModes

Available selectable DPL configurations.

Enumerator
CalculateMinMaxAutomatic 

Automatically select either CalculateMinMaxOnlyFromDicomTags or CalculateMinMaxMaxScanImageData mode.

CalculateMinMaxOnlyFromDicomTags 

Determine min/max values only from DICOM tags SmallestPixelValue or LargestPixelValue, (image pixel data is not scanned).

CalculateMinMaxMaxScanImageData 

Pixel data tags are scanned regardless of SmallestPixelValue or LargestPixelValue tags.

NUM__CALC_MIN_MAX_FROM_DICOM_ENUMS 

Number of available min/max calculation modes (no valid mode!).

Definition at line 34 of file mlDicomTreeMinMaxTools.h.

◆ FillPageMethods

Methods how to fill a page with data from the DICOM file or tree.

Enumerator
FILL_WITH_IMG_FILE_READER_WO_DICOM 

Uses ImgFileReader to read and copy the file, suppress direct DICOM read.

FILL_WITH_IMG_FILE_READER 

Uses only MFL ImgFileReader to read and copy files, allowing optimized DICOM read.

FILL_WITH_SPECTROSCOPY_DATA_TAG_DATA 

Content of Spectroscopy data tag is copied.

FILL_WITH_PIXEL_DATA_TAG_DATA 

Content of PixelData tag is copied.

FILL_WITH_DEFAULT_FILL_VAL 

Page is filled with default value.

FILL_DO_NOT_FILL 

Do not fill at all.

Definition at line 48 of file mlDicomToMLTools.h.

◆ OutputDataTypeSelector

Specifies whether the output voxel type shall be adopted when the data is scaled.

Enumerator
NoChange 

Do not change the voxel type.

Automatic 

Adopts the data type such that range and precision is always maintained.

UseMLuint8 

Always use MLuint8 as output type.

UseMLint8 

Always use MLint8 as output type.

UseMLuint16 

Always use MLuint16 as output type.

UseMLint16 

Always use MLint16 as output type.

UseMLuint32 

Always use MLuint32 as output type.

UseMLint32 

Always use MLint32 as output type.

UseMLFloat 

Always use float as output type.

UseMLDouble 

Always use double as output type.

Definition at line 444 of file mlDicomToMLTools.h.

◆ VoxelDoubleOperations

Defines some modes how a (voxel) value can be manipulated with a double value.

Enumerator
Copy 

Copy the input value to output without modification.

Add 

Copy the sum of the input value and the double to output.

Multiply 

Copy the product of the input value and the double to output.

Definition at line 31 of file mlDicomFrameSelectionTools.h.

Function Documentation

◆ applyFrameSpecificOperation()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::applyFrameSpecificOperation ( const VoxelDoubleOperations & operationMode,
const SubImage & srcSubImage,
SubImage & dstSubImage,
const PositionSpecificDoubleVector & positionDoubles,
const VoxelDoubleOperations dummyOperationMode = Copy,
const MLdouble dummyOperationValue = 0.0,
PositionSpecificDoubleVector * valueFreePositions = nullptr,
bool isOldMultiFrameDICOM = false )

Copy voxels from overlapping regions of srcSubImage to dstSubImage and apply
the operationMode if for the z, t, u position of the slice an entry can be found in positionDoubles whose double value can be used for modification.

The double operation is performed regardless of the voxel data type and whether it can store the result precision or not. If no such entry is found and the isOldMultiFrameDICOM mode is not executed as explained below then the dummyOperationMode and value are used.

Parameters
operationModeThe operation to be applied as transfer operation from srcSubImage voxels to dstSubImage voxels on slices where an entry in positionDoubles could be found.
srcSubImageThe source of the voxels to be processed and written into dstSubImage.
dstSubImageThe target for the voxels to be read from dstSubImage and then processed.
positionDoublesA set of double values associated to frame positions in z,t, and u.
dummyOperationModeThe operation to be applied as transfer operation from srcSubImage voxels to dstSubImage voxels on slices for which no entry in positionDoubles could be found.
dummyOperationValueThe double to be used as value in conjunction with dummOperationMode.
valueFreePositionsIf non nullptr: An array of z, t, and u positions for which no entries in doublePositions exist and for which the copy operation was performed. Ignored if nullptr.
isOldMultiFrameDICOMIn the case of old multi-frame files we have only one pixel buffer with multiple slices (appears e.g. in RTDose or US images). In these cases we typically also have only one positionDoubles at (0,0,0) which must be applied to the entire image. Will be ignored if positionDoubles contains more than one entry or the first entry is not of position 0,0,0.
Returns
true if dstSubImage was modified during the call, otherwise false.

References applyFrameSpecificOperation().

Referenced by applyFrameSpecificOperation().

◆ applyPaletteInfosToPagedImage()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::applyPaletteInfosToPagedImage ( const DICOMTagTools::DicomPaletteInfo & paletteInfos,
PagedImage & pagedImage,
const bool adjustToLUTType = false )

If possible then this function modifies pagedImage according to the settings paletteInfos.

Parameters
paletteInfosThe palette information is considered valid if paletteInfos.dataType is MLuint8Type or MLuint16Type.
pagedImageThe PagedImage to be adopted according to the settings in paletteInfos if possible. Input extent in c dimension must be 1. Changed are CDimensionInfos, ImageExtent, and PageExtent.
adjustToLUTTypeIf false, usually the function updates the dataType of PagedImage only if needed but usually remains in the incoming data type; if true, the data type of the palette is used instead to maximize the quality of the color.
Returns
true if pagedImage could be modified successfully according to the settings in paletteInfos, false otherwise. In case of false the pagedImage is left unchanged.

References applyPaletteInfosToPagedImage().

Referenced by applyPaletteInfosToPagedImage().

◆ applyPhotometricInterpretationChangesToPagedImage()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::applyPhotometricInterpretationChangesToPagedImage ( const DCMTree::Const_TreePtr & dcmTree,
PagedImage & pagedImage )

If possible then this function modifies pagedImage according to the photometric interpretation such that pixel values can be translated correctly.

This function should be used together with applyPhotometricInterpretationToSubImg. Currently only MONOCHROME1 and YBR_FULL conversions to RGB are implemented. Do not use this function for PALETTE COLOR conversion; see determinePaletteInformation, applyPaletteInfosToPagedImage, and applySubImageColorLookUp for that purpose.

Parameters
dcmTreeThe palette information is considered valid if paletteInfos.dataType is MLuint8Type or MLuint16Type.
pagedImageThe PagedImage to be adopted according to the DICOM tag "Photometric Interpretation" if possible. Input extent in c dimension must be 1 for MONOCHROME1 and 3 for YBR_FULL. Changes CDimensionInfos, ImageExtent, and PageExtent. For YBR_FULL the voxel data type must be MLuint8Type and a one or two byte type for MONOCHROME1.
Returns
true if pagedImage could be modified successfully, false otherwise. In case of false the pagedImage is left unchanged.

References applyPhotometricInterpretationChangesToPagedImage().

Referenced by applyPhotometricInterpretationChangesToPagedImage().

◆ applyPhotometricInterpretationToSubImg()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::applyPhotometricInterpretationToSubImg ( DCMTree::Const_TreePtr dcmTree,
const SubImage & inSubImg,
const double minVoxelValue,
const double maxVoxelValue,
SubImage & outSubImg )

Applies a color format conversion from input subimage to output subimage according to the photometric interpretation tag in dcmTree.

This function shall be used in conjunction with applyPhotometricInterpretationChangesToPagedImage which should be used to set up the image configuration of the subimages. Currently only MONOCHROME1 and YBR_FULL conversions to RGB are implemented. Do not use this function for PALETTE COLOR conversion; see determinePaletteInformation, applyPaletteInfosToPagedImage, and applySubImageColorLookUp for that purpose.

Parameters
dcmTreeThe DICOM tree from which the information about the color format conversion is retrieved.
inSubImgThe input subimage whose voxels must be of MLuint8Type, MLint8Type, MLuint16Type, or MLint16Type for MONOCHROME1 MLuint8Type for YBR_FULL. Must have same extent in x,y,z,t, and u dimension like outSubImg, and c-extent must be 1 for MONOCHROME1 and 3 for YBR_FULL conversion.
minVoxelValueThe minimum voxel value of the input image; lower voxel values will be clamped against it.
maxVoxelValueThe maximum voxel value of the input image; larger voxel values will be clamped against it.
outSubImgThe output subimage to be filled with the converted color information from inSubImg. Must have same extent in x, y, z, t, and u dimension like inSubImg, and c must be 1 for MONOCHROME1 and 3 for YBR_FULL conversion. Voxel type must be the same as in inSubImg.
Returns
true on success, false otherwise (for example no supported photometric interpretation in dcmTree, invalid image extent or voxel data types).

References applyPhotometricInterpretationToSubImg().

Referenced by applyPhotometricInterpretationToSubImg().

◆ applySubImageColorLookUp()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::applySubImageColorLookUp ( const SubImage & inSubImg,
const DICOMTagTools::DicomPaletteInfo & paletteInfo,
SubImage & outSubImg )

Applies an intensity to color look up from valid region of inSubImg and paletteInfo to outSubImg.

Parameters
inSubImgThe input subimage whose voxels must be of MLuint8Type, MLint8Type, MLuint16Type, or MLint16Type. Must have same extent in x,y,z,t, and u dimension like outSubImg, and c-extent must be 1.
paletteInfoTranslation information from intensity values to color values; it is considered valid if dataType is MLuint8Type or MLint8Type and numEntries are > 0.
outSubImgThe output subimage to be filled with color information looked up from inSubImag via paletteInfo. Must have same extent in x, y, z, t, and u dimension like inSubImg, and c must be 3.
Returns
true on success, false otherwise (for example invalid paletteInfo, or incorrect/non matching subimage extents).

References applySubImageColorLookUp().

Referenced by applySubImageColorLookUp().

◆ calcImageDataMinMaxFromTag()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::calcImageDataMinMaxFromTag ( DCMTree::Const_TreePtr & treePtr,
MLint64 & minValInt64,
MLint64 & maxValInt64,
MLdouble & minValDbl,
MLdouble & maxValDbl,
DicomMessageCollector & dcmMsgCollector )

Traverse all pixel values in the first found pixel data tag in the tree given by treePtr and returns their minimum and maximum values in minValDbl and maxValDbl as well as in minValInt64 and maxValint64.

In case of complex spectroscopy data the data is scanned after decomposing the complex values as twice as many float data. If

  • the tag pointer is nullptr or
  • if it is no pixel data, spectroscopy data or multi-frame data tag or
  • the data type is MLuint64Type or any other non standard data types than complexf then the maximum values are returned with values smaller the minimum values which can easily be tested with (maxVal < minVal) == true.
    Parameters
    treePtrThe DICOM tree whose min/max values shall be determined.
    minValInt64Found minimum value cast to MLint64.
    maxValInt64Found maximum value cast to MLint64.
    minValDblFound minimum value cast to MLdouble.
    maxValDblFound maximum value cast to MLdouble.
    dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).

References calcImageDataMinMaxFromTag().

Referenced by calcImageDataMinMaxFromTag().

◆ checkAndCorrectImageExtentAccordingToPixelData()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::checkAndCorrectImageExtentAccordingToPixelData ( DCMTree::Const_TreePtr treePtr,
size_t pixelDataSizeInBytes,
ImageVector & imgExt,
DicomMessageCollector & dcmMsgCollector )

Check especially whether the extent of the image given in imgExt is larger by a multiple than the pixel data where the multiple is the same as imgExt.z, imgExt.t or imgExt.z*imgExt.t.

This sometimes happens on frame data exported from multi-frame as single frames where for example NumberOfSlices or NumberOfFrame tags are not correct reset/removed in the written single frame data. This routine can do these correction only if the pixel data tag stores its data in-memory and if it is still inside of the treePtr.

Parameters
treePtrThe DICOM tree from which the image extent was calculated.
imgExtThe extent of the image determined from treePtr and which
pixelDataSizeInBytesThe give number of bytes pixel data used as the true size to compare against the other parameters. shall be checked for inconsistencies and/or corrected.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).

References checkAndCorrectImageExtentAccordingToPixelData().

Referenced by checkAndCorrectImageExtentAccordingToPixelData().

◆ convertDCMTreeToSubImage()

MLDICOM_TO_ML_TOOLS_EXPORT MLErrorCode ml::DicomToMLTools::convertDCMTreeToSubImage ( const DICOMCachedIOFileHandle & dcmFrameHandle,
DCMTree::Const_TreePtr alternativeDCMTree,
SubImage & subImage,
DicomMessageCollector & dcmMsgCollector )

Reads the DICOM file given by dcmFrameHandle via the MLDICOMCachedIOTreeCache (or uses alternativeDCMTree if dcmFrameHandle is empty), and updates subImage to its data content.

This is intended and works only for 2D DICOM frames which can be copied with DicomToMLTools::copyFromDcmFileToSubImg and whose image properties are detected correctly with DicomToMLTools::getAnyDICOMImageProperties.

Parameters
dcmFrameHandleFile handle to the DICOM frame to be converted.
alternativeDCMTreeIf dcmFileHandle is empty then this tree is used as source to copy from instead. Ignored if dcmFileHandle is not empty.
subImageFilled with the data from subImage or reset to an empty SubImage. The subimage owns the data allocated in the memory manager and will be destroyed automatically with subImage.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
ML_RESULT_OK if subImage could be set up successfully with image data from the DICOM frame, or another error code describing the problem.

References convertDCMTreeToSubImage().

Referenced by convertDCMTreeToSubImage().

◆ convertToFrameSpecificDoubles()

MLDICOM_TO_ML_TOOLS_EXPORT size_t ml::DicomToMLTools::convertToFrameSpecificDoubles ( const FrameSpecificTagsVector & frameSpecificTags,
PositionSpecificDoubleVector & frameSpecificDoubles )

Converts first entries of each entries in FrameSpecificTagsVector to a PositionSpecificDoubleVector object.

The value of the first valid tag of each entry of frameSpecifcTags is converted to an entry of frameSpecificDoubles and its value is convertible to double, otherwise the corresponding entry in frameSpecifcDoubles is not created at all.

Parameters
frameSpecificTagsThe frame specific tag sets from which the first entries are converted to frameSpecificDoubles.
frameSpecificDoublesThe container for converted entries from frameSpecificTags.
Returns
The number of entries which could not be converted successfully to double or the tag is not valid at all (for example a nullptr pointer); frameSpecificDoubles will contain only successfully converted entries.

References convertToFrameSpecificDoubles().

Referenced by convertToFrameSpecificDoubles().

◆ convertToImageProperties()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::convertToImageProperties ( DCMTree::StructuredMFPtr & baseSMFPtr,
const std::string & firstFileName,
PagedImage & resultImgProps,
FillPageMethods * fillPageMethod,
const ZTUFileNameSet * setOfFileHandles,
double defaultFillValue,
CalculateMinMaxFromDicomModes minMaxCalcMode,
const std::string & versionString,
bool anonymize,
bool removePrivateMultiFrameSQTag,
bool forceOrthogonalWorldMatrix,
bool copyPrivateTopLevelSrcTags,
DicomMessageCollector & dcmMsgCollector )

Determines as much PagedImage information from baseSMFPtr as possible and.

  • if setOfFileHandles is non nullptr - it also creates the structured multi-frame tree baseSMFPtr. In some cases tags in baseSMFPtr are updated if they do not seem consistent, (e.g. SpacingBetweenSlices) if the DICOM tree structure suggests that. The DICOMTreeImagePropertyextension is also created and appended to the resultImgProps. The frames added to resultImgProps PagedImage resultSMFPtr are copies of the returned srcFrameTrees whose pixel data tags are removed.
    Parameters
    baseSMFPtrThe structured MF tree to be generated/composed and appended to resultImgProps as DICOMTreeImagePropertyExtension.
    firstFileNameThe name of the file to be used as the source file the DICOM image properties come from. If multiple file names are available then that one corresponding to the first DICOM frame should be taken.
    resultImgPropsThe properties to be set up with properties determined from from baseSMFPtr.
    fillPageMethodIf nullptr (the default) it is ignored, otherwise it returns the way how data from the files in the pageFileNames should be copied to ML pages.
    setOfFileHandlesIf it is non nullptr then it is used to create a new structured multi-frame tree in baseSMFPtr. If nullptr is passed (the default) then all following arguments are not used and ignored.
    defaultFillValueFill value for image regions which cannot be read from DICOM.
    minMaxCalcModeThe way how min/max value are to be determined from DICOM tags, see CalculateMinMaxFromDicomModes for details.
    versionStringString to be added to the DICOM as private description about the used importer version.
    anonymizeIf true then the created patientIdName and birth date will be anonymized. WARNING: This is only a partial and incomplete anonymization of the DICOM information. For a reliable anonymization other approaches are needed.
    removePrivateMultiFrameSQTagIf true then a private MeVis sequence tag with DICOM frame information will be removed (if it exists) before adding the tree to image properties, otherwise the tag is left unchanged.
    forceOrthogonalWorldMatrixIf enabled then the world matrix is always determined from the first ImageOrientationPatient of the first frame in frame set. use with care because gantry tilted data will be imported with incorrect world matrices then.
    copyPrivateTopLevelSrcTagsIf true then private top level tags from source frames are copied to the baseSMFPtr, otherwise they are removed.
    dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
    Returns
    A string describing the error or "" on success. resultImgProps will be validated/up to date on successful conversion, otherwise it will be set invalid. The DicomImagePropertyExtension appended to resultImgProps will set from a copy of baseSMFPtr->tagTree with removed pixel-, spectroscopy and REG data tags.

References convertToImageProperties().

Referenced by convertToImageProperties().

◆ copyFromDCMTreeToSubImg()

MLDICOM_TO_ML_TOOLS_EXPORT MLErrorCode ml::DicomToMLTools::copyFromDCMTreeToSubImg ( const DICOMCachedIOFileHandle & dcmFileHandle,
DCMTree::Const_TreePtr alternativeDCMTree,
SubImage & outSubImg,
bool force,
DicomMessageCollector & dcmMsgCollector )

Tries to fill the given output subimage outSubImg with pixel data from the DICOM tree given by either dcmFileHandle or alternativeDCMTree.

Parameters
dcmFileHandleIf non empty then this handle is used as source to load the DICOM tree via the DICOM tree cache.
alternativeDCMTreeIf dcmFileHandle is empty then this tree is used as source to copy from instead. Ignored if dcmFileHandle is not empty.
outSubImgThe data from the DIOCM tree will be copied into this SubImage.
forceIf true then images are also loaded with limited support, e.g. for unsupported color formats or so. They will be loaded incorrectly, however, they will be loaded if possible.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
On success ML_RESULT_OK is returned, otherwise an error describing the problem. Valid compression schemes which are not decompressible (e.g. JPEG2000) are identified with ML_UNKNOWN_OR_INVALID_COMPRESSION_SCHEME.

References copyFromDCMTreeToSubImg().

Referenced by copyFromDCMTreeToSubImg().

◆ copySpectData()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::copySpectData ( SubImage & outSubImg,
const ImageVector & outImgExtent,
const DICOMTagTools::SpectComplex * mrsData,
size_t spectDataSizeInBytes )

Copies the complex spectroscopy data from mrsData to the output subimage assuming appropriate sizes of mrsData which must have been calculated successfully with getSpectDICOMImageProperties and which must match the PagedImage properties calculated in the same routine.

The call is ignored if mrsData is nullptr. If any voxel access was out of range then false is returned, otherwise true.

References copySpectData().

Referenced by copySpectData().

◆ createOverlayBitSubImages()

MLDICOM_TO_ML_TOOLS_EXPORT std::string ml::DicomToMLTools::createOverlayBitSubImages ( const FrameSpecificTagsVector & tagSet,
MLint z,
MLint t,
MLint u,
std::vector< BitImage > & bitImages )

Create and return a BitImage in bitSubImages for each overlay for which all required type 1 tags are found in the first z,t,u frame occurrence.

All type 1 DICOM tags must be consistent according to the DICOM standard or the returned BitImage entries will be valid but empty. The OverlayOrigin tag is evaluated and transformed into ML voxel image coordinates such that the sourceBox member in each BitImage returns the subimage box of the overlay in directly usable voxel image space.

Parameters
tagSetAll overlay tags for all frames in the z,t,u-space.
zz-position of the frame for which the BitImages shall be extracted.
tt-position of the frame for which the BitImages shall be extracted.
uu-position of the frame for which the BitImages shall be extracted.
bitImagesA vector of BitImages which are set according to the overlays defined in the found overlay tags.
Returns
An empty string on success or a string describing the problem; successfully determined overlays will be coded into the output image regardless of any errors in other overlays or possible non empty return strings.

References createOverlayBitSubImages().

Referenced by createOverlayBitSubImages().

◆ determineBasicREGProperties()

MLDICOM_TO_ML_TOOLS_EXPORT std::string ml::DicomToMLTools::determineBasicREGProperties ( DCMTree::Const_TreePtr treePtr,
size_t extent[3],
double voxelSize[3],
MLErrorCode & errCode,
DicomMessageCollector & dcmMsgCollector )

Extract basic image properties from a DICOM tree of REG modality and SOP Class UID "1.2.840.10008.5.1.4.1.1.66.3" (Deformable Registration Storage).

Spatial registration storage with SOP Class UID "1.2.840.10008.5.1.4.1.1.66.1" will result to empty return string, errCode = ML_RESULT_OK, (0,...,0) extent, and voxel size (1,1,1).

Parameters
treePtrThe DICOM tree from which the properties shall be extracted.
extentThe extent of the extracted grid from the tag (0064,0007) UL [GridDimensions] or (0,0,0) if not valid.
voxelSizeWill be set with the value from the tag (0064,0008) FD [GridResolution] to be used as voxel size or (1,1,1) if not valid.
errCodeAn ML error code corresponding to the returned string is returned, ML_RESULT_OK on success.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
An empty string on success or a string describing the problem.

References determineBasicREGProperties().

Referenced by determineBasicREGProperties().

◆ determineDCMTreeInfo()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::determineDCMTreeInfo ( DCMTree::Const_TreePtr dcmTree,
DCMTreeInfo & dcmTreeInfo )

Stores some statistical information from dcmTree in dcmTreeInfo.

References determineDCMTreeInfo().

Referenced by determineDCMTreeInfo().

◆ determineImageExtentsFromDCMTree()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::determineImageExtentsFromDCMTree ( DCMTree::Const_TreePtr treePtr,
ImageVector & imgExt,
std::vector< std::string > * cDimInfos,
bool overrideBadTagInfos,
DicomMessageCollector & dcmMsgCollector )

Update imgExt and - if non nullptr - cDimInfos from treePtr if possible, otherwise they are left unchanged.

Does not throw DCMTree::Exceptions.

Parameters
treePtrDCMTree in which the tags are searched and whose content is analyzed for image extent and color channel infos.
imgExtImage extent modified if appropriate information is found in treePtr.
cDimInfosDescriptive color channel information for PagedImage.cDimInfo to which ML constants like ML_RED, ML_HUE, ML_LUMINANCE etc. are appended if appropriate information is found in treePtr. Ignored if nullptr.
overrideBadTagInfosIf true then inconsistencies found in the tagTree will corrected and errorInfos will be added if necessary; if false then the already known settings from imgExt will be considered with priority and won't be overwritten by heuristics correcting bad DICOM tags.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
true on successful update of imgExt and cDimInfos, otherwise false.

References determineImageExtentsFromDCMTree().

Referenced by determineImageExtentsFromDCMTree().

◆ determineMinMaxValues()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::determineMinMaxValues ( DCMTree::Const_TreePtr treePtr,
PagedImage & pagedImg )

Update min/max voxel values of pagedImg from tags in treePtr if possible, otherwise these settings are left unchanged.

Does not throw DCMTree::Exceptions.

Parameters
treePtrDCMTree in which the tags are searched and whose content is analyzed for color channel infos.
pagedImgThe PagedImage whose min/max voxel values are updated if possible.

References determineMinMaxValues().

Referenced by determineMinMaxValues().

◆ determineOutputVoxelType()

MLDICOM_TO_ML_TOOLS_EXPORT MLDataType ml::DicomToMLTools::determineOutputVoxelType ( DCMTree::StructuredMFPtr & srcVolumeSMFTree,
const MLDataType inVoxDataType,
const SubImageBox & volumeBox,
const double inDataRangeMin,
const double inDataRangeMax,
const OutputDataTypeSelector voxelTypeSelector,
const VoxelDoubleOperations operationMode,
const PositionSpecificDoubleVector & posDbls,
const VoxelDoubleOperations defaultOperationMode,
const double defaultOperationDouble,
double & resultRangeMin,
double & resultRangeMax )

Determines a voxel type for an ML output image from some properties of an input image and a set of double values applied to different slices of the input image.

Parameters
srcVolumeSMFTreeThe Structured multi-frame tree related to the input image.
inVoxDataTypeThe voxel data type of the input image.
volumeBoxThe SubImageBox covering the extents of the input image.
inDataRangeMinThe minimum voxel values of the input volume.
inDataRangeMaxThe maximum voxel values of the input volume.
voxelTypeSelectorSelects the calculation mode for the output voxel type, see OutputDataTypeSelector for details.
operationModeThe mode how double values of the output image are calculated from double values from posDbls and input image voxels. See VoxelDoubleOperations for details.
posDblsA vector of positions specifying slices of the input volume together with double values to be applied to those slices with operationMode.
defaultOperationModeThe calculation which is applied to slices of the the volume where no corresponding entry in posDbls exist.
defaultOperationDoubleThe double value to be used to process volume slices for which no corresponding entry in posDbls exist.
resultRangeMinThe minimum of the voxel value range for the output image which has been determined from the given parameters. Will be set to inDataRangeMin on error or if return type is ML_INVALID_DATA_TYPE.
resultRangeMaxThe maximum of the voxel value range for the output image which has been determined from the given parameters. Will be set to inDataRangeMax on error or if return type is ML_INVALID_DATA_TYPE.
Returns
The voxel type determined from the arguments or ML_INVALID_DATA_TYPE on errors or if no type could be determined.

References determineOutputVoxelType().

Referenced by determineOutputVoxelType().

◆ determineREGProperties()

MLDICOM_TO_ML_TOOLS_EXPORT std::string ml::DicomToMLTools::determineREGProperties ( DCMTree::Const_TreePtr treePtr,
ImageVector & extent,
Vector3 & voxelSize,
SubImage * subImage,
MLErrorCode * errCode,
DicomMessageCollector & dcmMsgCollector )

Extract image properties and deformable vector field from a DICOM tree of REG modality and SOP Class UID "1.2.840.10008.5.1.4.1.1.66.3" (Deformable Registration Storage) Spatial registration storage with SOP Class UID "1.2.840.10008.5.1.4.1.1.66.1" will result to empty return string, ML_RESULT_OK (if errCode is provided), (0,...,0) extent, voxel size (1,1,1), subImage with empty box, nullptr data, and MLuint8Type.

Parameters
treePtrThe DICOM tree from which the properties shall be extracted.
extentThe extent of the extracted grid from the tag (0064,0007) UL [GridDimensions] or (0,0,0,0,0,0) if not valid.
voxelSizeWill be set with the value from the tag (0064,0008) FD [GridResolution] to be used as voxel size or (1,1,1) if not valid.
subImageIf passed non nullptr then the subImage content will be freed its box.v1 will be set to (0,0,0,0,0,0), box.v2 to extent-Vector(1) and its data will be allocated and filled with a copy of the the VectorGridData from the tag (0064,0009) OF [VectorGridData]. The voxel type will be of Vector3f. On any failure the subImage box will be set empty, the data type to MLuint8Type, and the data to nullptr.
errCodeIf non nullptr an ML error code corresponding to the returned string is returned. If nullptr then it will be ignored.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
An empty string on success or a string describing the problem.

References determineREGProperties().

Referenced by determineREGProperties().

◆ getAnyDICOMImageProperties()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::getAnyDICOMImageProperties ( DCMTree::Const_TreePtr treePtr,
PagedImage & outInfos,
bool overrideBadTagInfos,
DicomMessageCollector & dcmMsgCollector )

Extract as many PagedImage properties from the passed DICOM treePtr as possible.

Note that this function does not set or handle the DICOM tree or other image property extensions. If no useful properties can be found or the treePtr is invalid then properties are set invalid. Note that this function overwrites only found properties. Therefore image and page extents should be initialized with at least ImageVector(1) before calling this function.

Parameters
treePtrThe DICOM tree from which the outInfos settings are derived.
outInfosThe destination for the image information derived from treePtr tags.
overrideBadTagInfosIf true then inconsistencies found in the tagTree will corrected and errorInfos will be added if necessary; if false then the already known settings from outInfos will be considered with priority and won't be overwritten by heuristics correcting bad DICOM tags.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).

References getAnyDICOMImageProperties().

Referenced by getAnyDICOMImageProperties().

◆ getDCMTreeFromAnyFileType()

MLMULTI_FILE_VOLUME_EXPORT void ml::DicomToMLTools::getDCMTreeFromAnyFileType ( const std::string & fileName,
bool postError,
DCMTree::Const_TreePtr & treePtr,
size_t & numVols,
DicomMessageCollector & dcmMsgCollector )

Loads a Const_TreePtr from a file given by the absolute file path fileName if possible (currently .dcm and .mlimage files are supported); this function implements a subfunctionality of getInputDCMTree() and needs no Base or Module.

Parameters
fileNameThe absolute file name path to the file from which the DCMTree shall be loaded.
postErrorIf true then an error will be appended to dcmMsgCollector on any file IO error or if no DICOM tree could be found in any file, otherwise errors will silently be ignored.
treePtrReturns the loaded DCMTree on success, or nullptr on failure; if file can be loaded successfully but does not contain a DCMTree then no messages may be generated/logged/posted but treePtr may be returned as nullptr.
numVolsWill return 1 on successful DCMTree load, otherwise 0.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).

References getDCMTreeFromAnyFileType().

Referenced by getDCMTreeFromAnyFileType().

◆ getFrameSpecificDoubleTag()

void ml::DicomToMLTools::getFrameSpecificDoubleTag ( const DCMTree::StructuredMF & smfTree,
const unsigned int z,
const unsigned int t,
const unsigned int u,
const DCMTree::RawTagId rawTagId,
FrameSpecificValueTag< double > & valTagInfos )
inline

Retrieves a double tag value from a frame specific tag with id rawTagId at (z,t,u) from smfTree, and returns all result information in valTagInfos; if the value cannot be retrieved from the given frame then it is tried to get it from the tree root.

Definition at line 238 of file mlDicomSingleFrameSelectionTools.h.

References getFrameSpecificDoubleTag(), and mlrange_cast().

Referenced by getFrameSpecificDoubleTag().

◆ getFrameSpecificStringTag()

void ml::DicomToMLTools::getFrameSpecificStringTag ( const DCMTree::StructuredMF & smfTree,
const unsigned int z,
const unsigned int t,
const unsigned int u,
const DCMTree::RawTagId rawTagId,
FrameSpecificValueTag< std::string > & valTagInfos )
inline

Same as getFrameSpecificDoubleTag() but for std::string values.

Definition at line 248 of file mlDicomSingleFrameSelectionTools.h.

References getFrameSpecificStringTag(), and mlrange_cast().

Referenced by getFrameSpecificStringTag().

◆ getFrameSpecificTags()

MLDICOM_TO_ML_TOOLS_EXPORT FrameSpecificTagsVector ml::DicomToMLTools::getFrameSpecificTags ( const DCMTree::Const_StructuredMFPtr & smfTree,
DCMTree::RawTagId tagId )

Returns an entry for each frame in which a tag with id tagId can be found and store the corresponding z, t, and u location in the entry as well as the found pointer to the tag.

If a tag cannot be found in the specific frame but it exist on tree root as common tag then the common tag will be set for the specific frame.

Parameters
smfTreeThe structured multi-frame tree in whose frames the tags shall be searched.
tagIdThe DICOM tag id to search in the frames.
Returns
A vector with an entry for each frame in z, t, and u dimension; if a tag with

References getFrameSpecificTags().

Referenced by getFrameSpecificTags().

◆ getFrameSpecificTagSet()

MLDICOM_TO_ML_TOOLS_EXPORT FrameSpecificTagsVector ml::DicomToMLTools::getFrameSpecificTagSet ( const DCMTree::Const_StructuredMFPtr & smfTree,
const std::vector< DCMTree::RawTagId > & tagIds )

Returns an entry for each frame and each tag id from tagIds in which any tagId can be found and store the corresponding z, t, and u location in the entry as well as the found pointer to the tag.

If a tag cannot be found in the specific frame but it exist on tree root as common tag then the common tag will be set for the specific frame.

Parameters
smfTreeThe structured multi-frame tree in whose frames the tags shall be searched.
tagIdsThe DICOM tag ids to search in the frames.
Returns
A vector with an entry for each frame in z, t, and u dimension; if a tag with

References getFrameSpecificTagSet().

Referenced by getFrameSpecificTagSet().

◆ getFrameSpecificTagsSet()

MLDICOM_TO_ML_TOOLS_EXPORT const FrameSpecificTags * ml::DicomToMLTools::getFrameSpecificTagsSet ( const FrameSpecificTagsVector & tagSet,
MLint z,
MLint t,
MLint u )

Returns pointer to the first occurrence of a FrameSpecificTags entry which has the given z, t, and u positions or nullptr if not found.


References getFrameSpecificTagsSet().

Referenced by getFrameSpecificTagsSet().

◆ getInputDCMTree()

MLMULTI_FILE_VOLUME_EXPORT DCMTree::Const_TreePtr ml::DicomToMLTools::getInputDCMTree ( Module & moduleWithInFields,
const std::string & inputSourceName,
const std::string & fileName,
Base * basePtr,
const MLint volIdx,
size_t * numVolumes,
bool allowEmptyFileNames,
DicomMessageCollector & dcmMsgCollector )

Gets a DCMTree from an input which is selected via a string name.

If any specified module input (field), base pointer, list, or entry in list does not exist or is empty then simply a nullptr tree is returned. If a file is specified as input and cannot be read then an ML_PRINT_ERROR is performed.

Parameters
moduleWithInFieldsThe module from which the image connector fields can be used to retrieve the DCMTree.
inputSourceNameA string specifier describing which input source shall be used to retrieve the DCMTree. Allowed strings are "ImageConnector" get the DCMTree from image input #0 "ImageConnector #0" get the DCMTree from image input #0 "ImageConnector #1" get the DCMTree from image input #1 "ImageConnector #2" get the DCMTree from image input #2 "File",
get the DCMTree from a file named fileName "MultiFileVolumeCache",
get the DCMTree from a stored MultFileVolume(List) given by fileName. The volIdx is used to select the entry of the MultiFileVolumeList which shall be used. "DirectDicomImport" or "BaseConnector" (BaseConnector might have suffixes " #0", " #1", " #2" for convenience, which does not change functionality)
get DCMTree from Base connector expecting MultiFileVolumeListRefCounted or DCMTreeRefCounted. The volIdx is used to select the entry of the MultiFileVolumeList which shall be used.
fileNamePath and name to the DICOM file if inputSourceName is "File", otherwise its value is ignored.
basePtrPointer to a base object if inputSourceName is "DirectDicomImport" or "BaseConnector", otherwise its value is ignored.
volIdxOnly used for case if inputSourceName is "DirectDicomImport", "BaseConnector", "BaseConnector #0", "BaseConnector #1", "BaseConnector #2", or "MultiFileVolumeList", otherwise ignored.
numVolumesIf passed non nullptr then the number of volumes at the selected input is returned. This will be one for normal valid inputs or the number of list entries if a Base objects with a list of objects is connected.
allowEmptyFileNamesIf true then empty file names do not cause errors appended to dcmMsgCollector when calling this function; in this case only an nullptr tree is returned.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
The found DCMTree or nullptr if not found.

References getInputDCMTree().

Referenced by getInputDCMTree().

◆ getMLDataTypeFromDCMTree()

MLDICOM_TO_ML_TOOLS_EXPORT MLDataType ml::DicomToMLTools::getMLDataTypeFromDCMTree ( DCMTree::Const_TreePtr treePtr,
DicomMessageCollector & dcmMsgCollector )

Determines the ML data type of pixel data in the given DICOM tree treePtr.

On success the data type is returned, otherwise ML_INVALID_DATA_TYPE.

Parameters
treePtrThe DICOM tree the data type is computed from.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
Returns the determined data type or ML_INVALID_DATA_TYPE on failure.

References getMLDataTypeFromDCMTree().

Referenced by getMLDataTypeFromDCMTree().

◆ getOverlayTagSet()

MLDICOM_TO_ML_TOOLS_EXPORT std::vector< DCMTree::RawTagId > ml::DicomToMLTools::getOverlayTagSet ( )

Create a vector with all possible ids of type 1 and important type 3 overlay tags.

References getOverlayTagSet().

Referenced by getOverlayTagSet().

◆ getPositionSpecificDoubleProperties()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::getPositionSpecificDoubleProperties ( const PositionSpecificDoubleVector & positions,
double & rangeMin,
double & rangeMax,
bool & hasFractionalParts )

Returns some properties of the double values in valuePositions, the minimum / maximum range, and whether any value is a non integer one.

If positions is empty then passed values are left unchanged and false is returned, otherwise the passed values are adjusted and true is returned.

References getPositionSpecificDoubleProperties().

Referenced by getPositionSpecificDoubleProperties().

◆ getSMFTreeFromPagedImage()

MLDICOM_TO_ML_TOOLS_EXPORT DCMTree::Const_StructuredMFPtr ml::DicomToMLTools::getSMFTreeFromPagedImage ( const PagedImage & pImg)

Tries to get the first DICOM image property extension and returns its DCMTree wrapped as Structured MF Tree if possible; otherwise nullptr is returned.

References getSMFTreeFromPagedImage().

Referenced by getSMFTreeFromPagedImage().

◆ getSpectDICOMImageProperties()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::getSpectDICOMImageProperties ( DCMTree::Const_TreePtr treePtr,
const std::string & fileNameUTF8,
PagedImage & outInfos,
Vector4 & rotAxisAndRadians,
Vector3 & ipp,
Vector3 & relMRSPositionVector,
Vector3 & mrsPositionVector,
Vector3 & voiVector,
Vector3 & fovVector,
bool useOldWorldMatrixCalculation,
DicomMessageCollector & dcmMsgCollector )

Extract spectroscopy image properties and some other infos from the passed DICOM tree.

Note that this function does not set or handle the DICOM tree or other image property extensions. They have to be added be the caller.

Parameters
treePtrThe DICOM tree all tags are extracted from to set up the image properties.
fileNameUTF8The name of the DICOM file given as treePtr. This is also stored in outInfos to be able to created related target file from it. Be aware that WIN has problems with UTF8-code.
outInfosThe PagedImage properties to be set up from the treePtr tags.
rotAxisAndRadiansIf a Siemens CSA-Header is found then it set with values from sSliceArray.asSlice[0].[sNormal.dSag, sNormal.dCor, sNormal.dTra, dInPlaneRot]; otherwise it is set to vec4(0,0,1, 0).
ippIf a Siemens CSA-Header is found then it is set with scanned ASCII values after "ImagePositionPatient"; otherwise it is filled with values from normal DICOM tags via a getImagePositionPatient-call.
relMRSPositionVectorIf a Siemens CSA-Header is found then it is set to scanned ASCII values from ipp - mrsPositionVector; otherwise it is set to vec3(0,0,0).
mrsPositionVectorIf a Siemens CSA-Header is found then it is set to scanned ASCII values from sSliceArray.asSlice[0].sPosition.[dSag, dCor, dTra]; otherwise it is set to vec3(0,0,0).
voiVectorIf a Siemens CSA-Header is found then it is set to scanned ASCII values from sSpecPara.sVoI.[dReadoutFOV, dPhaseFOV, dThickness]; otherwise it is set to vec3(0,0,0).
fovVectorIf a Siemens CSA-Header is found then it is set to scanned ASCII values from sSliceArray.asSlice[0].[dReadoutFOV, dPhaseFOV, dThickness]; otherwise it is set to vec3(0,0,0).
useOldWorldMatrixCalculationIf enabled then for standard DICOM files the original world matrix calculation is used as implemented in LoadRawSiemensSpectData. If disabled (the default) then the normal DICOM world matrix calculation is used.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
outInfos will be set up from the treePtr tags if possible. On success outInfos.upToDate() will be true, on failure it will be set out of date.

References getSpectDICOMImageProperties().

Referenced by getSpectDICOMImageProperties().

◆ getVoxelSize()

MLDICOM_TO_ML_TOOLS_EXPORT size_t ml::DicomToMLTools::getVoxelSize ( DCMTree::Const_TreePtr treePtr,
double & voxSizeX,
double & voxSizeY,
double & voxSizeZ,
bool replaceOnlyIfFound,
bool * isPrecise,
std::vector< DCMTree::RawTagId > * usedTags,
DicomMessageCollector & dcmMsgCollector )

Determine the voxel size from the DICOM tags and returns the number of found extents.

All not found extents are filled with 1 if replaceOnlyIfFound==false, otherwise they are only set if they are found.

Parameters
treePtrThe DICOM tree from which the voxel size shall be determined.
isPreciseIf this is passed non nullptr then its return value is set to true if the standard DICOM tags could be retrieved which determine a precise voxel spacing. If tags were used which do not describe the physically exact spacing then false is returned.
  • Tags considered precise are:
    • DCMTree_PixelSpacing
    • DCMTree_SpacingBetweenSlices
    • DCMTree_SliceThickness
    • RTDOSE DCMTree_GridFrameOffsetVector
    • REG DCMTree::TagId(0x0064,0x0008) (=GridResolution)
  • Tags considered imprecise are:
    • DCMTree_PixelAspectRatio,
    • DCMTree_CompensatorPixelSpacing
    • DCMTree_ReconstructionPixelSpacing
    • DCMTree_ImagerPixelSpacing
    • DCMTree_ImagePlanePixelSpacing
    • DCMTree_PresentationPixelSpacing
    • DCMTree_PresentationPixelAspectRatio
    • DCMTree_NominalScannedPixelSpacing
voxSizeXUpdate to the x-extent of voxels if it can be determined from treePtr. If it cannot be determined unchanged if replaceOnlyIfFound, or 1 otherwise.
voxSizeYLike voxSizeX for the y extent of the voxels.
voxSizeZLike voxSizeX for the z extent of the voxels.
replaceOnlyIfFoundIf true then the arguments voxSizeX, voxSizeY, and voxSizeZ are only modified if valid values are found, otherwise they are left unchanged. If case of false these arguments are set to 1 if they cannot be determined.
usedTagsIf this is passed non nullptr then the DICOM tag ids used to determine the voxel size are returned in the vector.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
The number of found extent dimensions, for example 2 if x and y extent of the voxel size could be determined.

References getVoxelSize().

Referenced by getVoxelSize().

◆ guessMinMaxRangeFromDICOMTags()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::guessMinMaxRangeFromDICOMTags ( DCMTree::Const_TreePtr treePtr,
MLdouble & minPixVal,
MLdouble & maxPixVal,
DicomMessageCollector & dcmMsgCollector )

Try to guess a min/max range from DICOM tags for the case that they cannot be determined in another way.

The pixel data type, the used bits, the highest bit and stored bit tags can at least limit the min/max range to a useful range if other approaches failed.

Parameters
treePtrThe tree to be checked for min/max pixel tags.
minPixValThe found minimum value if return value is true, otherwise ML_DOUBLE_MAX.
maxPixValThe found maximum value if return value is true, otherwise -ML_DOUBLE_MAX.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).
Returns
true if both min/max values were set, false if any of both could not be determined.

References guessMinMaxRangeFromDICOMTags().

Referenced by guessMinMaxRangeFromDICOMTags().

◆ hasValidNonImageModality()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::hasValidNonImageModality ( DCMTree::Const_TreePtr treePtr)

Returns true only if the passed string is a known, non-empty and valid modality string which is a non image modality (RTSTRUCT, RTPLAN, RTRECORD, AU, SR, HD, ECG, FID...) and the DCMTree is not a Secondary Capture IOD.

The treePtr will also be examined for modalities such as REG whether it is an image like REG deformation field or only Matrix storage and therefore no image. It also will be checked for the Secondary Capture IOD which always is an image modality and which will result to a false return even if the modality tag value indicates a non image one. nullptr treePtrs will be handled as ML error.

References hasValidNonImageModality().

Referenced by hasValidNonImageModality().

◆ isImageFrameNotOfBits()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::isImageFrameNotOfBits ( DCMTree::Const_TreePtr treePtr)

Returns true if the DICOM tree seems to describe a sensible image with column and row extents > 1 as well as pixels with more than one bit per pixel, otherwise false.

PixelData presence is not checked, thus it can be used to check frames without pixel data to be image frames.

References isImageFrameNotOfBits().

Referenced by isImageFrameNotOfBits().

◆ isVolumeCovered()

MLDICOM_TO_ML_TOOLS_EXPORT bool ml::DicomToMLTools::isVolumeCovered ( const PositionSpecificDoubleVector & positions,
const SubImageBox & volume )

Returns true if the (z,t,u) positions in positions cover all (z,t,u) slices in volume, otherwise false is returned.

References isVolumeCovered().

Referenced by isVolumeCovered().

◆ rasterOverlays()

MLDICOM_TO_ML_TOOLS_EXPORT std::string ml::DicomToMLTools::rasterOverlays ( DicomToMLTools::FrameSpecificTagsVector & overlayTagSet,
SubImage & outSubImg )

Takes overlay DICOM tags from overlayTagSet matching the x/y plane of outSubImage.getBox().v1, create BitImages from them and copies them into outSubImage where the entire background it filled with 0, and valid overlay bits are set to 1.

The return value is empty on success or if no overlays to render are found, and a descriptive string if anything fails, for example if overlay tags contain inconsistent information.

References rasterOverlays().

Referenced by rasterOverlays().

◆ setUpMinMaxVoxelValues()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::setUpMinMaxVoxelValues ( std::string & errStr,
DCMTree::Const_DictPtr dcmTreeDictPtr,
double smallestPixelValue,
double largestPixelValue,
DCMTree::TreePtr dcmTree )

Set up DCMTree_SmallestImagePixelValue and DCMTree_LargestImagePixelValue tags in dcmTree; requires that DCMTree_PixelRepresentation, DCMTree_SmallestImagePixelValue, or DCMTree_LargestImagePixelValue tags exist from which the value representation of the DCMTree_SmallestImagePixelValue and DCMTree_LargestImagePixelValue can be determined.

Parameters
errStrOn success errStr is left unchanged, on error the error description is appended.
dcmTreeDictPtrA required dictionary pointer to decode tag names and ids.
smallestPixelValueThe tag value for DCMTree_SmallestImagePixelValue.
largestPixelValueThe tag value for DCMTree_LargestImagePixelValue.
dcmTreeTree to which the tags are added.

References setUpMinMaxVoxelValues().

Referenced by setUpMinMaxVoxelValues().

◆ setUpOverlayOutputProperties()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::setUpOverlayOutputProperties ( DCMTree::Const_TreePtr dcmTree,
PagedImage & overlayPagedImg,
DicomToMLTools::FrameSpecificTagsVector & overlayTagSet )

Determine DICOM overlay information from dcmTree, configures (or if necessary invalidates) the passed overlayPagedImg such that it can display these overlays correctly, and sets up overlayTagSet such that it provides all required DICOM tags to display them properly in calculateOutputSubImage.

It is assumed that overlayPagedImg is configured in the same ways as the image on which the overlay lives. As an example: Output image 0 shows a DICOM image and output image 1 shall display its overlays. Then set overlayPagedImg the same properties as output image 0 and then call this function. Specified properties are:

  • ImageExtent to 1 in c.
  • PageExtent to 1 in z, c, t, and u.
  • Voxel type to MLuint8Type.
  • min/max to [0,1].

References setUpOverlayOutputProperties().

Referenced by setUpOverlayOutputProperties().

◆ setWorldMatrixFromDcmTree()

MLDICOM_TO_ML_TOOLS_EXPORT void ml::DicomToMLTools::setWorldMatrixFromDcmTree ( DCMTree::Const_TreePtr treePtr,
PagedImage & outInfos,
DicomMessageCollector & dcmMsgCollector )

If possible all image properties from the DcmTree needed to set up the world matrix are searched and converted to a world matrix and voxel size and set in outInfos.

If no or only partial values are found then default settings are used instead.

Parameters
treePtrThe DICOM tree the matrix is computed from.
outInfosThe PagedImage in which the worldMatrix is set up as good as possible.
dcmMsgCollectorCollects error, info and issue messages (typically related to a handle).

References setWorldMatrixFromDcmTree().

Referenced by setWorldMatrixFromDcmTree().

Variable Documentation

◆ CalculateMinMaxFromDicomModesEnumStrings

MLDICOM_TO_ML_TOOLS_EXPORT const char* const ml::DicomToMLTools::CalculateMinMaxFromDicomModesEnumStrings[NUM__CALC_MIN_MAX_FROM_DICOM_ENUMS]
extern

Strings names corresponding to the selectable DplMinMaxEnums.

◆ OutputDataTypeSelectorsStrings

MLDICOM_TO_ML_TOOLS_EXPORT const char* const ml::DicomToMLTools::OutputDataTypeSelectorsStrings[NumOutputDataTypeSelectors]
extern

Strings according to OutputDataTypeSelector.

◆ VoxelDoubleOperationsStrings

MLDICOM_TO_ML_TOOLS_EXPORT const char* const ml::DicomToMLTools::VoxelDoubleOperationsStrings[NumberOfVoxelDoubleOperations]
extern

Strings according to VoxelDoubleOperations.