vtk-dicom  0.8.17
vtkDICOMParser.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 vtkDICOMParser_h
15 #define vtkDICOMParser_h
16 
17 #include "vtkObject.h"
18 #include "vtkStdString.h" // For std::string
19 #include "vtkDICOMModule.h" // For export macro
20 #include "vtkDICOMConfig.h" // For configuration details
21 #include "vtkDICOMCharacterSet.h" // For character sets
22 
23 // Declare VTK classes within VTK's optional namespace
24 #if defined(VTK_ABI_NAMESPACE_BEGIN)
25 VTK_ABI_NAMESPACE_BEGIN
26 #endif
27 
28 class vtkUnsignedShortArray;
29 
30 #if defined(VTK_ABI_NAMESPACE_BEGIN)
31 VTK_ABI_NAMESPACE_END
32 #endif
33 
34 class vtkDICOMFile;
35 class vtkDICOMItem;
36 class vtkDICOMMetaData;
37 class vtkDICOMParserInternalFriendship;
38 
40 
47 class VTKDICOM_EXPORT vtkDICOMParser : public vtkObject
48 {
49 public:
51  static vtkDICOMParser *New();
52 
54  vtkTypeMacro(vtkDICOMParser, vtkObject);
55 
57  void PrintSelf(ostream& os, vtkIndent indent) VTK_DICOM_OVERRIDE;
58 
60  vtkSetStringMacro(FileName);
62  vtkGetStringMacro(FileName);
64 
66  void SetMetaData(vtkDICOMMetaData *);
68  vtkDICOMMetaData *GetMetaData() { return this->MetaData; }
70 
72  vtkSetMacro(Index, int);
74  int GetIndex() { return this->Index; }
76 
78 
87  vtkDICOMCharacterSet GetDefaultCharacterSet() {
88  return this->DefaultCharacterSet; }
89 
91 
97  void OverrideCharacterSetOn() {
98  this->SetOverrideCharacterSet(true); }
99  void OverrideCharacterSetOff() {
100  this->SetOverrideCharacterSet(false); }
101  bool GetOverrideCharacterSet() {
102  return this->OverrideCharacterSet; }
104 
106 
113  vtkDICOMMetaData *GetQuery() { return this->Query; }
115 
117 
124  void SetQueryItem(const vtkDICOMItem& query);
126 
128 
132  void SetGroups(vtkUnsignedShortArray *groups);
133  vtkUnsignedShortArray *GetGroups() { return this->Groups; }
135 
137  bool GetQueryMatched() { return this->QueryMatched; }
139 
141  bool GetPixelDataFound() { return this->PixelDataFound; }
142 
144  unsigned int GetPixelDataVL() { return this->PixelDataVL; }
146 
148 
153  vtkTypeInt64 GetFileOffset() { return this->FileOffset; }
154 
156  vtkTypeInt64 GetFileSize() { return this->FileSize; }
157 
159 
164  void SetBufferSize(int size);
165  int GetBufferSize() { return this->BufferSize; }
167 
169  virtual void Update();
171 
173  unsigned long GetErrorCode() { return this->ErrorCode; }
175 
176 protected:
177  vtkDICOMParser();
178  ~vtkDICOMParser() VTK_DICOM_OVERRIDE;
179 
181 
191  virtual bool FillBuffer(
192  const unsigned char* &cp, const unsigned char* &ep);
193 
195 
198  virtual bool SeekBuffer(
199  const unsigned char* &cp, const unsigned char* &ep, vtkTypeInt64 offset);
200 
202 
207  virtual bool SkipValue(
208  const unsigned char* &cp, const unsigned char* &ep, unsigned int vl);
209 
211  virtual vtkTypeInt64 GetBytesRemaining(
212  const unsigned char *cp, const unsigned char *ep);
213 
215  virtual void ParseError(
216  const unsigned char *cp, const unsigned char *ep, const char *message);
217 
219  void SetErrorCode(unsigned long e) { this->ErrorCode = e; }
220 
222  virtual bool ReadFile(vtkDICOMMetaData *data, int idx);
223 
226  const unsigned char* &cp, const unsigned char* &ep,
227  vtkDICOMMetaData *data, int idx);
228 
231  const unsigned char* &cp, const unsigned char* &ep,
232  vtkDICOMMetaData *data, int idx);
233 
235  vtkTypeInt64 GetBytesProcessed(
236  const unsigned char* cp, const unsigned char* ep);
237 
238  char *FileName;
239  std::string TransferSyntax;
240  vtkDICOMMetaData *MetaData;
241  vtkDICOMMetaData *Query;
242  vtkDICOMItem *QueryItem;
243  vtkUnsignedShortArray *Groups;
244  vtkDICOMFile *InputFile;
245  vtkTypeInt64 BytesRead;
246  vtkTypeInt64 FileOffset;
247  vtkTypeInt64 FileSize;
248  unsigned char *Buffer;
249  int BufferSize;
250  int ChunkSize;
251  int Index;
252  unsigned int PixelDataVL;
253  bool PixelDataFound;
254  bool QueryMatched;
255  vtkDICOMCharacterSet DefaultCharacterSet;
256  bool OverrideCharacterSet;
257  unsigned long ErrorCode;
258 
259  // used to share FillBuffer with internal classes
260  friend class vtkDICOMParserInternalFriendship;
261 
262 private:
263 #ifdef VTK_DICOM_DELETE
264  vtkDICOMParser(const vtkDICOMParser&) VTK_DICOM_DELETE;
265  void operator=(const vtkDICOMParser&) VTK_DICOM_DELETE;
266 #else
267  vtkDICOMParser(const vtkDICOMParser&) = delete;
268  void operator=(const vtkDICOMParser&) = delete;
269 #endif
270 };
271 
272 #endif /* vtkDICOMParser_h */
Character sets.
Definition: vtkDICOMCharacterSet.h:55
A class that provides basic input/output operations.
Definition: vtkDICOMFile.h:34
An item in a DICOM sequence (type SQ).
Definition: vtkDICOMItem.h:34
A container class for DICOM metadata.
Definition: vtkDICOMMetaData.h:44
A meta data reader for DICOM data.
Definition: vtkDICOMParser.h:48
virtual bool ReadFile(vtkDICOMMetaData *data, int idx)
Read the file into the provided metadata object.
static vtkDICOMParser * New()
Create a new vtkDICOMParser instance.
unsigned int GetPixelDataVL()
Get the VL for the PixelData, will be 0xffffffff if compressed.
Definition: vtkDICOMParser.h:144
void SetQuery(vtkDICOMMetaData *query)
Set a query. Only matching data will be retrieved.
void SetBufferSize(int size)
Set the buffer size, the default is 8192 (8k).
vtkTypeInt64 GetFileSize()
Get the total file length (only valid after Update).
Definition: vtkDICOMParser.h:156
void SetGroups(vtkUnsignedShortArray *groups)
Set specific metadata groups to read (obsolete).
vtkTypeInt64 GetFileOffset()
Get the byte offset to the end of the metadata.
Definition: vtkDICOMParser.h:153
bool ReadMetaHeader(const unsigned char *&cp, const unsigned char *&ep, vtkDICOMMetaData *data, int idx)
Read just the meta header (group 0x0002).
void SetOverrideCharacterSet(bool b)
Override the value stored in SpecificCharacterSet.
unsigned long GetErrorCode()
Get the error code.
Definition: vtkDICOMParser.h:173
bool GetPixelDataFound()
This is true only if PixelData was found in the file.
Definition: vtkDICOMParser.h:141
void SetQueryItem(const vtkDICOMItem &query)
Set a query, using an item instead of vtkDICOMMetaData.
void PrintSelf(ostream &os, vtkIndent indent) VTK_DICOM_OVERRIDE
Print a summary of the contents of this object.
bool ReadMetaData(const unsigned char *&cp, const unsigned char *&ep, vtkDICOMMetaData *data, int idx)
Read the meta data following the meta header.
vtkTypeInt64 GetBytesProcessed(const unsigned char *cp, const unsigned char *ep)
Compute the file offset to the current position.
void SetDefaultCharacterSet(vtkDICOMCharacterSet cs)
Set the character set to use if SpecificCharacterSet is missing.
abstract base class for most VTK objects
Definition: vtkObject.h:54