]> Creatis software - clitk.git/blob - common/rtkEdfImageIO.h
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
[clitk.git] / common / rtkEdfImageIO.h
1 /*=========================================================================
2  *
3  *  Copyright RTK Consortium
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *=========================================================================*/
18
19 #ifndef __rtkEdfImageIO_h
20 #define __rtkEdfImageIO_h
21
22 #include <itkImageIOBase.h>
23 #include <fstream>
24 #include <string.h>
25
26 namespace rtk {
27
28 /** \class EdfImageIO
29  * \brief Class for reading Edf image file format. Edf is the format of
30  * X-ray projection images at the ESRF.
31  *
32  * \author Simon Rit
33  *
34  * \ingroup IOFilters
35  */
36 class EdfImageIO : public itk::ImageIOBase
37 {
38 public:
39   /** Standard class typedefs. */
40   typedef EdfImageIO              Self;
41   typedef itk::ImageIOBase        Superclass;
42   typedef itk::SmartPointer<Self> Pointer;
43
44   EdfImageIO() : Superclass() {
45   }
46
47   /** Method for creation through the object factory. */
48   itkNewMacro(Self);
49
50   /** Run-time type information (and related methods). */
51   itkTypeMacro(EdfImageIO, ImageIOBase);
52
53   /*-------- This part of the interface deals with reading data. ------ */
54   virtual void ReadImageInformation();
55
56   virtual bool CanReadFile( const char* FileNameToRead );
57
58   virtual void Read(void * buffer);
59
60   /*-------- This part of the interfaces deals with writing data. ----- */
61   virtual void WriteImageInformation(bool keepOfStream);
62
63   virtual void WriteImageInformation() {
64     WriteImageInformation(false);
65   }
66
67   virtual bool CanWriteFile(const char* filename);
68
69   virtual void Write(const void* buffer);
70
71 protected:
72   std::string m_BinaryFileName;
73   int         m_BinaryFileSkip;
74
75   static char* edf_findInHeader( char* header, const char* key );
76
77   /* List of EDF supported datatypes
78    */
79   enum DataType {
80     U_CHAR_DATATYPE = 0, CHAR_DATATYPE,        //  8 bits = 1 B
81     U_SHORT_DATATYPE,    SHORT_DATATYPE,       // 16 bits = 2 B
82     U_INT_DATATYPE,      INT_DATATYPE,         // 32 bits = 4 B
83     U_L_INT_DATATYPE,    L_INT_DATATYPE,       // 32 bits = 4 B
84     FLOAT_DATATYPE,      DOUBLE_DATATYPE,      // 4 B, 8 B
85     UNKNOWN_DATATYPE = -1
86     };
87
88   /* Note - compatibility:
89     Unsigned8 = 1,Signed8,  Unsigned16, Signed16,
90     Unsigned32,   Signed32, Unsigned64, Signed64,
91     FloatIEEE32,  DoubleIEEE64
92   */
93
94   /***************************************************************************
95    * Tables
96    ***************************************************************************/
97
98   // table key-value structure
99   struct table {
100     const char *key;
101     int value;
102     };
103
104   struct table3 {
105     const char *key;
106     int value;
107     short sajzof;
108     };
109
110   /* Returns index of the table tbl whose key matches the beginning of the
111    * search string search_str.
112    * It returns index into the table or -1 if there is no match.
113    */
114   static int
115   lookup_table_nth( const struct table *tbl, const char *search_str )
116   {
117     int k = -1;
118
119     while (tbl[++k].key)
120       if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key) ) )
121         return k;
122     return -1; // not found
123   }
124
125   static int
126   lookup_table3_nth( const struct table3 *tbl, const char *search_str )
127   {
128     int k = -1;
129
130     while (tbl[++k].key)
131       if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key) ) )
132         return k;
133     return -1; // not found
134   }
135
136   ///* Orientation of axes of the raster, as the binary matrix is saved in
137   // * the file. (Determines the scanning direction, or the "fastest" index
138   // * of the matrix in the data file.)
139   // */
140   //enum EdfRasterAxes {
141   //RASTER_AXES_XrightYdown, // matricial format: rows, columns
142   //RASTER_AXES_XrightYup    // cartesian coordinate system
143   //    // other 6 combinations not available (not needed until now)
144   //};
145
146   //static const struct table rasteraxes_table[] =
147   //{
148   //    { "XrightYdown", RASTER_AXES_XrightYdown },
149   //    { "XrightYup",   RASTER_AXES_XrightYup },
150   //    { NULL, -1 }
151   //};
152
153 }; // end class EdfImageIO
154
155 } // end namespace
156
157 #endif