vtk-dicom  0.8.17
vtkDICOMReader.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 =========================================================================*/
22 #ifndef vtkDICOMReader_h
23 #define vtkDICOMReader_h
24 
25 #include "vtkImageReader2.h"
26 #include "vtkDICOMModule.h" // For export macro
27 #include "vtkDICOMConfig.h" // For configuration details
28 #include "vtkDICOMCharacterSet.h" // For character sets
29 
30 // Declare VTK classes within VTK's optional namespace
31 #if defined(VTK_ABI_NAMESPACE_BEGIN)
32 VTK_ABI_NAMESPACE_BEGIN
33 #endif
34 
35 class vtkIntArray;
36 class vtkTypeInt64Array;
37 class vtkStringArray;
38 class vtkMatrix4x4;
39 class vtkMedicalImageProperties;
40 
41 #if defined(VTK_ABI_NAMESPACE_BEGIN)
42 VTK_ABI_NAMESPACE_END
43 #endif
44 
45 class vtkDICOMMetaData;
46 class vtkDICOMParser;
48 
49 // For compatibility with VTK 7.0 and earlier
50 #ifndef VTK_TYPE_BOOL_TYPEDEFED
51 #define VTK_TYPE_BOOL_TYPEDEFED
52 typedef int vtkTypeBool;
53 #endif
54 
55 //----------------------------------------------------------------------------
56 class VTKDICOM_EXPORT vtkDICOMReader : public vtkImageReader2
57 {
58 public:
60 
62  static vtkDICOMReader *New();
63 
65  void PrintSelf(ostream& os, vtkIndent indent) VTK_DICOM_OVERRIDE;
66 
68  const char* GetFileExtensions() VTK_DICOM_OVERRIDE {
70  return ".dcm .dc"; }
71 
73  const char* GetDescriptiveName() VTK_DICOM_OVERRIDE {
74  return "DICOM"; }
75 
77  int CanReadFile(const char* filename) VTK_DICOM_OVERRIDE;
79 
81 
87  void SetDesiredStackID(const char *stackId);
88  const char *GetDesiredStackID() { return this->DesiredStackID; }
89 
91 
94  vtkStringArray *GetStackIDs() { return this->StackIDs; }
96 
98 
111  vtkIntArray *GetFileIndexArray() { return this->FileIndexArray; }
112 
114 
120  vtkIntArray *GetFrameIndexArray() { return this->FrameIndexArray; }
122 
124 
132  vtkDICOMMetaData *GetMetaData() { return this->MetaData; }
134 
136 
146  vtkDICOMCharacterSet GetDefaultCharacterSet() {
147  return this->DefaultCharacterSet; }
148 
150 
155  vtkSetMacro(OverrideCharacterSet, bool);
156  vtkBooleanMacro(OverrideCharacterSet, bool);
157  bool GetOverrideCharacterSet() {
158  return this->OverrideCharacterSet; }
160 
162  vtkGetMacro(Sorting, int);
164  vtkSetMacro(Sorting, int);
165  vtkBooleanMacro(Sorting, int);
167 
169 
175  vtkDICOMSliceSorter *GetSorter() { return this->Sorter; }
177 
179 
187  vtkGetMacro(TimeAsVector, int);
188  vtkSetMacro(TimeAsVector, int);
189  vtkBooleanMacro(TimeAsVector, int);
191 
193  int GetTimeDimension() { return this->TimeDimension; }
195  double GetTimeSpacing() { return this->TimeSpacing; }
197 
199  vtkSetMacro(DesiredTimeIndex, int);
201  vtkGetMacro(DesiredTimeIndex, int);
203 
205 
210  vtkGetMacro(AutoYBRToRGB, int);
211  vtkSetMacro(AutoYBRToRGB, int);
212  vtkBooleanMacro(AutoYBRToRGB, int);
214 
216 
227  vtkGetMacro(AutoRescale, int);
228  vtkSetMacro(AutoRescale, int);
229  vtkBooleanMacro(AutoRescale, int);
231 
233 
244  double GetRescaleSlope() { return this->RescaleSlope; }
245  double GetRescaleIntercept() { return this->RescaleIntercept; }
247 
249 
255  vtkMatrix4x4 *GetPatientMatrix() { return this->PatientMatrix; }
257 
259 
267  vtkImageData *GetOverlayOutput();
268  vtkAlgorithmOutput *GetOverlayOutputPort();
269  void SetOverlayOutput(vtkImageData *data);
270 
272  bool HasOverlay() { return (this->OverlayBitfield != 0); }
273 
275  unsigned short GetOverlayBitfield() { return this->OverlayBitfield; }
277 
279  vtkMedicalImageProperties *GetMedicalImageProperties();
282 
284  enum RowOrder { FileNative, TopDown, BottomUp };
285 
287 
293  void SetMemoryRowOrder(int order);
294  void SetMemoryRowOrderToFileNative() {
295  this->SetMemoryRowOrder(FileNative); }
296  void SetMemoryRowOrderToTopDown() {
297  this->SetMemoryRowOrder(TopDown); }
298  void SetMemoryRowOrderToBottomUp() {
299  this->SetMemoryRowOrder(BottomUp); }
300  int GetMemoryRowOrder() { return this->MemoryRowOrder; }
301  const char *GetMemoryRowOrderAsString();
303 
305 
314  vtkSetMacro(OutputScalarType, int);
315  vtkGetMacro(OutputScalarType, int);
317 
318 #ifndef __WRAP__
320  using Superclass::Update;
322  void Update() VTK_DICOM_OVERRIDE;
324 #endif
325 
327 
336  static void RegisterCodecs();
337  static void UnRegisterCodecs();
339 
340 protected:
341  vtkDICOMReader();
342  ~vtkDICOMReader() VTK_DICOM_OVERRIDE;
343 
345  vtkTypeBool ProcessRequest(
347  vtkInformation* request, vtkInformationVector** inputVector,
348  vtkInformationVector* outputVector) VTK_DICOM_OVERRIDE;
349 
351  int RequestInformation(
352  vtkInformation* request, vtkInformationVector** inputVector,
353  vtkInformationVector* outputVector) VTK_DICOM_OVERRIDE;
354 
356  int RequestData(
357  vtkInformation* request, vtkInformationVector** inputVector,
358  vtkInformationVector* outputVector) VTK_DICOM_OVERRIDE;
360 
362  virtual bool ReadOverlays(vtkImageData *data);
364 
366  void UnpackOverlay(
367  const void *filePtr, vtkIdType bitskip, vtkIdType count,
368  void *buffer, vtkIdType incr, int bit);
370 
372  virtual bool ReadOneFile(
374  const char *filename, int idx,
375  unsigned char *buffer, vtkIdType bufferSize);
376 
378  void MaskBits(void *buffer, vtkIdType bufferSize, int scalarSize,
379  int bitsStored, int pixelRepresentation);
380 
382  void UnpackBits(
383  const void *source, void *buffer, vtkIdType bufferSize, int bits);
384 
386  void UnpackYBR422(
387  const void *source, void *buffer, vtkIdType bufferSize, vtkIdType rowlen);
388 
390  virtual bool ReadFileNative(
391  const char *filename, int idx,
392  unsigned char *buffer, vtkIdType bufferSize);
393 
395  virtual bool ReadFileDelegated(
396  const char *filename, int idx,
397  unsigned char *buffer, vtkIdType bufferSize);
399 
401  virtual int ComputeRescaledScalarType(
403  int scalarType, int bitsStored, int pixelRepresentation);
404 
406  virtual void RescaleBuffer(
407  int fileIdx, int frameIdx, int fileType, int outputType,
408  int numFileComponents, int numComponents,
409  void *fileBuffer, void *outputBuffer, vtkIdType bufferSize);
410 
412  virtual void YBRToRGB(
413  int fileIdx, int frameIdx, void *buffer, vtkIdType bufferSize);
415 
417  void RelayError(vtkObject *o, unsigned long e, void *data);
420 
422 
427  virtual bool ValidateStructure(
428  vtkIntArray *fileArray, vtkIntArray *frameArray);
429 
431  virtual void SortFiles(vtkIntArray *fileArray, vtkIntArray *frameArray);
432 
434  void NoSortFiles(vtkIntArray *fileArray, vtkIntArray *frameArray);
436 
438  virtual void UpdateMedicalImageProperties();
441 
443  int Sorting;
444 
446  double RescaleIntercept;
447  double RescaleSlope;
448 
450  vtkMatrix4x4 *PatientMatrix;
451 
453  vtkDICOMMetaData *MetaData;
454 
456  vtkMedicalImageProperties *MedicalImageProperties;
457 
459  vtkDICOMCharacterSet DefaultCharacterSet;
460 
462  bool OverrideCharacterSet;
463 
465  vtkDICOMParser *Parser;
466 
469 
471  vtkTypeInt64Array *FileOffsetArray;
472 
474  vtkIntArray *FileIndexArray;
475 
477  vtkIntArray *FrameIndexArray;
478 
480  vtkStringArray *StackIDs;
481 
483  int MemoryRowOrder;
484 
486  int NeedsRescale;
487  int AutoRescale;
488  int FileScalarType;
489  int OutputScalarType;
490 
492  int NeedsYBRToRGB;
493  int AutoYBRToRGB;
494 
496 
499  int NumberOfPackedComponents;
500 
502  int NumberOfPlanarComponents;
503 
505  int TimeAsVector;
506  int TimeDimension;
507  int DesiredTimeIndex;
508  double TimeSpacing;
509 
511  char DesiredStackID[20];
512 
514  unsigned short OverlayBitfield;
515  bool UpdateOverlayFlag;
516 
517 private:
518 #ifdef VTK_DICOM_DELETE
519  vtkDICOMReader(const vtkDICOMReader&) VTK_DICOM_DELETE;
520  void operator=(const vtkDICOMReader&) VTK_DICOM_DELETE;
521 #else
522  vtkDICOMReader(const vtkDICOMReader&) = delete;
523  void operator=(const vtkDICOMReader&) = delete;
524 #endif
525 };
526 
529 
533 class VTKDICOM_EXPORT vtkDICOMReaderInitializer
534 {
535 public:
536  vtkDICOMReaderInitializer();
537  ~vtkDICOMReaderInitializer();
538 private:
539  vtkDICOMReaderInitializer(const vtkDICOMReaderInitializer&);
540  vtkDICOMReaderInitializer& operator=(const vtkDICOMReaderInitializer&);
541 };
542 
543 static vtkDICOMReaderInitializer vtkDICOMReaderInitializerInstance;
545 
546 #endif // vtkDICOMReader_h
Character sets.
Definition: vtkDICOMCharacterSet.h:55
A container class for DICOM metadata.
Definition: vtkDICOMMetaData.h:44
A meta data reader for DICOM data.
Definition: vtkDICOMParser.h:48
Read DICOM image files.
Definition: vtkDICOMReader.h:57
void PrintSelf(ostream &os, vtkIndent indent) VTK_DICOM_OVERRIDE
Print information about this object.
vtkIntArray * GetFrameIndexArray()
Get an array that converts slice index to frame index.
Definition: vtkDICOMReader.h:120
bool HasOverlay()
Returns true if any overlays are present.
Definition: vtkDICOMReader.h:272
void SetDefaultCharacterSet(vtkDICOMCharacterSet cs)
Set the character set to use if SpecificCharacterSet is missing.
vtkIntArray * GetFileIndexArray()
Get an array that converts slice index to input file index.
Definition: vtkDICOMReader.h:111
vtkImageData * GetOverlayOutput()
Get the overlay.
static void RegisterCodecs()
Control registration of image codecs (DCMTK-specific).
int CanReadFile(const char *filename) VTK_DICOM_OVERRIDE
Return true if this reader can read the given file.
vtkStringArray * GetStackIDs()
Get a list of the stacks that are present in the input files.
Definition: vtkDICOMReader.h:94
static vtkDICOMReader * New()
Static method for construction.
void SetSorter(vtkDICOMSliceSorter *sorter)
Set a custom sorter to be used to sort files and frames into slices.
void SetDesiredStackID(const char *stackId)
Set the Stack ID of the stack to load, for named stacks.
unsigned short GetOverlayBitfield()
Returns a bitfield that indicates which overlays are present.
Definition: vtkDICOMReader.h:275
double GetRescaleSlope()
Get the slope and intercept for rescaling the scalar values.
Definition: vtkDICOMReader.h:244
void Update() VTK_DICOM_OVERRIDE
Update both the image and, if present, the overlay.
const char * GetDescriptiveName() VTK_DICOM_OVERRIDE
Return a descriptive name that might be useful in a GUI.
Definition: vtkDICOMReader.h:73
vtkMatrix4x4 * GetPatientMatrix()
Get a matrix to place the image within DICOM patient coords.
Definition: vtkDICOMReader.h:255
vtkDICOMMetaData * GetMetaData()
Get the meta data for the DICOM files.
Definition: vtkDICOMReader.h:132
RowOrder
Enumeration for top-down vs. bottom-up ordering.
Definition: vtkDICOMReader.h:284
void SetMemoryRowOrder(int order)
Set the ordering of the image rows in memory.
Index a DICOM series to allow proper dimensional ordering.
Definition: vtkDICOMSliceSorter.h:43
Superclass of binary file readers.
Definition: vtkImageReader2.h:53
virtual const char * GetFileExtensions()
Definition: vtkImageReader2.h:289
abstract base class for most VTK objects
Definition: vtkObject.h:54