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 {
00047 class ITK_EXPORT IPLCommonImageIO :
public ImageIOBase
00048 {
00049
public:
00051
typedef IPLCommonImageIO
Self;
00052 typedef ImageIOBase Superclass;
00053 typedef SmartPointer<Self> Pointer;
00054 typedef unsigned char U8;
00055 typedef signed char S8;
00056 typedef unsigned short U16;
00057 typedef signed short S16;
00058 typedef unsigned int U32;
00059 typedef signed int S32;
00060 typedef unsigned long U64;
00061 typedef signed long S64;
00062 typedef float F32;
00063 typedef double F64;
00064
00066
itkNewMacro(
Self);
00067
00069
itkTypeMacro(IPLCommonImageIO,
Superclass);
00070
00071
00072
00079
virtual bool CanReadFile(
const char* FileNameToRead) ;
00080
00082
virtual void ReadImageInformation();
00083
00085
virtual const std::type_info& GetPixelType() const;
00086
00088 virtual
void Read(
void* buffer);
00089
00093 virtual
unsigned int GetComponentSize() const;
00094
00095
00096
00103 virtual
bool CanWriteFile(const
char * FileNameToWrite);
00104
00106 virtual
void WriteImageInformation();
00107
00110 virtual
void Write(const
void* buffer);
00111
00112
00113 protected:
00114 IPLCommonImageIO();
00115 ~IPLCommonImageIO();
00116
void PrintSelf(std::ostream& os,
Indent indent) const;
00117
00118
int AddElementToList(
char const * const filename, const
float sliceLocation, const
int offset, const
int XDim, const
int YDim, const
int Key1, const
int Key2 );
00119
void sortImageListAscend ();
00120
void sortImageListDescend ();
00121
int statTimeToAscii (
void *clock,
char *timeString);
00122 virtual struct
GEImageHeader *ReadHeader(const
char *FileNameToRead);
00123
00124
00125 struct
GEImageHeader *m_ImageHeader;
00126 ImageIOBase::ByteOrder m_system_byteOrder;
00127 IPLFileNameList *m_fnlist;
00128
00129
00130
int GetStringAt(std::ifstream &f,std::streamoff
Offset,
char *buf,
00131 size_t amount,
bool throw_exception = true);
00132
int GetIntAt(std::ifstream &f,std::streamoff Offset,
int *ip,
00133
bool throw_exception = true);
00134
int GetShortAt(std::ifstream &f,std::streamoff Offset,
short *ip,
00135
bool throw_exception = true);
00136
int GetFloatAt(std::ifstream &f,std::streamoff Offset,
float *ip,
00137
bool throw_exception = true);
00138
int GetDoubleAt(std::ifstream &f,std::streamoff Offset,
double *ip,
00139
bool throw_exception = true);
00140
00141
short hdr2Short(
char *hdr);
00142
int hdr2Int(
char *hdr);
00143
float hdr2Float(
char *hdr);
00144
double hdr2Double(
char *hdr);
00145 private:
00146 IPLCommonImageIO(const
Self&);
00147
void operator=(const Self&);
00148 };
00149
00150 }
00151 #define RAISE_EXCEPTION() \
00152 { ExceptionObject exception(__FILE__, __LINE__); \
00153 exception.SetDescription(
"File cannot be read"); \
00154
throw exception; }
00155
00156
#define IOCHECK() \
00157 if(f.fail()) \
00158
{ \
00159
if(f.is_open()) \
00160
f.close(); \
00161
RAISE_EXCEPTION(); \
00162
}
00163
00164
00165
#endif // __itkAnalyzeImageIO_h