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  itkOverrideGetNameOfClassMacro(EdfImageIO);
59 
60  /*-------- This part of the interface deals with reading data. ------ */
61  void
62  ReadImageInformation() override;
63 
64  bool
65  CanReadFile(const char * FileNameToRead) override;
66 
67  void
68  Read(void * buffer) override;
69 
70  /*-------- This part of the interfaces deals with writing data. ----- */
71  virtual void
72  WriteImageInformation(bool keepOfStream);
73 
74  void
76  {
77  WriteImageInformation(false);
78  }
79 
80  bool
81  CanWriteFile(const char * filename) override;
82 
83  void
84  Write(const void * buffer) override;
85 
86 protected:
87  std::string m_BinaryFileName;
89 
90  static char *
91  edf_findInHeader(char * header, const char * key);
92 
93  /* List of EDF supported datatypes
94  */
95  enum DataType
96  {
97  U_CHAR_DATATYPE = 0,
98  CHAR_DATATYPE, // 8 bits = 1 B
100  SHORT_DATATYPE, // 16 bits = 2 B
102  INT_DATATYPE, // 32 bits = 4 B
104  L_INT_DATATYPE, // 32 bits = 4 B
106  DOUBLE_DATATYPE, // 4 B, 8 B
107  UNKNOWN_DATATYPE = -1
108  };
109 
110  /* Note - compatibility:
111  Unsigned8 = 1,Signed8, Unsigned16, Signed16,
112  Unsigned32, Signed32, Unsigned64, Signed64,
113  FloatIEEE32, DoubleIEEE64
114  */
115 
116 /***************************************************************************
117  * Tables
118  ***************************************************************************/
119 
120  // table key-value structure
121  struct table
122  {
123  const char * key;
124  int value;
125  };
126 
127  struct table3
128  {
129  const char * key;
130  int value;
131  short sajzof;
132  };
133 
134  /* Returns index of the table tbl whose key matches the beginning of the
135  * search string search_str.
136  * It returns index into the table or -1 if there is no match.
137  */
138  static int
139  lookup_table_nth(const struct table * tbl, const char * search_str)
140  {
141  int k = -1;
142 
143  while (tbl[++k].key)
144  if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key)))
145  return k;
146  return -1; // not found
147  }
148 
149  static int
150  lookup_table3_nth(const struct table3 * tbl, const char * search_str)
151  {
152  int k = -1;
153 
154  while (tbl[++k].key)
155  if (tbl[k].key && !strncmp(search_str, tbl[k].key, strlen(tbl[k].key)))
156  return k;
157  return -1; // not found
158  }
159 
161  // * the file. (Determines the scanning direction, or the "fastest" index
162  // * of the matrix in the data file.)
163  // */
164  // enum EdfRasterAxes {
165  // RASTER_AXES_XrightYdown, // matricial format: rows, columns
166  // RASTER_AXES_XrightYup // cartesian coordinate system
167  // // other 6 combinations not available (not needed until now)
168  //};
169 
170  // static const struct table rasteraxes_table[] =
171  //{
172  // { "XrightYdown", RASTER_AXES_XrightYdown },
173  // { "XrightYup", RASTER_AXES_XrightYup },
174  // { NULL, -1 }
175  //};
176 
177 }; // end class EdfImageIO
178 
179 } // namespace rtk
180 
181 #endif
void WriteImageInformation() override
Definition: rtkEdfImageIO.h:75
std::string m_BinaryFileName
Definition: rtkEdfImageIO.h:87
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)