# 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-2009 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 #include "gdcmTypes.h" // GDCM_EXPORT
    00071
    00072 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00073 #else
    00074 class vtkMedicalImageProperties;
    00075 #endif
    00076 #if ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
    00077 #else
    00078 class vtkStringArray;
    00079 #endif
    00080 class vtkPolyData;
    00081
    00082 // vtkSystemIncludes.h defines:
    00083 // #define VTK_LUMINANCE       1
    00084 // #define VTK_LUMINANCE_ALPHA 2
    00085 // #define VTK_RGB             3
    00086 // #define VTK_RGBA            4
    00087 #ifndef VTK_INVERSE_LUMINANCE
    00088 #define VTK_INVERSE_LUMINANCE 5
    00089 #endif
    00090 #ifndef VTK_LOOKUP_TABLE
    00091 #define VTK_LOOKUP_TABLE 6
    00092 #endif
    00093 #ifndef VTK_YBR
    00094 #define VTK_YBR 7
    00095 #endif
    00096 #ifndef VTK_CMYK
    00097 #define VTK_CMYK 8
    00098 #endif
    00099
    00100 //BTX
    00101 namespace gdcm { class ImageReader; }
    00102 //ETX
    00103 class vtkMatrix4x4;
    00104 class VTK_EXPORT vtkGDCMImageReader : public vtkMedicalImageReader2
    00105 {
    00106 public:
    00107   static vtkGDCMImageReader *New();
    00108   vtkTypeRevisionMacro(vtkGDCMImageReader,vtkMedicalImageReader2);
    00109   virtual void PrintSelf(ostream& os, vtkIndent indent);
    00110
    00111   // Description: is the given file name a DICOM file containing an image ?
    00112   virtual int CanReadFile(const char* fname);
    00113
    00114   // Description:
    00115   // Valid extensions
    00116   virtual const char* GetFileExtensions()
    00117     {
    00118     // I would like to get rid of ACR/NEMA/IMA so only allow dcm extension for now
    00119     return ".dcm .DCM";
    00120     }
    00121
    00122   // Description:
    00123   // A descriptive name for this format
    00124   virtual const char* GetDescriptiveName()
    00125     {
    00126     return "DICOM";
    00127     }
    00128
    00129   // Description:
    00130   // Get the Image Position (Patient) as stored in the DICOM file
    00131   // This is a read-only data member
    00132   vtkGetObjectMacro(DirectionCosines, vtkMatrix4x4);
    00133
    00134 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00135 #else
    00136   // Description:
    00137   // Get the medical image properties object
    00138   vtkGetObjectMacro(MedicalImageProperties, vtkMedicalImageProperties);
    00139 #endif
    00140   virtual void SetMedicalImageProperties(vtkMedicalImageProperties *pd);
    00141
    00142 #if ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
    00143 #else
    00144   virtual void SetFileNames(vtkStringArray*);
    00145   vtkGetObjectMacro(FileNames, vtkStringArray);
    00146 #endif
    00147
    00148   // Description:
    00149   // Specifically request to load the overlay into the gdcm-VTK layer (gdcm always loads them when found).
    00150   // If no overlay is found in the image, then the vtkImageData for the overlay will be empty.
    00151   vtkGetMacro(LoadOverlays,int);
    00152   vtkSetMacro(LoadOverlays,int);
    00153   vtkBooleanMacro(LoadOverlays,int);
    00154
    00155   // Description:
    00156   // Set/Get whether or not to load the Icon as vtkImageData (if found in the DICOM file)
    00157   vtkGetMacro(LoadIconImage,int);
    00158   vtkSetMacro(LoadIconImage,int);
    00159   vtkBooleanMacro(LoadIconImage,int);
    00160
    00161   // Description:
    00162   // Set/Get whether or not the image was compressed using a lossy compression algorithm
    00163   vtkGetMacro(LossyFlag,int);
    00164   vtkSetMacro(LossyFlag,int);
    00165   vtkBooleanMacro(LossyFlag,int);
    00166
    00167   // Description:
    00168   // Read only: number of overlays as found in this image (multiple overlays per slice is allowed)
    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   vtkGetMacro(NumberOfIconImages,int);
    00174
    00175   // Description:
    00176   // Get Overlay/IconImage
    00177   // Remember to ALWAYS use those methods in your code, as the internal number for the output port
    00178   // is not garantee to remain the same, as features are added to the reader
    00179 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00180 //FIXME: Need to get rid of BTX/ETX if only the Python Wrapper of VTK 4.2 would let me
    00181 //BTX
    00182   vtkAlgorithmOutput* GetOverlayPort(int index);
    00183   vtkAlgorithmOutput* GetIconImagePort();
    00184 //ETX
    00185 #endif
    00186   vtkImageData* GetOverlay(int i);
    00187   vtkImageData* GetIconImage();
    00188
    00189   // Description:
    00190   // Load image with its associated Lookup Table
    00191   vtkGetMacro(ApplyLookupTable,int);
    00192   vtkSetMacro(ApplyLookupTable,int);
    00193   vtkBooleanMacro(ApplyLookupTable,int);
    00194
    00195   // Description:
    00196   // Load image as YBR
    00197   vtkGetMacro(ApplyYBRToRGB,int)
    00198   vtkSetMacro(ApplyYBRToRGB,int)
    00199   vtkBooleanMacro(ApplyYBRToRGB,int);
    00200
    00201   // Description:
    00202   // Return VTK_LUMINANCE, VTK_INVERSE_LUMINANCE, VTK_RGB, VTK_RGBA, VTK_LOOKUP_TABLE, VTK_YBR or VTK_CMYK
    00203   // or 0 when ImageFormat is not handled.
    00204   // Warning: For color image, PlanarConfiguration need to be taken into account.
    00205   vtkGetMacro(ImageFormat,int);
    00206
    00207   // Description:
    00208   // Return the Planar Configuration. This simply means that the internal DICOM image was stored
    00209   // using a particular planar configuration (most of the time: 0)
    00210   // For monochrome image, PlanarConfiguration is always 0
    00211   vtkGetMacro(PlanarConfiguration,int);
    00212
    00213   // Description:
    00214   // Return the 'raw' information stored in the DICOM file:
    00215   // In case of a series of multiple files, only the first file is considered. The Image Orientation (Patient)
    00216   // is garantee to remain the same, and image Image Position (Patient) in other slice can be computed
    00217   // using the ZSpacing (3rd dimension)
    00218   // (0020,0032) DS [87.774866\-182.908510\168.629671]       #  32, 3 ImagePositionPatient
    00219   // (0020,0037) DS [0.001479\0.999989\-0.004376\-0.002039\-0.004372\-0.999988] #  58, 6 ImageOrientationPatient
    00220   vtkGetVector3Macro(ImagePositionPatient,double);
    00221   vtkGetVector6Macro(ImageOrientationPatient,double);
    00222
    00223   // Description:
    00224   // Set/Get the first Curve Data:
    00225   vtkGetObjectMacro(Curve,vtkPolyData);
    00226   virtual void SetCurve(vtkPolyData *pd);
    00227
    00228   // Description:
    00229   // \DEPRECATED:
    00230   // Modality LUT
    00231   // Value returned by GetShift/GetScale might be innacurate since Shift/Scale could be
    00232   // varying along the Series read. Therefore user are advices not to use those functions
    00233   // anymore
    00234   vtkGetMacro(Shift,double);
    00235   vtkGetMacro(Scale,double);
    00236
    00237 protected:
    00238   vtkGDCMImageReader();
    00239   ~vtkGDCMImageReader();
    00240
    00241   vtkSetVector6Macro(ImageOrientationPatient,double);
    00242
    00243 //BTX
    00244   void FillMedicalImageInformation(const gdcm::ImageReader &reader);
    00245 //ETX
    00246   int RequestInformationCompat();
    00247   int RequestDataCompat();
    00248
    00249 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00250   int ProcessRequest(vtkInformation* request,
    00251                                  vtkInformationVector** inputVector,
    00252                                  vtkInformationVector* outputVector);
    00253   int RequestInformation(vtkInformation *request,
    00254                          vtkInformationVector **inputVector,
    00255                          vtkInformationVector *outputVector);
    00256   int RequestData(vtkInformation *request,
    00257                   vtkInformationVector **inputVector,
    00258                   vtkInformationVector *outputVector);
    00259 #else /*(VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )*/
    00260   void ExecuteInformation();
    00261   void ExecuteData(vtkDataObject *out);
    00262 #endif /*(VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )*/
    00263
    00264 protected:
    00265 #if (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 5 )
    00266 #else
    00267   // Description:
    00268   // Medical Image properties
    00269   vtkMedicalImageProperties *MedicalImageProperties;
    00270 #endif
    00271 #if ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0 )
    00272 #else
    00273   vtkStringArray *FileNames;
    00274 #endif
    00275
    00276   vtkMatrix4x4 *DirectionCosines;
    00277   int LoadOverlays;
    00278   int NumberOfOverlays;
    00279   int LoadIconImage;
    00280   int NumberOfIconImages;
    00281   int IconImageDataExtent[6];
    00282   double ImagePositionPatient[3];
    00283   double ImageOrientationPatient[6];
    00284   vtkPolyData *Curve;
    00285
    00286   int ImageFormat;
    00287   // the following 3, should remain optional
    00288   int ApplyInverseVideo;
    00289   int ApplyLookupTable;
    00290   int ApplyYBRToRGB;
    00291   // I think that planar configuration need to always be applied as far as VTK is concerned
    00292   int ApplyPlanarConfiguration;
    00293   int ApplyShiftScale;
    00294
    00295   int LoadSingleFile(const char *filename, char *pointer, unsigned long &outlen);
    00296
    00297   double Shift;
    00298   double Scale;
    00299   int IconDataScalarType;
    00300   int IconNumberOfScalarComponents;
    00301   int PlanarConfiguration;
    00302   int LossyFlag;
    00303
    00304 protected:
    00305   // TODO / FIXME
    00306   void SetFilePrefix(const char *) {}
    00307   vtkGetStringMacro(FilePrefix);
    00308   void SetFilePattern(const char *) {}
    00309   vtkGetStringMacro(FilePattern);
    00310
    00311 private:
    00312   vtkGDCMImageReader(const vtkGDCMImageReader&);  // Not implemented.
    00313   void operator=(const vtkGDCMImageReader&);  // Not implemented.
    00314 };
    00315 #endif
    00316