GDCM  2.2.0
vtkGDCMImageReader.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: GDCM (Grassroots DICOM). A DICOM library
4 
5  Copyright (c) 2006-2011 Mathieu Malaterre
6  All rights reserved.
7  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html 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 // .NAME vtkGDCMImageReader - read DICOM Image files (Pixel Data)
15 // .SECTION Description
16 // vtkGDCMImageReader is a source object that reads some DICOM files
17 // this reader is single threaded.
18 // .SECTION Implementation note: when FileLowerLeft is set to on the image is not flipped
19 // upside down as VTK would expect, use this option only if you know what you are doing.
20 // .SECTION Implementation note: when reading a series of 2D slices, user is
21 // expected to provide an ordered list of filenames. No sorting will be applied afterward.
22 // .SECTION Implementation note: Although 99% of the time the Zspacing as read
23 // from a tag in a 2D DICOM file should be correct, there has been reports that this
24 // value can be missing, or incorrect, in which case users are advised to override this
25 // value using the return value from gdcm::IPPSorter::GetZSpacing() and set it via
26 // vtkImageChangeInformation on the reader itself.
27 // .SECTION TODO
28 // This reader does not handle a series of 3D images, only a single 3D (multi frame) or a
29 // list of 2D files are supported for now.
30 // .SECTION TODO
31 // Did not implement SetFilePattern / SetFilePrefix API, move it to protected section for now.
32 // .SECTION BUG
33 // Overlay are assumed to have the same extent as image. Right now if overlay origin is not
34 // 0,0 the overlay will have an offset...
35 // Only the very first overlay is loaded at the VTK level, for now (even if there are more than one in the file)
36 // .SECTION DataOrigin
37 // When the reader is instanciated with FileLowerLeftOn the DataOrigin and Image Position (Patient) are
38 // identical. But when FileLowerLeft is Off, we have to reorder the Y-line of the image, and thus the DataOrigin
39 // is then translated to the other side of the image.
40 // .SECTION Spacing
41 // When reading a 3D volume, the spacing along the Z dimension might be negative (so as to respect up-side-down)
42 // as specified in the Image Orientation (Patient) tag. When Z-spacing is 0, this means the multi-frame object
43 // contains image which do not represent uniform volume.
44 // .SECTION Warning
45 // When using vtkGDCMPolyDataReader in conjonction with vtkGDCMImageReader
46 // it is *required* that FileLowerLeft is set to ON as coordinate system
47 // would be inconsistant in between the two data structures.
48 // .SECTION Color Space mapping:
49 // * VTK_LUMINANCE <-> MONOCHROME2
50 // * VTK_LUMINANCE_ALPHA <-> Not supported
51 // * VTK_RGB <-> RGB
52 // * VTK_RGBA <-> ARGB (deprecated, DICOM 2008)
53 // * VTK_INVERSE_LUMINANCE <-> MONOCHROME1
54 // * VTK_LOOKUP_TABLE <-> PALETTE COLOR
55 // * VTK_YBR <-> YBR_FULL
56 //
57 // For detailed information on color space transformation and true lossless transformation see:
58 // http://apps.sourceforge.net/mediawiki/gdcm/index.php?title=Color_Space_Transformations
59 
60 // .SECTION See Also
61 // vtkMedicalImageReader2 vtkMedicalImageProperties vtkGDCMPolyDataReader vtkGDCMImageWriter
62 // vtkDICOMImageReader
63 
64 #ifndef VTKGDCMIMAGEREADER_H
65 #define VTKGDCMIMAGEREADER_H
66 
67 #include "vtkMedicalImageReader2.h"
68 #include "vtkImageData.h"
69 
70 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
71 #else
72 class vtkMedicalImageProperties;
73 #endif
74 #if ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
75 #else
76 class vtkStringArray;
77 #endif
78 class vtkPolyData;
79 
80 // vtkSystemIncludes.h defines:
81 // #define VTK_LUMINANCE 1
82 // #define VTK_LUMINANCE_ALPHA 2
83 // #define VTK_RGB 3
84 // #define VTK_RGBA 4
85 #ifndef VTK_INVERSE_LUMINANCE
86 #define VTK_INVERSE_LUMINANCE 5
87 #endif
88 #ifndef VTK_LOOKUP_TABLE
89 #define VTK_LOOKUP_TABLE 6
90 #endif
91 #ifndef VTK_YBR
92 #define VTK_YBR 7
93 #endif
94 #ifndef VTK_CMYK
95 #define VTK_CMYK 8
96 #endif
97 
98 //BTX
99 namespace gdcm { class ImageReader; }
100 //ETX
101 class vtkMatrix4x4;
102 class VTK_EXPORT vtkGDCMImageReader : public vtkMedicalImageReader2
103 {
104 public:
105  static vtkGDCMImageReader *New();
106  vtkTypeRevisionMacro(vtkGDCMImageReader,vtkMedicalImageReader2);
107  virtual void PrintSelf(ostream& os, vtkIndent indent);
108 
109  // Description: is the given file name a DICOM file containing an image ?
110  virtual int CanReadFile(const char* fname);
111 
112  // Description:
113  // Valid extensions
114  virtual const char* GetFileExtensions()
115  {
116  // I would like to get rid of ACR/NEMA/IMA so only allow dcm extension for now
117  return ".dcm .DCM";
118  }
119 
120  // Description:
121  // A descriptive name for this format
122  virtual const char* GetDescriptiveName()
123  {
124  return "DICOM";
125  }
126 
127  // Description:
128  // Get the Image Position (Patient) as stored in the DICOM file
129  // This is a read-only data member
130  vtkGetObjectMacro(DirectionCosines, vtkMatrix4x4);
131 
132 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
133 #else
134  // Description:
135  // Get the medical image properties object
136  vtkGetObjectMacro(MedicalImageProperties, vtkMedicalImageProperties);
137 #endif
138  virtual void SetMedicalImageProperties(vtkMedicalImageProperties *pd);
139 
140 #if ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
141 #else
142  virtual void SetFileNames(vtkStringArray*);
143  vtkGetObjectMacro(FileNames, vtkStringArray);
144 #endif
145 
146  // Description:
147  // Specifically request to load the overlay into the gdcm-VTK layer (gdcm always loads them when found).
148  // If no overlay is found in the image, then the vtkImageData for the overlay will be empty.
149  vtkGetMacro(LoadOverlays,int);
150  vtkSetMacro(LoadOverlays,int);
151  vtkBooleanMacro(LoadOverlays,int);
152 
153  // Description:
154  // Set/Get whether or not to load the Icon as vtkImageData (if found in the DICOM file)
155  vtkGetMacro(LoadIconImage,int);
156  vtkSetMacro(LoadIconImage,int);
157  vtkBooleanMacro(LoadIconImage,int);
158 
159  // Description:
160  // Set/Get whether or not the image was compressed using a lossy compression algorithm
161  vtkGetMacro(LossyFlag,int);
162  vtkSetMacro(LossyFlag,int);
163  vtkBooleanMacro(LossyFlag,int);
164 
165  // Description:
166  // Read only: number of overlays as found in this image (multiple overlays per slice is allowed)
167  // Only valid when LoadOverlays is true
168  vtkGetMacro(NumberOfOverlays,int);
169 
170  // Description:
171  // Read only: number of icon image (there can only be zero or one icon per file)
172  // Only valid when LoadIconImage is true
173  vtkGetMacro(NumberOfIconImages,int);
174 
175  // Description:
176  // Get Overlay/IconImage
177  // Remember to ALWAYS use those methods in your code, as the internal number for the output port
178  // is not garantee to remain the same, as features are added to the reader
179 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
180 //FIXME: Need to get rid of BTX/ETX if only the Python Wrapper of VTK 4.2 would let me
181 //BTX
182  vtkAlgorithmOutput* GetOverlayPort(int index);
183  vtkAlgorithmOutput* GetIconImagePort();
184 //ETX
185 #endif
186  vtkImageData* GetOverlay(int i);
187  vtkImageData* GetIconImage();
188 
189  // Description:
190  // Load image with its associated Lookup Table
191  vtkGetMacro(ApplyLookupTable,int);
192  vtkSetMacro(ApplyLookupTable,int);
193  vtkBooleanMacro(ApplyLookupTable,int);
194 
195  // Description:
196  // Load image as YBR
197  vtkGetMacro(ApplyYBRToRGB,int)
198  vtkSetMacro(ApplyYBRToRGB,int)
199  vtkBooleanMacro(ApplyYBRToRGB,int);
200 
201  // Description:
202  // Return VTK_LUMINANCE, VTK_INVERSE_LUMINANCE, VTK_RGB, VTK_RGBA, VTK_LOOKUP_TABLE, VTK_YBR or VTK_CMYK
203  // or 0 when ImageFormat is not handled.
204  // Warning: For color image, PlanarConfiguration need to be taken into account.
205  vtkGetMacro(ImageFormat,int);
206 
207  // Description:
208  // Return the Planar Configuration. This simply means that the internal DICOM image was stored
209  // using a particular planar configuration (most of the time: 0)
210  // For monochrome image, PlanarConfiguration is always 0
211  vtkGetMacro(PlanarConfiguration,int);
212 
213  // Description:
214  // Return the 'raw' information stored in the DICOM file:
215  // In case of a series of multiple files, only the first file is considered. The Image Orientation (Patient)
216  // is garantee to remain the same, and image Image Position (Patient) in other slice can be computed
217  // using the ZSpacing (3rd dimension)
218  // (0020,0032) DS [87.774866\-182.908510\168.629671] # 32, 3 ImagePositionPatient
219  // (0020,0037) DS [0.001479\0.999989\-0.004376\-0.002039\-0.004372\-0.999988] # 58, 6 ImageOrientationPatient
220  vtkGetVector3Macro(ImagePositionPatient,double);
221  vtkGetVector6Macro(ImageOrientationPatient,double);
222 
223  // Description:
224  // Set/Get the first Curve Data:
225  vtkGetObjectMacro(Curve,vtkPolyData);
226  virtual void SetCurve(vtkPolyData *pd);
227 
228  // Description:
229  // \DEPRECATED:
230  // Modality LUT
231  // Value returned by GetShift/GetScale might be innacurate since Shift/Scale could be
232  // varying along the Series read. Therefore user are advices not to use those functions
233  // anymore
234  vtkGetMacro(Shift,double);
235  vtkGetMacro(Scale,double);
236 
237 protected:
239  ~vtkGDCMImageReader();
240 
241  vtkSetVector6Macro(ImageOrientationPatient,double);
242 
243 //BTX
244  void FillMedicalImageInformation(const gdcm::ImageReader &reader);
245 //ETX
246  int RequestInformationCompat();
247  int RequestDataCompat();
248 
249 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
250  int ProcessRequest(vtkInformation* request,
251  vtkInformationVector** inputVector,
252  vtkInformationVector* outputVector);
253  int RequestInformation(vtkInformation *request,
254  vtkInformationVector **inputVector,
255  vtkInformationVector *outputVector);
256  int RequestData(vtkInformation *request,
257  vtkInformationVector **inputVector,
258  vtkInformationVector *outputVector);
259 #else /*(VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )*/
260  void ExecuteInformation();
261  void ExecuteData(vtkDataObject *out);
262 #endif /*(VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )*/
263 
264 protected:
265 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
266 #else
267  // Description:
268  // Medical Image properties
269  vtkMedicalImageProperties *MedicalImageProperties;
270 #endif
271 #if ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
272 #else
273  vtkStringArray *FileNames;
274 #endif
275 
276  vtkMatrix4x4 *DirectionCosines;
281  int IconImageDataExtent[6];
282  double ImagePositionPatient[3];
283  double ImageOrientationPatient[6];
284  vtkPolyData *Curve;
285 
287  // the following 3, should remain optional
291  // I think that planar configuration need to always be applied as far as VTK is concerned
294 
295  int LoadSingleFile(const char *filename, char *pointer, unsigned long &outlen);
296 
297  double Shift;
298  double Scale;
304 
305 protected:
306  // TODO / FIXME
307  void SetFilePrefix(const char *) {}
308  vtkGetStringMacro(FilePrefix);
309  void SetFilePattern(const char *) {}
310  vtkGetStringMacro(FilePattern);
311 
312 private:
313  vtkGDCMImageReader(const vtkGDCMImageReader&); // Not implemented.
314  void operator=(const vtkGDCMImageReader&); // Not implemented.
315 };
316 #endif

Generated on Wed Jun 13 2012 20:40:37 for GDCM by doxygen 1.8.1
SourceForge.net Logo