ITK  5.2.0
Insight Toolkit
itkIPLCommonImageIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  *=========================================================================*/
32 #ifndef itkIPLCommonImageIO_h
33 #define itkIPLCommonImageIO_h
34 #include "ITKIOIPLExport.h"
35 
36 #include "itkImageIOBase.h"
37 #include "itkIPLFileNameList.h"
38 #include "itkGEImageHeader.h"
39 
40 namespace itk
41 {
51 class ITKIOIPL_EXPORT IPLCommonImageIO : public ImageIOBase
52 {
53 public:
54  ITK_DISALLOW_COPY_AND_MOVE(IPLCommonImageIO);
55 
60 
61  using U8 = unsigned char;
62  using S8 = signed char;
63  using U16 = unsigned short;
64  using S16 = signed short;
65  using U32 = unsigned int;
66  using S32 = signed int;
67  using U64 = uint64_t;
68  using S64 = int64_t;
69  using F32 = float;
70  using F64 = double;
71 
73  itkNewMacro(Self);
74 
76  itkTypeMacro(IPLCommonImageIO, Superclass);
77 
78  /*-------- This part of the interfaces deals with reading data. ----- */
79 
86  bool
87  CanReadFile(const char * FileNameToRead) override;
88 
90  void
91  ReadImageInformation() override;
92 
94  virtual void
96  {}
97 
99  void
100  Read(void * buffer) override;
101 
105  unsigned int
106  GetComponentSize() const override;
107 
108  /*-------- This part of the interfaces deals with writing data. ----- */
109 
116  bool
117  CanWriteFile(const char * FileNameToWrite) override;
118 
120  void
121  WriteImageInformation() override;
122 
125  void
126  Write(const void * buffer) override;
127 
129  virtual void
130  SortImageListByNameAscend();
131 
133  virtual void
134  SortImageListByNameDescend();
135 
136 protected:
138  ~IPLCommonImageIO() override;
139  void
140  PrintSelf(std::ostream & os, Indent indent) const override;
141 
142  int
143  AddElementToList(char const * const filename,
144  const float sliceLocation,
145  const int offset,
146  const int XDim,
147  const int YDim,
148  const float XRes,
149  const float YRes,
150  const int Key1,
151  const int Key2);
152 
153  void
154  sortImageListAscend();
155 
156  void
157  sortImageListDescend();
158 
159  int
160  statTimeToAscii(void * clock, char * timeString, int len);
161 
162  virtual GEImageHeader *
163  ReadHeader(const char * FileNameToRead);
164 
165  //
166  // data members
169  IPLFileNameList * m_FilenameList;
170  //
171  // return 0 on success, -1 on failure
172  int
173  GetStringAt(std::ifstream & f, std::streamoff Offset, char * buf, size_t amount, bool throw_exception = true);
174 
175  int
176  GetIntAt(std::ifstream & f, std::streamoff Offset, int * ip, bool throw_exception = true);
177 
178  int
179  GetShortAt(std::ifstream & f, std::streamoff Offset, short * ip, bool throw_exception = true);
180 
181  int
182  GetFloatAt(std::ifstream & f, std::streamoff Offset, float * ip, bool throw_exception = true);
183 
184  int
185  GetDoubleAt(std::ifstream & f, std::streamoff Offset, double * ip, bool throw_exception = true);
186 
187  short
188  hdr2Short(char * hdr);
189 
190  int
191  hdr2Int(char * hdr);
192 
193  float
194  hdr2Float(char * hdr);
195 
196  double
197  hdr2Double(char * hdr);
198 };
199 } // end namespace itk
200 #define RAISE_EXCEPTION() \
201  { \
202  ExceptionObject exception(__FILE__, __LINE__); \
203  exception.SetDescription("File cannot be read"); \
204  throw exception; \
205  } \
206  ITK_MACROEND_NOOP_STATEMENT
207 
208 #define IOCHECK() \
209  if (f.fail()) \
210  { \
211  if (f.is_open()) \
212  { \
213  f.close(); \
214  } \
215  RAISE_EXCEPTION(); \
216  } \
217  ITK_MACROEND_NOOP_STATEMENT
218 
219 #endif // itkIPLCommonImageIO_h
itk::ImageIOBase
Abstract superclass defines image IO interface.
Definition: itkImageIOBase.h:77
itk::CommonEnums::IOByteOrder
IOByteOrder
Definition: itkCommonEnums.h:127
itk::IPLCommonImageIO::S16
signed short S16
Definition: itkIPLCommonImageIO.h:64
itk::IPLCommonImageIO::U16
unsigned short U16
Definition: itkIPLCommonImageIO.h:63
itk::IPLCommonImageIO::U64
uint64_t U64
Definition: itkIPLCommonImageIO.h:67
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::IPLCommonImageIO::m_SystemByteOrder
IOByteOrderEnum m_SystemByteOrder
Definition: itkIPLCommonImageIO.h:168
itk::IPLCommonImageIO::F64
double F64
Definition: itkIPLCommonImageIO.h:70
itk::IPLCommonImageIO::S32
signed int S32
Definition: itkIPLCommonImageIO.h:66
itk::int64_t
::int64_t int64_t
Definition: itkIntTypes.h:34
itk::IPLCommonImageIO::S64
int64_t S64
Definition: itkIPLCommonImageIO.h:68
itk::IPLCommonImageIO::ModifyImageInformation
virtual void ModifyImageInformation()
Definition: itkIPLCommonImageIO.h:95
GEImageHeader
Definition: itkGEImageHeader.h:41
itk::uint64_t
::uint64_t uint64_t
Definition: itkIntTypes.h:35
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::IPLCommonImageIO
Class that defines how to read GE4 file format.
Definition: itkIPLCommonImageIO.h:51
itk::IPLCommonImageIO::S8
signed char S8
Definition: itkIPLCommonImageIO.h:62
itkImageIOBase.h
itk::Offset
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition: itkOffset.h:67
itk::IPLCommonImageIO::U8
unsigned char U8
Definition: itkIPLCommonImageIO.h:61
itk::IPLCommonImageIO::m_FilenameList
IPLFileNameList * m_FilenameList
Definition: itkIPLCommonImageIO.h:169
itk::IPLCommonImageIO::F32
float F32
Definition: itkIPLCommonImageIO.h:69
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkIPLFileNameList.h
itkGEImageHeader.h
itk::IPLCommonImageIO::m_ImageHeader
GEImageHeader * m_ImageHeader
Definition: itkIPLCommonImageIO.h:167
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::IPLCommonImageIO::U32
unsigned int U32
Definition: itkIPLCommonImageIO.h:65