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);
00073
00078 class UnknownType {};
00079
00083 typedef enum {UNKNOWNPIXELTYPE,SCALAR,RGB,RGBA,OFFSET,VECTOR,
00084 POINT,COVARIANTVECTOR,SYMMETRICSECONDRANKTENSOR,
00085 DIFFUSIONTENSOR3D,COMPLEX,FIXEDARRAY,MATRIX} IOPixelType;
00086
00091 typedef enum {UNKNOWNCOMPONENTTYPE,UCHAR,CHAR,USHORT,SHORT,UINT,INT,
00092 ULONG,LONG, FLOAT,DOUBLE} IOComponentType;
00093
00097 void SetNumberOfDimensions(unsigned int);
00098 itkGetConstMacro(NumberOfDimensions, unsigned int);
00100
00104 virtual void SetDimensions(unsigned int i, unsigned int dim);
00105 virtual unsigned int GetDimensions(unsigned int i) const
00106 { return m_Dimensions[i]; }
00108
00111 virtual void SetOrigin(unsigned int i, double origin);
00112 virtual double GetOrigin(unsigned int i) const
00113 {
00114 return m_Origin[i];
00115 }
00117
00120 virtual void SetSpacing(unsigned int i, double spacing);
00121 virtual double GetSpacing(unsigned int i) const
00122 {
00123 return m_Spacing[i];
00124 }
00126
00129 virtual void SetDirection(unsigned int i, std::vector<double> &direction);
00130 virtual void SetDirection(unsigned int i, vnl_vector<double> &direction);
00131 virtual std::vector<double> GetDirection(unsigned int i) const
00132 {
00133 return m_Direction[i];
00134 }
00136
00139 virtual std::vector<double> GetDefaultDirection(unsigned int i) const;
00140
00147 itkSetMacro(IORegion, ImageIORegion);
00148 itkGetConstReferenceMacro(IORegion, ImageIORegion);
00150
00156 itkSetEnumMacro(PixelType, IOPixelType);
00157 itkGetEnumMacro(PixelType, IOPixelType);
00159
00166 virtual bool SetPixelTypeInfo(const std::type_info& ptype);
00167
00170 itkSetEnumMacro(ComponentType,IOComponentType);
00171 itkGetEnumMacro(ComponentType,IOComponentType);
00172 virtual const std::type_info& GetComponentTypeInfo() const;
00174
00179 itkSetMacro(NumberOfComponents,unsigned int);
00180 itkGetConstReferenceMacro(NumberOfComponents,unsigned int);
00182
00184 itkSetMacro(UseCompression,bool);
00185 itkGetConstMacro(UseCompression,bool);
00186 itkBooleanMacro(UseCompression);
00188
00190 itkSetMacro(UseStreamedReading,bool);
00191 itkGetConstMacro(UseStreamedReading,bool);
00192 itkBooleanMacro(UseStreamedReading);
00194
00196 itkSetMacro(UseStreamedWriting,bool);
00197 itkGetConstMacro(UseStreamedWriting,bool);
00198 itkBooleanMacro(UseStreamedWriting);
00200
00201
00204 std::string GetComponentTypeAsString(IOComponentType) const;
00205
00208 std::string GetPixelTypeAsString(IOPixelType) const;
00209
00212 typedef enum {ASCII,Binary,TypeNotApplicable} FileType;
00213
00216 typedef enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00217
00220 itkSetEnumMacro(FileType,FileType);
00221 itkGetEnumMacro(FileType,FileType);
00222 void SetFileTypeToASCII()
00223 {
00224 this->SetFileType(ASCII);
00225 }
00226 void SetFileTypeToBinary()
00227 {
00228 this->SetFileType(Binary);
00229 }
00231
00243 itkSetEnumMacro(ByteOrder,ByteOrder);
00244 itkGetEnumMacro(ByteOrder,ByteOrder);
00245 void SetByteOrderToBigEndian()
00246 {
00247 this->SetByteOrder(BigEndian);
00248 }
00249 void SetByteOrderToLittleEndian()
00250 {
00251 this->SetByteOrder(LittleEndian);
00252 }
00254
00257 std::string GetFileTypeAsString(FileType) const;
00258
00261 std::string GetByteOrderAsString(ByteOrder) const;
00262
00264 typedef std::streamoff SizeType;
00265
00268 virtual SizeType GetPixelStride () const;
00269
00271 SizeType GetImageSizeInPixels() const;
00272
00274 SizeType GetImageSizeInBytes() const;
00275
00278 SizeType GetImageSizeInComponents() const;
00279
00280
00281
00284 virtual bool CanReadFile(const char*) = 0;
00285
00288 virtual bool CanStreamRead()
00289 {
00290 return false;
00291 }
00292
00295 virtual void ReadImageInformation() = 0;
00296
00298 virtual void Read(void* buffer) = 0;
00299
00300
00301
00302
00305 virtual bool CanWriteFile(const char*) = 0;
00306
00312 virtual bool CanStreamWrite()
00313 {
00314 return false;
00315 }
00316
00319 virtual void WriteImageInformation() = 0;
00320
00324 virtual void Write( const void* buffer) = 0;
00325
00326
00327
00333 virtual bool SupportsDimension(unsigned long dim)
00334 {
00335 return (dim == 2);
00336 }
00337
00349 virtual ImageIORegion
00350 GenerateStreamableReadRegionFromRequestedRegion( const ImageIORegion & requested ) const;
00351
00352
00353
00368 virtual unsigned int GetActualNumberOfSplitsForWriting(unsigned int numberOfRequestedSplits,
00369 const ImageIORegion &pasteRegion,
00370 const ImageIORegion &largestPossibleRegion);
00371
00378 virtual ImageIORegion GetSplitRegionForWriting(unsigned int ithPiece,
00379 unsigned int numberOfActualSplits,
00380 const ImageIORegion &pasteRegion,
00381 const ImageIORegion &largestPossibleRegion);
00382
00384 typedef std::vector< std::string > ArrayOfExtensionsType;
00385
00390 const ArrayOfExtensionsType & GetSupportedReadExtensions() const;
00391
00396 const ArrayOfExtensionsType & GetSupportedWriteExtensions() const;
00397
00398
00399 protected:
00400 ImageIOBase();
00401 ~ImageIOBase();
00402 void PrintSelf(std::ostream& os, Indent indent) const;
00403
00405 IOPixelType m_PixelType;
00406
00409 IOComponentType m_ComponentType;
00410
00412 ByteOrder m_ByteOrder;
00413 FileType m_FileType;
00414
00416 bool m_Initialized;
00417
00419 std::string m_FileName;
00420
00423 unsigned int m_NumberOfComponents;
00424
00426 unsigned int m_NumberOfDimensions;
00427
00429 bool m_UseCompression;
00430
00432 bool m_UseStreamedReading;
00433
00435 bool m_UseStreamedWriting;
00436
00439 ImageIORegion m_IORegion;
00440
00442 std::vector<unsigned int> m_Dimensions;
00443
00446 std::vector<double> m_Spacing;
00447
00449 std::vector<double> m_Origin;
00450
00452 std::vector<std::vector<double> > m_Direction;
00453
00456 std::vector< SizeType > m_Strides;
00457
00459 virtual void Reset(const bool freeDynamic = true);
00460
00462 void Resize(const unsigned int numDimensions,
00463 const unsigned int* dimensions);
00464
00471 void ComputeStrides();
00472
00475 virtual unsigned int GetPixelSize() const;
00476
00481 virtual unsigned int GetComponentSize() const;
00482
00485 SizeType GetComponentStride() const;
00486
00489 SizeType GetRowStride () const;
00490
00493 SizeType GetSliceStride () const;
00494
00496 void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00497 IOComponentType ctype,
00498 SizeType numberOfBytesToWrite);
00499
00501 void ReadBufferAsASCII(std::istream& os, void *buffer,
00502 IOComponentType ctype,
00503 SizeType numberOfBytesToBeRead);
00504
00506 bool ReadBufferAsBinary(std::istream& os, void *buffer, SizeType numberOfBytesToBeRead);
00507
00508
00510 void AddSupportedReadExtension( const char * extension );
00511
00513 void AddSupportedWriteExtension( const char * extension );
00514
00517 virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(unsigned int numberOfRequestedSplits,
00518 const ImageIORegion &pasteRegion) const;
00519
00522 virtual ImageIORegion GetSplitRegionForWritingCanStreamWrite(unsigned int ithPiece,
00523 unsigned int numberOfActualSplits,
00524 const ImageIORegion &pasteRegion) const;
00525
00526 private:
00527 ImageIOBase(const Self&);
00528 void operator=(const Self&);
00529
00530 ArrayOfExtensionsType m_SupportedReadExtensions;
00531 ArrayOfExtensionsType m_SupportedWriteExtensions;
00532
00533 };
00534
00535 }
00536
00537 #endif // __itkImageIOBase_h
00538