1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
|
/*!
\page mod_dcmpmap dcmpmap: a library for working with parametric map objects
This module contains classes to create, load, access and store DICOM Parametric
Map objects, which have originally been introduced to the DICOM standard with
<a href="ftp://medical.nema.org/medical/dicom/final/sup172_ft2.pdf">Supplement
172</a> in 2014.
In the standard, the data inside each Parametric Map object must rely on one of
these data types:
\li 16 bit unsigned integer
\li 16 bit signed integer
\li 32 bit floating point
\li 64 bit floating point
All of them are supported by the dcmpmap library.
The main class of this module is:
\li \b DPMParametricMapIOD
This module makes heavy use of the \ref mod_dcmiod "dcmiod" module for managing
common IOD attributes and the \ref mod_dcmfg "dcmfg" module for functional group
support. Read the "Examples" sections for more explanations.
\section dcmpmap_examples Examples
The following two examples show:
\li How to access and dump information (including the binary data values) from a
Parametric Map object
\li and how to use the API to create such an object yourself.
\subsection example_dump 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 \ref mod_dcmiod "dcmiod" and
\ref mod_dcmfg "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.
\code
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmpmap/dpmparametricmapiod.h"
static void dumpRWVM(const unsigned long frameNumber,
FGInterface& fg)
{
FGRealWorldValueMapping* rw = OFstatic_cast(FGRealWorldValueMapping*, fg.get(frameNumber, DcmFGTypes::EFG_REALWORLDVALUEMAPPING));
if (rw)
{
size_t numMappings = rw->getRealWorldValueMapping().size();
COUT << " Number of Real World Value Mappings defined: " << numMappings << OFendl;
for (size_t m = 0; m < numMappings; m++)
{
FGRealWorldValueMapping::RWVMItem* item = rw->getRealWorldValueMapping()[m];
OFString label, expl;
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++)
{
ContentItemMacro* macro = item->getEntireQuantityDefinitionSequence()[q];
COUT << " Quantity #" << q << ": " << macro->toString() << OFendl;
}
}
}
}
else
{
CERR << " Error: No Real World Value Mappings defined for frame #" << frameNumber << OFendl;
}
}
class DumpFramesVisitor
{
public:
DumpFramesVisitor(DPMParametricMapIOD* map,
const unsigned long numPerFrame)
: m_Map(map)
, m_numPerFrame(numPerFrame)
{
}
template<typename T>
OFBool operator()(DPMParametricMapIOD::Frames<T>& frames)
{
dumpDataType(frames);
for (unsigned long f = 0; f < m_Map->getNumberOfFrames(); f++)
{
COUT << "Dumping info of frame #" << f << ":" << OFendl;
FGInterface& fg = m_Map->getFunctionalGroups();
dumpRWVM(f, fg);
COUT << "Dumping data for frame #" << f << ": " << OFendl;
T* frame = frames.getFrame(f);
for (unsigned long p = 0; p < m_numPerFrame; p++)
{
COUT << frame[p] << " ";
}
COUT << OFendl << OFendl;
}
return 0;
}
OFBool operator()(OFCondition& cond)
{
// Avoid compiler warning
(void)cond;
CERR << "Type of data samples not supported" << OFendl;
return OFFalse;
}
OFBool dumpHeader(DPMParametricMapIOD::Frames<Float32>& frames)
{
// Avoid compiler warning
(void)frames;
COUT << "File has 32 Bit float data" << OFendl;
return OFFalse;
}
OFBool dumpHeader(DPMParametricMapIOD::Frames<Uint16>& frames)
{
// Avoid compiler warning
(void)frames;
COUT << "File has 16 Bit unsigned integer data" << OFendl;
return OFFalse;
}
OFBool dumpHeader(DPMParametricMapIOD::Frames<Sint16>& frames)
{
// Avoid compiler warning
(void)frames;
COUT << "File has 16 Bit signed integer data" << OFendl;
return OFFalse;
}
OFBool dumpHeader(DPMParametricMapIOD::Frames<Float64>& frames)
{
// Avoid compiler warning
(void)frames;
COUT << "File has 64 Bit float data" << OFendl;
return OFTrue;
}
template<typename T>
OFBool dumpDataType(DPMParametricMapIOD::Frames<T>& frames)
{
// Avoid compiler warning
(void)frames;
CERR << "Type of data samples not supported" << OFendl;
return OFFalse;
}
DPMParametricMapIOD* m_Map;
unsigned long m_numPerFrame;
};
static void dumpGeneral(DPMParametricMapIOD& map)
{
OFString patName, patID, studyUID, studyDate, seriesUID, modality, sopUID;
map.getPatient().getPatientName(patName);
map.getPatient().getPatientID(patID);
map.getStudy().getStudyInstanceUID(studyUID);
map.getStudy().getStudyDate(studyDate);
map.getSeries().getSeriesInstanceUID(seriesUID);
map.getSeries().getModality(modality);
map.getSOPCommon().getSOPInstanceUID(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;
map.getFunctionalGroups().get(0, DcmFGTypes::EFG_REALWORLDVALUEMAPPING, 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[])
{
// OFLog::configure(OFLogger::DEBUG_LOG_LEVEL);
OFString inputFile;
if (argc < 2)
{
CERR << "Usage: dump_pmp <input-file>" << std::endl;
return 1;
}
else
{
inputFile = argv[1];
if (!OFStandard::fileExists(inputFile))
{
CERR << "Input file " << inputFile << " does not exist " << OFendl;
return 1;
}
}
OFvariant<OFCondition,DPMParametricMapIOD*> result = DPMParametricMapIOD::loadFile(inputFile);
if (OFget<DPMParametricMapIOD*>(&result))
{
DPMParametricMapIOD* map = *OFget<DPMParametricMapIOD*>(&result);
dumpGeneral(*map);
COUT << "Dumping #" << map->getNumberOfFrames() << " frames of file " << inputFile << OFendl;
Uint16 rows, cols = 0;
map->getRows(rows);
map->getColumns(cols);
unsigned long numPerFrame = rows * cols;
DPMParametricMapIOD::FramesType frames = map->getFrames();
OFvisit<OFBool>(DumpFramesVisitor(map, numPerFrame), frames);
}
else
{
CERR << "Could not load parametric map: " << (*OFget<OFCondition>(&result)).text() << OFendl;
exit(1);
}
exit(0);
}
\endcode
\subsection example_create 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:
\li 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.
\li test_pmap() demonstrates the overall steps to create the map:
\li Create a new Parametric Map by calling DPMParametricMapIOD::create()
(via create_pmap()), and then
\li add shared functional groups,
\li add dimensions,
\li and add frames with the related per-frame functional groups to the object.
\li Finally, general data regarding Patient and Study is set.
\li 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.
\code
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/ofstd/oftest.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;
// Set Patient and Study example data
static void setGenericData(DPMParametricMapIOD& map)
{
map.getPatient().setPatientName("Onken^Michael");
map.getPatient().setPatientID("007");
map.getStudy().setStudyDate("20160721");
map.getStudy().setStudyTime("111200");
map.getStudy().setStudyID("4711");
}
// Create Parametric Map
template<typename ImagePixel>
static OFvariant<OFCondition,DPMParametricMapIOD> create_pmap()
{
return DPMParametricMapIOD::create<ImagePixel>
(
"MR", // Modality
"1", // Series Number
"1", // Instance Number
ROWS,
COLS,
IODEnhGeneralEquipmentModule::EquipmentInfo("Open Connections GmbH", "make_pmp", "SN_0815", "0.1"),
ContentIdentificationMacro("1", "PARAMAP_LABEL", "Example description from test program", "Onken^Michael"),
"VOLUME", // Image Flavor
"MTT", // Derived Pixel Contrast
DPMTypes::CQ_RESEARCH // Content Qualification
);
}
// Add those functional groups that are common for all frames
static OFCondition addSharedFunctionalGroups(DPMParametricMapIOD& map)
{
FGPixelMeasures pixelMeasures;
pixelMeasures.setPixelSpacing("1\\1");
pixelMeasures.setSliceThickness("0.1");
pixelMeasures.setSpacingBetweenSlices("0.1");
FGPlaneOrientationPatient planeOrientPatientFG;
planeOrientPatientFG.setImageOrientationPatient("1", "0", "0", "0", "1", "0");
FGFrameAnatomy frameAnaFG;
frameAnaFG.setLaterality(FGFrameAnatomy::LATERALITY_UNPAIRED);
frameAnaFG.getAnatomy().getAnatomicRegion().set("T-A0100", "SRT", "Brain");
FGIdentityPixelValueTransformation idTransFG;
FGParametricMapFrameType frameTypeFG;
frameTypeFG.setFrameType("DERIVED\\PRIMARY\\VOLUME\\MTT");
// Add groups to Parametric Map
OFCondition result;
if ((result = map.addForAllFrames(pixelMeasures)).good())
if ((result = map.addForAllFrames(planeOrientPatientFG)).good())
if ((result = map.addForAllFrames(frameAnaFG)).good())
if ((result = map.addForAllFrames(idTransFG)).good())
result = map.addForAllFrames(frameTypeFG);
return result;
}
// Add a single dimension for demonstration purposes based on "Image Position Patient"
static OFCondition addDimensions(DPMParametricMapIOD& map)
{
IODMultiframeDimensionModule& mod = map.getIODMultiframeDimensionModule();
OFString dimUID = DcmIODUtil::createUID(0);
OFCondition result = mod.addDimensionIndex(DCM_ImagePositionPatient, dimUID, DCM_RealWorldValueMappingSequence, "Frame position");
return result;
}
// Add one frame to parametric map. Frame number is used to compute some
// varying example data values differing from frame to frame
template <typename PixelType>
static OFCondition addFrame(DPMParametricMapIOD& map,
const unsigned long frameNo)
{
// Create example data
OFVector<PixelType> data(NUM_VALUES_PER_FRAME);
for (size_t n=0; n < data.size(); ++n)
{
data[n] = (n*frameNo+n) + (0.1 * (frameNo % 10));
}
Uint16 rows, cols;
OFCondition cond = map.getImagePixel().getRows(rows);
cond = map.getImagePixel().getColumns(cols);
// Create functional groups
OFVector<FGBase*> groups;
OFunique_ptr<FGPlanePosPatient> fgPlanePos(new FGPlanePosPatient);
OFunique_ptr<FGFrameContent > fgFracon(new FGFrameContent);
OFunique_ptr<FGRealWorldValueMapping> fgRVWM(new FGRealWorldValueMapping());
FGRealWorldValueMapping::RWVMItem* rvwmItemSimple = new FGRealWorldValueMapping::RWVMItem();
if (!fgPlanePos || !fgFracon || !fgRVWM || !rvwmItemSimple )
return EC_MemoryExhausted;
// Fill in functional group values
// Real World Value Mapping
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");
CodeSequenceMacro* qCodeName = new CodeSequenceMacro("G-C1C6", "SRT", "Quantity");
CodeSequenceMacro* qSpec = new CodeSequenceMacro("110805", "SRT", "T2 Weighted MR Signal Intensity");
ContentItemMacro* quantity = new ContentItemMacro;
if (!quantity || !qSpec || !quantity)
return EC_MemoryExhausted;
quantity->getEntireConceptNameCodeSequence().push_back(qCodeName);
quantity->getEntireConceptCodeSequence().push_back(qSpec);
rvwmItemSimple->getEntireQuantityDefinitionSequence().push_back(quantity);
quantity->setValueType(ContentItemMacro::VT_CODE);
fgRVWM->getRealWorldValueMapping().push_back(rvwmItemSimple);
// Plane Position
OFStringStream ss;
ss << frameNo;
OFSTRINGSTREAM_GETOFSTRING(ss, framestr) // convert number to string
fgPlanePos->setImagePositionPatient("0", "0", framestr);
// Frame Content
OFCondition result = fgFracon->setDimensionIndexValues(frameNo+1 /* value within dimension */, 0 /* first dimension */);
// Add frame with related groups
if (result.good())
{
// Add frame
groups.push_back(fgPlanePos.get());
groups.push_back(fgFracon.get());
groups.push_back(fgRVWM.get());
groups.push_back(fgPlanePos.get());
DPMParametricMapIOD::FramesType frames = map.getFrames();
result = OFget<DPMParametricMapIOD::Frames<PixelType> >(&frames)->addFrame(&*data.begin(), NUM_VALUES_PER_FRAME, groups);
}
return result;
}
// Main routine that creates Parametric Maps
template<typename ImagePixel>
static OFCondition test_pmap(const OFString& saveDestination)
{
OFvariant<OFCondition,DPMParametricMapIOD> obj = create_pmap<ImagePixel>();
if (OFCondition* pCondition = OFget<OFCondition>(&obj))
return *pCondition;
DPMParametricMapIOD& map = *OFget<DPMParametricMapIOD>(&obj);
OFCondition result;
if ((result = addSharedFunctionalGroups(map)).good())
if ((result = addDimensions(map)).good())
{
// Add frames (parametric map data), and per-frame functional groups
for (unsigned long f = 0; result.good() && (f < NUM_FRAMES); f++)
result = addFrame<OFTypename ImagePixel::value_type>(map, f);
}
// Set some generic data (keep dciodvfy happy on DICOMDIR warnings)
if (result.good())
{
setGenericData(map);
}
// Save
if (result.good())
{
return map.saveFile(saveDestination.c_str());
}
else
{
return result;
}
}
int main (int argc, char* argv[])
{
OFString outputDir;
if (argc < 2)
{
CERR << "Usage: make_pmp <output-dir>" << std::endl;
return 1;
}
else
{
outputDir = argv[1];
if (!OFStandard::dirExists(outputDir))
{
CERR << "Output directory " << outputDir << " does not exist " << OFendl;
return 1;
}
}
//OFLog::configure(OFLogger::DEBUG_LOG_LEVEL);
// Test all possible parametric map types (signed and unsigned integer, floating point
// and double floating point)
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;
}
\endcode
*/
|