ITK  6.0.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 * 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 *=========================================================================*/
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
40namespace itk
41{
51class ITKIOIPL_EXPORT IPLCommonImageIO : public ImageIOBase
52{
53public:
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 = short;
65 using U32 = unsigned int;
66 using S32 = 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 itkOverrideGetNameOfClassMacro(IPLCommonImageIO);
77
78 /*-------- This part of the interfaces deals with reading data. ----- */
79
86 bool
87 CanReadFile(const char * FileNameToRead) override;
88
90 void
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
122
125 void
126 Write(const void * buffer) override;
127
129 virtual void
131
133 virtual void
135
136protected:
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
155
156 void
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
167 GEImageHeader * m_ImageHeader{};
168 IOByteOrderEnum m_SystemByteOrder{};
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
Class that defines how to read GE4 file format.
void WriteImageInformation() override
short hdr2Short(char *hdr)
int statTimeToAscii(void *clock, char *timeString, int len)
int hdr2Int(char *hdr)
void Read(void *buffer) override
int AddElementToList(char const *const filename, const float sliceLocation, const int offset, const int XDim, const int YDim, const float XRes, const float YRes, const int Key1, const int Key2)
int GetShortAt(std::ifstream &f, std::streamoff Offset, short *ip, bool throw_exception=true)
float hdr2Float(char *hdr)
bool CanWriteFile(const char *FileNameToWrite) override
void PrintSelf(std::ostream &os, Indent indent) const override
int GetIntAt(std::ifstream &f, std::streamoff Offset, int *ip, bool throw_exception=true)
virtual void SortImageListByNameAscend()
virtual GEImageHeader * ReadHeader(const char *FileNameToRead)
double hdr2Double(char *hdr)
int GetStringAt(std::ifstream &f, std::streamoff Offset, char *buf, vcl_size_t amount, bool throw_exception=true)
bool CanReadFile(const char *FileNameToRead) override
void Write(const void *buffer) override
unsigned int GetComponentSize() const override
virtual void ModifyImageInformation()
virtual void SortImageListByNameDescend()
int GetFloatAt(std::ifstream &f, std::streamoff Offset, float *ip, bool throw_exception=true)
void ReadImageInformation() override
~IPLCommonImageIO() override
int GetDoubleAt(std::ifstream &f, std::streamoff Offset, double *ip, bool throw_exception=true)
Abstract superclass defines image IO interface.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition: itkOffset.h:67