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