/* * * Copyright (C) 1998-2018, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by * * OFFIS e.V. * R&D Division Health * Escherweg 2 * D-26121 Oldenburg, Germany * * * Module: dcmpstat * * Author: Marco Eichelberg * * Purpose: * classes: DVPSGraphicObject * */ #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ #include "dcmtk/dcmpstat/dvpsgr.h" #include "dcmtk/ofstd/ofstring.h" #include "dcmtk/dcmpstat/dvpsdef.h" /* for constants and macros */ /* --------------- class DVPSGraphicObject --------------- */ DVPSGraphicObject::DVPSGraphicObject() : graphicAnnotationUnits(DCM_GraphicAnnotationUnits) , numberOfGraphicPoints(DCM_NumberOfGraphicPoints) , graphicData(DCM_GraphicData) , graphicType(DCM_GraphicType) , graphicFilled(DCM_GraphicFilled) { } DVPSGraphicObject::DVPSGraphicObject(const DVPSGraphicObject& copy) : graphicAnnotationUnits(copy.graphicAnnotationUnits) , numberOfGraphicPoints(copy.numberOfGraphicPoints) , graphicData(copy.graphicData) , graphicType(copy.graphicType) , graphicFilled(copy.graphicFilled) { } DVPSGraphicObject::~DVPSGraphicObject() { } OFCondition DVPSGraphicObject::read(DcmItem &dset) { OFCondition result = EC_Normal; DcmStack stack; DcmUnsignedShort graphicDimensions(DCM_GraphicDimensions); // VR=US, VM=1, Type 1 READ_FROM_DATASET(DcmCodeString, EVR_CS, graphicAnnotationUnits) READ_FROM_DATASET(DcmUnsignedShort, EVR_US, graphicDimensions) READ_FROM_DATASET(DcmUnsignedShort, EVR_US, numberOfGraphicPoints) READ_FROM_DATASET(DcmFloatingPointSingle, EVR_FL, graphicData) READ_FROM_DATASET(DcmCodeString, EVR_CS, graphicType) READ_FROM_DATASET(DcmCodeString, EVR_CS, graphicFilled) /* Now perform basic sanity checks */ if (graphicAnnotationUnits.getLength() == 0) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with graphicAnnotationUnits absent or empty"); } else if (graphicAnnotationUnits.getVM() != 1) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with graphicAnnotationUnits VM != 1"); } if (graphicDimensions.getVM() != 1) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with graphicDimensions VM != 1"); } else { Uint16 dimension=0; if ((EC_Normal != graphicDimensions.getUint16(dimension,0))||(dimension != 2)) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with graphicDimensions != 2"); } } if (numberOfGraphicPoints.getLength() == 0) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with numberOfGraphicPoints absent or empty"); } else if (numberOfGraphicPoints.getVM() != 1) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with numberOfGraphicPoints VM != 1"); } if (graphicData.getLength() == 0) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with graphicData absent or empty"); } else if (graphicData.getVM() < 2) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with graphicData VM < 2"); } if (graphicType.getLength() == 0) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with graphicType absent or empty"); } else if (graphicType.getVM() != 1) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with graphicType VM != 1"); } if ((graphicFilled.getLength() > 0)&&(graphicFilled.getVM() != 1)) { result=EC_IllegalCall; DCMPSTAT_WARN("presentation state contains a graphic object SQ item with graphicFilled present but VM != 1"); } return result; } OFCondition DVPSGraphicObject::write(DcmItem &dset) { OFCondition result = EC_Normal; DcmElement *delem=NULL; DcmUnsignedShort graphicDimensions(DCM_GraphicDimensions); // VR=US, VM=1, Type 1 Uint16 dimensions=2; graphicDimensions.putUint16(dimensions,0); ADD_TO_DATASET(DcmCodeString, graphicAnnotationUnits) ADD_TO_DATASET(DcmUnsignedShort, graphicDimensions) ADD_TO_DATASET(DcmUnsignedShort, numberOfGraphicPoints) ADD_TO_DATASET(DcmFloatingPointSingle, graphicData) ADD_TO_DATASET(DcmCodeString, graphicType) // strictly speaking we are not allowed to include graphicFilled // when the graphicType is "POLYLINE" or "INTERPOLATED" and the // first point of graphicData is not equal the last point. // For simplicity reasons we always include the attribute unless // the graphic type is POINT. if (DVPST_point != getGraphicType()) { ADD_TO_DATASET(DcmCodeString, graphicFilled) } return result; } DVPSannotationUnit DVPSGraphicObject::getAnnotationUnits() { DVPSannotationUnit aresult = DVPSA_pixels; OFString aString; OFCondition result = graphicAnnotationUnits.getOFString(aString,0); if ((result==EC_Normal)&&(aString == "DISPLAY")) aresult = DVPSA_display; return aresult; } size_t DVPSGraphicObject::getNumberOfPoints() { Uint16 result=0; if (EC_Normal == numberOfGraphicPoints.getUint16(result,0)) return result; else return 0; } OFCondition DVPSGraphicObject::getPoint(size_t idx, Float32& x, Float32& y) { x=0.0; y=0.0; OFCondition result = EC_IllegalCall; if ((idx*2+1)