00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00031 #ifndef __itkIPLCommonImageIO_h
00032 #define __itkIPLCommonImageIO_h
00033
00034 #include <fstream>
00035 #include "itkImageIOBase.h"
00036 #include "itkIOCommon.h"
00037 #include "itkGEImageHeader.h"
00038 #include "itkIPLFileNameList.h"
00039
00040 namespace itk
00041 {
00049 class ITK_EXPORT IPLCommonImageIO : public ImageIOBase
00050 {
00051 public:
00053 typedef IPLCommonImageIO Self;
00054 typedef ImageIOBase Superclass;
00055 typedef SmartPointer<Self> Pointer;
00056
00057 typedef unsigned char U8;
00058 typedef signed char S8;
00059 typedef unsigned short U16;
00060 typedef signed short S16;
00061 typedef unsigned int U32;
00062 typedef signed int S32;
00063 typedef unsigned long U64;
00064 typedef signed long S64;
00065 typedef float F32;
00066 typedef double F64;
00067
00069 itkNewMacro(Self);
00070
00072 itkTypeMacro(IPLCommonImageIO, Superclass);
00073
00074
00075
00082 virtual bool CanReadFile(const char* FileNameToRead);
00083
00085 virtual void ReadImageInformation();
00086
00088 virtual void ModifyImageInformation() {};
00089
00091 virtual const std::type_info& GetPixelTypeInfo() const;
00092
00094 virtual const std::type_info& GetComponentTypeInfo() const;
00095
00097 virtual void Read(void* buffer);
00098
00102 virtual unsigned int GetComponentSize() const;
00103
00104
00105
00112 virtual bool CanWriteFile(const char * FileNameToWrite);
00113
00115 virtual void WriteImageInformation();
00116
00119 virtual void Write(const void* buffer);
00120
00122 virtual void SortImageListByNameAscend();
00123
00125 virtual void SortImageListByNameDescend();
00126
00127
00128 protected:
00129 IPLCommonImageIO();
00130 ~IPLCommonImageIO();
00131 void PrintSelf(std::ostream& os, Indent indent) const;
00132
00133 int AddElementToList(char const * const filename,
00134 const float sliceLocation,
00135 const int offset,
00136 const int XDim,
00137 const int YDim,
00138 const int Key1,
00139 const int Key2 );
00140 void sortImageListAscend ();
00141 void sortImageListDescend ();
00142 int statTimeToAscii (void *clock, char *timeString);
00143 virtual struct GEImageHeader *ReadHeader(const char *FileNameToRead);
00144
00145
00146 struct GEImageHeader *m_ImageHeader;
00147 ImageIOBase::ByteOrder m_SystemByteOrder;
00148 IPLFileNameList *m_FilenameList;
00149
00150
00151 int GetStringAt(std::ifstream &f,std::streamoff Offset,char *buf,
00152 size_t amount, bool throw_exception = true);
00153 int GetIntAt(std::ifstream &f,std::streamoff Offset,int *ip,
00154 bool throw_exception = true);
00155 int GetShortAt(std::ifstream &f,std::streamoff Offset,short *ip,
00156 bool throw_exception = true);
00157 int GetFloatAt(std::ifstream &f,std::streamoff Offset,float *ip,
00158 bool throw_exception = true);
00159 int GetDoubleAt(std::ifstream &f,std::streamoff Offset,double *ip,
00160 bool throw_exception = true);
00161
00162 short hdr2Short(char *hdr);
00163 int hdr2Int(char *hdr);
00164 float hdr2Float(char *hdr);
00165 double hdr2Double(char *hdr);
00166 private:
00167 IPLCommonImageIO(const Self&);
00168 void operator=(const Self&);
00169 };
00170
00171 }
00172 #define RAISE_EXCEPTION() \
00173 { ExceptionObject exception(__FILE__, __LINE__); \
00174 exception.SetDescription("File cannot be read"); \
00175 throw exception; }
00176
00177 #define IOCHECK() \
00178 if(f.fail()) \
00179 { \
00180 if(f.is_open()) \
00181 f.close(); \
00182 RAISE_EXCEPTION(); \
00183 }
00184
00185
00186 #endif // __itkAnalyzeImageIO_h
00187