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 "itkImageIOBase.h"
00035 #include "itkIPLFileNameList.h"
00036 #include "itkGEImageHeader.h"
00037
00038 namespace itk
00039 {
00047 class ITK_EXPORT IPLCommonImageIO : public ImageIOBase
00048 {
00049 public:
00051 typedef IPLCommonImageIO Self;
00052 typedef ImageIOBase Superclass;
00053 typedef SmartPointer<Self> Pointer;
00054
00055 typedef unsigned char U8;
00056 typedef signed char S8;
00057 typedef unsigned short U16;
00058 typedef signed short S16;
00059 typedef unsigned int U32;
00060 typedef signed int S32;
00061 typedef unsigned long U64;
00062 typedef signed long S64;
00063 typedef float F32;
00064 typedef double F64;
00065
00067 itkNewMacro(Self);
00068
00070 itkTypeMacro(IPLCommonImageIO, Superclass);
00071
00072
00073
00080 virtual bool CanReadFile(const char* FileNameToRead);
00081
00083 virtual void ReadImageInformation();
00084
00086 virtual void ModifyImageInformation() {};
00087
00089 virtual const std::type_info& GetPixelTypeInfo() const;
00090
00092 virtual const std::type_info& GetComponentTypeInfo() const;
00093
00095 virtual void Read(void* buffer);
00096
00100 virtual unsigned int GetComponentSize() const;
00101
00102
00103
00110 virtual bool CanWriteFile(const char * FileNameToWrite);
00111
00113 virtual void WriteImageInformation();
00114
00117 virtual void Write(const void* buffer);
00118
00120 virtual void SortImageListByNameAscend();
00121
00123 virtual void SortImageListByNameDescend();
00124
00125
00126 protected:
00127 IPLCommonImageIO();
00128 ~IPLCommonImageIO();
00129 void PrintSelf(std::ostream& os, Indent indent) const;
00130
00131 int AddElementToList(char const * const filename,
00132 const float sliceLocation,
00133 const int offset,
00134 const int XDim,
00135 const int YDim,
00136 const int Key1,
00137 const int Key2 );
00138 void sortImageListAscend ();
00139 void sortImageListDescend ();
00140 int statTimeToAscii (void *clock, char *timeString);
00141 virtual GEImageHeader *ReadHeader(const char *FileNameToRead);
00142
00143
00144 GEImageHeader *m_ImageHeader;
00145 ImageIOBase::ByteOrder m_SystemByteOrder;
00146 IPLFileNameList *m_FilenameList;
00147
00148
00149 int GetStringAt(std::ifstream &f,std::streamoff Offset,char *buf,
00150 size_t amount, bool throw_exception = true);
00151 int GetIntAt(std::ifstream &f,std::streamoff Offset,int *ip,
00152 bool throw_exception = true);
00153 int GetShortAt(std::ifstream &f,std::streamoff Offset,short *ip,
00154 bool throw_exception = true);
00155 int GetFloatAt(std::ifstream &f,std::streamoff Offset,float *ip,
00156 bool throw_exception = true);
00157 int GetDoubleAt(std::ifstream &f,std::streamoff Offset,double *ip,
00158 bool throw_exception = true);
00159
00160 short hdr2Short(char *hdr);
00161 int hdr2Int(char *hdr);
00162 float hdr2Float(char *hdr);
00163 double hdr2Double(char *hdr);
00164 private:
00165 IPLCommonImageIO(const Self&);
00166 void operator=(const Self&);
00167 };
00168
00169 }
00170 #define RAISE_EXCEPTION() \
00171 { ExceptionObject exception(__FILE__, __LINE__); \
00172 exception.SetDescription("File cannot be read"); \
00173 throw exception; }
00174
00175 #define IOCHECK() \
00176 if(f.fail()) \
00177 { \
00178 if(f.is_open()) \
00179 f.close(); \
00180 RAISE_EXCEPTION(); \
00181 }
00182
00183
00184 #endif // __itkAnalyzeImageIO_h
00185