vtk-dicom  0.8.17
vtkDICOMCompiler.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 vtkDICOMCompiler_h
15 #define vtkDICOMCompiler_h
16 
17 #include "vtkObject.h"
18 #include "vtkDICOMModule.h" // For export macro
19 #include "vtkDICOMConfig.h" // For configuration details
20 
21 // Declare VTK classes within VTK's optional namespace
22 #if defined(VTK_ABI_NAMESPACE_BEGIN)
23 VTK_ABI_NAMESPACE_BEGIN
24 #endif
25 
26 class vtkStringArray;
27 
28 #if defined(VTK_ABI_NAMESPACE_BEGIN)
29 VTK_ABI_NAMESPACE_END
30 #endif
31 
32 class vtkDICOMFile;
33 class vtkDICOMMetaData;
34 class vtkDICOMCompilerInternalFriendship;
35 
37 
41 class VTKDICOM_EXPORT vtkDICOMCompiler : public vtkObject
42 {
43 public:
45  static vtkDICOMCompiler *New();
46 
48  vtkTypeMacro(vtkDICOMCompiler, vtkObject);
49 
51  void PrintSelf(ostream& os, vtkIndent indent) VTK_DICOM_OVERRIDE;
52 
54  vtkSetStringMacro(FileName);
56  vtkGetStringMacro(FileName);
58 
60 
65  vtkSetStringMacro(SOPInstanceUID);
66  vtkGetStringMacro(SOPInstanceUID);
68 
70 
75  vtkSetStringMacro(SeriesInstanceUID);
76  vtkGetStringMacro(SeriesInstanceUID);
78 
80 
85  vtkSetStringMacro(StudyInstanceUID);
86  vtkGetStringMacro(StudyInstanceUID);
88 
90 
94  vtkSetStringMacro(ImplementationClassUID);
95  vtkGetStringMacro(ImplementationClassUID);
97 
99 
103  vtkSetStringMacro(ImplementationVersionName);
104  vtkGetStringMacro(ImplementationVersionName);
106 
108 
114  vtkSetStringMacro(SourceApplicationEntityTitle);
115  vtkGetStringMacro(SourceApplicationEntityTitle);
117 
119 
127  vtkSetStringMacro(TransferSyntaxUID);
128  vtkGetStringMacro(TransferSyntaxUID);
130 
132  void SetMetaData(vtkDICOMMetaData *);
134  vtkDICOMMetaData *GetMetaData() { return this->MetaData; }
136 
138  vtkSetMacro(Index, int);
140  int GetIndex() { return this->Index; }
142 
144 
149  void SetBufferSize(int size);
150  int GetBufferSize() { return this->BufferSize; }
152 
154  virtual void WriteHeader();
156 
158 
163  virtual void WritePixelData(const unsigned char *cp, vtkIdType size);
164 
166  virtual void WriteFrame(const unsigned char *cp, vtkIdType size);
167 
169  virtual void Close();
170 
172 
176  virtual void CloseAndRemove();
177 
179  unsigned long GetErrorCode() { return this->ErrorCode; }
181 
183 
192 
194 
199  vtkSetMacro(KeepOriginalPixelDataVR, bool);
200  vtkBooleanMacro(KeepOriginalPixelDataVR, bool);
201  vtkGetMacro(KeepOriginalPixelDataVR, bool);
203 
204 protected:
206  ~vtkDICOMCompiler() VTK_DICOM_OVERRIDE;
207 
209 
220  virtual bool FlushBuffer(unsigned char* &cp, unsigned char* &ep);
221 
223  virtual void CompileError(const char *message);
224 
226  virtual void DiskFullError();
227 
229  void SetErrorCode(unsigned long e) { this->ErrorCode = e; }
230 
232  virtual bool WriteFile(vtkDICOMMetaData *data, int idx);
233 
236  unsigned char* &cp, unsigned char* &ep,
237  vtkDICOMMetaData *data, int idx);
238 
241  unsigned char* &cp, unsigned char* &ep,
242  vtkDICOMMetaData *data, int idx);
243 
246 
249 
251  unsigned int ComputePixelDataSize();
252 
253  char *FileName;
254  char *SOPInstanceUID;
255  char *SeriesInstanceUID;
256  char *StudyInstanceUID;
257  char *ImplementationClassUID;
258  char *ImplementationVersionName;
259  char *SourceApplicationEntityTitle;
260  char *TransferSyntaxUID;
261  vtkDICOMMetaData *MetaData;
262  vtkStringArray *SeriesUIDs;
263  vtkDICOMFile *OutputFile;
264  unsigned char *Buffer;
265  unsigned char **FrameData;
266  unsigned int *FrameLength;
267  unsigned int FrameCounter;
268  int BufferSize;
269  int ChunkSize;
270  int Index;
271  bool BigEndian;
272  bool Compressed;
273  bool KeepOriginalPixelDataVR;
274  unsigned long ErrorCode;
275 
276  static char StudyUID[64];
277 
278  // used to share FlushBuffer with internal classes
279  friend class vtkDICOMCompilerInternalFriendship;
280 
281 private:
282 #ifdef VTK_DICOM_DELETE
283  vtkDICOMCompiler(const vtkDICOMCompiler&) VTK_DICOM_DELETE;
284  void operator=(const vtkDICOMCompiler&) VTK_DICOM_DELETE;
285 #else
286  vtkDICOMCompiler(const vtkDICOMCompiler&) = delete;
287  void operator=(const vtkDICOMCompiler&) = delete;
288 #endif
289 };
290 
291 #endif /* vtkDICOMCompiler_h */
A writer for DICOM meta data.
Definition: vtkDICOMCompiler.h:42
virtual void Close()
Close the file.
virtual void WriteFrame(const unsigned char *cp, vtkIdType size)
Write one frame to the end of the file.
unsigned long GetErrorCode()
Get the IO error code.
Definition: vtkDICOMCompiler.h:179
void SetBufferSize(int size)
Set the buffer size, the default is 8192 (8k).
virtual bool WriteFile(vtkDICOMMetaData *data, int idx)
Generate the file from the provided metadata object.
static vtkDICOMCompiler * New()
Create a new vtkDICOMCompiler instance.
virtual void WritePixelData(const unsigned char *cp, vtkIdType size)
Write all of the pixel data in one go.
unsigned int ComputePixelDataSize()
Compute the size of the pixel data (0xffffffff if compressed).
bool WriteMetaHeader(unsigned char *&cp, unsigned char *&ep, vtkDICOMMetaData *data, int idx)
Write just the meta header (group 0x0002).
void GenerateSeriesUIDs()
Generate a series UID and instance UIDs for the meta data.
virtual void CloseAndRemove()
Close the file and delete it.
void PrintSelf(ostream &os, vtkIndent indent) VTK_DICOM_OVERRIDE
Print a summary of the contents of this object.
void FreeFragments()
Free any fragments that are stored in memory.
bool WriteFragments()
Write the fragments of the compressed data.
bool WriteMetaData(unsigned char *&cp, unsigned char *&ep, vtkDICOMMetaData *data, int idx)
Write the meta data following the meta header.
A class that provides basic input/output operations.
Definition: vtkDICOMFile.h:34
A container class for DICOM metadata.
Definition: vtkDICOMMetaData.h:44
abstract base class for most VTK objects
Definition: vtkObject.h:54