MeVisLab Toolbox Reference
mlDICOMGetTools.h
Go to the documentation of this file.
1 // Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2 // **InsertLicense** code
3 //----------------------------------------------------------------------------------
5 
10 //----------------------------------------------------------------------------------
11 #pragma once
12 
13 #include "MLDICOMTagsSystem.h"
14 
15 #include <ThirdPartyWarningsDisable.h>
16 #include <list>
17 #include <set>
18 #include <string>
19 #include <vector>
20 #include <ThirdPartyWarningsRestore.h>
21 
22 #include <mlLinearAlgebra.h>
23 #include <mlScaleShiftData.h>
24 
25 // DICOM Tree prototypes.
26 #include <DCMTree_Lib.h>
27 
28 ML_START_NAMESPACE
29 
30 // Forwards
31 class DicomMessageCollector;
32 
33 //----------------------------------------------------------------------------------
35 //----------------------------------------------------------------------------------
36 namespace DICOMTagTools {
37 
41 MLDICOMTags_EXPORT std::string createInstanceUID(bool useFMEUIDPrefix=false);
42 
44 MLDICOMTags_EXPORT bool looksLikeValidDICOMUID(const std::string &uidStrToCheck);
45 
50 
55 MLDICOMTags_EXPORT bool looksLikeValidCSVrValue(const std::string &codedString,
56  std::string *explanation=nullptr);
57 
66  const DCMTree::TagId &tagId,
67  const size_t numTagsToFind,
68  std::vector<DCMTree::Const_TagPtr> &tagVector);
69 
74  const DCMTree::TagId &tagId,
75  const size_t numTagsToFind,
76  std::vector<DCMTree::TagPtr> &tagVector);
77 
85  const DCMTree::TagId &tagId,
86  DCMTree::Const_TagPtr &result);
87 
91  const DCMTree::TagId &tagId,
92  DCMTree::TagPtr &result);
93 
94 
101  const std::string &tagIdStr,
102  DCMTree::Const_TagPtr &result);
103 
107  const std::string &tagIdStr,
108  DCMTree::TagPtr &result);
109 
114  DCMTree::RawTagId sequenceTagId);
115 
123  DCMTree::RawTagId tagId,
124  bool useNumericTagValueSorting);
125 
131  DCMTree::RawTagId tagId,
132  double &ippX, double &ippY, double &ippZ,
133  double initX, double initY, double initZ);
134 
140  DCMTree::RawTagId tagId,
141  double &ippX1, double &ippY1, double &ippZ1,
142  double &ippX2, double &ippY2, double &ippZ2,
143  double initX1, double initY1, double initZ1,
144  double initX2, double initY2, double initZ2);
145 
156 MLDICOMTags_EXPORT std::string isValidDICOMDate(std::string str,
157  bool allowEmptyStrings = true,
158  bool allowOldFormat = true);
159 
167 MLDICOMTags_EXPORT std::string isValidDICOMTime(const std::string &str,
168  bool allowEmptyStrings = true);
169 
175  bool *isRetired=nullptr);
176 
183 
188 
196  bool searchOnlyOnTopLevel=false);
197 
201 
208  double &ippX,
209  double &ippY,
210  double &ippZ,
211  bool replaceOnlyIfFound);
212 
219  double &iopX1,
220  double &iopY1,
221  double &iopZ1,
222  double &iopX2,
223  double &iopY2,
224  double &iopZ2);
225 
226 
229 {
231  Axial ,
232  Prone ,
246 
248 };
249 
252 extern const char * const OrientationName[NumberOfOrientationTypes];
253 
262  int *resultOType=nullptr);
263 
268 
280  bool searchRecursivly=false);
281 
284  size_t *valSizeInBytes,
285  DicomMessageCollector &dcmMsgCollector);
286 
291  DCMTree::Const_TagPtr &tagPtr);
292 
296 
303 MLDICOMTags_EXPORT const boost::shared_array<unsigned char> getPixelDataFrame(DCMTree::Const_TagPtr pixTag,
304  boost::uint32_t frameIdx);
305 
309 
312 
316 
320 
325 
334  MLdouble &minPixVal,
335  MLdouble &maxPixVal);
336 
346 
356 MLDICOMTags_EXPORT bool getDoubleVectorFromTag(DCMTree::Const_TagPtr tagPtr, std::vector<double> &returnDbls);
357 
367 
377 
387 
397 
405  DCMTree::TagId tagId,
406  std::string *errStr=nullptr);
407 
415  std::string *errStr);
416 
426  const std::string &privateCreatorString);
427 
448  const std::string &privateCreatorString="",
449  MLuint16 desiredPrivateGroupId=0x09,
450  MLuint8 desiredPrivateElementGroupId=0x10);
451 
456  DCMTree::Const_TreePtr dcmTree);
457 
465  std::string &sopInstanceUID);
466 
482  DCMTree::Const_TagPtr sequenceInWhichToSearch,
483  std::string &tagValuesStringListToExtend,
484  const std::string &sep,
485  std::set<std::string> *makeUniqueSet=nullptr,
486  bool searchAsLower8BitOfPrivateFMETag=false);
487 
490 
492 MLDICOMTags_EXPORT DCMTree::Const_TagPtr getPrivateTag(const std::string &privateCreatorString,
493  unsigned short groupId,
494  DCMTree::RawTagId lowerEightBitOfElementId,
495  DCMTree::Const_TreePtr dcmTree);
496 
498 MLDICOMTags_EXPORT bool isPhilips3D(DCMTree::Const_TreePtr treePtr, MLint *spatialExtent=nullptr);
499 
502  unsigned int *fromTagOnly=nullptr);
503 
520  DCMTree::Const_TreePtr dcmTree,
521  std::string &tagValuesStringListToExtend,
522  bool alsoAddTopLevelTags,
523  const std::string &sep,
524  std::set<std::string> *makeUniqueSet=nullptr);
525 
542  const std::vector<MLuint64> &rawTagIds,
543  bool appendFrameCount,
544  bool appendCoords,
545  std::list<std::vector<std::string> > &tagValuesListToExtend);
546 
550  const std::vector<MLuint64> &rawTagIds,
551  std::vector<std::string> &rootEntries);
552 };
553 
554 ML_END_NAMESPACE
Project global and OS specific declarations.
#define MLDICOMTags_EXPORT
If included by external modules, exported symbols are declared as import symbols.
Class to wrap a tag-id.
Definition: DCMTree_TagId.h:40
Class to collect messages and errors related to a given frame handle.
unsigned char MLuint8
Definition: mlTypeDefs.h:115
double MLdouble
Definition: mlTypeDefs.h:223
unsigned short MLuint16
Definition: mlTypeDefs.h:148
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
boost::shared_ptr< const Tag > Const_TagPtr
Definition: DCMTree_Lib.h:63
boost::shared_ptr< const StructuredMF > Const_StructuredMFPtr
Definition: DCMTree_Lib.h:170
boost::shared_ptr< StructuredMF > StructuredMFPtr
Definition: DCMTree_Lib.h:168
boost::shared_ptr< const Tree > Const_TreePtr
Definition: DCMTree_Lib.h:73
boost::shared_ptr< Tag > TagPtr
shared-pointer to tag
Definition: DCMTree_Lib.h:59
std::vector< TreePtr > TreePtrVector
a vector of TreePtr - used for sequences
Definition: DCMTree_Lib.h:85
boost::shared_ptr< Tree > TreePtr
shared pointer to a DCMTree::Tree
Definition: DCMTree_Lib.h:70
unsigned int RawTagId
Definition: DCMTree_Lib.h:147
MLDICOMTags_EXPORT bool updateMinMaxFromDICOMTags(DCMTree::Const_TreePtr treePtr, MLdouble &minPixVal, MLdouble &maxPixVal)
Checks for min/max DICOM tags on top level and - if both are found - updates the passed min/max value...
const char *const OrientationName[NumberOfOrientationTypes]
String representations analog to the OrientationType, however, NumberOfOrientationTypes is out of ran...
MLDICOMTags_EXPORT bool looksLikeValidCSVrValue(const std::string &codedString, std::string *explanation=nullptr)
Returns true if codedString looks like a string valid for a coded segmentation, otherwise false; if e...
MLDICOMTags_EXPORT bool isJPEG2000Compressed(DCMTree::Const_TreePtr treePtr)
Returns true if any JPEG2000 compression was used to compress the pixel data, otherwise false.
MLDICOMTags_EXPORT void getTagStringValuesFromSMFSequence(DCMTree::Const_TreePtr inputDcmTree, const std::vector< MLuint64 > &rawTagIds, bool appendFrameCount, bool appendCoords, std::list< std::vector< std::string > > &tagValuesListToExtend)
Looks for frame-specific tags rawTagIds in getMeVisStructuredMFDimensionSequence of inputDcmTree and ...
MLDICOMTags_EXPORT bool isValidCSVrCharacter(const char ch)
Returns true if ch is a character valid of CS value representations, otherwise false (uppercase lette...
MLDICOMTags_EXPORT DCMTree::TagPtr getTagIfItExists(DCMTree::TreePtr dcmTree, DCMTree::TagId tagId, std::string *errStr=nullptr)
MLDICOMTags_EXPORT bool looksLikeValidDICOMUID(const std::string &uidStrToCheck)
Returns true if uidStrToCheck looks like a plausible valid DICOM UID, otherwise false.
MLDICOMTags_EXPORT bool deepSearchTag(DCMTree::TreePtr treePtr, const std::string &tagIdStr, DCMTree::TagPtr &result)
Alternative version to deepSearchTags(DCMTree::Const_TreePtr, const std::string &,...
MLDICOMTags_EXPORT bool isCompressed(DCMTree::Const_TreePtr treePtr)
Returns true if the DICOM tree has a transfer syntax UID which indicates compression,...
MLDICOMTags_EXPORT unsigned int searchPrivateCreator(DCMTree::TreePtr dcmTree, const std::string &privateCreatorString="", MLuint16 desiredPrivateGroupId=0x09, MLuint8 desiredPrivateElementGroupId=0x10)
Determine the first odd group id with private element group id.
MLDICOMTags_EXPORT ScaleShiftData getRescaleSlopeInterceptAsScaleShift(DCMTree::Const_TreePtr treePtr)
Returns a ScaleShiftData object according to rescale and slope tag values.
MLDICOMTags_EXPORT bool getVector6FromTag(DCMTree::Const_TagPtr tagPtr, Vector6 &returnVec)
Converts six values of tagPtr to six Vector6 values in returnVec, respectively.
MLDICOMTags_EXPORT bool get4x4DoubleMatrixFromTag(DCMTree::Const_TagPtr tagPtr, Matrix4 &returnMat)
Converts 16 values of tagPtr to 16 double matrix values in returnMat, respectively.
MLDICOMTags_EXPORT void extractTagValuesFromPerFrameAndMeVisMFSequence(DCMTree::RawTagId rawTagId, DCMTree::Const_TreePtr dcmTree, std::string &tagValuesStringListToExtend, bool alsoAddTopLevelTags, const std::string &sep, std::set< std::string > *makeUniqueSet=nullptr)
Looks for frame-specific tags with ID rawTagId in sequences DCMTree_PerFrameFunctionalGroupsSequence ...
MLDICOMTags_EXPORT size_t getImageOrientationPatient(DCMTree::Const_TreePtr treePtr, double &iopX1, double &iopY1, double &iopZ1, double &iopX2, double &iopY2, double &iopZ2)
Return the DICOM tag ImageOrientationPatient as two 3D vectors (iopX1, iopY1, iopZ1) and (iopX2,...
MLDICOMTags_EXPORT bool hasMFPixelDataTag(DCMTree::Const_TreePtr treePtr, DCMTree::Const_TagPtr &tagPtr)
Returns true if the tree has a multi-frame pixel data tag containing many frames or false otherwise.
MLDICOMTags_EXPORT DCMTree::TreePtr cloneDCMTree(DCMTree::Const_TreePtr dcmTree, std::string *errStr)
Create a deep-copy of the passed dcmTree as DICOM tree to be modified.
MLDICOMTags_EXPORT std::string isLossyCompressed(DCMTree::Const_TreePtr treePtr)
Returns "Yes" if the DICOM tree has a tag indicating a lossy compression, or if the tag indicates no ...
MLDICOMTags_EXPORT bool hasAtMostOneFrameInSMFGrid(const DCMTree::Const_StructuredMFPtr &smfTree)
Returns true if the passed constant SMFTree has only one grid entry, if smfTree is nullptr or smfTree...
MLDICOMTags_EXPORT bool getVector3FromTag(DCMTree::Const_TagPtr tagPtr, Vector3 &returnVec)
Converts three values of tagPtr to three Vector3 values in returnVec, respectively.
MLDICOMTags_EXPORT const boost::shared_array< unsigned char > getPixelDataFrame(DCMTree::Const_TagPtr pixTag, boost::uint32_t frameIdx)
Returns a memory copy of the frame at index position frameIdx of the pixel data tag pixTag or nullptr...
MLDICOMTags_EXPORT std::string isValidDICOMDate(std::string str, bool allowEmptyStrings=true, bool allowOldFormat=true)
Checks whether str is a valid DICOM date string and returns an empty string on success or a non empty...
MLDICOMTags_EXPORT void getTagStringValuesFromTopLevel(DCMTree::Const_TreePtr inputDcmTree, const std::vector< MLuint64 > &rawTagIds, std::vector< std::string > &rootEntries)
Like getTagStringValuesFromSMFSequence() but retrieves tags only from top level of inputDcmTree into ...
MLDICOMTags_EXPORT bool hasNegativeSliceSpacing(DCMTree::Const_TreePtr treePtr)
Returns true if the tree has a SpacingBetweenSlices tag with a negative value.
MLDICOMTags_EXPORT size_t getHexTag(DCMTree::Const_TreePtr treePtr, DCMTree::RawTagId tagId, double &ippX1, double &ippY1, double &ippZ1, double &ippX2, double &ippY2, double &ippZ2, double initX1, double initY1, double initZ1, double initX2, double initY2, double initZ2)
Returns the given DICOM tag as two 3 component double vectors; all values which can not be retrieved ...
MLDICOMTags_EXPORT bool getVector2FromTag(DCMTree::Const_TagPtr tagPtr, Vector2 &returnVec)
Converts two values of tagPtr to two Vector2 values in returnVec, respectively.
MLDICOMTags_EXPORT bool getDoubleVectorFromTag(DCMTree::Const_TagPtr tagPtr, std::vector< double > &returnDbls)
Converts all values of tagPtr to a std::vector of doubles in returnDbls.
MLDICOMTags_EXPORT bool usesNegativeNMStacking(DCMTree::Const_TreePtr treePtr)
Returns true if the tree has tags which indicate that it is NM data and the pixel data is stacked in ...
MLDICOMTags_EXPORT size_t getTripleTag(DCMTree::Const_TreePtr treePtr, DCMTree::RawTagId tagId, double &ippX, double &ippY, double &ippZ, double initX, double initY, double initZ)
Returns the given DICOM tag as three double values; all values which can not be retrieved are returne...
MLDICOMTags_EXPORT bool getTopLevelSOPInstanceUID(DCMTree::Const_TreePtr dcmTree, std::string &sopInstanceUID)
Get the original SOPInstanceUID from top level of dcmTree, returns the value in sopInstanceUID and re...
MLDICOMTags_EXPORT std::string isValidDICOMTime(const std::string &str, bool allowEmptyStrings=true)
Checks whether str is a valid DICOM time string of the formats HHMM, HHMMSS, or HHMMSS....
MLDICOMTags_EXPORT std::string createInstanceUID(bool useFMEUIDPrefix=false)
Generate new IDs for DICOM frames, for example new SOPinstanceUIDs.
MLDICOMTags_EXPORT bool getDoubleFromTag(DCMTree::Const_TagPtr tagPtr, double &returnDbl)
Converts one values of tagPtr to a double values in returnDbl.
MLDICOMTags_EXPORT DCMTree::Const_TagPtr getPrivateTag(const std::string &privateCreatorString, unsigned short groupId, DCMTree::RawTagId lowerEightBitOfElementId, DCMTree::Const_TreePtr dcmTree)
See DICOMCachedIOTools::getPrivateTag().
MLDICOMTags_EXPORT bool isPhilips3D(DCMTree::Const_TreePtr treePtr, MLint *spatialExtent=nullptr)
See DICOMCachedIOTools::isPhilips3D().
MLDICOMTags_EXPORT DCMTree::Const_TagPtr getAnyPixelDataTag(DCMTree::Const_TreePtr treePtr, bool searchRecursivly=false)
Searches and returns the first pixel data pointer on top level found in treePtr, or a nil tag if not ...
OrientationType
Enumerator for typical human readable anatomic orientations.
@ LessAlmostCoronal
Less approximately Coronal.
@ NumberOfOrientationTypes
Number of available orientation modes.
@ LessAlmostSagittal
Less approximately Sagittal.
@ Axial
axial in supine position
@ LessAlmostAxial
Less approximately Axial.
@ Prone
axial in prone position
@ InvalidOrientation
Something in the orientation is not standard compliant.
@ AlmostSagittal
Approximately Sagittal.
@ NotApplicable
Orientation type makes no sense in this context.
@ OtherOrientation
A valid orientation, but non of the upper ones.
@ AlmostCoronal
Approximately Coronal.
@ AlmostAxial
Approximately Axial.
@ NoValues
No orientation values found in DICOM tree.
MLDICOMTags_EXPORT std::string getCompressionDescription(DCMTree::Const_TreePtr treePtr, bool *isRetired=nullptr)
Returns a textual description of a compression type if it is found in the available transfer UIDs sto...
MLDICOMTags_EXPORT std::string getHumanReadableImageOrientationPatient(DCMTree::Const_TreePtr dcmTree, int *resultOType=nullptr)
Determine (ACR_NEMA)ImageOrientationPatient from dcmTree and create a human readable orientation from...
MLDICOMTags_EXPORT DCMTree::PixelData getPixelDataPtrFromTree(DCMTree::Const_TreePtr treePtr, size_t *valSizeInBytes, DicomMessageCollector &dcmMsgCollector)
Same as DICOMCachedIOTools::getPixelDataPtrFromTree().
MLDICOMTags_EXPORT unsigned int getNumberOfFrames(DCMTree::Const_TreePtr dcmTree, unsigned int *fromTagOnly=nullptr)
See DICOMCachedIOTools::getNumberOfFrames().
MLDICOMTags_EXPORT std::string getTagValue(DCMTree::Const_TreePtr treePtr, DCMTree::RawTagId tagId, bool useNumericTagValueSorting)
Return tag value of first tag with id tagId in the DICOM tree treePtr as string if it exists,...
MLDICOMTags_EXPORT unsigned int findPrivateTagGroup(DCMTree::TreePtr dcmTree, const std::string &privateCreatorString)
Determine tag ID mask of the private creator given by privateCreatorString and return it as mask 0xGG...
MLDICOMTags_EXPORT void deepSearchTags(DCMTree::TreePtr treePtr, const DCMTree::TagId &tagId, const size_t numTagsToFind, std::vector< DCMTree::TagPtr > &tagVector)
Alternative version to deepSearchTags(DCMTree::Const_TreePtr, const DCMTree::TagId,...
MLDICOMTags_EXPORT bool isBitImageDICOM(DCMTree::Const_TreePtr treePtr)
Returns true if the DICOM pixel size seems to be single bit (indicated by appropriate values of BitsA...
MLDICOMTags_EXPORT size_t getImagePositionPatient(DCMTree::Const_TreePtr treePtr, double &ippX, double &ippY, double &ippZ, bool replaceOnlyIfFound)
Return the DICOM tag ImagePositionPatient as three double values; all values which can not be retriev...
MLDICOMTags_EXPORT void getTagStringValuesFromSequence(DCMTree::RawTagId rawTagId, DCMTree::Const_TagPtr sequenceInWhichToSearch, std::string &tagValuesStringListToExtend, const std::string &sep, std::set< std::string > *makeUniqueSet=nullptr, bool searchAsLower8BitOfPrivateFMETag=false)
Deep-searches all occurrences of the tag with id tagToSearch in the sequence tag sequenceInWhichToSea...
MLDICOMTags_EXPORT DCMTree::Const_TagPtr getMeVisStructuredMFDimensionSequence(DCMTree::Const_TreePtr dcmTree)
Searches the structured multi-frame sequence tag on top-level in dcmTree or nullptr if not found or d...
MLDICOMTags_EXPORT std::string getTransferSyntaxUIDAsString(DCMTree::Const_TreePtr treePtr, bool searchOnlyOnTopLevel=false)
Deep search and return the value of the DICOM tag TransferSyntaxUID as string.
MLDICOMTags_EXPORT DCMTree::Const_TagPtr getPrivateFMETag(DCMTree::RawTagId lowerEightBitOfElementId, DCMTree::Const_TreePtr dcmTree)
Searches private FME tag with lower 8 bit element id lowerEightBitOfElementId with FMEPrivateTagsGrou...
MLDICOMTags_EXPORT const DCMTree::MFPixelTag * getAsMFPixelPtr(DCMTree::Const_TagPtr tag)
Returns a pointer to the correctly cast multi-frame class type of tag if it is a valid multi-frame pi...
MLDICOMTags_EXPORT const DCMTree::TreePtrVector * getSequenceItemTreePtrVector(DCMTree::Const_TreePtr dcmMFTree, DCMTree::RawTagId sequenceTagId)
If possible it returns a pointer to the vector of sequence item (trees) of the tag with id sequenceTa...
Contains pixel data which is either shared/ref counted or a direct pointer.
Definition: DCMTree_Lib.h:105