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
00041 namespace itk
00042 {
00050 class ITK_EXPORT IPLCommonImageIO : public ImageIOBase
00051 {
00052 public:
00054 typedef IPLCommonImageIO Self;
00055 typedef ImageIOBase Superclass;
00056 typedef SmartPointer<Self> Pointer;
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 const std::type_info& GetPixelTypeInfo() const;
00089
00091 virtual const std::type_info& GetComponentTypeInfo() const;
00092
00094 virtual void Read(void* buffer);
00095
00099 virtual unsigned int GetComponentSize() const;
00100
00101
00102
00109 virtual bool CanWriteFile(const char * FileNameToWrite);
00110
00112 virtual void WriteImageInformation();
00113
00116 virtual void Write(const void* buffer);
00117
00119 virtual void SortImageListByNameAscend();
00120
00122 virtual void SortImageListByNameDescend();
00123
00124
00125 protected:
00126 IPLCommonImageIO();
00127 ~IPLCommonImageIO();
00128 void PrintSelf(std::ostream& os, Indent indent) const;
00129
00130 int AddElementToList(char const * const filename, const float sliceLocation, const int offset, const int XDim, const int YDim, const int Key1, const int Key2 );
00131 void sortImageListAscend ();
00132 void sortImageListDescend ();
00133 int statTimeToAscii (void *clock, char *timeString);
00134 virtual struct GEImageHeader *ReadHeader(const char *FileNameToRead);
00135
00136
00137 struct GEImageHeader *m_ImageHeader;
00138 ImageIOBase::ByteOrder m_system_byteOrder;
00139 IPLFileNameList *m_fnlist;
00140
00141
00142 int GetStringAt(std::ifstream &f,std::streamoff Offset,char *buf,
00143 size_t amount, bool throw_exception = true);
00144 int GetIntAt(std::ifstream &f,std::streamoff Offset,int *ip,
00145 bool throw_exception = true);
00146 int GetShortAt(std::ifstream &f,std::streamoff Offset,short *ip,
00147 bool throw_exception = true);
00148 int GetFloatAt(std::ifstream &f,std::streamoff Offset,float *ip,
00149 bool throw_exception = true);
00150 int GetDoubleAt(std::ifstream &f,std::streamoff Offset,double *ip,
00151 bool throw_exception = true);
00152
00153 short hdr2Short(char *hdr);
00154 int hdr2Int(char *hdr);
00155 float hdr2Float(char *hdr);
00156 double hdr2Double(char *hdr);
00157 private:
00158 IPLCommonImageIO(const Self&);
00159 void operator=(const Self&);
00160 };
00161
00162 }
00163 #define RAISE_EXCEPTION() \
00164 { ExceptionObject exception(__FILE__, __LINE__); \
00165 exception.SetDescription("File cannot be read"); \
00166 throw exception; }
00167
00168 #define IOCHECK() \
00169 if(f.fail()) \
00170 { \
00171 if(f.is_open()) \
00172 f.close(); \
00173 RAISE_EXCEPTION(); \
00174 }
00175
00176
00177 #endif // __itkAnalyzeImageIO_h