ITK  4.3.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 
35 #include "itkImageIOBase.h"
36 #include "itkIPLFileNameList.h"
37 #include "itkGEImageHeader.h"
38 
39 namespace itk
40 {
49 class ITK_EXPORT IPLCommonImageIO:public ImageIOBase
50 {
51 public:
56 
57  typedef unsigned char U8;
58  typedef signed char S8;
59  typedef unsigned short U16;
60  typedef signed short S16;
61  typedef unsigned int U32;
62  typedef signed int S32;
63  typedef uint64_t U64;
64  typedef int64_t S64;
65  typedef float F32;
66  typedef double F64;
67 
69  itkNewMacro(Self);
70 
72  itkTypeMacro(IPLCommonImageIO, Superclass);
73 
74  /*-------- This part of the interfaces deals with reading data. ----- */
75 
82  virtual bool CanReadFile(const char *FileNameToRead);
83 
85  virtual void ReadImageInformation();
86 
88  virtual void ModifyImageInformation() {}
89 
91  virtual void Read(void *buffer);
92 
96  virtual unsigned int GetComponentSize() const;
97 
98  /*-------- This part of the interfaces deals with writing data. ----- */
99 
106  virtual bool CanWriteFile(const char *FileNameToWrite);
107 
109  virtual void WriteImageInformation();
110 
113  virtual void Write(const void *buffer);
114 
116  virtual void SortImageListByNameAscend();
117 
119  virtual void SortImageListByNameDescend();
120 
121 protected:
123  ~IPLCommonImageIO();
124  void PrintSelf(std::ostream & os, Indent indent) const;
125 
126  int AddElementToList(char const *const filename,
127  const float sliceLocation,
128  const int offset,
129  const int XDim,
130  const int YDim,
131  const float XRes,
132  const float YRes,
133  const int Key1,
134  const int Key2);
135 
136  void sortImageListAscend();
137 
138  void sortImageListDescend();
139 
140  int statTimeToAscii(void *clock, char *timeString, int len);
141 
142  virtual GEImageHeader * ReadHeader(const char *FileNameToRead);
143 
144  //
145  // data members
148  IPLFileNameList *m_FilenameList;
149  //
150  // return 0 on success, -1 on failure
151  int GetStringAt(std::ifstream & f, std::streamoff Offset, char *buf,
152  size_t amount, bool throw_exception = true);
153 
154  int GetIntAt(std::ifstream & f, std::streamoff Offset, int *ip,
155  bool throw_exception = true);
156 
157  int GetShortAt(std::ifstream & f, std::streamoff Offset, short *ip,
158  bool throw_exception = true);
159 
160  int GetFloatAt(std::ifstream & f, std::streamoff Offset, float *ip,
161  bool throw_exception = true);
162 
163  int GetDoubleAt(std::ifstream & f, std::streamoff Offset, double *ip,
164  bool throw_exception = true);
165 
166  short hdr2Short(char *hdr);
167 
168  int hdr2Int(char *hdr);
169 
170  float hdr2Float(char *hdr);
171 
172  double hdr2Double(char *hdr);
173 
174 private:
175  IPLCommonImageIO(const Self &); //purposely not implemented
176  void operator=(const Self &); //purposely not implemented
177 };
178 } // end namespace itk
179 #define RAISE_EXCEPTION() \
180  { ExceptionObject exception(__FILE__, __LINE__); \
181  exception.SetDescription("File cannot be read"); \
182  throw exception; }
183 
184 #define IOCHECK() \
185  if ( f.fail() ) \
186  { \
187  if ( f.is_open() ) \
188  { \
189  f.close(); \
190  } \
191  RAISE_EXCEPTION(); \
192  }
193 
194 #endif // __itkAnalyzeImageIO_h
195