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: 2005/07/08 03:35:56 $
00007   Version:   $Revision: 1.38 $
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 
00057 class ITK_EXPORT ImageIOBase : public LightProcessObject
00058 {
00059 public:
00061   typedef ImageIOBase            Self;
00062   typedef LightProcessObject  Superclass;
00063   typedef SmartPointer<Self>  Pointer;
00064   
00066   itkTypeMacro(ImageIOBase, Superclass);
00067 
00069   itkSetStringMacro(FileName);
00070   itkGetStringMacro(FileName);
00071   
00073   class UnknownType {};
00074 
00078   typedef  enum {UNKNOWNPIXELTYPE,SCALAR,RGB,RGBA,OFFSET,VECTOR,
00079                  POINT,COVARIANTVECTOR,SYMMETRICSECONDRANKTENSOR,
00080                  DIFFUSIONTENSOR3D,COMPLEX,FIXEDARRAY}  IOPixelType;
00081 
00086   typedef  enum {UNKNOWNCOMPONENTTYPE,UCHAR,CHAR,USHORT,SHORT,UINT,INT,
00087                  ULONG,LONG, FLOAT,DOUBLE} IOComponentType;
00088 
00092   void SetNumberOfDimensions(unsigned int);
00093   itkGetMacro(NumberOfDimensions, unsigned int);
00094 
00098   virtual void SetDimensions(unsigned int i, unsigned int dim);
00099   virtual unsigned int GetDimensions(unsigned int i) const
00100   { return m_Dimensions[i]; }
00101 
00104   virtual void SetOrigin(unsigned int i, double origin);
00105   virtual double GetOrigin(unsigned int i) const
00106   { return m_Origin[i]; }
00107 
00110   virtual void SetSpacing(unsigned int i, double spacing);
00111   virtual double GetSpacing(unsigned int i) const
00112   { return m_Spacing[i]; }
00113 
00116   virtual void SetDirection(unsigned int i, std::vector<double> &direction);
00117   virtual void SetDirection(unsigned int i, vnl_vector<double> &direction);
00118   virtual std::vector<double> GetDirection(unsigned int i) const
00119   { return m_Direction[i]; }
00120 
00127   itkSetMacro(IORegion, ImageIORegion);
00128   itkGetMacro(IORegion, ImageIORegion);
00129 
00135   itkSetMacro(PixelType, IOPixelType);
00136   itkGetConstReferenceMacro(PixelType, IOPixelType);
00137 
00144   virtual bool SetPixelTypeInfo(const std::type_info& ptype);
00145   
00148   itkSetMacro(ComponentType,IOComponentType);
00149   itkGetConstReferenceMacro(ComponentType,IOComponentType);
00150   virtual const std::type_info& GetComponentTypeInfo() const;
00151   
00156   itkSetMacro(NumberOfComponents,unsigned int);
00157   itkGetConstReferenceMacro(NumberOfComponents,unsigned int);
00158 
00160   itkSetMacro(UseCompression,bool);
00161   itkGetConstReferenceMacro(UseCompression,bool);
00162 
00165   std::string GetComponentTypeAsString(IOComponentType) const;
00166 
00169   std::string GetPixelTypeAsString(IOPixelType) const;
00170   
00173   typedef  enum {ASCII,Binary,TypeNotApplicable} FileType;
00174   
00177   typedef  enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00178   
00181   itkSetMacro(FileType,FileType);
00182   itkGetConstReferenceMacro(FileType,FileType);
00183   void SetFileTypeToASCII()
00184   { this->SetFileType(ASCII); }
00185   void SetFileTypeToBinary()
00186   { this->SetFileType(Binary); }
00187 
00199   itkSetMacro(ByteOrder,ByteOrder);
00200   itkGetConstReferenceMacro(ByteOrder,ByteOrder);
00201   void SetByteOrderToBigEndian()
00202   { this->SetByteOrder(BigEndian); }
00203   void SetByteOrderToLittleEndian()
00204   { this->SetByteOrder(LittleEndian); }
00205   
00208   std::string GetFileTypeAsString(FileType) const;
00209 
00212   std::string GetByteOrderAsString(ByteOrder) const;
00213 
00216   virtual unsigned int GetPixelStride () const;
00217 
00219   unsigned int GetImageSizeInPixels() const;
00220 
00222   unsigned int GetImageSizeInBytes() const;
00223   
00226   unsigned int GetImageSizeInComponents() const;
00227 
00228   /*-------- This part of the interfaces deals with reading data ----- */
00229 
00232   virtual bool CanReadFile(const char*) = 0;
00233 
00236   virtual bool CanStreamRead() { return false; };
00237   
00240   virtual void ReadImageInformation() = 0;
00241   
00243   virtual void Read(void* buffer) = 0;
00244 
00245 
00246   /*-------- This part of the interfaces deals with writing data ----- */
00247 
00250   virtual bool CanWriteFile(const char*)  = 0;
00251 
00254   virtual bool CanStreamWrite() { return false; };
00255 
00258   virtual void WriteImageInformation() = 0;
00259   
00263   virtual void Write( const void* buffer) = 0;
00264 
00265   /* --- Support reading and writing data as a series of files. --- */
00266 
00272   virtual bool SupportsDimension(unsigned long dim)
00273   {return (dim == 2);}
00274 
00275 protected:
00276   ImageIOBase();
00277   ~ImageIOBase();
00278   void PrintSelf(std::ostream& os, Indent indent) const;
00279 
00281   IOPixelType m_PixelType;
00282 
00285   IOComponentType m_ComponentType;
00286 
00288   ByteOrder      m_ByteOrder;
00289   FileType       m_FileType;
00290 
00292   bool m_Initialized;
00293 
00295   std::string m_FileName;
00296 
00299   unsigned int m_NumberOfComponents;
00300 
00302   unsigned int m_NumberOfDimensions;
00303 
00305   bool m_UseCompression;
00306 
00309   ImageIORegion m_IORegion;
00310 
00312   std::vector<unsigned int> m_Dimensions;
00313 
00316   std::vector<double> m_Spacing;
00317 
00319   std::vector<double> m_Origin;
00320 
00322   std::vector<std::vector<double> > m_Direction;
00323 
00326   std::vector<unsigned int> m_Strides;
00327 
00329   virtual void Reset(const bool freeDynamic = true);
00330 
00332   void Resize(const unsigned int numDimensions, 
00333               const unsigned int* dimensions);
00334 
00341   void ComputeStrides();
00342 
00345   virtual unsigned int GetPixelSize() const;
00346 
00351   virtual unsigned int GetComponentSize() const;
00352 
00355   unsigned int GetComponentStride() const;
00356 
00359   unsigned int GetRowStride () const;
00360 
00363   unsigned int GetSliceStride () const;
00364 
00366   void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00367                           IOComponentType ctype,
00368                           unsigned int numComp);
00369 
00371   void ReadBufferAsASCII(std::istream& os, void *buffer,
00372                          IOComponentType ctype,
00373                          unsigned int numComp);
00374 
00376   bool ReadBufferAsBinary(std::istream& os, void *buffer,unsigned int numComp);
00377 
00378   
00379 private:
00380   ImageIOBase(const Self&); //purposely not implemented
00381   void operator=(const Self&); //purposely not implemented
00382 
00383 
00384 };
00385 
00386 } // end namespace itk
00387 
00388 #endif // __itkImageIOBase_h

Generated at Tue Aug 30 16:44:22 2005 for ITK by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2000