1 /*
2 *
3 * Copyright (C) 1998-2018, 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: dcmpstat
15 *
16 * Author: Marco Eichelberg
17 *
18 * Purpose:
19 * classes: DVPSGraphicLayer
20 *
21 */
22
23 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
24 #include "dcmtk/dcmpstat/dvpsgl.h"
25 #include "dcmtk/dcmpstat/dvpsdef.h" /* for constants and macros */
26
27 #define INCLUDE_CSTDIO
28 #include "dcmtk/ofstd/ofstdinc.h"
29
30 /* --------------- class DVPSGraphicLayer --------------- */
31
DVPSGraphicLayer()32 DVPSGraphicLayer::DVPSGraphicLayer()
33 : graphicLayer(DCM_GraphicLayer)
34 , graphicLayerOrder(DCM_GraphicLayerOrder)
35 , graphicLayerRecommendedDisplayGrayscaleValue(DCM_GraphicLayerRecommendedDisplayGrayscaleValue)
36 , graphicLayerRecommendedDisplayRGBValue(DCM_RETIRED_GraphicLayerRecommendedDisplayRGBValue)
37 , graphicLayerDescription(DCM_GraphicLayerDescription)
38 {
39 }
40
DVPSGraphicLayer(const DVPSGraphicLayer & copy)41 DVPSGraphicLayer::DVPSGraphicLayer(const DVPSGraphicLayer& copy)
42 : graphicLayer(copy.graphicLayer)
43 , graphicLayerOrder(copy.graphicLayerOrder)
44 , graphicLayerRecommendedDisplayGrayscaleValue(copy.graphicLayerRecommendedDisplayGrayscaleValue)
45 , graphicLayerRecommendedDisplayRGBValue(copy.graphicLayerRecommendedDisplayRGBValue)
46 , graphicLayerDescription(copy.graphicLayerDescription)
47 {
48 }
49
~DVPSGraphicLayer()50 DVPSGraphicLayer::~DVPSGraphicLayer()
51 {
52 }
53
read(DcmItem & dset)54 OFCondition DVPSGraphicLayer::read(DcmItem &dset)
55 {
56 OFCondition result = EC_Normal;
57 DcmStack stack;
58
59 READ_FROM_DATASET(DcmCodeString, EVR_CS, graphicLayer)
60 READ_FROM_DATASET(DcmIntegerString, EVR_IS, graphicLayerOrder)
61 READ_FROM_DATASET(DcmUnsignedShort, EVR_US, graphicLayerRecommendedDisplayGrayscaleValue)
62 READ_FROM_DATASET(DcmUnsignedShort, EVR_US, graphicLayerRecommendedDisplayRGBValue)
63 READ_FROM_DATASET(DcmLongString, EVR_LO, graphicLayerDescription)
64
65 /* Now perform basic sanity checks */
66
67 if (graphicLayer.getLength() == 0)
68 {
69 result=EC_IllegalCall;
70 DCMPSTAT_WARN("presentation state contains a graphic layer SQ item with graphicLayer absent or empty");
71 }
72 else if (graphicLayer.getVM() != 1)
73 {
74 result=EC_IllegalCall;
75 DCMPSTAT_WARN("presentation state contains a graphic layer SQ item with graphicLayer VM != 1");
76 }
77
78 if (graphicLayerOrder.getLength() == 0)
79 {
80 result=EC_IllegalCall;
81 DCMPSTAT_WARN("presentation state contains a graphic layer SQ item with graphicLayerOrder absent or empty");
82 }
83 else if (graphicLayerOrder.getVM() != 1)
84 {
85 result=EC_IllegalCall;
86 DCMPSTAT_WARN("presentation state contains a graphic layer SQ item with graphicLayerOrder VM != 1");
87 }
88
89 if (graphicLayerRecommendedDisplayGrayscaleValue.getVM()>1)
90 {
91 result=EC_IllegalCall;
92 DCMPSTAT_WARN("presentation state contains a graphic layer SQ item with graphicLayerRecommendedDisplayGrayscaleValue VM != 1");
93 }
94
95 if ((graphicLayerRecommendedDisplayRGBValue.getVM()>0)&&(graphicLayerRecommendedDisplayRGBValue.getVM() != 3))
96 {
97 result=EC_IllegalCall;
98 DCMPSTAT_WARN("presentation state contains a graphic layer SQ item with graphicLayerRecommendedDisplayRGBValue VM != 3");
99 }
100
101 if (graphicLayerDescription.getVM() > 1)
102 {
103 result=EC_IllegalCall;
104 DCMPSTAT_WARN("presentation state contains a graphic layer SQ item with graphicLayerDescription VM > 1");
105 }
106
107 return result;
108 }
109
write(DcmItem & dset)110 OFCondition DVPSGraphicLayer::write(DcmItem &dset)
111 {
112 OFCondition result = EC_Normal;
113 DcmElement *delem=NULL;
114
115 ADD_TO_DATASET(DcmCodeString, graphicLayer)
116 ADD_TO_DATASET(DcmIntegerString, graphicLayerOrder)
117 if (graphicLayerRecommendedDisplayGrayscaleValue.getLength() >0) { ADD_TO_DATASET(DcmUnsignedShort, graphicLayerRecommendedDisplayGrayscaleValue) }
118 if (graphicLayerRecommendedDisplayRGBValue.getLength() >0) { ADD_TO_DATASET(DcmUnsignedShort, graphicLayerRecommendedDisplayRGBValue) }
119 if (graphicLayerDescription.getLength() >0) { ADD_TO_DATASET(DcmLongString, graphicLayerDescription) }
120
121 return result;
122 }
123
getGL()124 const char *DVPSGraphicLayer::getGL()
125 {
126 char *c = NULL;
127 if (EC_Normal == graphicLayer.getString(c)) return c; else return NULL;
128 }
129
getGLDescription()130 const char *DVPSGraphicLayer::getGLDescription()
131 {
132 char *c = NULL;
133 if (EC_Normal == graphicLayerDescription.getString(c)) return c; else return NULL;
134 }
135
136
setGL(const char * gl)137 void DVPSGraphicLayer::setGL(const char *gl)
138 {
139 if (gl) graphicLayer.putString(gl); else graphicLayer.clear();
140 return;
141 }
142
setGLOrder(Sint32 glOrder)143 void DVPSGraphicLayer::setGLOrder(Sint32 glOrder)
144 {
145 char buf[100];
146 sprintf(buf, "%ld", (long)glOrder);
147 graphicLayerOrder.putString(buf);
148 return;
149 }
150
setGLRecommendedDisplayValueGray(Uint16 gray)151 void DVPSGraphicLayer::setGLRecommendedDisplayValueGray(Uint16 gray)
152 {
153 graphicLayerRecommendedDisplayGrayscaleValue.clear();
154 graphicLayerRecommendedDisplayGrayscaleValue.putUint16(gray,0);
155 return;
156 }
157
setGLRecommendedDisplayValueRGB(Uint16 r,Uint16 g,Uint16 b)158 void DVPSGraphicLayer::setGLRecommendedDisplayValueRGB(Uint16 r, Uint16 g, Uint16 b)
159 {
160 graphicLayerRecommendedDisplayRGBValue.clear();
161 graphicLayerRecommendedDisplayRGBValue.putUint16(r,0);
162 graphicLayerRecommendedDisplayRGBValue.putUint16(g,1);
163 graphicLayerRecommendedDisplayRGBValue.putUint16(b,2);
164 return;
165 }
166
setGLDescription(const char * glDescription)167 void DVPSGraphicLayer::setGLDescription(const char *glDescription)
168 {
169 if (glDescription) graphicLayerDescription.putString(glDescription); else graphicLayerDescription.clear();
170 return;
171 }
172
173
getGLOrder()174 Sint32 DVPSGraphicLayer::getGLOrder()
175 {
176 Sint32 result=0;
177 if (EC_Normal == graphicLayerOrder.getSint32(result,0)) return result; else return 0;
178 }
179
haveGLRecommendedDisplayValue()180 OFBool DVPSGraphicLayer::haveGLRecommendedDisplayValue()
181 {
182 if ((graphicLayerRecommendedDisplayGrayscaleValue.getVM() == 1) ||
183 (graphicLayerRecommendedDisplayRGBValue.getVM() == 3))
184 return OFTrue; else return OFFalse;
185 }
186
getGLRecommendedDisplayValueGray(Uint16 & gray)187 OFCondition DVPSGraphicLayer::getGLRecommendedDisplayValueGray(Uint16& gray)
188 {
189 gray = 0;
190 OFCondition result = EC_Normal;
191 if (graphicLayerRecommendedDisplayGrayscaleValue.getVM()==1)
192 {
193 Uint16 gr=0;
194 result = graphicLayerRecommendedDisplayGrayscaleValue.getUint16(gr,0);
195 if (result==EC_Normal) gray = gr;
196 } else if (graphicLayerRecommendedDisplayRGBValue.getVM() == 3)
197 {
198 Uint16 r=0;
199 Uint16 g=0;
200 Uint16 b=0;
201 result = graphicLayerRecommendedDisplayRGBValue.getUint16(r,0);
202 if (EC_Normal==result) result = graphicLayerRecommendedDisplayRGBValue.getUint16(g,1);
203 if (EC_Normal==result) result = graphicLayerRecommendedDisplayRGBValue.getUint16(b,2);
204 if (result==EC_Normal)
205 {
206 double dg = 0.299*(double)r + 0.587*(double)g +0.114*(double)b;
207 gray = (Uint16) dg;
208 }
209 } else result=EC_IllegalCall;
210 return result;
211 }
212
getGLRecommendedDisplayValueRGB(Uint16 & r,Uint16 & g,Uint16 & b)213 OFCondition DVPSGraphicLayer::getGLRecommendedDisplayValueRGB(Uint16& r, Uint16& g, Uint16& b)
214 {
215 r = 0;
216 g = 0;
217 b = 0;
218 OFCondition result = EC_Normal;
219 if (graphicLayerRecommendedDisplayRGBValue.getVM()==3)
220 {
221 Uint16 rr=0;
222 Uint16 gg=0;
223 Uint16 bb=0;
224 result = graphicLayerRecommendedDisplayRGBValue.getUint16(rr,0);
225 if (EC_Normal==result) result = graphicLayerRecommendedDisplayRGBValue.getUint16(gg,1);
226 if (EC_Normal==result) result = graphicLayerRecommendedDisplayRGBValue.getUint16(bb,2);
227 if (result==EC_Normal)
228 {
229 r = rr;
230 g = gg;
231 b = bb;
232 }
233 }
234 else if (graphicLayerRecommendedDisplayGrayscaleValue.getVM() == 1)
235 {
236 Uint16 gr=0;
237 result = graphicLayerRecommendedDisplayGrayscaleValue.getUint16(gr,0);
238 if (result==EC_Normal)
239 {
240 r = gr;
241 g = gr;
242 b = gr;
243 }
244 } else result=EC_IllegalCall;
245 return result;
246 }
247
removeRecommendedDisplayValue(OFBool rgb,OFBool monochrome)248 void DVPSGraphicLayer::removeRecommendedDisplayValue(OFBool rgb, OFBool monochrome)
249 {
250 if (rgb) graphicLayerRecommendedDisplayRGBValue.clear();
251 if (monochrome) graphicLayerRecommendedDisplayGrayscaleValue.clear();
252 return;
253 }
254