RTK  2.6.0
Reconstruction Toolkit
rtkEdfImageIO.h
Go to the documentation of this file.
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  * https://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 <cstring>
25 
26 #include "RTKExport.h"
27 #include "rtkMacro.h"
28 
29 namespace rtk
30 {
31 
40 class RTK_EXPORT EdfImageIO : public itk::ImageIOBase
41 {
42 public:
43  ITK_DISALLOW_COPY_AND_MOVE(EdfImageIO);
44 
46  using Self = EdfImageIO;
49 
51  : Superclass()
52  {}
53 
55  itkNewMacro(Self);
56 
58 #ifdef itkOverrideGetNameOfClassMacro
59  itkOverrideGetNameOfClassMacro(EdfImageIO);
60 #else
61  itkTypeMacro(EdfImageIO, ImageIOBase);
62 #endif
63 
64 
65  /*-------- This part of the interface deals with reading data. ------ */
66  void
67  ReadImageInformation() override;
68 
69  bool
70  CanReadFile(const char * FileNameToRead) override;
71 
72  void
73  Read(void * buffer) override;
74 
75  /*-------- This part of the interfaces deals with writing data. ----- */
76  virtual void
77  WriteImageInformation(bool keepOfStream);
78 
79  void
81  {
82  WriteImageInformation(false);
83  }
84 
85  bool
86  CanWriteFile(const char * filename) override;
87 
88  void
89  Write(const void * buffer) override;
90 
91 protected:
92  std::string m_BinaryFileName;
94 
95  static char *
96  edf_findInHeader(char * header, const char * key);
97 
98  /* List of EDF supported datatypes
99  */
100  enum DataType
101  {
102  U_CHAR_DATATYPE = 0,
103  CHAR_DATATYPE, // 8 bits = 1 B
105  SHORT_DATATYPE, // 16 bits = 2 B
107  INT_DATATYPE, // 32 bits = 4 B
109  L_INT_DATATYPE, // 32 bits = 4 B
111  DOUBLE_DATATYPE, // 4 B, 8 B
112  UNKNOWN_DATATYPE = -1
113  };
114 
115  /* Note - compatibility:
116  Unsigned8 = 1,Signed8, Unsigned16, Signed16,
117  Unsigned32, Signed32, Unsigned64, Signed64,
118  FloatIEEE32, DoubleIEEE64
119  */
120 
121 /***************************************************************************
122  * Tables
123  ***************************************************************************/
124 
125  // table key-value structure
126  struct table
127  {
128  const char * key;
129  int value;
130  };
131 
132  struct table3
133  {
134  const char * key;
135  int value;
136  short sajzof;
137  };
138 
139  /* Returns index of the table tbl whose key matches the beginning of the
140  * search string search_str.
141  * It returns index into the table or -1 if there is no match.
142  */
143  static int
144  lookup_table_nth(const struct table * tbl, const char * search_str)
145  {
146  int k = -1;
147 
148  while (tbl[++k].key)
149  if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key)))
150  return k;
151  return -1; // not found
152  }
153 
154  static int
155  lookup_table3_nth(const struct table3 * tbl, const char * search_str)
156  {
157  int k = -1;
158 
159  while (tbl[++k].key)
160  if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key)))
161  return k;
162  return -1; // not found
163  }
164 
166  // * the file. (Determines the scanning direction, or the "fastest" index
167  // * of the matrix in the data file.)
168  // */
169  // enum EdfRasterAxes {
170  // RASTER_AXES_XrightYdown, // matricial format: rows, columns
171  // RASTER_AXES_XrightYup // cartesian coordinate system
172  // // other 6 combinations not available (not needed until now)
173  //};
174 
175  // static const struct table rasteraxes_table[] =
176  //{
177  // { "XrightYdown", RASTER_AXES_XrightYdown },
178  // { "XrightYup", RASTER_AXES_XrightYup },
179  // { NULL, -1 }
180  //};
181 
182 }; // end class EdfImageIO
183 
184 } // namespace rtk
185 
186 #endif
void WriteImageInformation() override
Definition: rtkEdfImageIO.h:80
std::string m_BinaryFileName
Definition: rtkEdfImageIO.h:92
static int lookup_table3_nth(const struct table3 *tbl, const char *search_str)
Class for reading Edf image file format. Edf is the format of X-ray projection images at the ESRF...
Definition: rtkEdfImageIO.h:40
static int lookup_table_nth(const struct table *tbl, const char *search_str)