ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkIPLCommonImageIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software 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  *=========================================================================*/
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 {
50 class ITKIOIPL_EXPORT IPLCommonImageIO:public ImageIOBase
51 {
52 public:
53  ITK_DISALLOW_COPY_AND_ASSIGN(IPLCommonImageIO);
54 
59 
60  using U8 = unsigned char;
61  using S8 = signed char;
62  using U16 = unsigned short;
63  using S16 = signed short;
64  using U32 = unsigned int;
65  using S32 = signed int;
66  using U64 = uint64_t;
67  using S64 = int64_t;
68  using F32 = float;
69  using F64 = double;
70 
72  itkNewMacro(Self);
73 
75  itkTypeMacro(IPLCommonImageIO, Superclass);
76 
77  /*-------- This part of the interfaces deals with reading data. ----- */
78 
85  bool CanReadFile(const char *FileNameToRead) override;
86 
88  void ReadImageInformation() override;
89 
91  virtual void ModifyImageInformation() {}
92 
94  void Read(void *buffer) override;
95 
99  unsigned int GetComponentSize() const override;
100 
101  /*-------- This part of the interfaces deals with writing data. ----- */
102 
109  bool CanWriteFile(const char *FileNameToWrite) override;
110 
112  void WriteImageInformation() override;
113 
116  void Write(const void *buffer) override;
117 
119  virtual void SortImageListByNameAscend();
120 
122  virtual void SortImageListByNameDescend();
123 
124 protected:
126  ~IPLCommonImageIO() override;
127  void PrintSelf(std::ostream & os, Indent indent) const override;
128 
129  int AddElementToList(char const *const filename,
130  const float sliceLocation,
131  const int offset,
132  const int XDim,
133  const int YDim,
134  const float XRes,
135  const float YRes,
136  const int Key1,
137  const int Key2);
138 
139  void sortImageListAscend();
140 
141  void sortImageListDescend();
142 
143  int statTimeToAscii(void *clock, char *timeString, int len);
144 
145  virtual GEImageHeader * ReadHeader(const char *FileNameToRead);
146 
147  //
148  // data members
151  IPLFileNameList *m_FilenameList;
152  //
153  // return 0 on success, -1 on failure
154  int GetStringAt(std::ifstream & f, std::streamoff Offset, char *buf,
155  size_t amount, bool throw_exception = true);
156 
157  int GetIntAt(std::ifstream & f, std::streamoff Offset, int *ip,
158  bool throw_exception = true);
159 
160  int GetShortAt(std::ifstream & f, std::streamoff Offset, short *ip,
161  bool throw_exception = true);
162 
163  int GetFloatAt(std::ifstream & f, std::streamoff Offset, float *ip,
164  bool throw_exception = true);
165 
166  int GetDoubleAt(std::ifstream & f, std::streamoff Offset, double *ip,
167  bool throw_exception = true);
168 
169  short hdr2Short(char *hdr);
170 
171  int hdr2Int(char *hdr);
172 
173  float hdr2Float(char *hdr);
174 
175  double hdr2Double(char *hdr);
176 };
177 } // end namespace itk
178 #define RAISE_EXCEPTION() \
179  { ExceptionObject exception(__FILE__, __LINE__); \
180  exception.SetDescription("File cannot be read"); \
181  throw exception; }
182 
183 #define IOCHECK() \
184  if ( f.fail() ) \
185  { \
186  if ( f.is_open() ) \
187  { \
188  f.close(); \
189  } \
190  RAISE_EXCEPTION(); \
191  }
192 
193 #endif // itkIPLCommonImageIO_h
Light weight base class for most itk classes.
Abstract superclass defines image IO interface.
IPLFileNameList * m_FilenameList
Class that defines how to read GE4 file format.
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image...
Definition: itkOffset.h:67
ImageIOBase::ByteOrder m_SystemByteOrder
::int64_t int64_t
Definition: itkIntTypes.h:34
Control indentation during Print() invocation.
Definition: itkIndent.h:49
GEImageHeader * m_ImageHeader
virtual void ModifyImageInformation()
Base class for most ITK classes.
Definition: itkObject.h:60
::uint64_t uint64_t
Definition: itkIntTypes.h:35