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: 2002/07/29 14:51:21 $
00007   Version:   $Revision: 1.20 $
00008 
00009   Copyright (c) 2002 Insight 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 
00044 class ITK_EXPORT ImageIOBase : public LightProcessObject
00045 {
00046 public:
00048   typedef ImageIOBase            Self;
00049   typedef LightProcessObject  Superclass;
00050   typedef SmartPointer<Self>  Pointer;
00051   
00053   itkTypeMacro(ImageIOBase, Superclass);
00054 
00056   class UnknownType {};
00057 
00060   typedef  enum {UNKNOWN,UCHAR,CHAR,USHORT,SHORT,UINT,INT,ULONG,LONG,
00061                  FLOAT,DOUBLE,RGB,RGBA} IODataType;
00062 
00064   itkSetStringMacro(FileName);
00065   itkGetStringMacro(FileName);
00066   
00068   itkSetStringMacro(FilePrefix);
00069   itkGetStringMacro(FilePrefix);
00070   
00073   void SetNumberOfDimensions(unsigned int);
00074   itkGetMacro(NumberOfDimensions, unsigned int);
00075 
00079   virtual void SetDimensions(unsigned int i, unsigned int dim);
00080   virtual unsigned int GetDimensions(unsigned int i) const
00081     { return m_Dimensions[i]; }
00082 
00085   virtual void SetOrigin(unsigned int i, double origin);
00086   virtual double GetOrigin(unsigned int i) const
00087     { return m_Origin[i]; }
00088 
00091   virtual void SetSpacing(unsigned int i, double spacing);
00092   virtual double GetSpacing(unsigned int i) const
00093     { return m_Spacing[i]; }
00094 
00101   itkSetMacro(IORegion, ImageIORegion);
00102   itkGetMacro(IORegion, ImageIORegion);
00103 
00108   virtual const std::type_info& GetPixelType() const;
00109   virtual void SetPixelType(const IODataType ctype);
00110 
00114   virtual bool SetPixelType(const std::type_info& ptype);
00115 
00119   itkSetMacro(ComponentType,IODataType);
00120   itkGetMacro(ComponentType,IODataType);
00121 
00124   itkSetMacro(NumberOfComponents,unsigned int);
00125   itkGetMacro(NumberOfComponents,unsigned int);
00126 
00129   std::string ReturnTypeAsString(IODataType) const;
00130 
00133   typedef  enum {ASCII,Binary,TypeNotApplicable} FileType;
00134   
00137   typedef  enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00138   
00141   itkSetMacro(FileType,FileType);
00142   itkGetConstMacro(FileType,FileType);
00143   void SetFileTypeToASCII()
00144     { this->SetFileType(ASCII); }
00145   void SetFileTypeToBinary()
00146     { this->SetFileType(Binary); }
00147 
00159   itkSetMacro(ByteOrder,ByteOrder);
00160   itkGetConstMacro(ByteOrder,ByteOrder);
00161   void SetByteOrderToBigEndian()
00162     { this->SetByteOrder(BigEndian); }
00163   void SetByteOrderToLittleEndian()
00164     { this->SetByteOrder(LittleEndian); }
00165   
00168   virtual unsigned int GetPixelStride () const;
00169 
00171   unsigned int GetImageSizeInPixels() const;
00172 
00174   unsigned int GetImageSizeInBytes() const;
00175   
00178   unsigned int GetImageSizeInComponents() const;
00179 
00180  /*-------- This part of the interfaces deals with reading data ----- */
00181 
00184   virtual bool CanReadFile(const char*) = 0;
00185   
00188   virtual void ReadImageInformation() = 0;
00189   
00191   virtual void Read(void* buffer) = 0;
00192 
00193 
00194   /*-------- This part of the interfaces deals with writing data ----- */
00195 
00198   virtual bool CanWriteFile(const char*)  = 0;
00199 
00202   virtual void WriteImageInformation() = 0;
00203   
00206   virtual void Write( const void* buffer) = 0;
00207 
00208 protected:
00209   ImageIOBase();
00210   ~ImageIOBase();
00211   void PrintSelf(std::ostream& os, Indent indent) const;
00212 
00214   const std::type_info& ConvertToTypeInfo(IODataType ) const;
00215   unsigned int GetSizeOfType(IODataType ) const;
00216     
00218   IODataType m_PixelType;
00219 
00222   IODataType m_ComponentType;
00223 
00225   unsigned int m_NumberOfDimensions;
00226 
00228   ByteOrder      m_ByteOrder;
00229   FileType       m_FileType;
00230 
00232   bool m_Initialized;
00233 
00235   std::string m_FileName;
00236 
00238   std::string m_FilePrefix;
00239 
00242   unsigned int m_NumberOfComponents;
00243 
00246   ImageIORegion m_IORegion;
00247 
00249   std::vector<unsigned int> m_Dimensions;
00250 
00253   std::vector<double> m_Spacing;
00254 
00256   std::vector<double> m_Origin;
00257 
00260   std::vector<unsigned int> m_Strides;
00261 
00263   virtual void Reset(const bool freeDynamic = true);
00264 
00266   void Resize(const unsigned int numDimensions, 
00267               const unsigned int* dimensions);
00268 
00275   void ComputeStrides();
00276 
00279   virtual unsigned int GetPixelSize() const;
00280 
00285   virtual unsigned int GetComponentSize() const;
00286 
00289   unsigned int GetComponentStride() const;
00290 
00293   unsigned int GetRowStride () const;
00294 
00297   unsigned int GetSliceStride () const;
00298 
00300   void WriteBufferAsASCII(std::ostream& os, const void *buffer, IODataType ctype,
00301                           unsigned int numComp);
00302 
00304   void ReadBufferAsASCII(std::istream& os, void *buffer, IODataType ctype,
00305                          unsigned int numComp);
00306 
00307 private:
00308   ImageIOBase(const Self&); //purposely not implemented
00309   void operator=(const Self&); //purposely not implemented
00310 
00311 };
00312 
00313 } // end namespace itk
00314 
00315 #endif // __itkImageIOBase_h

Generated at Wed Mar 12 01:13:00 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000