GDCM 3.0.24
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 instantiated 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 conjunction with vtkGDCMImageReader
46// it is *required* that FileLowerLeft is set to ON as coordinate system
47// would be inconsistent 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://gdcm.sourceforge.net/wiki/index.php/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 "vtkgdcmModule.h"
68#include "vtkMedicalImageReader2.h"
69#include "vtkImageData.h"
70#include "vtkVersion.h"
71
72#if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
73#else
74class vtkMedicalImageProperties;
75#endif
76#if (VTK_MAJOR_VERSION > 5) || ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
77#else
78class vtkStringArray;
79#endif
80class vtkPolyData;
81
82// vtkSystemIncludes.h defines:
83// #define VTK_LUMINANCE 1
84// #define VTK_LUMINANCE_ALPHA 2
85// #define VTK_RGB 3
86// #define VTK_RGBA 4
87#ifndef VTK_INVERSE_LUMINANCE
88#define VTK_INVERSE_LUMINANCE 5
89#endif
90#ifndef VTK_LOOKUP_TABLE
91#define VTK_LOOKUP_TABLE 6
92#endif
93#ifndef VTK_YBR
94#define VTK_YBR 7
95#endif
96#ifndef VTK_CMYK
97#define VTK_CMYK 8
98#endif
99
100//BTX
101namespace gdcm { class ImageReader; }
102//ETX
103class vtkMatrix4x4;
104class VTKGDCM_EXPORT vtkGDCMImageReader : public vtkMedicalImageReader2
105{
106public:
108 vtkTypeMacro(vtkGDCMImageReader,vtkMedicalImageReader2);
109 virtual void PrintSelf(ostream& os, vtkIndent indent);
110
111 // Description: is the given file name a DICOM file containing an image ?
112 virtual int CanReadFile(const char* fname);
113
114 // Description:
115 // Valid extensions
116 virtual const char* GetFileExtensions()
117 {
118 // I would like to get rid of ACR/NEMA/IMA so only allow dcm extension for now
119 return ".dcm .DCM";
120 }
121
122 // Description:
123 // A descriptive name for this format
124 virtual const char* GetDescriptiveName()
125 {
126 return "DICOM";
127 }
128
129 // Description:
130 // Get the Image Position (Patient) as stored in the DICOM file
131 // This is a read-only data member
132 vtkGetObjectMacro(DirectionCosines, vtkMatrix4x4);
133
134#if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
135#else
136 // Description:
137 // Get the medical image properties object
138 vtkGetObjectMacro(MedicalImageProperties, vtkMedicalImageProperties);
139#endif
140 virtual void SetMedicalImageProperties(vtkMedicalImageProperties *pd);
141
142#if (VTK_MAJOR_VERSION > 5) || ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
143#else
144 virtual void SetFileNames(vtkStringArray*);
145 vtkGetObjectMacro(FileNames, vtkStringArray);
146#endif
147
148 // Description:
149 // Specifically request to load the overlay into the gdcm-VTK layer (gdcm always loads them when found).
150 // If no overlay is found in the image, then the vtkImageData for the overlay will be empty.
151 vtkGetMacro(LoadOverlays,int);
152 vtkSetMacro(LoadOverlays,int);
153 vtkBooleanMacro(LoadOverlays,int);
154
155 // Description:
156 // Set/Get whether or not to load the Icon as vtkImageData (if found in the DICOM file)
157 vtkGetMacro(LoadIconImage,int);
158 vtkSetMacro(LoadIconImage,int);
159 vtkBooleanMacro(LoadIconImage,int);
160
161 // Description:
162 // Set/Get whether or not the image was compressed using a lossy compression algorithm
163 vtkGetMacro(LossyFlag,int);
164 vtkSetMacro(LossyFlag,int);
165 vtkBooleanMacro(LossyFlag,int);
166
167 // Description:
168 // Read only: number of overlays as found in this image (multiple overlays per slice is allowed)
169 // Only valid when LoadOverlays is true
170 vtkGetMacro(NumberOfOverlays,int);
171
172 // Description:
173 // Read only: number of icon image (there can only be zero or one icon per file)
174 // Only valid when LoadIconImage is true
175 vtkGetMacro(NumberOfIconImages,int);
176
177 // Description:
178 // Get Overlay/IconImage
179 // Remember to ALWAYS use those methods in your code, as the internal number for the output port
180 // is not guaranteed to remain the same, as features are added to the reader
181#if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
182//FIXME: Need to get rid of BTX/ETX if only the Python Wrapper of VTK 4.2 would let me
183//BTX
184 vtkAlgorithmOutput* GetOverlayPort(int index);
185 vtkAlgorithmOutput* GetIconImagePort();
186//ETX
187#endif
188 vtkImageData* GetOverlay(int i);
189 vtkImageData* GetIconImage();
190
191 // Description:
192 // Load image with its associated Lookup Table
193 vtkGetMacro(ApplyLookupTable,int);
194 vtkSetMacro(ApplyLookupTable,int);
195 vtkBooleanMacro(ApplyLookupTable,int);
196
197 // Description:
198 // Load image as YBR
199 vtkGetMacro(ApplyYBRToRGB,int)
200 vtkSetMacro(ApplyYBRToRGB,int)
201 vtkBooleanMacro(ApplyYBRToRGB,int);
202
203 // Description:
204 // Return VTK_LUMINANCE, VTK_INVERSE_LUMINANCE, VTK_RGB, VTK_RGBA, VTK_LOOKUP_TABLE, VTK_YBR or VTK_CMYK
205 // or 0 when ImageFormat is not handled.
206 // Warning: For color image, PlanarConfiguration need to be taken into account.
207 vtkGetMacro(ImageFormat,int);
208
209 // Description:
210 // Return the Planar Configuration. This simply means that the internal DICOM image was stored
211 // using a particular planar configuration (most of the time: 0)
212 // For monochrome image, PlanarConfiguration is always 0
213 vtkGetMacro(PlanarConfiguration,int);
214
215 // Description:
216 // Return the 'raw' information stored in the DICOM file:
217 // In case of a series of multiple files, only the first file is considered. The Image Orientation (Patient)
218 // is guaranteed to remain the same, and image Image Position (Patient) in other slice can be computed
219 // using the ZSpacing (3rd dimension)
220 // (0020,0032) DS [87.774866\-182.908510\168.629671] # 32, 3 ImagePositionPatient
221 // (0020,0037) DS [0.001479\0.999989\-0.004376\-0.002039\-0.004372\-0.999988] # 58, 6 ImageOrientationPatient
222 vtkGetVector3Macro(ImagePositionPatient,double);
223 vtkGetVector6Macro(ImageOrientationPatient,double);
224
225 // Description:
226 // Set/Get the first Curve Data:
227 vtkGetObjectMacro(Curve,vtkPolyData);
228 virtual void SetCurve(vtkPolyData *pd);
229
230 // Description:
231 // \DEPRECATED:
232 // Modality LUT
233 // Value returned by GetShift/GetScale might be inaccurate since Shift/Scale could be
234 // varying along the Series read. Therefore user are advices not to use those functions
235 // anymore
236 vtkGetMacro(Shift,double);
237 vtkGetMacro(Scale,double);
238
239protected:
242
243 vtkSetVector6Macro(ImageOrientationPatient,double);
244
245//BTX
246 void FillMedicalImageInformation(const gdcm::ImageReader &reader);
247//ETX
248 int RequestInformationCompat();
249 int RequestDataCompat();
250
251#if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
252 int ProcessRequest(vtkInformation* request,
253 vtkInformationVector** inputVector,
254 vtkInformationVector* outputVector);
255 int RequestInformation(vtkInformation *request,
256 vtkInformationVector **inputVector,
257 vtkInformationVector *outputVector);
258 int RequestData(vtkInformation *request,
259 vtkInformationVector **inputVector,
260 vtkInformationVector *outputVector);
261#else /*(VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )*/
263 void ExecuteData(vtkDataObject *out);
264#endif /*(VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )*/
265
266protected:
267#if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
268#else
269 // Description:
270 // Medical Image properties
271 vtkMedicalImageProperties *MedicalImageProperties;
272#endif
273#if (VTK_MAJOR_VERSION > 5) || ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
274#else
275 vtkStringArray *FileNames;
276#endif
277
278 vtkMatrix4x4 *DirectionCosines;
283 int IconImageDataExtent[6];
284 double ImagePositionPatient[3];
285 double ImageOrientationPatient[6];
286 vtkPolyData *Curve;
287
289 // the following 3, should remain optional
293 // I think that planar configuration need to always be applied as far as VTK is concerned
296
297 int LoadSingleFile(const char *filename, char *pointer, unsigned long &outlen);
298
299 double Shift;
300 double Scale;
306
307protected:
308 // TODO / FIXME
309 void SetFilePrefix(const char *) {}
310 vtkGetStringMacro(FilePrefix);
311 void SetFilePattern(const char *) {}
312 vtkGetStringMacro(FilePattern);
313
314private:
315 vtkGDCMImageReader(const vtkGDCMImageReader&); // Not implemented.
316 void operator=(const vtkGDCMImageReader&); // Not implemented.
317};
318#endif
Definition vtkGDCMImageReader.h:105
void SetFilePattern(const char *)
Definition vtkGDCMImageReader.h:311
int NumberOfIconImages
Definition vtkGDCMImageReader.h:282
virtual void SetFileNames(vtkStringArray *)
vtkGetObjectMacro(MedicalImageProperties, vtkMedicalImageProperties)
int ForceRescale
Definition vtkGDCMImageReader.h:305
vtkGetMacro(NumberOfOverlays, int)
int LoadSingleFile(const char *filename, char *pointer, unsigned long &outlen)
virtual const char * GetDescriptiveName()
Definition vtkGDCMImageReader.h:124
int LossyFlag
Definition vtkGDCMImageReader.h:304
virtual void SetMedicalImageProperties(vtkMedicalImageProperties *pd)
vtkGetObjectMacro(DirectionCosines, vtkMatrix4x4)
double Shift
Definition vtkGDCMImageReader.h:299
int ApplyLookupTable
Definition vtkGDCMImageReader.h:291
vtkMedicalImageProperties * MedicalImageProperties
Definition vtkGDCMImageReader.h:271
virtual void PrintSelf(ostream &os, vtkIndent indent)
int ApplyPlanarConfiguration
Definition vtkGDCMImageReader.h:294
int ImageFormat
Definition vtkGDCMImageReader.h:288
vtkSetMacro(LoadIconImage, int)
vtkGetMacro(LoadIconImage, int)
vtkBooleanMacro(LossyFlag, int)
vtkGetStringMacro(FilePattern)
vtkImageData * GetOverlay(int i)
vtkBooleanMacro(LoadOverlays, int)
int ApplyInverseVideo
Definition vtkGDCMImageReader.h:290
vtkSetMacro(ApplyLookupTable, int)
vtkGetObjectMacro(FileNames, vtkStringArray)
vtkSetMacro(LossyFlag, int)
vtkGetMacro(ApplyLookupTable, int)
vtkPolyData * Curve
Definition vtkGDCMImageReader.h:286
static vtkGDCMImageReader * New()
vtkGetMacro(LossyFlag, int)
int LoadIconImage
Definition vtkGDCMImageReader.h:281
vtkGetStringMacro(FilePrefix)
vtkImageData * GetIconImage()
vtkBooleanMacro(ApplyLookupTable, int)
int LoadOverlays
Definition vtkGDCMImageReader.h:279
virtual int CanReadFile(const char *fname)
int ApplyShiftScale
Definition vtkGDCMImageReader.h:295
int ApplyYBRToRGB
Definition vtkGDCMImageReader.h:292
vtkSetMacro(LoadOverlays, int)
vtkStringArray * FileNames
Definition vtkGDCMImageReader.h:275
vtkMatrix4x4 * DirectionCosines
Definition vtkGDCMImageReader.h:278
void ExecuteData(vtkDataObject *out)
vtkGetMacro(LoadOverlays, int)
int PlanarConfiguration
Definition vtkGDCMImageReader.h:303
int IconNumberOfScalarComponents
Definition vtkGDCMImageReader.h:302
vtkGetMacro(ApplyYBRToRGB, int) vtkSetMacro(ApplyYBRToRGB
vtkBooleanMacro(LoadIconImage, int)
int IconDataScalarType
Definition vtkGDCMImageReader.h:301
double Scale
Definition vtkGDCMImageReader.h:300
int NumberOfOverlays
Definition vtkGDCMImageReader.h:280
virtual const char * GetFileExtensions()
Definition vtkGDCMImageReader.h:116
vtkTypeMacro(vtkGDCMImageReader, vtkMedicalImageReader2)
void SetFilePrefix(const char *)
Definition vtkGDCMImageReader.h:309
vtkGetMacro(NumberOfIconImages, int)
Definition gdcmASN1.h:21