vtk-dicom  0.8.14
vtkDICOMReader.h
1 /*=========================================================================
2 
3  Program: DICOM for VTK
4 
5  Copyright (c) 2012-2022 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 
326 protected:
327  vtkDICOMReader();
328  ~vtkDICOMReader() VTK_DICOM_OVERRIDE;
329 
331  vtkTypeBool ProcessRequest(
333  vtkInformation* request, vtkInformationVector** inputVector,
334  vtkInformationVector* outputVector) VTK_DICOM_OVERRIDE;
335 
337  int RequestInformation(
338  vtkInformation* request, vtkInformationVector** inputVector,
339  vtkInformationVector* outputVector) VTK_DICOM_OVERRIDE;
340 
342  int RequestData(
343  vtkInformation* request, vtkInformationVector** inputVector,
344  vtkInformationVector* outputVector) VTK_DICOM_OVERRIDE;
346 
348  virtual bool ReadOverlays(vtkImageData *data);
350 
352  void UnpackOverlay(
353  const void *filePtr, vtkIdType bitskip, vtkIdType count,
354  void *buffer, vtkIdType incr, int bit);
356 
358  virtual bool ReadOneFile(
360  const char *filename, int idx,
361  unsigned char *buffer, vtkIdType bufferSize);
362 
364  void MaskBits(void *buffer, vtkIdType bufferSize, int scalarSize,
365  int bitsStored, int pixelRepresentation);
366 
368  void UnpackBits(
369  const void *source, void *buffer, vtkIdType bufferSize, int bits);
370 
372  void UnpackYBR422(
373  const void *source, void *buffer, vtkIdType bufferSize, vtkIdType rowlen);
374 
376  virtual bool ReadFileNative(
377  const char *filename, int idx,
378  unsigned char *buffer, vtkIdType bufferSize);
379 
381  virtual bool ReadFileDelegated(
382  const char *filename, int idx,
383  unsigned char *buffer, vtkIdType bufferSize);
385 
387  virtual int ComputeRescaledScalarType(
389  int scalarType, int bitsStored, int pixelRepresentation);
390 
392  virtual void RescaleBuffer(
393  int fileIdx, int frameIdx, int fileType, int outputType,
394  int numFileComponents, int numComponents,
395  void *fileBuffer, void *outputBuffer, vtkIdType bufferSize);
396 
398  virtual void YBRToRGB(
399  int fileIdx, int frameIdx, void *buffer, vtkIdType bufferSize);
401 
403  void RelayError(vtkObject *o, unsigned long e, void *data);
406 
408 
413  virtual bool ValidateStructure(
414  vtkIntArray *fileArray, vtkIntArray *frameArray);
415 
417  virtual void SortFiles(vtkIntArray *fileArray, vtkIntArray *frameArray);
418 
420  void NoSortFiles(vtkIntArray *fileArray, vtkIntArray *frameArray);
422 
424  virtual void UpdateMedicalImageProperties();
427 
429  int Sorting;
430 
432  double RescaleIntercept;
433  double RescaleSlope;
434 
436  vtkMatrix4x4 *PatientMatrix;
437 
439  vtkDICOMMetaData *MetaData;
440 
442  vtkMedicalImageProperties *MedicalImageProperties;
443 
445  vtkDICOMCharacterSet DefaultCharacterSet;
446 
448  bool OverrideCharacterSet;
449 
451  vtkDICOMParser *Parser;
452 
455 
457  vtkTypeInt64Array *FileOffsetArray;
458 
460  vtkIntArray *FileIndexArray;
461 
463  vtkIntArray *FrameIndexArray;
464 
466  vtkStringArray *StackIDs;
467 
469  int MemoryRowOrder;
470 
472  int NeedsRescale;
473  int AutoRescale;
474  int FileScalarType;
475  int OutputScalarType;
476 
478  int NeedsYBRToRGB;
479  int AutoYBRToRGB;
480 
482 
485  int NumberOfPackedComponents;
486 
488  int NumberOfPlanarComponents;
489 
491  int TimeAsVector;
492  int TimeDimension;
493  int DesiredTimeIndex;
494  double TimeSpacing;
495 
497  char DesiredStackID[20];
498 
500  unsigned short OverlayBitfield;
501  bool UpdateOverlayFlag;
502 
503 private:
504 #ifdef VTK_DICOM_DELETE
505  vtkDICOMReader(const vtkDICOMReader&) VTK_DICOM_DELETE;
506  void operator=(const vtkDICOMReader&) VTK_DICOM_DELETE;
507 #else
508  vtkDICOMReader(const vtkDICOMReader&) = delete;
509  void operator=(const vtkDICOMReader&) = delete;
510 #endif
511 };
512 
513 #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.
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