vtk-dicom  0.8.17
vtkDICOMTagPath.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 vtkDICOMTagPath_h
15 #define vtkDICOMTagPath_h
16 
17 #include "vtkSystemIncludes.h"
18 #include "vtkDICOMModule.h" // For export macro
19 #include "vtkDICOMTag.h"
20 
22 
26 class VTKDICOM_EXPORT vtkDICOMTagPath
27 {
28 public:
30  vtkDICOMTagPath() : Size(0), Head(), Index(0), Tail(), List(nullptr) {}
32 
34  vtkDICOMTagPath(vtkDICOMTag seqTag, unsigned int i, vtkDICOMTag tag)
35  : Size(2), Head(seqTag), Index(i), Tail(tag), List(nullptr) {}
36 
38  vtkDICOMTagPath(vtkDICOMTag seqTag, unsigned int i, vtkDICOMTag tag,
39  unsigned int j, vtkDICOMTag tag2)
40  : Size(3), Head(seqTag), Index(i), Tail(tag) {
41  Last.Index = j; Last.Tag.Key = tag2.GetKey(); }
42 
44  vtkDICOMTagPath(const vtkDICOMTagPath& path, unsigned int i,
45  vtkDICOMTag tag);
46 
49  : Size(1), Head(tag), Index(0), Tail(), List(nullptr) {}
50 
53  : Size(o.Size), Head(o.Head), Index(o.Index), Tail(o.Tail) {
54  if (o.Size <= 3) {
55  this->Last = o.Last; }
56  else {
57  this->List = vtkDICOMTagPath::CopyList(o.List, o.Size - 2); } }
59 
61  ~vtkDICOMTagPath() {
63  if (this->Size > 3) { delete [] this->List; } }
65 
67  vtkDICOMTagPath& operator=(const vtkDICOMTagPath& o);
70 
72  bool HasTail() const {
74  return (this->Size > 1); }
75 
77  vtkDICOMTag GetHead() const {
78  return this->Head; }
79 
81  unsigned int GetIndex() const {
82  return this->Index; }
83 
85  unsigned int GetIndex(unsigned int i) const;
86 
88  vtkDICOMTag GetTag(unsigned int i) const;
89 
91  unsigned int GetSize() const {
92  return this->Size; }
93 
97 
99  bool operator==(const vtkDICOMTagPath& b) const;
100  bool operator!=(const vtkDICOMTagPath& b) const;
101  bool operator<=(const vtkDICOMTagPath& b) const;
102  bool operator>=(const vtkDICOMTagPath& b) const;
103  bool operator<(const vtkDICOMTagPath& b) const;
104  bool operator>(const vtkDICOMTagPath& b) const;
106 
107 private:
108  struct Pair
109  {
110  unsigned int Index;
112  };
113 
114  vtkDICOMTagPath(vtkDICOMTag seqTag, unsigned int i, vtkDICOMTag tag,
115  unsigned int n, Pair *l) :
116  Size(n+2), Head(seqTag), Index(i), Tail(tag), List(l) {}
117 
118  static Pair *CopyList(const Pair *o, unsigned int n);
119 
120  unsigned int Size;
121  vtkDICOMTag Head;
122  unsigned int Index;
123  vtkDICOMTag Tail;
124  union {
125  Pair Last;
126  Pair *List;
127  };
128 };
129 
130 VTKDICOM_EXPORT ostream& operator<<(ostream& o, const vtkDICOMTagPath& a);
131 
132 #endif /* vtkDICOMTagPath_h */
133 // VTK-HeaderTest-Exclude: vtkDICOMTagPath.h
A tag path for digging values out of sequence items.
Definition: vtkDICOMTagPath.h:27
vtkDICOMTagPath(const vtkDICOMTagPath &path, unsigned int i, vtkDICOMTag tag)
Construct a tag path by adding to an existing tag path.
vtkDICOMTagPath(vtkDICOMTag tag)
Construct a tag path from just a single tag.
Definition: vtkDICOMTagPath.h:48
vtkDICOMTag GetHead() const
Get the path head, which should be a sequence if HasTail() is true.
Definition: vtkDICOMTagPath.h:77
vtkDICOMTag GetTag(unsigned int i) const
Get the nth tag in the path.
vtkDICOMTagPath(vtkDICOMTag seqTag, unsigned int i, vtkDICOMTag tag, unsigned int j, vtkDICOMTag tag2)
Construct a tag path that goes two levels deep.
Definition: vtkDICOMTagPath.h:38
vtkDICOMTagPath(const vtkDICOMTagPath &o)
Copy constructor.
Definition: vtkDICOMTagPath.h:52
vtkDICOMTagPath(vtkDICOMTag seqTag, unsigned int i, vtkDICOMTag tag)
Construct a tag path from a sequence tag, item index, and item tag.
Definition: vtkDICOMTagPath.h:34
unsigned int GetIndex() const
Get the index of the item within the sequence.
Definition: vtkDICOMTagPath.h:81
unsigned int GetSize() const
Get the number of tags in the path.
Definition: vtkDICOMTagPath.h:91
vtkDICOMTagPath GetTail() const
Get the remainder of the path (after Head and Index).
unsigned int GetIndex(unsigned int i) const
Get the nth index in the path.
A (group,element) identifier tag for DICOM attributes.
Definition: vtkDICOMTag.h:23
unsigned int GetKey() const
Get the tag as a 32-bit key.
Definition: vtkDICOMTag.h:56
A struct that provides static storage for a DICOM tag.
Definition: vtkDICOMTag.h:27