File: dvpsabl.cc

package info (click to toggle)
dcmtk 3.6.9-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,648 kB
  • sloc: ansic: 426,874; cpp: 318,177; makefile: 6,401; sh: 4,341; yacc: 1,026; xml: 482; lex: 321; perl: 277
file content (211 lines) | stat: -rw-r--r-- 5,700 bytes parent folder | download | duplicates (3)
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
/*
 *
 *  Copyright (C) 1999-2024, 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: DVPSAnnotationContent_PList
 *
 */

#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmpstat/dvpsabl.h"
#include "dcmtk/dcmpstat/dvpsab.h"      /* for DVPSAnnotationContent */
#include "dcmtk/dcmpstat/dvpshlp.h"     /* for class DVPSHelper */

/* --------------- class DVPSAnnotationContent_PList --------------- */

DVPSAnnotationContent_PList::DVPSAnnotationContent_PList()
: list_()
{
}

DVPSAnnotationContent_PList::DVPSAnnotationContent_PList(const DVPSAnnotationContent_PList &arg)
: list_()
{
  OFListConstIterator(DVPSAnnotationContent *) first = arg.list_.begin();
  OFListConstIterator(DVPSAnnotationContent *) last = arg.list_.end();
  while (first != last)
  {
    list_.push_back((*first)->clone());
    ++first;
  }
}

DVPSAnnotationContent_PList::~DVPSAnnotationContent_PList()
{
  clear();
}

void DVPSAnnotationContent_PList::clear()
{
  OFListIterator(DVPSAnnotationContent *) first = list_.begin();
  OFListIterator(DVPSAnnotationContent *) last = list_.end();
  while (first != last)
  {
    delete (*first);
    first = list_.erase(first);
  }
}

OFCondition DVPSAnnotationContent_PList::read(DcmItem &dset)
{
  OFCondition result = EC_Normal;
  DcmStack stack;
  DVPSAnnotationContent *newAnnotation = NULL;
  DcmSequenceOfItems *dseq=NULL;
  DcmItem *ditem=NULL;

  if (EC_Normal == dset.search(DCM_RETIRED_AnnotationContentSequence, stack, ESM_fromHere, OFFalse) && (stack.top()->ident() == EVR_SQ))
  {
    dseq=(DcmSequenceOfItems *)stack.top();
    if (dseq)
    {
      unsigned long numItems = dseq->card();
      for (unsigned int i=0; i<numItems; i++)
      {
        ditem = dseq->getItem(i);
        newAnnotation = new DVPSAnnotationContent();
        if (newAnnotation && ditem)
        {
          result = newAnnotation->read(*ditem);
          list_.push_back(newAnnotation);
        } else result = EC_MemoryExhausted;
      }
    }
  }

  return result;
}

OFCondition DVPSAnnotationContent_PList::write(DcmItem &dset)
{
  if (size()==0) return EC_Normal; // don't write if sequence is empty

  OFCondition result = EC_Normal;
  DcmSequenceOfItems *dseq=NULL;
  DcmItem *ditem=NULL;

  dseq = new DcmSequenceOfItems(DCM_RETIRED_AnnotationContentSequence);
  if (dseq)
  {
    OFListIterator(DVPSAnnotationContent *) first = list_.begin();
    OFListIterator(DVPSAnnotationContent *) last = list_.end();
    while (first != last)
    {
      if (result==EC_Normal)
      {
        ditem = new DcmItem();
        if (ditem)
        {
          result = (*first)->write(*ditem);
          if (result==EC_Normal) dseq->insert(ditem); else delete ditem;
        } else result = EC_MemoryExhausted;
      }
      ++first;
    }
    if (result==EC_Normal) dset.insert(dseq, OFTrue /*replaceOld*/); else delete dseq;
  } else result = EC_MemoryExhausted;
  return result;
}


OFCondition DVPSAnnotationContent_PList::addAnnotationBox(
    const char *instanceuid,
    const char *text,
    Uint16 position)
{
  OFCondition result = EC_Normal;
  DVPSAnnotationContent *newAnnotation = new DVPSAnnotationContent();
  if (newAnnotation)
  {
    result = newAnnotation->setContent(instanceuid, text, position);
    if (EC_Normal == result) list_.push_back(newAnnotation); else delete newAnnotation;
  } else result = EC_MemoryExhausted;
  return result;
}


OFCondition DVPSAnnotationContent_PList::deleteAnnotation(size_t idx)
{
  OFListIterator(DVPSAnnotationContent *) first = list_.begin();
  OFListIterator(DVPSAnnotationContent *) last = list_.end();
  while ((first != last)&&(idx--)) ++first;
  if (first != last)
  {
    delete (*first);
    list_.erase(first);
    return EC_Normal;
  }
  return EC_IllegalCall;
}

OFCondition DVPSAnnotationContent_PList::deleteMultipleAnnotations(size_t number)
{
  OFListIterator(DVPSAnnotationContent *) first = list_.begin();
  OFListIterator(DVPSAnnotationContent *) last = list_.end();
  while ((first != last)&&(number--))
  {
    delete (*first);
    first = list_.erase(first);
  }
  return EC_Normal;
}

DVPSAnnotationContent *DVPSAnnotationContent_PList::getAnnotationBox(size_t idx)
{
  OFListIterator(DVPSAnnotationContent *) first = list_.begin();
  OFListIterator(DVPSAnnotationContent *) last = list_.end();
  while (first != last)
  {
    if (idx==0) return *first;
    idx--;
    ++first;
  }
  return NULL;
}

OFCondition DVPSAnnotationContent_PList::setAnnotationSOPInstanceUID(size_t idx, const char *value)
{
  DVPSAnnotationContent *box = getAnnotationBox(idx);
  if (box) return box->setSOPInstanceUID(value);
  return EC_IllegalCall;
}

const char *DVPSAnnotationContent_PList::getSOPInstanceUID(size_t idx)
{
  DVPSAnnotationContent *box = getAnnotationBox(idx);
  if (box) return box->getSOPInstanceUID();
  return NULL;
}

OFCondition DVPSAnnotationContent_PList::prepareBasicAnnotationBox(size_t idx, DcmItem &dset)
{
  DVPSAnnotationContent *box = getAnnotationBox(idx);
  if (box) return box->prepareBasicAnnotationBox(dset);
  return EC_IllegalCall;
}

void DVPSAnnotationContent_PList::clearAnnotationSOPInstanceUIDs()
{
  OFListIterator(DVPSAnnotationContent *) first = list_.begin();
  OFListIterator(DVPSAnnotationContent *) last = list_.end();
  while (first != last)
  {
    (*first)->setSOPInstanceUID(NULL);
    ++first;
  }
}