]> Creatis software - gdcm.git/blob - vtk/vtkGdcmReader.h
e9846b545bd746424dfcd72b0dd30c61bf6f7a75
[gdcm.git] / vtk / vtkGdcmReader.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: vtkGdcmReader.h,v $
5   Language:  C++
6   Date:      $Date: 2011/03/31 12:37:54 $
7   Version:   $Revision: 1.40 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 ==========================================================================*/
18 #ifndef __vtkGdcmReader_h
19 #define __vtkGdcmReader_h
20
21 #include "gdcmCommon.h" // To avoid warnings concerning the std
22 #include "gdcmFile.h"
23
24 #include <vtkImageReader.h>
25 #include <list>
26 #include <string>
27 #include <vector>
28
29 typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, GDCM_NAME_SPACE::File *);
30
31 //-----------------------------------------------------------------------------
32 class vtkLookupTable;
33
34 //-----------------------------------------------------------------------------
35 class VTK_EXPORT vtkGdcmReader : public vtkImageReader
36 {
37 public:
38    static vtkGdcmReader *New();
39    vtkTypeRevisionMacro(vtkGdcmReader, vtkImageReader);
40    void PrintSelf(ostream& os, vtkIndent indent);
41
42    virtual void RemoveAllFileName(void);
43    virtual void AddFileName(const char *name);
44    virtual void SetFileName(const char *name);
45
46    //BTX
47    void SetCoherentFileList( std::vector<GDCM_NAME_SPACE::File* > *cfl) {
48                              CoherentFileList = cfl; }
49    //ETX
50
51    //vtkSetMacro(AllowLightChecking, bool);
52    //vtkGetMacro(AllowLightChecking, bool);
53    //vtkBooleanMacro(AllowLightChecking, bool);
54
55    //BTX
56
57    /// \todo fix possible problems around VTK pipelining
58
59    void SetUserFunction (VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc )
60                         { UserFunction = userFunc; } 
61    //ETX
62
63    // Description:
64    // If this flag is set and the DICOM reader encounters a dicom file with 
65    // lookup table the data will be kept as unsigned chars and a lookuptable 
66    // will be exported and accessible through GetLookupTable()
67
68    vtkSetMacro(AllowLookupTable, bool);
69    vtkGetMacro(AllowLookupTable, bool);
70    vtkBooleanMacro(AllowLookupTable, bool);
71
72    vtkSetMacro(KeepOverlays, bool);
73    vtkGetMacro(KeepOverlays, bool);
74    vtkBooleanMacro(KeepOverlays, bool);
75
76 //  Implementation note: when FileLowerLeft (gdcm2) is set to on the image is not flipped
77 // upside down as VTK would expect, use this option only if you know what you are doing.   
78   // vtkSetMacro(FileLowerLeft, bool);
79   // vtkGetMacro(FileLowerLeft, bool);
80   // vtkBooleanMacro(FileLowerLeft, bool);
81
82   vtkSetMacro(FlipY, bool);
83   vtkGetMacro(FlipY, bool);
84   vtkBooleanMacro(FlipY, bool);
85
86    vtkGetObjectMacro(LookupTable, vtkLookupTable);
87
88 // FIXME : HOW to doxygen a VTK macro?
89 /*
90  * \ brief Sets the LoadMode as a boolean string. 
91  *        gdcm.LD_NOSEQ, gdcm.LD_NOSHADOW, gdcm.LD_NOSHADOWSEQ... 
92  *        (nothing more, right now)
93  *        WARNING : before using NO_SHADOW, be sure *all* your files
94  *        contain accurate values in the 0x0000 element (if any) 
95  *        of *each* Shadow Group. The parser will fail if the size is wrong !
96  * @param   mode Load mode to be used
97  */
98    vtkSetMacro(LoadMode, int);
99    vtkGetMacro(LoadMode, int);
100    vtkBooleanMacro(LoadMode, int);
101  
102 /*
103  * \ brief drop images with duplicate position  
104  *         and therefore calculate ZSpacing for the whole file set
105  * @param   mode user wants to drop images with duplicate position
106  */
107    vtkSetMacro(DropDuplicatePositions, bool);
108    vtkGetMacro(DropDuplicatePositions, bool);
109    vtkBooleanMacro(DropDuplicatePositions, bool);
110
111 protected:
112    vtkGdcmReader();
113    ~vtkGdcmReader();
114
115    virtual void ExecuteInformation();
116    virtual void ExecuteData(vtkDataObject *output);
117
118    //virtual void BuildData(vtkDataObject *output); // for VTK5.0
119    virtual void BuildFileListFromPattern();
120    virtual void LoadFileInformation();
121    virtual void UpdateFileInformation();
122    //BTX
123    virtual void GetFileInformation(GDCM_NAME_SPACE::File *file);
124    virtual bool TestFileInformation(GDCM_NAME_SPACE::File *file);
125    //ETX
126
127 private:
128    void RemoveAllInternalFileName(void);
129    void AddInternalFileName(const char *name);
130    void RemoveAllInternalFile(void);
131
132    //BTX
133    void IncrementProgress(const unsigned long updateProgressTarget,
134                           unsigned long &updateProgressCount);
135    /*void LoadImageInMemory(std::string fileName, unsigned char *dest,
136                           const unsigned long updateProgressTarget,
137                           unsigned long &updateProgressCount);*/
138
139    void LoadImageInMemory(GDCM_NAME_SPACE::File *f, unsigned char *dest,
140                           const unsigned long updateProgressTarget,
141                           unsigned long &updateProgressCount);
142    //ETX
143
144 // Variables
145    //BTX
146    typedef std::vector<GDCM_NAME_SPACE::File *> gdcmFileList;
147    //ETX
148
149    vtkLookupTable *LookupTable;
150    vtkTimeStamp fileTime;
151
152    bool AllowLookupTable;
153    bool AllowLightChecking;
154
155    //BTX
156    // Number of columns of the image/volume to be loaded
157    int NumColumns;
158    // Number of lines of the image/volume to be loaded
159    int NumLines;
160    // Number of lines of the image/volume to be loaded
161    int NumPlanes;
162    // Total number of planes (or images) of the stack to be build.
163    int TotalNumberOfPlanes;
164    // Number of scalar components of the image to be loaded (1=monochrome 3=rgb)
165    int NumComponents;
166    // Type of the image[s]: 8/16/32 bits, signed/unsigned:
167    std::string ImageType;
168    // Pixel size (in number of bytes):
169    size_t PixelSize;
170    // List of filenames to be read in order to build a stack of images
171    // or volume. The order in the list shall be the order of the images.
172    std::list<std::string> FileNameList;
173    gdcmFileList *CoherentFileList;
174    bool OwnFile;
175
176    // List of filenames created in ExecuteInformation and used in
177    // ExecuteData.
178    // If FileNameList isn't empty, InternalFileNameList is a copy of
179    //    FileNameList
180    // Otherwise, InternalFileNameList correspond to the list of 
181    //    files patterned
182    std::list<std::string> InternalFileNameList;
183    gdcmFileList InternalFileList;
184    //bool Execution;  // For VTK5.0
185
186    //ETX
187
188    /// \brief Bit string integer (each one considered as a boolean)
189    ///        Bit 0 : Skip Sequences,    if possible
190    ///        Bit 1 : Skip Shadow Groups if possible
191    ///        Bit 2 : Skip Sequences inside a Shadow Group, if possible
192    ///        Probabely (?), some more to add
193    int LoadMode;
194     
195    bool DropDuplicatePositions;
196    
197    bool KeepOverlays;
198    
199   // bool FileLowerLeft;
200    bool FlipY;
201
202    /// Pointer to a user suplied function to allow modification of pixel order
203    VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
204
205 };
206
207 //-----------------------------------------------------------------------------
208 #endif