1 /*
2 *
3 * Copyright (C) 2019-2020, OFFIS e.V.
4 * All rights reserved. See COPYRIGHT file for details.
5 *
6 * This software and supporting documentation were developed by
7 *
8 * OFFIS e.V.
9 * R&D Division Health
10 * Escherweg 2
11 * D-26121 Oldenburg, Germany
12 *
13 *
14 * Module: dcmfg
15 *
16 * Author: Michael Onken
17 *
18 * Purpose: Tests for CT Image Frame Type FG class
19 *
20 */
21
22 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
23
24 #include "dcmtk/dcmfg/fgctimageframetype.h"
25 #include "dcmtk/dcmfg/fginterface.h"
26 #include "dcmtk/ofstd/ofcond.h"
27 #include "dcmtk/ofstd/oftest.h"
28
init_template(OFString & fg_dump)29 static void init_template(OFString& fg_dump)
30 {
31 fg_dump += "(fffe,e000) na (Item with explicit length #=1) # 0, 1 Item\n";
32 fg_dump += "(0018,9329) SQ (Sequence with explicit length #=1) # 0, 1 CTImageFrameTypeSequence\n";
33 fg_dump += " (fffe,e000) na (Item with explicit length #=4) # 0, 1 Item\n";
34 fg_dump += " (0008,9007) CS [ORIGINAL\\PRIMARY\\VOLUME\\NONE] # 28, 4 FrameType\n";
35 fg_dump += " (0008,9205) CS [MONOCHROME] # 10, 1 PixelPresentation\n";
36 fg_dump += " (0008,9206) CS [VOLUME] # 6, 1 VolumetricProperties\n";
37 fg_dump += " (0008,9207) CS [VOLUME_RENDER] # 14, 1 VolumeBasedCalculationTechnique\n";
38 fg_dump += " (fffe,e00d) na (ItemDelimitationItem for re-encoding) # 0, 0 ItemDelimitationItem\n";
39 fg_dump += "(fffe,e0dd) na (SequenceDelimitationItem for re-encod.) # 0, 0 SequenceDelimitationItem\n";
40 fg_dump += "(fffe,e00d) na (ItemDelimitationItem for re-encoding) # 0, 0 ItemDelimitationItem\n";
41 }
42
check_ct_image_frame_type_fg(FGCTImageFrameType & fg)43 static void check_ct_image_frame_type_fg(FGCTImageFrameType& fg)
44 {
45 OFCondition result;
46 OFString val;
47 OFCHECK(fg.getFrameType(val, -1 /* all components */).good());
48 OFCHECK(val == "ORIGINAL\\PRIMARY\\VOLUME\\NONE");
49 OFCHECK(fg.getPixelPresentation(val).good());
50 OFCHECK(val == "MONOCHROME");
51 OFCHECK(fg.getVolumetricProperties(val).good());
52 OFCHECK(val == "VOLUME");
53 OFCHECK(fg.getVolumeBasedCalculationTechnique(val).good());
54 OFCHECK(val == "VOLUME_RENDER");
55
56 // Check enum getters
57 FGCTImageFrameType::E_PixelPresentation pix;
58 OFCHECK(fg.getPixelPresentation(pix).good());
59 OFCHECK(pix == FGCTImageFrameType::E_PixelPres_Monochrome);
60
61 FGCTImageFrameType::E_VolumetricProperties vol;
62 OFCHECK(fg.getVolumetricProperties(vol).good());
63 OFCHECK(vol == FGCTImageFrameType::E_VolProp_Volume);
64 }
65
OFTEST(dcmfg_ct_image_frame_type)66 OFTEST(dcmfg_ct_image_frame_type)
67 {
68 // Make sure data dictionary is loaded
69 if (!dcmDataDict.isDictionaryLoaded())
70 {
71 OFCHECK_FAIL("no data dictionary loaded, check environment variable: " DCM_DICT_ENVIRONMENT_VARIABLE);
72 return;
73 }
74
75 OFString fg_dump;
76 init_template(fg_dump);
77
78 FGCTImageFrameType fg;
79 OFCHECK(fg.setFrameType("ORIGINAL\\PRIMARY\\VOLUME\\NONE").good());
80 OFCHECK(fg.setPixelPresentation(FGCTImageFrameType::E_PixelPres_Monochrome).good());
81 OFCHECK(fg.setVolumetricProperties(FGCTImageFrameType::E_VolProp_Volume).good());
82 OFCHECK(fg.setVolumeBasedCalculationTechnique(FGCTImageFrameType::DT_VolBasedCalcTechnique_VolumeRender).good());
83
84 // Check data structure in memory
85 check_ct_image_frame_type_fg(fg);
86
87 // Write to DcmItem and compare with pre-defined template
88 DcmItem dest_item;
89 OFCondition result = fg.write(dest_item);
90 OFCHECK(result.good());
91 OFStringStream out;
92 dest_item.print(out);
93 OFCHECK(out.str() == fg_dump.c_str()); /**/
94
95 // Test read method: Read from dataset, write again, and compare another time
96 FGCTImageFrameType fg_for_read;
97 out.str(""); // set to empty
98 fg_for_read.read(dest_item);
99 dest_item.clear();
100 result = fg_for_read.write(dest_item);
101 OFCHECK(result.good());
102 dest_item.print(out);
103 OFCHECK(out.str() == fg_dump.c_str());
104
105 // Test compare() method
106 OFCHECK(fg.compare(fg_for_read) == 0);
107 OFCHECK(fg_for_read.setVolumetricProperties(FGCTImageFrameType::E_VolProp_Distorted).good());
108 OFCHECK(fg.compare(fg_for_read) != 0);
109
110 // Test clone() method
111 FGCTImageFrameType* clone = OFstatic_cast(FGCTImageFrameType*, fg.clone());
112 OFCHECK(clone != NULL);
113 OFCHECK(clone->compare(fg) == 0);
114 delete clone;
115 }
116