|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (C) 2025, J. Riesmeier, Oldenburg, Germany |
| 4 | + * All rights reserved. See COPYRIGHT file for details. |
| 5 | + * |
| 6 | + * This software and supporting documentation are maintained by |
| 7 | + * |
| 8 | + * OFFIS e.V. |
| 9 | + * R&D Division Health |
| 10 | + * Escherweg 2 |
| 11 | + * D-26121 Oldenburg, Germany |
| 12 | + * |
| 13 | + * |
| 14 | + * Module: dcmsr |
| 15 | + * |
| 16 | + * Author: Joerg Riesmeier |
| 17 | + * |
| 18 | + * Purpose: |
| 19 | + * test program for class DSRImageReferenceValue |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | + |
| 24 | +#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ |
| 25 | + |
| 26 | +#include "dcmtk/ofstd/oftest.h" |
| 27 | + |
| 28 | +#include "dcmtk/dcmdata/dcuid.h" |
| 29 | +#include "dcmtk/dcmdata/dcdatset.h" |
| 30 | +#include "dcmtk/dcmdata/dcdeftag.h" |
| 31 | +#include "dcmtk/dcmdata/dctypes.h" |
| 32 | + |
| 33 | +#include "dcmtk/dcmsr/dsrimgvl.h" |
| 34 | +#include "dcmtk/dcmsr/dsrimgtn.h" |
| 35 | +#include "dcmtk/dcmsr/codes/dcm.h" |
| 36 | + |
| 37 | + |
| 38 | +OFTEST(dcmsr_createMonochromeIconImage) |
| 39 | +{ |
| 40 | + DSRImageReferenceValue imgValue(UID_CTImageStorage, "1.2.3.4.5.6.7.8.9.0.98"); |
| 41 | + OFCHECK(!imgValue.hasIconImage()); |
| 42 | + |
| 43 | + /* create a monochrome image dataset */ |
| 44 | + DcmDataset dataset; |
| 45 | + Uint8 pixelData[256]; |
| 46 | + for (int i = 0; i < 256; i++) |
| 47 | + pixelData[i] = OFstatic_cast(Uint8, i); |
| 48 | + OFCHECK(dataset.putAndInsertString(DCM_PhotometricInterpretation, "MONOCHROME2").good()); |
| 49 | + OFCHECK(dataset.putAndInsertUint16(DCM_SamplesPerPixel, 1).good()); |
| 50 | + OFCHECK(dataset.putAndInsertUint16(DCM_PixelRepresentation, 0).good()); |
| 51 | + OFCHECK(dataset.putAndInsertUint16(DCM_Rows, 16).good()); |
| 52 | + OFCHECK(dataset.putAndInsertUint16(DCM_Columns, 16).good()); |
| 53 | + OFCHECK(dataset.putAndInsertUint16(DCM_BitsAllocated, 8).good()); |
| 54 | + OFCHECK(dataset.putAndInsertUint16(DCM_BitsStored, 8).good()); |
| 55 | + OFCHECK(dataset.putAndInsertUint16(DCM_HighBit, 7).good()); |
| 56 | + OFCHECK(dataset.putAndInsertUint8Array(DCM_PixelData, pixelData, sizeof(pixelData)).good()); |
| 57 | + |
| 58 | + /* create an icon image with 64x64 pixels */ |
| 59 | + OFCHECK(imgValue.createIconImage(&dataset, EXS_Unknown /*xfer*/, 0 /*frame*/, 64 /*width*/, 64 /*height*/).good()); |
| 60 | + OFCHECK(imgValue.hasIconImage()); |
| 61 | + |
| 62 | + /* set value to image tree node and write to item */ |
| 63 | + DcmItem item; |
| 64 | + DSRImageTreeNode imgNode(DSRTypes::RT_contains); |
| 65 | + OFCHECK(imgNode.setConceptName(CODE_DCM_BestInSet).good()); |
| 66 | + OFCHECK(imgNode.setValue(imgValue).good()); |
| 67 | + OFCHECK(imgNode.hasIconImage()); |
| 68 | + OFCHECK(imgNode.write(item).good()); |
| 69 | + /* output content of the item (in debug mode only) */ |
| 70 | + if (DCM_dcmsrLogger.isEnabledFor(OFLogger::DEBUG_LOG_LEVEL)) |
| 71 | + item.print(COUT, DCMTypes::PF_shortenLongTagValues /*flags*/, 2 /*level*/); |
| 72 | + |
| 73 | + /* delete the icon image */ |
| 74 | + imgNode.deleteIconImage(); |
| 75 | + OFCHECK(!imgNode.hasIconImage()); |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | +OFTEST(dcmsr_createColorIconImage) |
| 80 | +{ |
| 81 | + DSRImageReferenceValue imgValue(UID_CTImageStorage, "1.2.3.4.5.6.7.8.9.0.99"); |
| 82 | + OFCHECK(!imgValue.hasIconImage()); |
| 83 | + |
| 84 | + /* create a color image dataset */ |
| 85 | + DcmDataset dataset; |
| 86 | + Uint8 pixelData[256][3]; |
| 87 | + for (int i = 0; i < 256; i++) |
| 88 | + { |
| 89 | + pixelData[i][0] = OFstatic_cast(Uint8, i); |
| 90 | + pixelData[i][1] = OFstatic_cast(Uint8, i); |
| 91 | + pixelData[i][2] = OFstatic_cast(Uint8, i); |
| 92 | + } |
| 93 | + OFCHECK(dataset.putAndInsertString(DCM_PhotometricInterpretation, "RGB").good()); |
| 94 | + OFCHECK(dataset.putAndInsertUint16(DCM_SamplesPerPixel, 3).good()); |
| 95 | + OFCHECK(dataset.putAndInsertUint16(DCM_PixelRepresentation, 0).good()); |
| 96 | + OFCHECK(dataset.putAndInsertUint16(DCM_PlanarConfiguration, 0).good()); |
| 97 | + OFCHECK(dataset.putAndInsertUint16(DCM_Rows, 16).good()); |
| 98 | + OFCHECK(dataset.putAndInsertUint16(DCM_Columns, 16).good()); |
| 99 | + OFCHECK(dataset.putAndInsertUint16(DCM_BitsAllocated, 8).good()); |
| 100 | + OFCHECK(dataset.putAndInsertUint16(DCM_BitsStored, 8).good()); |
| 101 | + OFCHECK(dataset.putAndInsertUint16(DCM_HighBit, 7).good()); |
| 102 | + OFCHECK(dataset.putAndInsertUint8Array(DCM_PixelData, pixelData[0], sizeof(pixelData)).good()); |
| 103 | + |
| 104 | + /* create an icon image with 64x64 pixels */ |
| 105 | + OFCHECK(imgValue.createIconImage(&dataset, EXS_Unknown /*xfer*/, 0 /*frame*/, 64 /*width*/, 64 /*height*/).good()); |
| 106 | + OFCHECK(imgValue.hasIconImage()); |
| 107 | + |
| 108 | + /* set value to image tree node and write to item */ |
| 109 | + DcmItem item; |
| 110 | + DSRImageTreeNode imgNode(DSRTypes::RT_hasProperties); |
| 111 | + OFCHECK(imgNode.setConceptName(CODE_DCM_BestIllustrationOfFinding).good()); |
| 112 | + OFCHECK(imgNode.setValue(imgValue).good()); |
| 113 | + OFCHECK(imgNode.hasIconImage()); |
| 114 | + OFCHECK(imgNode.write(item).good()); |
| 115 | + /* output content of the item (in debug mode only) */ |
| 116 | + if (DCM_dcmsrLogger.isEnabledFor(OFLogger::DEBUG_LOG_LEVEL)) |
| 117 | + item.print(COUT, DCMTypes::PF_shortenLongTagValues /*flags*/, 2 /*level*/); |
| 118 | + |
| 119 | + /* delete the icon image */ |
| 120 | + imgNode.deleteIconImage(); |
| 121 | + OFCHECK(!imgNode.hasIconImage()); |
| 122 | +} |
0 commit comments