Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkImageIOBase.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageIOBase.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-06-25 11:30:38 $
00007   Version:   $Revision: 1.49 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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   itkGetMacro(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 
00143   itkSetMacro(IORegion, ImageIORegion);
00144   itkGetConstMacro(IORegion, ImageIORegion);
00146 
00152   itkSetEnumMacro(PixelType, IOPixelType);
00153   itkGetEnumMacro(PixelType, IOPixelType);
00155 
00162   virtual bool SetPixelTypeInfo(const std::type_info& ptype);
00163 
00166   itkSetEnumMacro(ComponentType,IOComponentType);
00167   itkGetEnumMacro(ComponentType,IOComponentType);
00168   virtual const std::type_info& GetComponentTypeInfo() const;
00170 
00175   itkSetMacro(NumberOfComponents,unsigned int);
00176   itkGetConstReferenceMacro(NumberOfComponents,unsigned int);
00178 
00180   itkSetMacro(UseCompression,bool);
00181   itkGetConstReferenceMacro(UseCompression,bool);
00182   itkBooleanMacro(UseCompression);
00184 
00186   itkSetMacro(UseStreamedReading,bool);
00187   itkGetConstReferenceMacro(UseStreamedReading,bool);
00188   itkBooleanMacro(UseStreamedReading);
00190 
00192   itkSetMacro(UseStreamedWriting,bool);
00193   itkGetConstReferenceMacro(UseStreamedWriting,bool);
00194   itkBooleanMacro(UseStreamedWriting);
00196 
00199   std::string GetComponentTypeAsString(IOComponentType) const;
00200 
00203   std::string GetPixelTypeAsString(IOPixelType) const;
00204 
00207   typedef  enum {ASCII,Binary,TypeNotApplicable} FileType;
00208 
00211   typedef  enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00212 
00215   itkSetEnumMacro(FileType,FileType);
00216   itkGetEnumMacro(FileType,FileType);
00217   void SetFileTypeToASCII()
00218     {
00219     this->SetFileType(ASCII);
00220     }
00221   void SetFileTypeToBinary()
00222     {
00223     this->SetFileType(Binary);
00224     }
00226 
00238   itkSetEnumMacro(ByteOrder,ByteOrder);
00239   itkGetEnumMacro(ByteOrder,ByteOrder);
00240   void SetByteOrderToBigEndian()
00241     {
00242     this->SetByteOrder(BigEndian);
00243     }
00244   void SetByteOrderToLittleEndian()
00245     {
00246     this->SetByteOrder(LittleEndian);
00247     }
00249 
00252   std::string GetFileTypeAsString(FileType) const;
00253 
00256   std::string GetByteOrderAsString(ByteOrder) const;
00257 
00259   typedef std::streamoff SizeType;
00260 
00263   virtual SizeType GetPixelStride () const;
00264 
00266   SizeType GetImageSizeInPixels() const;
00267 
00269   SizeType GetImageSizeInBytes() const;
00270 
00273   SizeType GetImageSizeInComponents() const;
00274 
00275   /*-------- This part of the interfaces deals with reading data ----- */
00276 
00279   virtual bool CanReadFile(const char*) = 0;
00280 
00283   virtual bool CanStreamRead()
00284     {
00285     return false;
00286     }
00287 
00290   virtual void ReadImageInformation() = 0;
00291 
00293   virtual void Read(void* buffer) = 0;
00294 
00295 
00296   /*-------- This part of the interfaces deals with writing data ----- */
00297 
00300   virtual bool CanWriteFile(const char*)  = 0;
00301 
00304   virtual bool CanStreamWrite()
00305     {
00306     return false;
00307     }
00308 
00311   virtual void WriteImageInformation() = 0;
00312 
00316   virtual void Write( const void* buffer) = 0;
00317 
00318   /* --- Support reading and writing data as a series of files. --- */
00319 
00325   virtual bool SupportsDimension(unsigned long dim)
00326     {
00327     return (dim == 2);
00328     }
00329 
00334   virtual ImageIORegion 
00335   GenerateStreamableReadRegionFromRequestedRegion( const ImageIORegion & requested ) const;
00336 
00338   typedef  std::vector< std::string >    ArrayOfExtensionsType;
00339 
00344   const ArrayOfExtensionsType & GetSupportedReadExtensions() const;
00345 
00350   const ArrayOfExtensionsType & GetSupportedWriteExtensions() const;
00351 
00352 
00353 protected:
00354   ImageIOBase();
00355   ~ImageIOBase();
00356   void PrintSelf(std::ostream& os, Indent indent) const;
00357 
00359   IOPixelType m_PixelType;
00360 
00363   IOComponentType m_ComponentType;
00364 
00366   ByteOrder      m_ByteOrder;
00367   FileType       m_FileType;
00368 
00370   bool m_Initialized;
00371 
00373   std::string m_FileName;
00374 
00377   unsigned int m_NumberOfComponents;
00378 
00380   unsigned int m_NumberOfDimensions;
00381 
00383   bool m_UseCompression;
00384 
00386   bool m_UseStreamedReading;
00387 
00389   bool m_UseStreamedWriting;
00390 
00393   ImageIORegion m_IORegion;
00394 
00396   std::vector<unsigned int> m_Dimensions;
00397 
00400   std::vector<double> m_Spacing;
00401 
00403   std::vector<double> m_Origin;
00404 
00406   std::vector<std::vector<double> > m_Direction;
00407 
00410   std::vector< SizeType > m_Strides;
00411 
00413   virtual void Reset(const bool freeDynamic = true);
00414 
00416   void Resize(const unsigned int numDimensions, 
00417               const unsigned int* dimensions);
00418 
00425   void ComputeStrides();
00426 
00429   virtual unsigned int GetPixelSize() const;
00430 
00435   virtual unsigned int GetComponentSize() const;
00436 
00439   SizeType GetComponentStride() const;
00440 
00443   SizeType GetRowStride () const;
00444 
00447   SizeType GetSliceStride () const;
00448 
00450   void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00451                           IOComponentType ctype,
00452                           SizeType numberOfBytesToWrite);
00453 
00455   void ReadBufferAsASCII(std::istream& os, void *buffer,
00456                          IOComponentType ctype,
00457                          SizeType numberOfBytesToBeRead);
00458 
00460   bool ReadBufferAsBinary(std::istream& os, void *buffer, SizeType numberOfBytesToBeRead);
00461 
00462   
00464   void AddSupportedReadExtension( const char * extension );
00465 
00467   void AddSupportedWriteExtension( const char * extension );
00468 
00469 private:
00470   ImageIOBase(const Self&); //purposely not implemented
00471   void operator=(const Self&); //purposely not implemented
00472 
00473   ArrayOfExtensionsType    m_SupportedReadExtensions;
00474   ArrayOfExtensionsType    m_SupportedWriteExtensions;
00475 
00476 };
00477 
00478 } // end namespace itk
00479 
00480 #endif // __itkImageIOBase_h
00481 

Generated at Wed Nov 5 21:58:31 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000