This module contains classes to create, load, access and store DICOM Parametric Map objects, which have originally been introduced to the DICOM standard with Supplement 172 in 2014.
In the standard, the data inside each Parametric Map object must rely on one of these data types:
All of them are supported by the dcmpmap library.
The Parametric Map class uses a template in order to instantiate the correct pixel data type internally, and to offer a dedicated API for that type. Allowed types are Uint16, Sint16, Float32 and Float64.
Since internally the data types are handled in a C++ Variant, the usual concept to "switch" between these types in code is to use a Visitor which overloads the operator "()" for each data type that can occur in the Variant. This concept is also demonstrated below where the type of pixel data is printed.
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmpmap/dpmparametricmapiod.h"
static void dumpRWVM(const unsigned long frameNumber,
{
if (rw)
{
COUT << " Number of Real World Value Mappings defined: " << numMappings << OFendl;
for (size_t m = 0; m < numMappings; m++)
{
item->getLUTLabel(label);
item->getLUTExplanation(expl);
COUT << " RWVM Mapping #" << m << ":" << OFendl;
COUT << " LUT Label: << " << label << OFendl;
COUT << " LUT Explanation: " << expl << OFendl;
COUT << " Measurement Units Code: " << item->getMeasurementUnitsCode().toString() << OFendl;
size_t numQuant = item->getEntireQuantityDefinitionSequence().size();
if (numQuant > 0)
{
COUT << " Number of Quantities defined: " << numQuant << OFendl;
for (size_t q = 0; q < numQuant; q++)
{
COUT << " Quantity #" << q << ": " << macro->toString() << OFendl;
}
}
}
}
else
{
CERR << " Error: No Real World Value Mappings defined for frame #" << frameNumber << OFendl;
}
}
class DumpFramesVisitor
{
public:
const unsigned long numPerFrame)
: m_Map(map)
, m_numPerFrame(numPerFrame)
{
}
template<typename T>
{
dumpDataType(frames);
for (unsigned long f = 0; f < m_Map->getNumberOfFrames(); f++)
{
COUT << "Dumping info of frame #" << f << ":" << OFendl;
dumpRWVM(f, fg);
COUT << "Dumping data for frame #" << f << ": " << OFendl;
for (unsigned long p = 0; p < m_numPerFrame; p++)
{
COUT << frame[p] << " ";
}
COUT << OFendl << OFendl;
}
return 0;
}
{
(void)cond;
CERR << "Type of data samples not supported" << OFendl;
return OFFalse;
}
{
(void)frames;
COUT << "File has 32 Bit float data" << OFendl;
return OFFalse;
}
{
(void)frames;
COUT << "File has 16 Bit unsigned integer data" << OFendl;
return OFFalse;
}
{
(void)frames;
COUT << "File has 16 Bit signed integer data" << OFendl;
return OFFalse;
}
{
(void)frames;
COUT << "File has 64 Bit float data" << OFendl;
return OFTrue;
}
template<typename T>
{
(void)frames;
CERR << "Type of data samples not supported" << OFendl;
return OFFalse;
}
unsigned long m_numPerFrame;
};
{
OFString patName, patID, studyUID, studyDate, seriesUID, modality, sopUID;
COUT << "Patient Name : " << patName << OFendl;
COUT << "Patient ID : " << patID << OFendl;
COUT << "Study Instance UID : " << studyUID << OFendl;
COUT << "Study Date : " << studyDate << OFendl;
COUT << "Series Instance UID: " << seriesUID << OFendl;
COUT << "SOP Instance UID : " << sopUID << OFendl;
COUT << "---------------------------------------------------------------" << OFendl;
OFBool isPerFrame;
if (isPerFrame)
{
COUT << "Real World Value Mapping: Defined per-frame" << OFendl;
}
else
{
COUT << "Real World Value Mapping: Defined shared (i.e. single definition for all frames):" << OFendl;
}
COUT << "---------------------------------------------------------------" << OFendl;
}
int main (int argc, char* argv[])
{
if (argc < 2)
{
CERR << "Usage: dump_pmp <input-file>" << std::endl;
return 1;
}
else
{
inputFile = argv[1];
{
CERR << "Input file " << inputFile << " does not exist " << OFendl;
return 1;
}
}
if (OFget<DPMParametricMapIOD*>(&result))
{
dumpGeneral(*map);
COUT <<
"Dumping #" << map->
getNumberOfFrames() <<
" frames of file " << inputFile << OFendl;
Uint16 rows, cols = 0;
unsigned long numPerFrame = rows * cols;
OFvisit<OFBool>(DumpFramesVisitor(map, numPerFrame), frames);
}
else
{
CERR << "Could not load parametric map: " << (*OFget<OFCondition>(&result)).text() << OFendl;
exit(1);
}
exit(0);
}
Class representing the Content Item Macro:
Definition: iodcontentitemmacro.h:51
virtual FGInterface & getFunctionalGroups()
Get access to functional groups.
Inner class that offers typed interface to bulk data.
Definition: dpmparametricmapiod.h:41
PixelType * getFrame(const size_t frameNumber)
Type-specific getFrame() method that returns Float32, Uint16, or whatever is used in this Parametric ...
Class for managing the Parametric Map IOD attributes.
Definition: dpmparametricmapiod.h:34
static OFvariant< OFCondition, DPMParametricMapIOD * > loadFile(const OFString &filename)
Load Parametric Map object from file.
size_t getNumberOfFrames() const
Get number of frames, based on the number of items in the shared functional functional groups sequenc...
FramesType getFrames()
Get access to frame data.
virtual OFCondition getColumns(Uint16 &cols)
Get number of cols.
virtual OFCondition getRows(Uint16 &rows)
Get number of rows.
@ EFG_REALWORLDVALUEMAPPING
Real World Value Mapping.
Definition: fgtypes.h:190
IODGeneralSeriesModule & getSeries()
Get Series Module.
IODSOPCommonModule & getSOPCommon()
Get SOP Common Module.
IODGeneralStudyModule & getStudy()
Get General Study Module.
IODPatientModule & getPatient()
Get Patient Module.
Main interface class to access functional groups from DICOM Enhanced objects.
Definition: fginterface.h:45
virtual FGBase * get(const Uint32 frameNo, const DcmFGTypes::E_FGType fgType)
Get specific functional group for a frame, no matter whether it is stored per frame or shared.
Class representing the Real World Value Mapping Functional Group that specifies the mapping of stored...
Definition: fgrealworldvaluemapping.h:37
RWVMItem(OFshared_ptr< DcmItem > item, OFshared_ptr< IODRules > rules, IODComponent *parent=NULL)
Constructor.
virtual OFVector< RWVMItem * > & getRealWorldValueMapping()
Return references to the various items inside the Real World Value Mapping Sequence.
virtual OFCondition getModality(OFString &value, const signed long pos=0) const
Get Modality.
virtual OFCondition getSeriesInstanceUID(OFString &value, const signed long pos=0) const
Get series instance UID.
virtual OFCondition getStudyInstanceUID(OFString &value, const signed long pos=0) const
Get Study Instance UID.
virtual OFCondition getStudyDate(OFString &value, const signed long pos=0) const
Get Study Date.
virtual OFCondition getPatientID(OFString &value, const signed long pos=0) const
Get Patient ID.
virtual OFCondition getPatientName(OFString &value, const signed long pos=0) const
Get Patient's Name.
virtual OFCondition getSOPInstanceUID(OFString &value, const signed long pos=0) const
Get SOP Instance UID.
General purpose class for condition codes.
Definition: ofcond.h:164
static OFBool fileExists(const OFFilename &fileName)
check whether the given file exists.
a simple string class that implements a subset of std::string.
Definition: ofstring.h:76
size_type size() const
get the size of this OFVector.
Definition: ofvector.h:190
A class template that represents a type-safe union.
Definition: ofvriant.h:414
The Parametric Map class uses a template in order to instantiate the correct pixel data type internally, and to offer a dedicated API for that type. Allowed types are Uint16, Sint16, Float32 and Float64. The example below demonstrates that the API use is generally the same for all types.
The procedure in the example (and most of it applies for the general case) is as follows:
Of course, often you might want to put the new instance into an existing Series instead, or place the brand-new Series into an existing Study or at least assign it to an existing Patient. The easiest way to to do that is to use the call import() that imports Patient or even Study, Series and Frame of Reference information from an existing file, i.e. place it under an existing Patient, Study and/or Series.
When adding information to the Parametric Map using the public API, some basic checks are usually performed on the data. Finally, when calling saveFile(), some further checks take place, e.g. validating the structure of the functional groups or making sure that all required element values are set.
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmiod/iodutil.h"
#include "dcmtk/dcmpmap/dpmparametricmapiod.h"
#include "dcmtk/dcmfg/fgpixmsr.h"
#include "dcmtk/dcmfg/fgplanpo.h"
#include "dcmtk/dcmfg/fgplanor.h"
#include "dcmtk/dcmfg/fgfracon.h"
#include "dcmtk/dcmfg/fgframeanatomy.h"
#include "dcmtk/dcmfg/fgidentpixeltransform.h"
#include "dcmtk/dcmfg/fgframevoilut.h"
#include "dcmtk/dcmfg/fgrealworldvaluemapping.h"
#include "dcmtk/dcmfg/fgparametricmapframetype.h"
const size_t NUM_FRAMES = 10;
const Uint16 ROWS = 10;
const Uint16 COLS = 10;
const unsigned long NUM_VALUES_PER_FRAME = ROWS * COLS;
{
}
template<typename ImagePixel>
{
return DPMParametricMapIOD::create<ImagePixel>
(
"MR",
"1",
"1",
ROWS,
COLS,
"VOLUME",
"MTT",
);
}
{
FGIdentityPixelValueTransformation idTransFG;
return result;
}
{
return result;
}
template <typename PixelType>
const unsigned long frameNo)
{
for (size_t n=0; n < data.size(); ++n)
{
data[n] = (n*frameNo+n) + (0.1 * (frameNo % 10));
}
Uint16 rows, cols;
if (!fgPlanePos || !fgFracon || !fgRVWM || !rvwmItemSimple )
rvwmItemSimple->setRealWorldValueSlope(10);
rvwmItemSimple->setRealWorldValueIntercept(0);
rvwmItemSimple->setDoubleFloatRealWorldValueFirstValueMapped(0.12345);
rvwmItemSimple->setDoubleFloatRealWorldValueLastValueMapped(98.7654);
rvwmItemSimple->getMeasurementUnitsCode().set("{counts}/s", "UCUM", "Counts per second");
rvwmItemSimple->setLUTExplanation("We are mapping trash to junk.");
rvwmItemSimple->setLUTLabel("Just testing");
if (!quantity || !qSpec || !quantity)
rvwmItemSimple->getEntireQuantityDefinitionSequence().push_back(quantity);
fgRVWM->getRealWorldValueMapping().push_back(rvwmItemSimple);
OFStringStream ss;
ss << frameNo;
OFSTRINGSTREAM_GETOFSTRING(ss, framestr)
fgPlanePos->setImagePositionPatient("0", "0", framestr);
OFCondition result = fgFracon->setDimensionIndexValues(frameNo+1 , 0 );
{
result = OFget<DPMParametricMapIOD::Frames<PixelType> >(&frames)->addFrame(&*data.begin(), NUM_VALUES_PER_FRAME, groups);
}
return result;
}
template<typename ImagePixel>
{
if (
OFCondition* pCondition = OFget<OFCondition>(&obj))
return *pCondition;
if ((result = addSharedFunctionalGroups(map)).good())
if ((result = addDimensions(map)).good())
{
for (
unsigned long f = 0; result.
good() && (f < NUM_FRAMES); f++)
result = addFrame<OFTypename ImagePixel::value_type>(map, f);
}
{
setGenericData(map);
}
{
}
else
{
return result;
}
}
int main (int argc, char* argv[])
{
if (argc < 2)
{
CERR << "Usage: make_pmp <output-dir>" << std::endl;
return 1;
}
else
{
outputDir = argv[1];
{
CERR << "Output directory " << outputDir << " does not exist " << OFendl;
return 1;
}
}
test_pmap<IODImagePixelModule<Uint16> >(outputDir + "/uint_paramap.dcm");
test_pmap<IODImagePixelModule<Sint16> >(outputDir + "/sint_paramap.dcm");
test_pmap<IODFloatingPointImagePixelModule>(outputDir + "/float_paramap.dcm");
test_pmap<IODDoubleFloatingPointImagePixelModule>(outputDir + "/double_paramap.dcm");
return 0;
}
Class representing a Code Sequence Macro.
Definition: iodmacro.h:35
virtual OFCondition set(const OFString &value, const OFString &scheme, const OFString &meaning, const OFString &schemeVersion="", const OFBool checkValue=OFTrue, const OFBool autoTag=OFTrue)
Set all values in this class conveniently.
Content Identification Macro.
Definition: iodmacro.h:962
virtual OFCondition setValueType(const OFString &value, const OFBool checkValue=OFTrue)
Set ValueType.
virtual OFVector< CodeSequenceMacro * > & getEntireConceptNameCodeSequence()
Get a reference to the entire ConceptNameCodeSequence, including items exceeding the value multiplici...
virtual OFVector< CodeSequenceMacro * > & getEntireConceptCodeSequence()
Get a reference to the entire ConceptCodeSequence, including items exceeding the value multiplicity r...
virtual OFCondition saveFile(const OFString &filename, const E_TransferSyntax writeXfer=EXS_LittleEndianExplicit)
Save current object to given filename.
virtual IODMultiframeDimensionModule & getIODMultiframeDimensionModule()
Get Multi-frame Dimension Module.
virtual OFCondition addForAllFrames(const FGBase &group)
Add a functional group for all frames.
@ CQ_RESEARCH
RESEARCH.
Definition: dpmtypes.h:69
IODImagePixelModuleType & getImagePixel()
Get Image Pixel Module (variant)
Definition: iodimage.h:134
static OFString createUID(const Uint8 level=0)
Create new Unique Identifier (UID)
Class representing the Frame Anatomy Functional Group Macro.
Definition: fgframeanatomy.h:34
virtual GeneralAnatomyMacro & getAnatomy()
Get anatomy information.
@ LATERALITY_UNPAIRED
Unpaired body part.
Definition: fgframeanatomy.h:49
virtual OFCondition setLaterality(const LATERALITY &value)
Set Laterality.
Class representing the "Frame Content" Functional Group Macro.
Definition: fgfracon.h:36
Class representing the Parametric Map Frame Type Functional Group Macro.
Definition: fgparametricmapframetype.h:34
virtual OFCondition setFrameType(const OFString &value, const OFBool checkValue=OFTrue)
Set FrameType.
Class representing the Pixel Measures Functional Group Macro.
Definition: fgpixmsr.h:34
virtual OFCondition setPixelSpacing(const OFString &value, const OFBool checkValue=OFTrue)
Set Pixel Spacing.
virtual OFCondition setSliceThickness(const OFString &value, const OFBool checkValue=OFTrue)
Set Slice Thickness.
virtual OFCondition setSpacingBetweenSlices(const OFString &value, const OFBool checkValue=OFTrue)
Set Spacing between Slices.
Class representing the Plane Orientation (Patient) Functional Group Macro.
Definition: fgplanor.h:36
virtual OFCondition setImageOrientationPatient(const OFString &rowX, const OFString &rowY, const OFString &rowZ, const OFString &colX, const OFString &colY, const OFString &colZ, const OFBool checkValue=OFTrue)
Set all values of Image Orientation Patient at once.
Class representing the Plane Position (Patient) Functional Group containing the x,...
Definition: fgplanpo.h:36
virtual CodeSequenceMacro & getAnatomicRegion()
Return Anatomic Region.
virtual OFCondition setStudyDate(const OFString &value, const OFBool checkValue=OFTrue)
Set Study Date.
virtual OFCondition setStudyTime(const OFString &value, const OFBool checkValue=OFTrue)
set study time
virtual OFCondition setStudyID(const OFString &value, const OFBool checkValue=OFTrue)
Set Study ID.
OFCondition getRows(Uint16 &value, const unsigned long pos=0)
Get Rows.
Definition: modimagepixelvariant.h:150
OFCondition getColumns(Uint16 &value, const unsigned long pos=0)
Get Columns.
Definition: modimagepixelvariant.h:162
Class representing the Multi-Frame Dimension Module:
Definition: modmultiframedimension.h:47
virtual OFCondition addDimensionIndex(const DcmTagKey &dimensionIndexPointer, const OFString &dimensionOrganizationUID, const DcmTagKey &functionalGroupPointer, const OFString &dimensionDescriptionLabel="", const OFString &dimensionIndexPrivateCreator="", const OFString &functionalGroupPrivateCreator="")
Convenience method to add Dimension Index.
virtual OFCondition setPatientID(const OFString &value, const OFBool checkValue=OFTrue)
Set Patient ID.
virtual OFCondition setPatientName(const OFString &value, const OFBool checkValue=OFTrue)
Set Patient's Name.
OFBool good() const
check if the status is OK.
Definition: ofcond.h:293
static OFBool dirExists(const OFFilename &dirName)
check whether the given directory exists.
const char * c_str() const
returns a pointer to the initial element of an array of length size()+1 whose first size() elements e...
Definition: ofstring.h:388
this is a resizable array.
Definition: ofvector.h:54
void push_back(const T &v)
insert an entry at the end of this object
Definition: ofvector.h:301
OFunique_ptr is a smart pointer that retains sole ownership of an object through a pointer and destro...
Definition: ofmem.h:289
DCMTK_OFSTD_EXPORT const OFConditionConst EC_MemoryExhausted
condition constant: failure, memory exhausted
A simple framework for writing and running test cases.
Convenient struct containing all information required for setting enhanced equipment information (for...
Definition: modenhequipment.h:45