]> Creatis software - clitk.git/blob - common/rtkEdfImageIO.h
Add comment to precise the functionality of the inputs
[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 #include "clitkCommon.h"
27
28 namespace rtk {
29
30 /** \class EdfImageIO
31  * \brief Class for reading Edf image file format. Edf is the format of
32  * X-ray projection images at the ESRF.
33  *
34  * \author Simon Rit
35  *
36  * \ingroup IOFilters
37  */
38 class EdfImageIO : public itk::ImageIOBase
39 {
40 public:
41   /** Standard class typedefs. */
42   typedef EdfImageIO              Self;
43   typedef itk::ImageIOBase        Superclass;
44   typedef itk::SmartPointer<Self> Pointer;
45
46   EdfImageIO() : Superclass() {
47   }
48
49   /** Method for creation through the object factory. */
50   itkNewMacro(Self);
51
52   /** Run-time type information (and related methods). */
53   itkTypeMacro(EdfImageIO, ImageIOBase);
54
55   /*-------- This part of the interface deals with reading data. ------ */
56   virtual void ReadImageInformation() ITK_OVERRIDE;
57
58   virtual bool CanReadFile( const char* FileNameToRead ) ITK_OVERRIDE;
59
60   virtual void Read(void * buffer) ITK_OVERRIDE;
61
62   /*-------- This part of the interfaces deals with writing data. ----- */
63   virtual void WriteImageInformation(bool keepOfStream);
64
65   virtual void WriteImageInformation() ITK_OVERRIDE {
66     WriteImageInformation(false);
67   }
68
69   virtual bool CanWriteFile(const char* filename) ITK_OVERRIDE;
70
71   virtual void Write(const void* buffer) ITK_OVERRIDE;
72
73 protected:
74   std::string m_BinaryFileName;
75   int         m_BinaryFileSkip;
76
77   static char* edf_findInHeader( char* header, const char* key );
78
79   /* List of EDF supported datatypes
80    */
81   enum DataType {
82     U_CHAR_DATATYPE = 0, CHAR_DATATYPE,        //  8 bits = 1 B
83     U_SHORT_DATATYPE,    SHORT_DATATYPE,       // 16 bits = 2 B
84     U_INT_DATATYPE,      INT_DATATYPE,         // 32 bits = 4 B
85     U_L_INT_DATATYPE,    L_INT_DATATYPE,       // 32 bits = 4 B
86     FLOAT_DATATYPE,      DOUBLE_DATATYPE,      // 4 B, 8 B
87     UNKNOWN_DATATYPE = -1
88     };
89
90   /* Note - compatibility:
91     Unsigned8 = 1,Signed8,  Unsigned16, Signed16,
92     Unsigned32,   Signed32, Unsigned64, Signed64,
93     FloatIEEE32,  DoubleIEEE64
94   */
95
96   /***************************************************************************
97    * Tables
98    ***************************************************************************/
99
100   // table key-value structure
101   struct table {
102     const char *key;
103     int value;
104     };
105
106   struct table3 {
107     const char *key;
108     int value;
109     short sajzof;
110     };
111
112   /* Returns index of the table tbl whose key matches the beginning of the
113    * search string search_str.
114    * It returns index into the table or -1 if there is no match.
115    */
116   static int
117   lookup_table_nth( const struct table *tbl, const char *search_str )
118   {
119     int k = -1;
120
121     while (tbl[++k].key)
122       if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key) ) )
123         return k;
124     return -1; // not found
125   }
126
127   static int
128   lookup_table3_nth( const struct table3 *tbl, const char *search_str )
129   {
130     int k = -1;
131
132     while (tbl[++k].key)
133       if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key) ) )
134         return k;
135     return -1; // not found
136   }
137
138   ///* Orientation of axes of the raster, as the binary matrix is saved in
139   // * the file. (Determines the scanning direction, or the "fastest" index
140   // * of the matrix in the data file.)
141   // */
142   //enum EdfRasterAxes {
143   //RASTER_AXES_XrightYdown, // matricial format: rows, columns
144   //RASTER_AXES_XrightYup    // cartesian coordinate system
145   //    // other 6 combinations not available (not needed until now)
146   //};
147
148   //static const struct table rasteraxes_table[] =
149   //{
150   //    { "XrightYdown", RASTER_AXES_XrightYdown },
151   //    { "XrightYup",   RASTER_AXES_XrightYup },
152   //    { NULL, -1 }
153   //};
154
155 }; // end class EdfImageIO
156
157 } // end namespace
158
159 #endif