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:
- 16 bit unsigned integer
- 16 bit signed integer
- 32 bit floating point
- 64 bit floating point
All of them are supported by the dcmpmap library.
The main class of this module is:
This module makes heavy use of the dcmiod module for managing common IOD attributes and the dcmfg module for functional group support. Read the "Examples" sections for more explanations.
Examples
The following two examples show:
- How to access and dump information (including the binary data values) from a Parametric Map object
- and how to use the API to create such an object yourself.
Dumping information from Parametric Map
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.
The rest of the code uses the API of the dcmiod and dcmfg module in order to get basic information about Patient, Study, Series and Instance, as well as functional group information, especially the Real World Value Mapping defined in the file.
#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;
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);
}
Creation of Parametric Maps
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:
- The main() routine calls test_pmap() four times, each time using a different Image Pixel Module as template parameter which makes sure that the right pixel data type is used within the created Parametric Map.
- test_pmap() demonstrates the overall steps to create the map:
- Create a new Parametric Map by calling DPMParametricMapIOD::create() (via create_pmap()), and then
- add shared functional groups,
- add dimensions,
- and add frames with the related per-frame functional groups to the object.
- Finally, general data regarding Patient and Study is set.
- Note that the order of these steps in test_pmap() does not matter.
Per default, DPMParametricMapIOD::create() creates a new DICOM instance, within a brand-new DICOM Series that belongs to a brand-new DICOM Study. All minimal information for Patient, Study and Series will be set (e.g. Study, Series and SOP Instance UID as well as other information that is handed over to the create() call, like Series Number). Patient Name and ID are left empty per default.
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",
);
}
{
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);
}
if (result.good())
{
setGenericData(map);
}
if (result.good())
{
}
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;
}