vtk-dicom  0.8.17
vtkDICOMMetaData.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 vtkDICOMMetaData_h
15 #define vtkDICOMMetaData_h
16 
17 #include "vtkDataObject.h"
18 #include "vtkStdString.h" // For std::string
19 #include "vtkDICOMModule.h" // For export macro
20 #include "vtkDICOMConfig.h" // For configuration details
21 #include "vtkDICOMDataElement.h" // For method parameter
22 #include "vtkDICOMDictEntry.h" // For method parameter
23 
24 // Declare VTK classes within VTK's optional namespace
25 #if defined(VTK_ABI_NAMESPACE_BEGIN)
26 VTK_ABI_NAMESPACE_BEGIN
27 #endif
28 
29 class vtkIntArray;
30 
31 #if defined(VTK_ABI_NAMESPACE_BEGIN)
32 VTK_ABI_NAMESPACE_END
33 #endif
34 
35 class vtkDICOMTagPath;
36 
38 
43 class VTKDICOM_EXPORT vtkDICOMMetaData : public vtkDataObject
44 {
45 public:
47  static vtkDICOMMetaData *New();
48 
50  vtkTypeMacro(vtkDICOMMetaData, vtkDataObject);
51 
53  void PrintSelf(ostream& os, vtkIndent indent) VTK_DICOM_OVERRIDE;
54 
56 
64  int GetNumberOfInstances() { return this->NumberOfInstances; }
65  void SetNumberOfInstances(int n);
67 
69  void Clear();
71 
73  void Initialize() VTK_DICOM_OVERRIDE;
75 
77  int GetNumberOfDataElements() {
79  return this->NumberOfDataElements; }
80 
83  return this->Head.Next; }
84 
87  return &this->Tail; }
89 
91 
96  vtkDICOMDataElement *e = this->FindDataElement(tag);
97  return (e != nullptr ? e : &this->Tail); }
99 
101  bool Has(vtkDICOMTag tag);
103  bool HasAttribute(vtkDICOMTag tag) {
104  return this->Has(tag); }
105 
107  void Erase(vtkDICOMTag tag);
108  void RemoveAttribute(vtkDICOMTag tag) {
109  this->Erase(tag); }
111 
113 
121  const vtkDICOMValue &Get(const vtkDICOMTagPath &p);
122  const vtkDICOMValue &GetAttributeValue(vtkDICOMTag tag) {
123  return this->Get(tag); }
124  const vtkDICOMValue &GetAttributeValue(const vtkDICOMTagPath &p) {
125  return this->Get(p); }
127 
129 
137  const vtkDICOMValue &Get(int idx, vtkDICOMTag tag);
138  const vtkDICOMValue &Get(int idx, const vtkDICOMTagPath &p);
139  const vtkDICOMValue &GetAttributeValue(int idx, vtkDICOMTag tag) {
140  return this->Get(idx, tag); }
141  const vtkDICOMValue &GetAttributeValue(int idx, const vtkDICOMTagPath &p) {
142  return this->Get(idx, p); }
144 
146 
157  const vtkDICOMValue &Get(int idx, int frame, vtkDICOMTag tag);
158  const vtkDICOMValue &Get(int idx, int frame, const vtkDICOMTagPath &p);
159  const vtkDICOMValue &GetAttributeValue(int idx, int frame, vtkDICOMTag tag) {
160  return this->Get(idx, frame, tag); }
161  const vtkDICOMValue &GetAttributeValue(
162  int idx, int frame, const vtkDICOMTagPath &p) {
163  return this->Get(idx, frame, p); }
165 
167 
175  int GetFileIndex(int sliceIdx, int compIdx, int numComps);
176  int GetFileIndex(int sliceIdx);
178 
180 
188  int GetFrameIndex(int sliceIdx, int compIdx, int numComps);
189  int GetFrameIndex(int sliceIdx);
191 
193 
204  void Set(int idx, vtkDICOMTag tag, const vtkDICOMValue& v);
205  void Set(int idx, vtkDICOMTag tag, double v);
206  void Set(int idx, vtkDICOMTag tag, const std::string& v);
207  void SetAttributeValue(int idx, vtkDICOMTag tag, const vtkDICOMValue& v) {
208  this->Set(idx, tag, v); }
209  void SetAttributeValue(int idx, vtkDICOMTag tag, double v) {
210  this->Set(idx, tag, v); }
211  void SetAttributeValue(int idx, vtkDICOMTag tag, const std::string& v) {
212  this->Set(idx, tag, v); }
214 
216  void Set(vtkDICOMTag tag, const vtkDICOMValue& v);
218  void Set(vtkDICOMTag tag, double v);
219  void Set(vtkDICOMTag tag, const std::string& v);
220  void SetAttributeValue(vtkDICOMTag tag, const vtkDICOMValue& v) {
221  this->Set(tag, v); }
222  void SetAttributeValue(vtkDICOMTag tag, double v) {
223  this->Set(tag, v); }
224  void SetAttributeValue(vtkDICOMTag tag, const std::string& v) {
225  this->Set(tag, v); }
227 
229 
236  void Set(int idx, const vtkDICOMTagPath& tag, const vtkDICOMValue& v);
237  void Set(int idx, const vtkDICOMTagPath& tag, double v);
238  void Set(int idx, const vtkDICOMTagPath& tag, const std::string& v);
239  void SetAttributeValue(
240  int idx, const vtkDICOMTagPath& tag, const vtkDICOMValue& v) {
241  this->Set(idx, tag, v); }
242  void SetAttributeValue(
243  int idx, const vtkDICOMTagPath& tag, double v) {
244  this->Set(idx, tag, v); }
245  void SetAttributeValue(
246  int idx, const vtkDICOMTagPath& tag, const std::string& v) {
247  this->Set(idx, tag, v); }
249 
251  void Set(const vtkDICOMTagPath& tag, const vtkDICOMValue& v);
253  void Set(const vtkDICOMTagPath& tag, double v);
254  void Set(const vtkDICOMTagPath& tag, const std::string& v);
255  void SetAttributeValue(const vtkDICOMTagPath& tag, const vtkDICOMValue& v) {
256  this->Set(tag, v); }
257  void SetAttributeValue(const vtkDICOMTagPath& tag, double v) {
258  this->Set(tag, v); }
259  void SetAttributeValue(const vtkDICOMTagPath& tag, const std::string& v) {
260  this->Set(tag, v); }
262 
264 
274  vtkDICOMTag ResolvePrivateTag(vtkDICOMTag ptag, const std::string& creator);
275  vtkDICOMTag ResolvePrivateTag(
276  int idx, vtkDICOMTag ptag, const std::string& creator);
277 
279 
287  vtkDICOMTag ptag, const std::string& creator);
288  vtkDICOMTag ResolvePrivateTagForWriting(
289  int idx, vtkDICOMTag ptag, const std::string& creator);
291 
293 
300 
304 
306  vtkDICOMValue MakeValueWithSpecificCharacterSet(
308  vtkDICOMVR vr, const std::string& v);
310 
312  void SetFileIndexArray(vtkIntArray *fileArray);
314  vtkIntArray *GetFileIndexArray() { return this->FileIndexArray; }
316 
318  void SetFrameIndexArray(vtkIntArray *frameArray);
320  vtkIntArray *GetFrameIndexArray() { return this->FrameIndexArray; }
322 
324 
334 
336  void ShallowCopy(vtkDataObject *source) VTK_DICOM_OVERRIDE;
338  void DeepCopy(vtkDataObject *source) VTK_DICOM_OVERRIDE;
340 
341 protected:
343  ~vtkDICOMMetaData() VTK_DICOM_OVERRIDE;
344 
346  vtkDICOMDataElement *FindDataElement(vtkDICOMTag tag);
347 
349  vtkDICOMDataElement *FindDataElementOrInsert(vtkDICOMTag tag);
350 
352  int FindItemsOrInsert(
353  int idx, bool useidx, const vtkDICOMTagPath& tagpath,
354  vtkDICOMItem *items[]);
355 
357  vtkDICOMItem *FindItemOrInsert(int idx, const vtkDICOMTagPath& tagpath);
358 
360  const vtkDICOMValue *FindAttributeValue(int idx, vtkDICOMTag tag);
361 
363  const vtkDICOMValue *FindAttributeValue(
364  int idx, const vtkDICOMTagPath& tagpath);
365 
366 private:
368  int NumberOfInstances;
369 
371  vtkDICOMDataElement **Table;
372 
374  vtkDICOMDataElement Head;
375 
377  vtkDICOMDataElement Tail;
378 
380  int NumberOfDataElements;
381 
383  vtkIntArray *FileIndexArray;
384 
386  vtkIntArray *FrameIndexArray;
387 
388 #ifdef VTK_DICOM_DELETE
389  vtkDICOMMetaData(const vtkDICOMMetaData&) VTK_DICOM_DELETE;
390  void operator=(const vtkDICOMMetaData&) VTK_DICOM_DELETE;
391 #else
392  vtkDICOMMetaData(const vtkDICOMMetaData&) = delete;
393  void operator=(const vtkDICOMMetaData&) = delete;
394 #endif
395 };
396 
397 #endif /* vtkDICOMMetaData_h */
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
A container class for DICOM metadata.
Definition: vtkDICOMMetaData.h:44
void Set(int idx, const vtkDICOMTagPath &tag, const vtkDICOMValue &v)
Set the attribute at the specified path.
vtkDICOMDataElementIterator End()
Get an end iterator for the list of data elements.
Definition: vtkDICOMMetaData.h:86
void Set(int idx, vtkDICOMTag tag, const vtkDICOMValue &v)
Set an attribute value for the image at file index "idx".
void CopyAttributes(vtkDICOMMetaData *source)
Copy all the attributes from another MetaData object.
int GetFrameIndex(int sliceIdx, int compIdx, int numComps)
Get the frame index for the given image slice and component.
const vtkDICOMValue & Get(int idx, vtkDICOMTag tag)
Get an attribute value for the specified file index.
vtkDICOMVR FindDictVR(int idx, vtkDICOMTag tag)
Use the dictionary to get the VR, return UN if not found.
vtkDICOMDictEntry FindDictEntry(vtkDICOMTag tag)
Look up a tag in the DICOM dictionary.
const vtkDICOMValue & Get(int idx, int frame, vtkDICOMTag tag)
Get an attribute value for the specified file and frame index.
void PrintSelf(ostream &os, vtkIndent indent) VTK_DICOM_OVERRIDE
Print a summary of the contents of this object.
int GetFileIndex(int sliceIdx, int compIdx, int numComps)
Get the file index for the given image slice and component.
vtkDICOMTag ResolvePrivateTagForWriting(vtkDICOMTag ptag, const std::string &creator)
Resolve a private tag, and add the creator to the data set.
vtkDICOMDataElementIterator Find(vtkDICOMTag tag)
Get the iterator for a specific data element.
Definition: vtkDICOMMetaData.h:95
void Erase(vtkDICOMTag tag)
Erase an attribute.
static vtkDICOMMetaData * New()
Create a new vtkDICOMMetaData instance.
vtkDICOMTag ResolvePrivateTag(vtkDICOMTag ptag, const std::string &creator)
Resolve a private tag, or return (ffff,ffff) if not resolved.
vtkDICOMDataElementIterator Begin()
Get an iterator for the list of data elements.
Definition: vtkDICOMMetaData.h:82
int GetNumberOfInstances()
Get the number of instances (i.e. files).
Definition: vtkDICOMMetaData.h:64
void Initialize() VTK_DICOM_OVERRIDE
Remove all data elements and initialize all members.
const vtkDICOMValue & Get(vtkDICOMTag tag)
Get an attribute value.
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
A class to store attribute values for DICOM metadata.
Definition: vtkDICOMValue.h:51