00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkImageIOBase_h
00018 #define __itkImageIOBase_h
00019
00020 #include "itkLightProcessObject.h"
00021 #include "itkObjectFactory.h"
00022 #include "itkIndent.h"
00023 #include "itkImageIORegion.h"
00024 #include <string>
00025
00026 namespace itk
00027 {
00028
00047 class ITK_EXPORT ImageIOBase : public LightProcessObject
00048 {
00049 public:
00051 typedef ImageIOBase Self;
00052 typedef LightProcessObject Superclass;
00053 typedef SmartPointer<Self> Pointer;
00054
00056 itkTypeMacro(ImageIOBase, Superclass);
00057
00059 class UnknownType {};
00060
00063 typedef enum {UNKNOWN,UCHAR,CHAR,USHORT,SHORT,UINT,INT,
00064 ULONG,LONG, FLOAT,DOUBLE,
00065 RGB,RGBA,OFFSET,VECTOR,POINT,COVARIANTVECTOR} IODataType;
00066
00068 itkSetStringMacro(FileName);
00069 itkGetStringMacro(FileName);
00070
00072 itkSetStringMacro(FilePrefix);
00073 itkGetStringMacro(FilePrefix);
00074
00077 void SetNumberOfDimensions(unsigned int);
00078 itkGetMacro(NumberOfDimensions, unsigned int);
00079
00083 virtual void SetDimensions(unsigned int i, unsigned int dim);
00084 virtual unsigned int GetDimensions(unsigned int i) const
00085 { return m_Dimensions[i]; }
00086
00089 virtual void SetOrigin(unsigned int i, double origin);
00090 virtual double GetOrigin(unsigned int i) const
00091 { return m_Origin[i]; }
00092
00095 virtual void SetSpacing(unsigned int i, double spacing);
00096 virtual double GetSpacing(unsigned int i) const
00097 { return m_Spacing[i]; }
00098
00105 itkSetMacro(IORegion, ImageIORegion);
00106 itkGetMacro(IORegion, ImageIORegion);
00107
00112 virtual const std::type_info& GetPixelType() const;
00113 virtual void SetPixelType(const IODataType ctype);
00114
00118 virtual bool SetPixelType(const std::type_info& ptype);
00119
00123 itkSetMacro(ComponentType,IODataType);
00124 itkGetMacro(ComponentType,IODataType);
00125
00128 itkSetMacro(NumberOfComponents,unsigned int);
00129 itkGetMacro(NumberOfComponents,unsigned int);
00130
00133 std::string ReturnTypeAsString(IODataType) const;
00134
00137 typedef enum {ASCII,Binary,TypeNotApplicable} FileType;
00138
00141 typedef enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00142
00145 itkSetMacro(FileType,FileType);
00146 itkGetConstMacro(FileType,FileType);
00147 void SetFileTypeToASCII()
00148 { this->SetFileType(ASCII); }
00149 void SetFileTypeToBinary()
00150 { this->SetFileType(Binary); }
00151
00163 itkSetMacro(ByteOrder,ByteOrder);
00164 itkGetConstMacro(ByteOrder,ByteOrder);
00165 void SetByteOrderToBigEndian()
00166 { this->SetByteOrder(BigEndian); }
00167 void SetByteOrderToLittleEndian()
00168 { this->SetByteOrder(LittleEndian); }
00169
00172 virtual unsigned int GetPixelStride () const;
00173
00175 unsigned int GetImageSizeInPixels() const;
00176
00178 unsigned int GetImageSizeInBytes() const;
00179
00182 unsigned int GetImageSizeInComponents() const;
00183
00184
00185
00188 virtual bool CanReadFile(const char*) = 0;
00189
00192 virtual void ReadImageInformation() = 0;
00193
00195 virtual void Read(void* buffer) = 0;
00196
00197
00198
00199
00202 virtual bool CanWriteFile(const char*) = 0;
00203
00206 virtual void WriteImageInformation() = 0;
00207
00210 virtual void Write( const void* buffer) = 0;
00211
00212 protected:
00213 ImageIOBase();
00214 ~ImageIOBase();
00215 void PrintSelf(std::ostream& os, Indent indent) const;
00216
00218 const std::type_info& ConvertToTypeInfo(IODataType ) const;
00219 unsigned int GetSizeOfType(IODataType ) const;
00220
00222 IODataType m_PixelType;
00223
00226 IODataType m_ComponentType;
00227
00229 unsigned int m_NumberOfDimensions;
00230
00232 ByteOrder m_ByteOrder;
00233 FileType m_FileType;
00234
00236 bool m_Initialized;
00237
00239 std::string m_FileName;
00240
00242 std::string m_FilePrefix;
00243
00246 unsigned int m_NumberOfComponents;
00247
00250 ImageIORegion m_IORegion;
00251
00253 std::vector<unsigned int> m_Dimensions;
00254
00257 std::vector<double> m_Spacing;
00258
00260 std::vector<double> m_Origin;
00261
00264 std::vector<unsigned int> m_Strides;
00265
00267 virtual void Reset(const bool freeDynamic = true);
00268
00270 void Resize(const unsigned int numDimensions,
00271 const unsigned int* dimensions);
00272
00279 void ComputeStrides();
00280
00283 virtual unsigned int GetPixelSize() const;
00284
00289 virtual unsigned int GetComponentSize() const;
00290
00293 unsigned int GetComponentStride() const;
00294
00297 unsigned int GetRowStride () const;
00298
00301 unsigned int GetSliceStride () const;
00302
00304 void WriteBufferAsASCII(std::ostream& os, const void *buffer, IODataType ctype,
00305 unsigned int numComp);
00306
00308 void ReadBufferAsASCII(std::istream& os, void *buffer, IODataType ctype,
00309 unsigned int numComp);
00310
00311 private:
00312 ImageIOBase(const Self&);
00313 void operator=(const Self&);
00314
00315 };
00316
00317 }
00318
00319 #endif // __itkImageIOBase_h