vtk-dicom  0.8.17
vtkDICOMDataElement.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 vtkDICOMDataElement_h
15 #define vtkDICOMDataElement_h
16 
17 #include "vtkDICOMModule.h" // For export macro
18 #include "vtkDICOMTag.h"
19 #include "vtkDICOMValue.h"
20 
22 
29 class VTKDICOM_EXPORT vtkDICOMDataElement
30 {
31 public:
33  vtkDICOMDataElement() : Tag(), Value(), Next(nullptr), Prev(nullptr) {}
34  vtkDICOMDataElement(const vtkDICOMTag& t, const vtkDICOMValue &v) :
35  Tag(t), Value(v), Next(nullptr), Prev(nullptr) {}
37 
39  vtkDICOMTag GetTag() const { return this->Tag; }
41 
43  vtkDICOMVR GetVR() const { return this->Value.GetVR(); }
45 
47  bool IsPerInstance() const {
49  return (this->Value.GetMultiplexData() != nullptr); }
50 
52  int GetNumberOfInstances() const {
53  return static_cast<int>(this->Value.GetNumberOfValues()); }
54 
56  const vtkDICOMValue& GetValue() const { return this->Value; }
57 
59  const vtkDICOMValue& GetValue(int i) const {
60  const vtkDICOMValue *vptr = this->Value.GetMultiplexData();
61  return (vptr == nullptr ? this->Value : vptr[i]); }
63 
65  bool operator==(const vtkDICOMDataElement& o) const {
66  return (this->Tag == o.Tag && this->Value == o.Value); }
67 
68  bool operator!=(const vtkDICOMDataElement& o) const {
69  return (this->Tag != o.Tag || this->Value != o.Value); }
71 
72 private:
73  vtkDICOMTag Tag;
74  vtkDICOMValue Value;
75 
76  // for storing elements in a linked list
77  vtkDICOMDataElement *Next;
78  vtkDICOMDataElement *Prev;
79 
80  // the classes that need to manipulate lists of elements
81  friend class vtkDICOMDataElementIterator;
82  friend class vtkDICOMMetaData;
83  friend class vtkDICOMItem;
84 };
85 
87 class VTKDICOM_EXPORT vtkDICOMDataElementIterator
88 {
89 public:
91  vtkDICOMDataElementIterator() : Pointer(nullptr) {}
93 
95  vtkDICOMDataElementIterator& operator++() {
96  if (this->Pointer) { this->Pointer = this->Pointer->Next; }
97  return *this; }
98 
99  vtkDICOMDataElementIterator operator++(int) {
100  const vtkDICOMDataElement *ptr = this->Pointer;
101  if (ptr) { this->Pointer = this->Pointer->Next; }
102  return vtkDICOMDataElementIterator(ptr); }
103 
104  vtkDICOMDataElementIterator& operator--() {
105  if (this->Pointer) { this->Pointer = this->Pointer->Prev; }
106  return *this; }
107 
108  vtkDICOMDataElementIterator operator--(int) {
109  const vtkDICOMDataElement *ptr = this->Pointer;
110  if (ptr) { this->Pointer = this->Pointer->Prev; }
111  return vtkDICOMDataElementIterator(ptr); }
113 
115  const vtkDICOMDataElement *operator->() const { return this->Pointer; }
116  const vtkDICOMDataElement& operator*() const { return *this->Pointer; }
118 
120  bool operator==(const vtkDICOMDataElementIterator& it) const {
121  return (this->Pointer == it.Pointer); }
122 
123  bool operator!=(const vtkDICOMDataElementIterator& it) const {
124  return (this->Pointer != it.Pointer); }
126 
127 private:
129  this->Pointer = ptr; }
130 
131  const vtkDICOMDataElement *Pointer;
132 
133  friend class vtkDICOMMetaData;
134  friend class vtkDICOMItem;
135 };
136 
137 VTKDICOM_EXPORT ostream& operator<<(ostream& os, const vtkDICOMDataElement& v);
138 
139 #endif /* vtkDICOMDataElement_h */
140 // VTK-HeaderTest-Exclude: vtkDICOMDataElement.h
A const iterator for a vtkDataElement list.
Definition: vtkDICOMDataElement.h:88
A data element in a DICOM data set.
Definition: vtkDICOMDataElement.h:30
vtkDICOMVR GetVR() const
Get the VR for this data element.
Definition: vtkDICOMDataElement.h:43
int GetNumberOfInstances() const
Get the number of value instances in this data element.
Definition: vtkDICOMDataElement.h:52
const vtkDICOMValue & GetValue(int i) const
Get value instance i, if the data element is multi-valued.
Definition: vtkDICOMDataElement.h:59
const vtkDICOMValue & GetValue() const
Get the value of the data element, if not multi-valued.
Definition: vtkDICOMDataElement.h:56
An item in a DICOM sequence (type SQ).
Definition: vtkDICOMItem.h:34
A container class for DICOM metadata.
Definition: vtkDICOMMetaData.h:44
A (group,element) identifier tag for DICOM attributes.
Definition: vtkDICOMTag.h:23
VRs (Value Representations)
Definition: vtkDICOMVR.h:22
A class to store attribute values for DICOM metadata.
Definition: vtkDICOMValue.h:51