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 "vnl/vnl_vector.h"
00025
00026 #include <string>
00027
00028 namespace itk
00029 {
00030
00058 class ITK_EXPORT ImageIOBase : public LightProcessObject
00059 {
00060 public:
00062 typedef ImageIOBase Self;
00063 typedef LightProcessObject Superclass;
00064 typedef SmartPointer<Self> Pointer;
00065
00067 itkTypeMacro(ImageIOBase, Superclass);
00068
00070 itkSetStringMacro(FileName);
00071 itkGetStringMacro(FileName);
00072
00074 class UnknownType {};
00075
00079 typedef enum {UNKNOWNPIXELTYPE,SCALAR,RGB,RGBA,OFFSET,VECTOR,
00080 POINT,COVARIANTVECTOR,SYMMETRICSECONDRANKTENSOR,
00081 DIFFUSIONTENSOR3D,COMPLEX,FIXEDARRAY} IOPixelType;
00082
00087 typedef enum {UNKNOWNCOMPONENTTYPE,UCHAR,CHAR,USHORT,SHORT,UINT,INT,
00088 ULONG,LONG, FLOAT,DOUBLE} IOComponentType;
00089
00093 void SetNumberOfDimensions(unsigned int);
00094 itkGetMacro(NumberOfDimensions, unsigned int);
00095
00099 virtual void SetDimensions(unsigned int i, unsigned int dim);
00100 virtual unsigned int GetDimensions(unsigned int i) const
00101 { return m_Dimensions[i]; }
00102
00105 virtual void SetOrigin(unsigned int i, double origin);
00106 virtual double GetOrigin(unsigned int i) const
00107 { return m_Origin[i]; }
00108
00111 virtual void SetSpacing(unsigned int i, double spacing);
00112 virtual double GetSpacing(unsigned int i) const
00113 { return m_Spacing[i]; }
00114
00117 virtual void SetDirection(unsigned int i, std::vector<double> &direction);
00118 virtual void SetDirection(unsigned int i, vnl_vector<double> &direction);
00119 virtual std::vector<double> GetDirection(unsigned int i) const
00120 { return m_Direction[i]; }
00121
00128 itkSetMacro(IORegion, ImageIORegion);
00129 itkGetMacro(IORegion, ImageIORegion);
00130
00136 itkSetMacro(PixelType, IOPixelType);
00137 itkGetConstReferenceMacro(PixelType, IOPixelType);
00138
00145 virtual bool SetPixelTypeInfo(const std::type_info& ptype);
00146
00149 itkSetMacro(ComponentType,IOComponentType);
00150 itkGetConstReferenceMacro(ComponentType,IOComponentType);
00151 virtual const std::type_info& GetComponentTypeInfo() const;
00152
00157 itkSetMacro(NumberOfComponents,unsigned int);
00158 itkGetConstReferenceMacro(NumberOfComponents,unsigned int);
00159
00161 itkSetMacro(UseCompression,bool);
00162 itkGetConstReferenceMacro(UseCompression,bool);
00163
00166 std::string GetComponentTypeAsString(IOComponentType) const;
00167
00170 std::string GetPixelTypeAsString(IOPixelType) const;
00171
00174 typedef enum {ASCII,Binary,TypeNotApplicable} FileType;
00175
00178 typedef enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00179
00182 itkSetMacro(FileType,FileType);
00183 itkGetConstReferenceMacro(FileType,FileType);
00184 void SetFileTypeToASCII()
00185 { this->SetFileType(ASCII); }
00186 void SetFileTypeToBinary()
00187 { this->SetFileType(Binary); }
00188
00200 itkSetMacro(ByteOrder,ByteOrder);
00201 itkGetConstReferenceMacro(ByteOrder,ByteOrder);
00202 void SetByteOrderToBigEndian()
00203 { this->SetByteOrder(BigEndian); }
00204 void SetByteOrderToLittleEndian()
00205 { this->SetByteOrder(LittleEndian); }
00206
00209 std::string GetFileTypeAsString(FileType) const;
00210
00213 std::string GetByteOrderAsString(ByteOrder) const;
00214
00217 virtual unsigned int GetPixelStride () const;
00218
00220 unsigned int GetImageSizeInPixels() const;
00221
00223 unsigned int GetImageSizeInBytes() const;
00224
00227 unsigned int GetImageSizeInComponents() const;
00228
00229
00230
00233 virtual bool CanReadFile(const char*) = 0;
00234
00237 virtual bool CanStreamRead() { return false; };
00238
00241 virtual void ReadImageInformation() = 0;
00242
00244 virtual void Read(void* buffer) = 0;
00245
00246
00247
00248
00251 virtual bool CanWriteFile(const char*) = 0;
00252
00255 virtual bool CanStreamWrite() { return false; };
00256
00259 virtual void WriteImageInformation() = 0;
00260
00264 virtual void Write( const void* buffer) = 0;
00265
00266
00267
00273 virtual bool SupportsDimension(unsigned long dim)
00274 {return (dim == 2);}
00275
00276 protected:
00277 ImageIOBase();
00278 ~ImageIOBase();
00279 void PrintSelf(std::ostream& os, Indent indent) const;
00280
00282 IOPixelType m_PixelType;
00283
00286 IOComponentType m_ComponentType;
00287
00289 ByteOrder m_ByteOrder;
00290 FileType m_FileType;
00291
00293 bool m_Initialized;
00294
00296 std::string m_FileName;
00297
00300 unsigned int m_NumberOfComponents;
00301
00303 unsigned int m_NumberOfDimensions;
00304
00306 bool m_UseCompression;
00307
00310 ImageIORegion m_IORegion;
00311
00313 std::vector<unsigned int> m_Dimensions;
00314
00317 std::vector<double> m_Spacing;
00318
00320 std::vector<double> m_Origin;
00321
00323 std::vector<std::vector<double> > m_Direction;
00324
00327 std::vector<unsigned int> m_Strides;
00328
00330 virtual void Reset(const bool freeDynamic = true);
00331
00333 void Resize(const unsigned int numDimensions,
00334 const unsigned int* dimensions);
00335
00342 void ComputeStrides();
00343
00346 virtual unsigned int GetPixelSize() const;
00347
00352 virtual unsigned int GetComponentSize() const;
00353
00356 unsigned int GetComponentStride() const;
00357
00360 unsigned int GetRowStride () const;
00361
00364 unsigned int GetSliceStride () const;
00365
00367 void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00368 IOComponentType ctype,
00369 unsigned int numComp);
00370
00372 void ReadBufferAsASCII(std::istream& os, void *buffer,
00373 IOComponentType ctype,
00374 unsigned int numComp);
00375
00377 bool ReadBufferAsBinary(std::istream& os, void *buffer,unsigned int numComp);
00378
00379
00380 private:
00381 ImageIOBase(const Self&);
00382 void operator=(const Self&);
00383
00384
00385 };
00386
00387 }
00388
00389 #endif // __itkImageIOBase_h