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
|
/*
*
* Copyright (C) 2015-2022, Open Connections GmbH
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation are maintained by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmseg
*
* Author: Michael Onken
*
* Purpose: Class representing a Segment from the Segment Ident. Sequence
*
*/
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmiod/iodutil.h"
#include "dcmtk/dcmseg/segdoc.h"
#include "dcmtk/dcmseg/segment.h"
#include "dcmtk/dcmseg/segtypes.h"
OFCondition DcmSegment::create(DcmSegment*& segment,
const OFString& segmentLabel,
const CodeSequenceMacro& segmentedPropertyCategory,
const CodeSequenceMacro& segmentedPropertyType,
const DcmSegTypes::E_SegmentAlgoType algoType,
const OFString& algoName)
{
segment = new DcmSegment();
if (segment == NULL)
return EC_MemoryExhausted;
OFCondition result = segment->setSegmentLabel(segmentLabel, OFTrue /* check value */);
if (result.good())
{
segment->m_SegmentDescription.getSegmentedPropertyCategoryCode() = segmentedPropertyCategory;
result = segment->m_SegmentDescription.getSegmentedPropertyCategoryCode().check();
}
if (result.good())
{
segment->m_SegmentDescription.getSegmentedPropertyTypeCode() = segmentedPropertyType;
result = segment->getSegmentedPropertyTypeCode().check();
}
if (result.good())
{
result = segment->setSegmentAlgorithm(algoType, algoName, OFTrue);
}
if (result.bad())
{
delete segment;
segment = NULL;
}
return result;
}
OFCondition DcmSegment::read(DcmItem& item, const OFBool clearOldData)
{
if (clearOldData)
clearData();
m_SegmentDescription.read(item);
DcmIODUtil::getAndCheckElementFromDataset(item, m_SegmentAlgorithmName, m_Rules.getByTag(DCM_SegmentAlgorithmName));
DcmIODUtil::readSingleItem<AlgorithmIdentificationMacro>(item,
DCM_SegmentationAlgorithmIdentificationSequence,
m_SegmentationAlgorithmIdentification,
"3",
"Segmentation Image Module");
DcmIODUtil::getAndCheckElementFromDataset(
item, m_RecommendedDisplayGrayscaleValue, m_Rules.getByTag(DCM_RecommendedDisplayGrayscaleValue));
DcmIODUtil::getAndCheckElementFromDataset(
item, m_RecommendedDisplayCIELabValue, m_Rules.getByTag(DCM_RecommendedDisplayCIELabValue));
DcmIODUtil::getAndCheckElementFromDataset(item, m_TrackingID, m_Rules.getByTag(DCM_TrackingID));
DcmIODUtil::getAndCheckElementFromDataset(item, m_TrackingUID, m_Rules.getByTag(DCM_TrackingUID));
return EC_Normal;
}
OFCondition DcmSegment::write(DcmItem& item)
{
OFCondition result;
result = m_SegmentDescription.write(item);
DcmIODUtil::copyElementToDataset(result, item, m_SegmentAlgorithmName, m_Rules.getByTag(DCM_SegmentAlgorithmName));
if (result.good() && m_SegmentationAlgorithmIdentification.check(OFTrue /* quiet */).good())
{
DcmIODUtil::writeSingleItem<AlgorithmIdentificationMacro>(result,
DCM_SegmentationAlgorithmIdentificationSequence,
m_SegmentationAlgorithmIdentification,
item,
"3",
"Segmentation Image Module");
}
DcmIODUtil::copyElementToDataset(
result, item, m_RecommendedDisplayGrayscaleValue, m_Rules.getByTag(DCM_RecommendedDisplayGrayscaleValue));
DcmIODUtil::copyElementToDataset(
result, item, m_RecommendedDisplayCIELabValue, m_Rules.getByTag(DCM_RecommendedDisplayCIELabValue));
DcmIODUtil::copyElementToDataset(result, item, m_TrackingID, m_Rules.getByTag(DCM_TrackingID));
DcmIODUtil::copyElementToDataset(result, item, m_TrackingUID, m_Rules.getByTag(DCM_TrackingUID));
return result;
}
void DcmSegment::clearData()
{
m_SegmentDescription.clearData();
m_SegmentAlgorithmName.clear();
m_SegmentationAlgorithmIdentification.clearData();
m_RecommendedDisplayGrayscaleValue.clear();
m_RecommendedDisplayCIELabValue.clear();
m_TrackingID.clear();
m_TrackingUID.clear();
}
DcmSegment::~DcmSegment()
{
clearData();
}
// protected default constructor
DcmSegment::DcmSegment()
: m_SegmentationDoc(NULL)
, m_SegmentDescription()
, m_SegmentAlgorithmName(DCM_SegmentAlgorithmName)
, m_SegmentationAlgorithmIdentification()
, m_RecommendedDisplayGrayscaleValue(DCM_RecommendedDisplayGrayscaleValue)
, m_RecommendedDisplayCIELabValue(DCM_RecommendedDisplayCIELabValue)
, m_TrackingID(DCM_TrackingID)
, m_TrackingUID(DCM_TrackingUID)
, m_Rules()
{
initIODRules();
}
void DcmSegment::initIODRules()
{
m_Rules.addRule(new IODRule(DCM_SegmentAlgorithmName, "1", "1C", "SegmentationImageModule", DcmIODTypes::IE_IMAGE),
OFTrue);
m_Rules.addRule(
new IODRule(DCM_RecommendedDisplayGrayscaleValue, "1", "3", "SegmentationImageModule", DcmIODTypes::IE_IMAGE),
OFTrue);
m_Rules.addRule(
new IODRule(DCM_RecommendedDisplayCIELabValue, "3", "3", "SegmentationImageModule", DcmIODTypes::IE_IMAGE),
OFTrue);
m_Rules.addRule(new IODRule(DCM_TrackingID, "1", "1C", "SegmentationImageModule", DcmIODTypes::IE_IMAGE), OFTrue);
m_Rules.addRule(new IODRule(DCM_TrackingUID, "1", "1C", "SegmentationImageModule", DcmIODTypes::IE_IMAGE), OFTrue);
}
// -------------- getters --------------------
Uint16 DcmSegment::getSegmentNumber()
{
Uint16 value = 0;
if (m_SegmentationDoc != NULL)
{
size_t big = 0;
m_SegmentationDoc->getSegmentNumber(this, big);
if (big <= DCM_SEG_MAX_SEGMENTS)
{
value = OFstatic_cast(Uint16, big);
}
else
{
DCMSEG_ERROR("More segments (" << big << ") defined than permitted (" << DCM_SEG_MAX_SEGMENTS << ")");
}
}
return value;
}
OFCondition DcmSegment::getSegmentLabel(OFString& value, const signed long pos)
{
return m_SegmentDescription.getSegmentLabel(value, pos);
}
OFCondition DcmSegment::getSegmentDescription(OFString& value, const signed long pos)
{
return m_SegmentDescription.getSegmentDescription(value, pos);
}
DcmSegTypes::E_SegmentAlgoType DcmSegment::getSegmentAlgorithmType()
{
return m_SegmentDescription.getSegmentAlgorithmType();
}
OFCondition DcmSegment::getSegmentAlgorithmName(OFString& value, const signed long pos)
{
return DcmIODUtil::getStringValueFromElement(m_SegmentAlgorithmName, value, pos);
}
GeneralAnatomyMacro& DcmSegment::getGeneralAnatomyCode()
{
return m_SegmentDescription.getGeneralAnatomyCode();
}
AlgorithmIdentificationMacro& DcmSegment::getSegmentationAlgorithmIdentification()
{
return m_SegmentationAlgorithmIdentification;
}
CodeSequenceMacro& DcmSegment::getSegmentedPropertyCategoryCode()
{
return m_SegmentDescription.getSegmentedPropertyCategoryCode();
}
CodeSequenceMacro& DcmSegment::getSegmentedPropertyTypeCode()
{
return m_SegmentDescription.getSegmentedPropertyTypeCode();
}
OFVector<CodeSequenceMacro*>& DcmSegment::getSegmentedPropertyTypeModifierCode()
{
return m_SegmentDescription.getSegmentedPropertyTypeModifier();
}
OFCondition DcmSegment::getRecommendedDisplayGrayscaleValue(Uint16& value, const unsigned long pos)
{
return m_RecommendedDisplayGrayscaleValue.getUint16(value, pos);
}
OFCondition DcmSegment::getRecommendedDisplayCIELabValue(Uint16& L, Uint16& a, Uint16& b)
{
OFCondition result = m_RecommendedDisplayCIELabValue.getUint16(L, 0);
if (result.good())
result = m_RecommendedDisplayCIELabValue.getUint16(a, 1);
if (result.good())
result = m_RecommendedDisplayCIELabValue.getUint16(b, 2);
return result;
}
OFCondition DcmSegment::getTrackingID(OFString& value, const signed long pos)
{
return DcmIODUtil::getStringValueFromElement(m_TrackingID, value, pos);
}
OFCondition DcmSegment::getTrackingUID(OFString& value, const signed long pos)
{
return DcmIODUtil::getStringValueFromElement(m_TrackingUID, value, pos);
}
// -------------- setters --------------------
OFCondition DcmSegment::setSegmentLabel(const OFString& value, const OFBool checkValue)
{
return m_SegmentDescription.setSegmentLabel(value, checkValue);
}
OFCondition DcmSegment::setSegmentDescription(const OFString& value, const OFBool checkValue)
{
return m_SegmentDescription.setSegmentDescription(value, checkValue);
}
OFCondition DcmSegment::setSegmentAlgorithm(const DcmSegTypes::E_SegmentAlgoType algoType,
const OFString& algoName,
const OFBool checkValue)
{
if (checkValue && algoType == DcmSegTypes::SAT_UNKNOWN)
{
DCMSEG_ERROR("Algorithm type must be initialized to a valid value");
return EC_InvalidValue;
}
OFCondition result;
// Set algorithm name if algorithm type is not manual (otherwise do not set it at all)
if (algoType != DcmSegTypes::SAT_MANUAL)
{
if (checkValue && algoName.empty())
{
DCMSEG_ERROR("Algorithm name must be provided if Algorithm Type is not 'MANUAL'");
return EC_MissingValue;
}
if (!algoName.empty())
{
result = (checkValue) ? DcmLongString::checkStringValue(algoName, "1") : EC_Normal;
if (result.good())
{
result = m_SegmentAlgorithmName.putOFStringArray(algoName);
}
}
}
// Set algorithm type
if (result.good())
{
result = m_SegmentDescription.setSegmentAlgorithmType(algoType);
}
return result;
}
OFCondition DcmSegment::setSegmentationAlgorithmIdentification(const AlgorithmIdentificationMacro& value,
const OFBool checkValue)
{
m_SegmentationAlgorithmIdentification = value;
OFCondition result;
if (checkValue)
{
result = m_SegmentationAlgorithmIdentification.check();
}
if (result.bad())
{
m_SegmentationAlgorithmIdentification.clearData();
}
return result;
}
OFCondition DcmSegment::setRecommendedDisplayGrayscaleValue(const Uint16 value, const OFBool)
{
return m_RecommendedDisplayGrayscaleValue.putUint16(value, 0);
}
OFCondition DcmSegment::setRecommendedDisplayCIELabValue(const Uint16 r, const Uint16 g, const Uint16 b, const OFBool)
{
OFCondition result = m_RecommendedDisplayCIELabValue.putUint16(r, 0);
if (result.good())
result = m_RecommendedDisplayCIELabValue.putUint16(g, 1);
if (result.good())
result = m_RecommendedDisplayCIELabValue.putUint16(b, 2);
return result;
}
OFCondition DcmSegment::setTrackingID(const OFString& value, const OFBool checkValue)
{
// avoid compile warning on unused variable
(void)checkValue;
return m_TrackingID.putOFStringArray(value);
}
OFCondition DcmSegment::setTrackingUID(const OFString& value, const OFBool checkValue)
{
OFCondition result;
if (checkValue)
{
result = DcmUniqueIdentifier::checkStringValue(value, "1");
}
if (result.good())
{
result = m_TrackingUID.putOFStringArray(value);
}
return result;
}
void DcmSegment::referenceSegmentationDoc(DcmSegmentation* doc)
{
this->m_SegmentationDoc = doc;
}
|