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
|
/*
*
* Copyright (C) 1998-2005, OFFIS
*
* This software and supporting documentation were developed by
*
* Kuratorium OFFIS e.V.
* Healthcare Information and Communication Systems
* Escherweg 2
* D-26121 Oldenburg, Germany
*
* THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY
* REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR
* FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR
* ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
* PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
*
* Module: dcmpstat
*
* Author: Marco Eichelberg
*
* Purpose:
* classes: DVPSCurve
*
* Last Update: $Author: meichel $
* Update Date: $Date: 2005/12/08 15:46:21 $
* CVS/RCS Revision: $Revision: 1.6 $
* Status: $State: Exp $
*
* CVS/RCS Log at end of file
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmpstat/dvpscu.h"
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/ofstd/ofbmanip.h"
DVPSCurve::DVPSCurve()
: curveGroup(0)
, numberOfPoints(0)
, typeOfData(DVPSL_polylineCurve)
, curveData(NULL)
, curveDescription()
, curveLabel()
, axisUnitsX()
, axisUnitsY()
, logstream(&ofConsole)
, verboseMode(OFFalse)
, debugMode(OFFalse)
{
}
DVPSCurve::DVPSCurve(const DVPSCurve& copy)
: curveGroup(copy.curveGroup)
, numberOfPoints(copy.numberOfPoints)
, typeOfData(copy.typeOfData)
, curveData(NULL)
, curveDescription(copy.curveDescription)
, curveLabel(copy.curveLabel)
, axisUnitsX(copy.axisUnitsX)
, axisUnitsY(copy.axisUnitsY)
, logstream(copy.logstream)
, verboseMode(copy.verboseMode)
, debugMode(copy.debugMode)
{
if (copy.curveData)
{
curveData = new double[2*numberOfPoints];
if (curveData)
{
OFBitmanipTemplate<double>::copyMem(copy.curveData, curveData, 2*numberOfPoints);
}
}
}
DVPSCurve::~DVPSCurve()
{
if (curveData) delete[] curveData;
}
OFCondition DVPSCurve::read(DcmItem &dset, Uint8 group)
{
OFCondition result = EC_Normal;
DcmStack stack;
curveGroup = group;
DcmElement *d_curveDimensions = NULL;
DcmElement *d_numberOfPoints = NULL;
DcmElement *d_typeOfData = NULL;
DcmElement *d_dataVR = NULL;
DcmElement *d_curveData = NULL;
DcmElement *d_curveDescription = NULL;
DcmElement *d_axisUnits = NULL;
DcmElement *d_curveLabel = NULL;
/* first we look for the Curve Data */
DcmTagKey key(0x5000 + group,0x3000);
if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
{
d_curveData = (DcmElement *)(stack.top());
} else return EC_IllegalCall;
key.setElement(0x0005); // Curve Dimensions
stack.clear();
if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
{
d_curveDimensions = (DcmElement *)(stack.top());
} else return EC_IllegalCall;
key.setElement(0x0110); // Curve Data Descriptor
stack.clear();
if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
{
return EC_IllegalCall; // we don't support curves with Curve Data Descriptor!
}
key.setElement(0x0010); // Number of Points
stack.clear();
if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
{
d_numberOfPoints = (DcmElement *)(stack.top());
} else return EC_IllegalCall;
key.setElement(0x0020); // Type of Data
stack.clear();
if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
{
d_typeOfData = (DcmElement *)(stack.top());
} else return EC_IllegalCall;
key.setElement(0x0103); // Data Value Representation
stack.clear();
if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
{
d_dataVR = (DcmElement *)(stack.top());
} else return EC_IllegalCall;
key.setElement(0x0022); // Curve Description
stack.clear();
if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
{
d_curveDescription = (DcmElement *)(stack.top());
}
key.setElement(0x0030); // Axis Units
stack.clear();
if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
{
d_axisUnits = (DcmElement *)(stack.top());
}
key.setElement(0x2500); // Curve Label
stack.clear();
if (EC_Normal == dset.search(key, stack, ESM_fromHere, OFFalse))
{
d_curveLabel = (DcmElement *)(stack.top());
}
Uint16 u=0;
if ((EC_Normal != d_curveDimensions->getUint16(u,0))||(u != 2))
{
// Curve Dimensions unreadable or != 2, bail out
return EC_IllegalCall;
}
u=0;
if ((EC_Normal != d_numberOfPoints->getUint16(u,0))||(u == 0))
{
// Number of Points == 0 or unreadable, bail out.
return EC_IllegalCall;
} else numberOfPoints = u;
OFString aString;
if (EC_Normal != d_typeOfData->getOFString(aString,0))
{
// cannot read type of data, bail out
return EC_IllegalCall;
} else {
if (aString == "ROI") typeOfData=DVPSL_roiCurve;
else if (aString == "POLY") typeOfData=DVPSL_polylineCurve;
else return EC_IllegalCall; // unsupported type of data, bail out
}
if ((d_curveDescription) &&(EC_Normal == d_curveDescription->getOFString(aString,0)))
{
curveDescription = aString;
}
if ((d_axisUnits) &&(EC_Normal == d_axisUnits->getOFString(aString,0)))
{
axisUnitsX = aString;
}
if ((d_axisUnits) &&(EC_Normal == d_axisUnits->getOFString(aString,1)))
{
axisUnitsY = aString;
}
if ((d_curveLabel) &&(EC_Normal == d_curveLabel->getOFString(aString,0)))
{
curveLabel = aString;
}
Uint16 dataVR=0;
if (EC_Normal != d_dataVR->getUint16(dataVR,0))
{
// cannot read curve data VR, bail out
return EC_IllegalCall;
}
curveData = new double[numberOfPoints*2];
if (curveData==NULL) return EC_MemoryExhausted;
void *rawData=NULL;
size_t align=0;
Uint8 *pui8=NULL;
Uint16 *pui16=NULL;
Sint16 *psi16=NULL;
Float32 *pfl32=NULL;
Float64 *pfl64=NULL;
Sint32 *psi32=NULL;
switch (d_curveData->ident())
{
case EVR_OB:
case EVR_OW:
case EVR_ox:
case EVR_US:
if (EC_Normal == d_curveData->getUint8Array(pui8))
{
rawData = pui8;
align = 1;
}
else if (EC_Normal == d_curveData->getUint16Array(pui16))
{
rawData = pui16;
align = sizeof(Uint16);
}
else result = EC_IllegalCall;
break;
case EVR_SS:
if (EC_Normal == d_curveData->getSint16Array(psi16))
{
rawData = psi16;
align = sizeof(Sint16);
} else result = EC_IllegalCall;
break;
case EVR_FL:
if (EC_Normal == d_curveData->getFloat32Array(pfl32))
{
rawData = pfl32;
align = sizeof(Float32);
} else result = EC_IllegalCall;
break;
case EVR_FD:
if (EC_Normal == d_curveData->getFloat64Array(pfl64))
{
rawData = pfl64;
align = sizeof(Float64);
} else result = EC_IllegalCall;
break;
case EVR_SL:
if (EC_Normal == d_curveData->getSint32Array(psi32))
{
rawData = psi32;
align = sizeof(Sint32);
} else result = EC_IllegalCall;
break;
default:
result = EC_IllegalCall;
break;
}
size_t byteLength = (size_t)(d_curveData->getLength());
size_t maxidx = 2*numberOfPoints;
size_t i;
switch (dataVR)
{
case 0: // VR=US. align can be 1 or 2
if ((align==1)||(align==sizeof(Uint16)))
{
if (align==1) swapIfNecessary(gLocalByteOrder, EBO_LittleEndian, rawData, byteLength, sizeof(Uint16));
if (maxidx*sizeof(Uint16) <= byteLength)
{
for (i=0; i<maxidx; i++) curveData[i] = (double)(((Uint16 *)rawData)[i]);
} else result=EC_IllegalCall;
} else result=EC_IllegalCall;
break;
case 1: // VR=SS. align can be 1 or 2
if ((align==1)||(align==sizeof(Sint16)))
{
if (align==1) swapIfNecessary(gLocalByteOrder, EBO_LittleEndian, rawData, byteLength, sizeof(Sint16));
if (maxidx*sizeof(Sint16) <= byteLength)
{
for (i=0; i<maxidx; i++) curveData[i] = (double)(((Sint16 *)rawData)[i]);
} else result=EC_IllegalCall;
} else result=EC_IllegalCall;
break;
case 2: // VR=FL. align can be 1, 2, 4
if ((align==1)||(align==sizeof(Uint16))||(align==sizeof(Float32)))
{
// if data is word aligned, first swap back to little endian OB
if (align==sizeof(Uint16)) swapIfNecessary(EBO_LittleEndian, gLocalByteOrder, rawData, byteLength, sizeof(Uint16));
if ((align==1)||(align==sizeof(Uint16)))
swapIfNecessary(gLocalByteOrder, EBO_LittleEndian, rawData, byteLength, sizeof(Float32));
if (maxidx*sizeof(Float32) <= byteLength)
{
for (i=0; i<maxidx; i++) curveData[i] = (double)(((Float32 *)rawData)[i]);
} else result=EC_IllegalCall;
} else result=EC_IllegalCall;
break;
case 3: // VR=FD. align can be 1, 2, 8
if ((align==1)||(align==sizeof(Uint16))||(align==sizeof(Float64)))
{
// if data is word aligned, first swap back to little endian OB
if (align==sizeof(Uint16)) swapIfNecessary(EBO_LittleEndian, gLocalByteOrder, rawData, byteLength, sizeof(Uint16));
if ((align==1)||(align==sizeof(Uint16)))
swapIfNecessary(gLocalByteOrder, EBO_LittleEndian, rawData, byteLength, sizeof(Float64));
if (maxidx*sizeof(Float64) <= byteLength)
{
for (i=0; i<maxidx; i++) curveData[i] = (double)(((Float64 *)rawData)[i]);
} else result=EC_IllegalCall;
} else result=EC_IllegalCall;
break;
case 4: // VR=SL. align can be 1, 2, 4
if ((align==1)||(align==sizeof(Uint16))||(align==sizeof(Sint32)))
{
// if data is word aligned, first swap back to little endian OB
if (align==sizeof(Uint16)) swapIfNecessary(EBO_LittleEndian, gLocalByteOrder, rawData, byteLength, sizeof(Uint16));
if ((align==1)||(align==sizeof(Uint16)))
swapIfNecessary(gLocalByteOrder, EBO_LittleEndian, rawData, byteLength, sizeof(Sint32));
if (maxidx*sizeof(Sint32) <= byteLength)
{
for (i=0; i<maxidx; i++) curveData[i] = (double)(((Sint32 *)rawData)[i]);
} else result=EC_IllegalCall;
} else result=EC_IllegalCall;
break;
default:
result = EC_IllegalCall;
break;
}
return result;
}
OFCondition DVPSCurve::getPoint(size_t idx, double& x, double& y)
{
x=0.0;
y=0.0;
if (idx < numberOfPoints)
{
x = curveData[2*idx];
y = curveData[2*idx+1];
} else return EC_IllegalCall;
return EC_Normal;
}
void DVPSCurve::setLog(OFConsole *stream, OFBool verbMode, OFBool dbgMode)
{
if (stream) logstream = stream; else logstream = &ofConsole;
verboseMode = verbMode;
debugMode = dbgMode;
}
/*
* $Log: dvpscu.cc,v $
* Revision 1.6 2005/12/08 15:46:21 meichel
* Changed include path schema for all DCMTK header files
*
* Revision 1.5 2001/09/26 15:36:23 meichel
* Adapted dcmpstat to class OFCondition
*
* Revision 1.4 2001/06/01 15:50:28 meichel
* Updated copyright header
*
* Revision 1.3 2000/06/02 16:00:58 meichel
* Adapted all dcmpstat classes to use OFConsole for log and error output
*
* Revision 1.2 2000/03/08 16:29:03 meichel
* Updated copyright header.
*
* Revision 1.1 1998/12/22 17:57:14 meichel
* Implemented Presentation State interface for overlays,
* VOI LUTs, VOI windows, curves. Added test program that
* allows to add curve data to DICOM images.
*
*
*/
|