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
|
/*
*
* Copyright (C) 2000-2021, 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: dcmsr
*
* Author: Joerg Riesmeier
*
* Purpose:
* classes: DSRReferencedSamplePositionList
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmsr/dsrtcosp.h"
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmdata/dcvrul.h"
template<>
const Uint32& DSRgetEmptyItem<Uint32>()
{
// no need to be thread-safe, since it is only an int
static const Uint32 t = 0;
return t;
}
DSRReferencedSamplePositionList::DSRReferencedSamplePositionList()
: DSRListOfItems<Uint32>()
{
}
DSRReferencedSamplePositionList::DSRReferencedSamplePositionList(const DSRReferencedSamplePositionList &lst)
: DSRListOfItems<Uint32>(lst)
{
}
DSRReferencedSamplePositionList::~DSRReferencedSamplePositionList()
{
}
DSRReferencedSamplePositionList &DSRReferencedSamplePositionList::operator=(const DSRReferencedSamplePositionList &lst)
{
DSRListOfItems<Uint32>::operator=(lst);
return *this;
}
OFCondition DSRReferencedSamplePositionList::print(STD_NAMESPACE ostream &stream,
const size_t flags,
const char separator) const
{
const OFListConstIterator(Uint32) endPos = ItemList.end();
OFListConstIterator(Uint32) iterator = ItemList.begin();
while (iterator != endPos)
{
stream << (*iterator);
iterator++;
if (iterator != endPos)
{
if (flags & DSRTypes::PF_shortenLongItemValues)
{
stream << separator << "...";
/* goto last item */
iterator = endPos;
} else
stream << separator;
}
}
return EC_Normal;
}
OFCondition DSRReferencedSamplePositionList::read(DcmItem &dataset,
const size_t /*flags*/)
{
/* get element from dataset */
DcmUnsignedLong delem(DCM_ReferencedSamplePositions);
OFCondition result = DSRTypes::getAndCheckElementFromDataset(dataset, delem, "1-n", "1C", "TCOORD content item");
if (result.good())
{
/* clear internal list */
clear();
Uint32 value = 0;
const unsigned long count = delem.getVM();
/* fill list with values from integer string */
for (unsigned long i = 0; i < count; i++)
{
if (delem.getUint32(value, i).good())
addItem(value);
}
}
return result;
}
OFCondition DSRReferencedSamplePositionList::write(DcmItem &dataset) const
{
OFCondition result = EC_Normal;
unsigned long i = 0;
/* create element */
DcmUnsignedLong delem(DCM_ReferencedSamplePositions);
const OFListConstIterator(Uint32) endPos = ItemList.end();
OFListConstIterator(Uint32) iterator = ItemList.begin();
/* set element values */
while (iterator != endPos)
{
delem.putUint32(*iterator, i++);
iterator++;
}
/* add to dataset */
if (result.good())
result = DSRTypes::addElementToDataset(result, dataset, new DcmUnsignedLong(delem), "1-n", "1", "TCOORD content item");
return result;
}
OFCondition DSRReferencedSamplePositionList::putString(const char *stringValue)
{
OFCondition result = EC_Normal;
/* clear internal list */
clear();
/* check input string */
if ((stringValue != NULL) && (strlen(stringValue) > 0))
{
Uint32 value = 0;
const char *ptr = stringValue;
/* retrieve sample positions from string */
while (result.good() && (ptr != NULL))
{
#ifdef SCNu32
if (sscanf(ptr, "%" SCNu32, &value) == 1)
#elif SIZEOF_LONG == 8
if (sscanf(ptr, "%u", &value) == 1)
#else
if (sscanf(ptr, "%lu", &value) == 1)
#endif
{
addItem(value);
/* jump to next time offset */
ptr = strchr(ptr, ',');
if (ptr != NULL)
ptr++;
} else
result = EC_CorruptedData;
}
}
return result;
}
|