# vtkGDCMImageReader.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program: GDCM (Grassroots DICOM). A DICOM library
    00004   Module:  $URL$
    00005
    00006   Copyright (c) 2006-2010 Mathieu Malaterre
    00007   All rights reserved.
    00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
    00009
    00010      This software is distributed WITHOUT ANY WARRANTY; without even
    00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00012      PURPOSE.  See the above copyright notice for more information.
    00013
    00014 =========================================================================*/
    00015 // .NAME vtkGDCMImageReader - read DICOM Image files (Pixel Data)
    00016 // .SECTION Description
    00017 // vtkGDCMImageReader is a source object that reads some DICOM files
    00018 // this reader is single threaded.
    00019 // .SECTION Implementation note: when FileLowerLeft is set to on the image is not flipped
    00020 // upside down as VTK would expect, use this option only if you know what you are doing.
    00021 // .SECTION Implementation note: when reading a series of 2D slices, user is
    00022 // expected to provide an ordered list of filenames. No sorting will be applied afterward.
    00023 // .SECTION Implementation note: Although 99% of the time the Zspacing as read
    00024 // from a tag in a 2D DICOM file should be correct, there has been reports that this
    00025 // value can be missing, or incorrect, in which case users are advised to override this
    00026 // value using the return value from gdcm::IPPSorter::GetZSpacing() and set it via
    00027 // vtkImageChangeInformation on the reader itself.
    00028 // .SECTION TODO
    00029 // This reader does not handle a series of 3D images, only a single 3D (multi frame) or a
    00030 // list of 2D files are supported for now.
    00031 // .SECTION TODO
    00032 // Did not implement SetFilePattern / SetFilePrefix API, move it to protected section for now.
    00033 // .SECTION BUG
    00034 // Overlay are assumed to have the same extent as image. Right now if overlay origin is not
    00035 // 0,0 the overlay will have an offset...
    00036 // Only the very first overlay is loaded at the VTK level, for now (even if there are more than one in the file)
    00037 // .SECTION DataOrigin
    00038 // When the reader is instanciated with FileLowerLeftOn the DataOrigin and Image Position (Patient) are
    00039 // identical. But when FileLowerLeft is Off, we have to reorder the Y-line of the image, and thus the DataOrigin
    00040 // is then translated to the other side of the image.
    00041 // .SECTION Spacing
    00042 // When reading a 3D volume, the spacing along the Z dimension might be negative (so as to respect up-side-down)
    00043 // as specified in the Image Orientation (Patient) tag. When Z-spacing is 0, this means the multi-frame object
    00044 // contains image which do not represent uniform volume.
    00045 // .SECTION Warning
    00046 // When using vtkGDCMPolyDataReader in conjonction with vtkGDCMImageReader
    00047 // it is *required* that FileLowerLeft is set to ON as coordinate system
    00048 // would be inconsistant in between the two data structures.
    00049 // .SECTION Color Space mapping:
    00050 // * VTK_LUMINANCE         <-> MONOCHROME2
    00051 // * VTK_LUMINANCE_ALPHA   <-> Not supported
    00052 // * VTK_RGB               <-> RGB
    00053 // * VTK_RGBA              <-> ARGB (deprecated, DICOM 2008)
    00054 // * VTK_INVERSE_LUMINANCE <-> MONOCHROME1
    00055 // * VTK_LOOKUP_TABLE      <-> PALETTE COLOR
    00056 // * VTK_YBR               <-> YBR_FULL
    00057 //
    00058 // For detailed information on color space transformation and true lossless transformation see:
    00059 // http://apps.sourceforge.net/mediawiki/gdcm/index.php?title=Color_Space_Transformations
    00060
    00061 // .SECTION See Also
    00062 // vtkMedicalImageReader2 vtkMedicalImageProperties vtkGDCMPolyDataReader vtkGDCMImageWriter
    00063 // vtkDICOMImageReader
    00064
    00065 #ifndef VTKGDCMIMAGEREADER_H
    00066 #define VTKGDCMIMAGEREADER_H
    00067
    00068 #include "vtkMedicalImageReader2.h"
    00069 #include "vtkImageData.h"
    00070
    00071 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00072 #else
    00073 class vtkMedicalImageProperties;
    00074 #endif
    00075 #if ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
    00076 #else
    00077 class vtkStringArray;
    00078 #endif
    00079 class vtkPolyData;
    00080
    00081 // vtkSystemIncludes.h defines:
    00082 // #define VTK_LUMINANCE       1
    00083 // #define VTK_LUMINANCE_ALPHA 2
    00084 // #define VTK_RGB             3
    00085 // #define VTK_RGBA            4
    00086 #ifndef VTK_INVERSE_LUMINANCE
    00087 #define VTK_INVERSE_LUMINANCE 5
    00088 #endif
    00089 #ifndef VTK_LOOKUP_TABLE
    00090 #define VTK_LOOKUP_TABLE 6
    00091 #endif
    00092 #ifndef VTK_YBR
    00093 #define VTK_YBR 7
    00094 #endif
    00095 #ifndef VTK_CMYK
    00096 #define VTK_CMYK 8
    00097 #endif
    00098
    00099 //BTX
    00100 namespace gdcm { class ImageReader; }
    00101 //ETX
    00102 class vtkMatrix4x4;
    00103 class VTK_EXPORT vtkGDCMImageReader : public vtkMedicalImageReader2
    00104 {
    00105 public:
    00106   static vtkGDCMImageReader *New();
    00107   vtkTypeRevisionMacro(vtkGDCMImageReader,vtkMedicalImageReader2);
    00108   virtual void PrintSelf(ostream& os, vtkIndent indent);
    00109
    00110   // Description: is the given file name a DICOM file containing an image ?
    00111   virtual int CanReadFile(const char* fname);
    00112
    00113   // Description:
    00114   // Valid extensions
    00115   virtual const char* GetFileExtensions()
    00116     {
    00117     // I would like to get rid of ACR/NEMA/IMA so only allow dcm extension for now
    00118     return ".dcm .DCM";
    00119     }
    00120
    00121   // Description:
    00122   // A descriptive name for this format
    00123   virtual const char* GetDescriptiveName()
    00124     {
    00125     return "DICOM";
    00126     }
    00127
    00128   // Description:
    00129   // Get the Image Position (Patient) as stored in the DICOM file
    00130   // This is a read-only data member
    00131   vtkGetObjectMacro(DirectionCosines, vtkMatrix4x4);
    00132
    00133 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00134 #else
    00135   // Description:
    00136   // Get the medical image properties object
    00137   vtkGetObjectMacro(MedicalImageProperties, vtkMedicalImageProperties);
    00138 #endif
    00139   virtual void SetMedicalImageProperties(vtkMedicalImageProperties *pd);
    00140
    00141 #if ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
    00142 #else
    00143   virtual void SetFileNames(vtkStringArray*);
    00144   vtkGetObjectMacro(FileNames, vtkStringArray);
    00145 #endif
    00146
    00147   // Description:
    00148   // Specifically request to load the overlay into the gdcm-VTK layer (gdcm always loads them when found).
    00149   // If no overlay is found in the image, then the vtkImageData for the overlay will be empty.
    00150   vtkGetMacro(LoadOverlays,int);
    00151   vtkSetMacro(LoadOverlays,int);
    00152   vtkBooleanMacro(LoadOverlays,int);
    00153
    00154   // Description:
    00155   // Set/Get whether or not to load the Icon as vtkImageData (if found in the DICOM file)
    00156   vtkGetMacro(LoadIconImage,int);
    00157   vtkSetMacro(LoadIconImage,int);
    00158   vtkBooleanMacro(LoadIconImage,int);
    00159
    00160   // Description:
    00161   // Set/Get whether or not the image was compressed using a lossy compression algorithm
    00162   vtkGetMacro(LossyFlag,int);
    00163   vtkSetMacro(LossyFlag,int);
    00164   vtkBooleanMacro(LossyFlag,int);
    00165
    00166   // Description:
    00167   // Read only: number of overlays as found in this image (multiple overlays per slice is allowed)
    00168   // Only valid when LoadOverlays is true
    00169   vtkGetMacro(NumberOfOverlays,int);
    00170
    00171   // Description:
    00172   // Read only: number of icon image (there can only be zero or one icon per file)
    00173   // Only valid when LoadIconImage is true
    00174   vtkGetMacro(NumberOfIconImages,int);
    00175
    00176   // Description:
    00177   // Get Overlay/IconImage
    00178   // Remember to ALWAYS use those methods in your code, as the internal number for the output port
    00179   // is not garantee to remain the same, as features are added to the reader
    00180 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00181 //FIXME: Need to get rid of BTX/ETX if only the Python Wrapper of VTK 4.2 would let me
    00182 //BTX
    00183   vtkAlgorithmOutput* GetOverlayPort(int index);
    00184   vtkAlgorithmOutput* GetIconImagePort();
    00185 //ETX
    00186 #endif
    00187   vtkImageData* GetOverlay(int i);
    00188   vtkImageData* GetIconImage();
    00189
    00190   // Description:
    00191   // Load image with its associated Lookup Table
    00192   vtkGetMacro(ApplyLookupTable,int);
    00193   vtkSetMacro(ApplyLookupTable,int);
    00194   vtkBooleanMacro(ApplyLookupTable,int);
    00195
    00196   // Description:
    00197   // Load image as YBR
    00198   vtkGetMacro(ApplyYBRToRGB,int)
    00199   vtkSetMacro(ApplyYBRToRGB,int)
    00200   vtkBooleanMacro(ApplyYBRToRGB,int);
    00201
    00202   // Description:
    00203   // Return VTK_LUMINANCE, VTK_INVERSE_LUMINANCE, VTK_RGB, VTK_RGBA, VTK_LOOKUP_TABLE, VTK_YBR or VTK_CMYK
    00204   // or 0 when ImageFormat is not handled.
    00205   // Warning: For color image, PlanarConfiguration need to be taken into account.
    00206   vtkGetMacro(ImageFormat,int);
    00207
    00208   // Description:
    00209   // Return the Planar Configuration. This simply means that the internal DICOM image was stored
    00210   // using a particular planar configuration (most of the time: 0)
    00211   // For monochrome image, PlanarConfiguration is always 0
    00212   vtkGetMacro(PlanarConfiguration,int);
    00213
    00214   // Description:
    00215   // Return the 'raw' information stored in the DICOM file:
    00216   // In case of a series of multiple files, only the first file is considered. The Image Orientation (Patient)
    00217   // is garantee to remain the same, and image Image Position (Patient) in other slice can be computed
    00218   // using the ZSpacing (3rd dimension)
    00219   // (0020,0032) DS [87.774866\-182.908510\168.629671]       #  32, 3 ImagePositionPatient
    00220   // (0020,0037) DS [0.001479\0.999989\-0.004376\-0.002039\-0.004372\-0.999988] #  58, 6 ImageOrientationPatient
    00221   vtkGetVector3Macro(ImagePositionPatient,double);
    00222   vtkGetVector6Macro(ImageOrientationPatient,double);
    00223
    00224   // Description:
    00225   // Set/Get the first Curve Data:
    00226   vtkGetObjectMacro(Curve,vtkPolyData);
    00227   virtual void SetCurve(vtkPolyData *pd);
    00228
    00229   // Description:
    00230   // \DEPRECATED:
    00231   // Modality LUT
    00232   // Value returned by GetShift/GetScale might be innacurate since Shift/Scale could be
    00233   // varying along the Series read. Therefore user are advices not to use those functions
    00234   // anymore
    00235   vtkGetMacro(Shift,double);
    00236   vtkGetMacro(Scale,double);
    00237
    00238 protected:
    00239   vtkGDCMImageReader();
    00240   ~vtkGDCMImageReader();
    00241
    00242   vtkSetVector6Macro(ImageOrientationPatient,double);
    00243
    00244 //BTX
    00245   void FillMedicalImageInformation(const gdcm::ImageReader &reader);
    00246 //ETX
    00247   int RequestInformationCompat();
    00248   int RequestDataCompat();
    00249
    00250 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00251   int ProcessRequest(vtkInformation* request,
    00252                                  vtkInformationVector** inputVector,
    00253                                  vtkInformationVector* outputVector);
    00254   int RequestInformation(vtkInformation *request,
    00255                          vtkInformationVector **inputVector,
    00256                          vtkInformationVector *outputVector);
    00257   int RequestData(vtkInformation *request,
    00258                   vtkInformationVector **inputVector,
    00259                   vtkInformationVector *outputVector);
    00260 #else /*(VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )*/
    00261   void ExecuteInformation();
    00262   void ExecuteData(vtkDataObject *out);
    00263 #endif /*(VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )*/
    00264
    00265 protected:
    00266 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00267 #else
    00268   // Description:
    00269   // Medical Image properties
    00270   vtkMedicalImageProperties *MedicalImageProperties;
    00271 #endif
    00272 #if ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
    00273 #else
    00274   vtkStringArray *FileNames;
    00275 #endif
    00276
    00277   vtkMatrix4x4 *DirectionCosines;
    00278   int LoadOverlays;
    00279   int NumberOfOverlays;
    00280   int LoadIconImage;
    00281   int NumberOfIconImages;
    00282   int IconImageDataExtent[6];
    00283   double ImagePositionPatient[3];
    00284   double ImageOrientationPatient[6];
    00285   vtkPolyData *Curve;
    00286
    00287   int ImageFormat;
    00288   // the following 3, should remain optional
    00289   int ApplyInverseVideo;
    00290   int ApplyLookupTable;
    00291   int ApplyYBRToRGB;
    00292   // I think that planar configuration need to always be applied as far as VTK is concerned
    00293   int ApplyPlanarConfiguration;
    00294   int ApplyShiftScale;
    00295
    00296   int LoadSingleFile(const char *filename, char *pointer, unsigned long &outlen);
    00297
    00298   double Shift;
    00299   double Scale;
    00300   int IconDataScalarType;
    00301   int IconNumberOfScalarComponents;
    00302   int PlanarConfiguration;
    00303   int LossyFlag;
    00304   int ForceRescale;
    00305
    00306 protected:
    00307   // TODO / FIXME
    00308   void SetFilePrefix(const char *) {}
    00309   vtkGetStringMacro(FilePrefix);
    00310   void SetFilePattern(const char *) {}
    00311   vtkGetStringMacro(FilePattern);
    00312
    00313 private:
    00314   vtkGDCMImageReader(const vtkGDCMImageReader&);  // Not implemented.
    00315   void operator=(const vtkGDCMImageReader&);  // Not implemented.
    00316 };
    00317 #endif