ITK  4.8.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:
57 
58  typedef unsigned char U8;
59  typedef signed char S8;
60  typedef unsigned short U16;
61  typedef signed short S16;
62  typedef unsigned int U32;
63  typedef signed int S32;
64  typedef uint64_t U64;
65  typedef int64_t S64;
66  typedef float F32;
67  typedef double F64;
68 
70  itkNewMacro(Self);
71 
73  itkTypeMacro(IPLCommonImageIO, Superclass);
74 
75  /*-------- This part of the interfaces deals with reading data. ----- */
76 
83  virtual bool CanReadFile(const char *FileNameToRead) ITK_OVERRIDE;
84 
86  virtual void ReadImageInformation() ITK_OVERRIDE;
87 
89  virtual void ModifyImageInformation() {}
90 
92  virtual void Read(void *buffer) ITK_OVERRIDE;
93 
97  virtual unsigned int GetComponentSize() const ITK_OVERRIDE;
98 
99  /*-------- This part of the interfaces deals with writing data. ----- */
100 
107  virtual bool CanWriteFile(const char *FileNameToWrite) ITK_OVERRIDE;
108 
110  virtual void WriteImageInformation() ITK_OVERRIDE;
111 
114  virtual void Write(const void *buffer) ITK_OVERRIDE;
115 
117  virtual void SortImageListByNameAscend();
118 
120  virtual void SortImageListByNameDescend();
121 
122 protected:
124  ~IPLCommonImageIO();
125  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
126 
127  int AddElementToList(char const *const filename,
128  const float sliceLocation,
129  const int offset,
130  const int XDim,
131  const int YDim,
132  const float XRes,
133  const float YRes,
134  const int Key1,
135  const int Key2);
136 
137  void sortImageListAscend();
138 
139  void sortImageListDescend();
140 
141  int statTimeToAscii(void *clock, char *timeString, int len);
142 
143  virtual GEImageHeader * ReadHeader(const char *FileNameToRead);
144 
145  //
146  // data members
147  GEImageHeader *m_ImageHeader;
148  ImageIOBase::ByteOrder m_SystemByteOrder;
149  IPLFileNameList *m_FilenameList;
150  //
151  // return 0 on success, -1 on failure
152  int GetStringAt(std::ifstream & f, std::streamoff Offset, char *buf,
153  size_t amount, bool throw_exception = true);
154 
155  int GetIntAt(std::ifstream & f, std::streamoff Offset, int *ip,
156  bool throw_exception = true);
157 
158  int GetShortAt(std::ifstream & f, std::streamoff Offset, short *ip,
159  bool throw_exception = true);
160 
161  int GetFloatAt(std::ifstream & f, std::streamoff Offset, float *ip,
162  bool throw_exception = true);
163 
164  int GetDoubleAt(std::ifstream & f, std::streamoff Offset, double *ip,
165  bool throw_exception = true);
166 
167  short hdr2Short(char *hdr);
168 
169  int hdr2Int(char *hdr);
170 
171  float hdr2Float(char *hdr);
172 
173  double hdr2Double(char *hdr);
174 
175 private:
176  IPLCommonImageIO(const Self &); //purposely not implemented
177  void operator=(const Self &); //purposely not implemented
178 };
179 } // end namespace itk
180 #define RAISE_EXCEPTION() \
181  { ExceptionObject exception(__FILE__, __LINE__); \
182  exception.SetDescription("File cannot be read"); \
183  throw exception; }
184 
185 #define IOCHECK() \
186  if ( f.fail() ) \
187  { \
188  if ( f.is_open() ) \
189  { \
190  f.close(); \
191  } \
192  RAISE_EXCEPTION(); \
193  }
194 
195 #endif // itkAnalyzeImageIO_h
SmartPointer< Self > Pointer
Light weight base class for most itk classes.
Represent the offset between two n-dimensional indexes in a n-dimensional image.
Definition: itkOffset.h:55
Abstract superclass defines image IO interface.
typedef::itksysFundamentalType_Int64 int64_t
Definition: itkIntTypes.h:88
Class that defines how to read GE4 file format.
typedef::itksysFundamentalType_UInt64 uint64_t
Definition: itkIntTypes.h:89
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:57