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: 2004/11/04 20:40:41 $
00007   Version:   $Revision: 1.32 $
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 <string>
00025 
00026 namespace itk
00027 {
00028 
00055 class ITK_EXPORT ImageIOBase : public LightProcessObject
00056 {
00057 public:
00059   typedef ImageIOBase            Self;
00060   typedef LightProcessObject  Superclass;
00061   typedef SmartPointer<Self>  Pointer;
00062   
00064   itkTypeMacro(ImageIOBase, Superclass);
00065 
00067   itkSetStringMacro(FileName);
00068   itkGetStringMacro(FileName);
00069   
00071   class UnknownType {};
00072 
00076   typedef  enum {UNKNOWNPIXELTYPE,SCALAR,RGB,RGBA,OFFSET,VECTOR,
00077                  POINT,COVARIANTVECTOR}  IOPixelType;
00078 
00083   typedef  enum {UNKNOWNCOMPONENTTYPE,UCHAR,CHAR,USHORT,SHORT,UINT,INT,
00084                  ULONG,LONG, FLOAT,DOUBLE} IOComponentType;
00085 
00089   void SetNumberOfDimensions(unsigned int);
00090   itkGetMacro(NumberOfDimensions, unsigned int);
00091 
00095   virtual void SetDimensions(unsigned int i, unsigned int dim);
00096   virtual unsigned int GetDimensions(unsigned int i) const
00097   { return m_Dimensions[i]; }
00098 
00101   virtual void SetOrigin(unsigned int i, double origin);
00102   virtual double GetOrigin(unsigned int i) const
00103   { return m_Origin[i]; }
00104 
00107   virtual void SetSpacing(unsigned int i, double spacing);
00108   virtual double GetSpacing(unsigned int i) const
00109   { return m_Spacing[i]; }
00110 
00117   itkSetMacro(IORegion, ImageIORegion);
00118   itkGetMacro(IORegion, ImageIORegion);
00119 
00125   itkSetMacro(PixelType, IOPixelType);
00126   itkGetConstReferenceMacro(PixelType, IOPixelType);
00127 
00134   virtual bool SetPixelTypeInfo(const std::type_info& ptype);
00135   
00138   itkSetMacro(ComponentType,IOComponentType);
00139   itkGetConstReferenceMacro(ComponentType,IOComponentType);
00140   virtual const std::type_info& GetComponentTypeInfo() const;
00141   
00146   itkSetMacro(NumberOfComponents,unsigned int);
00147   itkGetConstReferenceMacro(NumberOfComponents,unsigned int);
00148 
00150   itkSetMacro(UseCompression,bool);
00151   itkGetConstReferenceMacro(UseCompression,bool);
00152 
00155   std::string GetComponentTypeAsString(IOComponentType) const;
00156 
00159   std::string GetPixelTypeAsString(IOPixelType) const;
00160   
00163   typedef  enum {ASCII,Binary,TypeNotApplicable} FileType;
00164   
00167   typedef  enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00168   
00171   itkSetMacro(FileType,FileType);
00172   itkGetConstReferenceMacro(FileType,FileType);
00173   void SetFileTypeToASCII()
00174   { this->SetFileType(ASCII); }
00175   void SetFileTypeToBinary()
00176   { this->SetFileType(Binary); }
00177 
00189   itkSetMacro(ByteOrder,ByteOrder);
00190   itkGetConstReferenceMacro(ByteOrder,ByteOrder);
00191   void SetByteOrderToBigEndian()
00192   { this->SetByteOrder(BigEndian); }
00193   void SetByteOrderToLittleEndian()
00194   { this->SetByteOrder(LittleEndian); }
00195   
00198   virtual unsigned int GetPixelStride () const;
00199 
00201   unsigned int GetImageSizeInPixels() const;
00202 
00204   unsigned int GetImageSizeInBytes() const;
00205   
00208   unsigned int GetImageSizeInComponents() const;
00209 
00210   /*-------- This part of the interfaces deals with reading data ----- */
00211 
00214   virtual bool CanReadFile(const char*) = 0;
00215 
00218   virtual bool CanStreamRead() { return false; };
00219   
00222   virtual void ReadImageInformation() = 0;
00223   
00225   virtual void Read(void* buffer) = 0;
00226 
00227 
00228   /*-------- This part of the interfaces deals with writing data ----- */
00229 
00232   virtual bool CanWriteFile(const char*)  = 0;
00233 
00236   virtual bool CanStreamWrite() { return false; };
00237 
00240   virtual void WriteImageInformation() = 0;
00241   
00245   virtual void Write( const void* buffer) = 0;
00246 
00247   /* --- Support reading and writing data as a series of files. --- */
00248 
00254   virtual bool SupportsDimension(unsigned long dim)
00255   {return (dim == 2);}
00256 
00257 protected:
00258   ImageIOBase();
00259   ~ImageIOBase();
00260   void PrintSelf(std::ostream& os, Indent indent) const;
00261 
00263   IOPixelType m_PixelType;
00264 
00267   IOComponentType m_ComponentType;
00268 
00270   ByteOrder      m_ByteOrder;
00271   FileType       m_FileType;
00272 
00274   bool m_Initialized;
00275 
00277   std::string m_FileName;
00278 
00281   unsigned int m_NumberOfComponents;
00282 
00284   unsigned int m_NumberOfDimensions;
00285 
00287   bool m_UseCompression;
00288 
00291   ImageIORegion m_IORegion;
00292 
00294   std::vector<unsigned int> m_Dimensions;
00295 
00298   std::vector<double> m_Spacing;
00299 
00301   std::vector<double> m_Origin;
00302 
00305   std::vector<unsigned int> m_Strides;
00306 
00308   virtual void Reset(const bool freeDynamic = true);
00309 
00311   void Resize(const unsigned int numDimensions, 
00312               const unsigned int* dimensions);
00313 
00320   void ComputeStrides();
00321 
00324   virtual unsigned int GetPixelSize() const;
00325 
00330   virtual unsigned int GetComponentSize() const;
00331 
00334   unsigned int GetComponentStride() const;
00335 
00338   unsigned int GetRowStride () const;
00339 
00342   unsigned int GetSliceStride () const;
00343 
00345   void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00346                           IOComponentType ctype,
00347                           unsigned int numComp);
00348 
00350   void ReadBufferAsASCII(std::istream& os, void *buffer,
00351                          IOComponentType ctype,
00352                          unsigned int numComp);
00353 
00355   bool ReadBufferAsBinary(std::istream& os, void *buffer,unsigned int numComp);
00356 
00357   
00358 private:
00359   ImageIOBase(const Self&); //purposely not implemented
00360   void operator=(const Self&); //purposely not implemented
00361 
00362 
00363 };
00364 
00365 } // end namespace itk
00366 
00367 #endif // __itkImageIOBase_h

Generated at Tue Mar 29 23:54:43 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000