vtk-dicom  0.8.17
vtkDICOMItem.h
1 /*=========================================================================
2 
3  Program: DICOM for VTK
4 
5  Copyright (c) 2012-2024 David Gobbi
6  All rights reserved.
7  See Copyright.txt or http://dgobbi.github.io/bsd3.txt for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef vtkDICOMItem_h
15 #define vtkDICOMItem_h
16 
17 #include "vtkDICOMModule.h" // For export macro
18 #include "vtkDICOMDataElement.h"
19 #include "vtkDICOMDictEntry.h"
20 #include "vtkDICOMReferenceCount.h"
21 
22 #include <string>
23 
24 class vtkDICOMTagPath;
25 class vtkDICOMMetaData;
26 
28 
33 class VTKDICOM_EXPORT vtkDICOMItem
34 {
35 private:
36 
38  struct List
39  {
42  vtkDICOMReferenceCount ReferenceCount;
43  int NumberOfDataElements;
44  vtkDICOMDataElement *DataElements;
45  unsigned int ByteOffset;
46  bool Delimited;
47  vtkDICOMCharacterSet CharacterSet;
48  vtkDICOMVR VRForXS;
49 
50  List() : Head(), Tail(), ReferenceCount(1),
51  NumberOfDataElements(0), DataElements(nullptr),
52  ByteOffset(0), Delimited(false),
53  CharacterSet(vtkDICOMCharacterSet::ISO_IR_6),
54  VRForXS(vtkDICOMVR::US) {}
55  };
56 
57 public:
58 
60  vtkDICOMItem() : L(nullptr) {}
62 
64 
71  explicit vtkDICOMItem(vtkDICOMMetaData *meta);
72 
74 
79  explicit vtkDICOMItem(
80  vtkDICOMCharacterSet cs, vtkDICOMVR vrForXS,
81  int delimited=0, unsigned int byteOffset=0);
82 
84  vtkDICOMItem(const vtkDICOMItem &o) : L(o.L) {
85  if (this->L) { ++(this->L->ReferenceCount); } }
86 
88  ~vtkDICOMItem() { this->Clear(); }
90 
92  void Clear() {
94  if (this->L && --(this->L->ReferenceCount) == 0) { this->FreeList(); }
95  else { this->L = nullptr; } }
96 
98  bool IsEmpty() const { return (this->L == nullptr); }
99 
101  bool IsDelimited() const {
102  return (this->L == nullptr || this->L->Delimited != 0); }
104 
106 
111  void Set(vtkDICOMTag tag, const vtkDICOMValue& v);
112  void Set(vtkDICOMTag tag, double v);
113  void Set(vtkDICOMTag tag, const std::string& v);
114  void SetAttributeValue(vtkDICOMTag tag, const vtkDICOMValue& v) {
115  this->Set(tag, v); }
116  void SetAttributeValue(vtkDICOMTag tag, double v) {
117  this->Set(tag, v); }
118  void SetAttributeValue(vtkDICOMTag tag, const std::string& v) {
119  this->Set(tag, v); }
121 
123 
130  void Set(const vtkDICOMTagPath& tag, const vtkDICOMValue& v);
131  void Set(const vtkDICOMTagPath& tag, double v);
132  void Set(const vtkDICOMTagPath& tag, const std::string& v);
133  void SetAttributeValue(const vtkDICOMTagPath& tag, const vtkDICOMValue& v) {
134  this->Set(tag, v); }
135  void SetAttributeValue(const vtkDICOMTagPath& tag, double v) {
136  this->Set(tag, v); }
137  void SetAttributeValue(const vtkDICOMTagPath& tag, const std::string& v) {
138  this->Set(tag, v); }
140 
142  const vtkDICOMValue &Get(vtkDICOMTag tag) const;
144  const vtkDICOMValue &Get(const vtkDICOMTagPath &tag) const;
145  const vtkDICOMValue &GetAttributeValue(vtkDICOMTag tag) const {
146  return this->Get(tag); }
147  const vtkDICOMValue &GetAttributeValue(const vtkDICOMTagPath &tag) const {
148  return this->Get(tag); }
150 
152 
158  unsigned int GetByteOffset() const {
159  return (this->L == nullptr ? 0 : this->L->ByteOffset); }
161 
163  int GetNumberOfDataElements() const {
165  return (this->L ? this->L->NumberOfDataElements : 0); }
166 
169  return (this->L ? this->L->Head.Next : nullptr); }
170 
173  return (this->L ? &this->L->Tail : nullptr); }
175 
177 
188  vtkDICOMTag ptag, const std::string& creator) const;
189 
191 
199  vtkDICOMTag ptag, const std::string& creator);
201 
203 
210 
214 
216  bool operator==(const vtkDICOMItem& o) const;
217  bool operator!=(const vtkDICOMItem& o) const {
218  return !(*this == o); }
220 
222  vtkDICOMItem &operator=(const vtkDICOMItem &o) {
224  if (this->L != o.L) {
225  if (o.L) { ++(o.L->ReferenceCount); }
226  if (this->L && --(this->L->ReferenceCount) == 0) { this->FreeList(); }
227  this->L = o.L; }
228  return *this; }
230 
231 private:
232  void FreeList();
233  vtkDICOMDataElement *NewDataElement(vtkDICOMDataElement **iter);
234  static void CopyList(const List *o, List *t);
235  static void CopyDataElements(
236  const vtkDICOMDataElement *begin, const vtkDICOMDataElement *end,
237  List *t);
238 
240  vtkDICOMDataElement *FindDataElementOrInsert(vtkDICOMTag tag);
241 
243  vtkDICOMItem *FindItemOrInsert(
244  const vtkDICOMTagPath& tagpath, vtkDICOMTag *tagptr);
245 
247  static const vtkDICOMValue InvalidValue;
248 
250  List *L;
251 };
252 
253 #endif /* vtkDICOMItem_h */
254 // VTK-HeaderTest-Exclude: vtkDICOMItem.h
Character sets.
Definition: vtkDICOMCharacterSet.h:55
A const iterator for a vtkDataElement list.
Definition: vtkDICOMDataElement.h:88
A data element in a DICOM data set.
Definition: vtkDICOMDataElement.h:30
An entry in the DICOM dictionary.
Definition: vtkDICOMDictEntry.h:24
An item in a DICOM sequence (type SQ).
Definition: vtkDICOMItem.h:34
vtkDICOMItem(const vtkDICOMItem &o)
Copy constructor does reference counting.
Definition: vtkDICOMItem.h:84
vtkDICOMVR FindDictVR(vtkDICOMTag tag) const
Use the dictionary to get the VR, returns UN on failure.
vtkDICOMDictEntry FindDictEntry(vtkDICOMTag tag) const
Look up a tag in the DICOM dictionary.
vtkDICOMDataElementIterator End() const
Get an end iterator for the list of data elements.
Definition: vtkDICOMItem.h:172
vtkDICOMTag ResolvePrivateTagForWriting(vtkDICOMTag ptag, const std::string &creator)
Resolve a private tag, and add the creator to the data set.
bool IsEmpty() const
Check if empty.
Definition: vtkDICOMItem.h:98
vtkDICOMDataElementIterator Begin() const
Get an iterator for the list of data elements.
Definition: vtkDICOMItem.h:168
vtkDICOMItem(vtkDICOMCharacterSet cs, vtkDICOMVR vrForXS, int delimited=0, unsigned int byteOffset=0)
Constructor with flag for delimitation and offset.
vtkDICOMItem(vtkDICOMMetaData *meta)
Constructor that takes certain properties from the data set.
bool IsDelimited() const
Check if this was read as a delimited item.
Definition: vtkDICOMItem.h:101
vtkDICOMTag ResolvePrivateTag(vtkDICOMTag ptag, const std::string &creator) const
Resolve a private tag, or return (ffff,ffff) if not resolved.
unsigned int GetByteOffset() const
Get the offset of this item from the beginning of the file.
Definition: vtkDICOMItem.h:158
void Set(vtkDICOMTag tag, const vtkDICOMValue &v)
Add a data element to this item.
void Set(const vtkDICOMTagPath &tag, const vtkDICOMValue &v)
Add a data element at the specified path.
~vtkDICOMItem()
Destructor does reference counting.
Definition: vtkDICOMItem.h:88
A container class for DICOM metadata.
Definition: vtkDICOMMetaData.h:44
An object for holding an atomic reference count.
Definition: vtkDICOMReferenceCount.h:27
A tag path for digging values out of sequence items.
Definition: vtkDICOMTagPath.h:27
A (group,element) identifier tag for DICOM attributes.
Definition: vtkDICOMTag.h:23
VRs (Value Representations)
Definition: vtkDICOMVR.h:22
@ US
Unsigned Short.
Definition: vtkDICOMVR.h:60
A class to store attribute values for DICOM metadata.
Definition: vtkDICOMValue.h:51