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: 2007/02/22 00:21:07 $
00007   Version:   $Revision: 1.40 $
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 
00075   class UnknownType {};
00076 
00080   typedef  enum {UNKNOWNPIXELTYPE,SCALAR,RGB,RGBA,OFFSET,VECTOR,
00081                  POINT,COVARIANTVECTOR,SYMMETRICSECONDRANKTENSOR,
00082                  DIFFUSIONTENSOR3D,COMPLEX,FIXEDARRAY}  IOPixelType;
00083 
00088   typedef  enum {UNKNOWNCOMPONENTTYPE,UCHAR,CHAR,USHORT,SHORT,UINT,INT,
00089                  ULONG,LONG, FLOAT,DOUBLE} IOComponentType;
00090 
00094   void SetNumberOfDimensions(unsigned int);
00095   itkGetMacro(NumberOfDimensions, unsigned int);
00097 
00101   virtual void SetDimensions(unsigned int i, unsigned int dim);
00102   virtual unsigned int GetDimensions(unsigned int i) const
00103   { return m_Dimensions[i]; }
00105 
00108   virtual void SetOrigin(unsigned int i, double origin);
00109   virtual double GetOrigin(unsigned int i) const
00110   { return m_Origin[i]; }
00112 
00115   virtual void SetSpacing(unsigned int i, double spacing);
00116   virtual double GetSpacing(unsigned int i) const
00117   { return m_Spacing[i]; }
00119 
00122   virtual void SetDirection(unsigned int i, std::vector<double> &direction);
00123   virtual void SetDirection(unsigned int i, vnl_vector<double> &direction);
00124   virtual std::vector<double> GetDirection(unsigned int i) const
00125   { return m_Direction[i]; }
00127 
00134   itkSetMacro(IORegion, ImageIORegion);
00135   itkGetMacro(IORegion, ImageIORegion);
00137 
00143   itkSetMacro(PixelType, IOPixelType);
00144   itkGetConstReferenceMacro(PixelType, IOPixelType);
00146 
00153   virtual bool SetPixelTypeInfo(const std::type_info& ptype);
00154 
00157   itkSetMacro(ComponentType,IOComponentType);
00158   itkGetConstReferenceMacro(ComponentType,IOComponentType);
00159   virtual const std::type_info& GetComponentTypeInfo() const;
00161 
00166   itkSetMacro(NumberOfComponents,unsigned int);
00167   itkGetConstReferenceMacro(NumberOfComponents,unsigned int);
00169 
00171   itkSetMacro(UseCompression,bool);
00172   itkGetConstReferenceMacro(UseCompression,bool);
00174 
00177   std::string GetComponentTypeAsString(IOComponentType) const;
00178 
00181   std::string GetPixelTypeAsString(IOPixelType) const;
00182 
00185   typedef  enum {ASCII,Binary,TypeNotApplicable} FileType;
00186 
00189   typedef  enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00190 
00193   itkSetMacro(FileType,FileType);
00194   itkGetConstReferenceMacro(FileType,FileType);
00195   void SetFileTypeToASCII()
00196   { this->SetFileType(ASCII); }
00197   void SetFileTypeToBinary()
00198   { this->SetFileType(Binary); }
00200 
00212   itkSetMacro(ByteOrder,ByteOrder);
00213   itkGetConstReferenceMacro(ByteOrder,ByteOrder);
00214   void SetByteOrderToBigEndian()
00215   { this->SetByteOrder(BigEndian); }
00216   void SetByteOrderToLittleEndian()
00217   { this->SetByteOrder(LittleEndian); }
00219 
00222   std::string GetFileTypeAsString(FileType) const;
00223 
00226   std::string GetByteOrderAsString(ByteOrder) const;
00227 
00230   virtual unsigned int GetPixelStride () const;
00231 
00233   unsigned int GetImageSizeInPixels() const;
00234 
00236   unsigned int GetImageSizeInBytes() const;
00237 
00240   unsigned int GetImageSizeInComponents() const;
00241 
00242   /*-------- This part of the interfaces deals with reading data ----- */
00243 
00246   virtual bool CanReadFile(const char*) = 0;
00247 
00250   virtual bool CanStreamRead() { return false; };
00251 
00254   virtual void ReadImageInformation() = 0;
00255 
00257   virtual void Read(void* buffer) = 0;
00258 
00259 
00260   /*-------- This part of the interfaces deals with writing data ----- */
00261 
00264   virtual bool CanWriteFile(const char*)  = 0;
00265 
00268   virtual bool CanStreamWrite() { return false; };
00269 
00272   virtual void WriteImageInformation() = 0;
00273 
00277   virtual void Write( const void* buffer) = 0;
00278 
00279   /* --- Support reading and writing data as a series of files. --- */
00280 
00286   virtual bool SupportsDimension(unsigned long dim)
00287   {return (dim == 2);}
00288 
00289 protected:
00290   ImageIOBase();
00291   ~ImageIOBase();
00292   void PrintSelf(std::ostream& os, Indent indent) const;
00293 
00295   IOPixelType m_PixelType;
00296 
00299   IOComponentType m_ComponentType;
00300 
00302   ByteOrder      m_ByteOrder;
00303   FileType       m_FileType;
00304 
00306   bool m_Initialized;
00307 
00309   std::string m_FileName;
00310 
00313   unsigned int m_NumberOfComponents;
00314 
00316   unsigned int m_NumberOfDimensions;
00317 
00319   bool m_UseCompression;
00320 
00323   ImageIORegion m_IORegion;
00324 
00326   std::vector<unsigned int> m_Dimensions;
00327 
00330   std::vector<double> m_Spacing;
00331 
00333   std::vector<double> m_Origin;
00334 
00336   std::vector<std::vector<double> > m_Direction;
00337 
00340   std::vector<unsigned int> m_Strides;
00341 
00343   virtual void Reset(const bool freeDynamic = true);
00344 
00346   void Resize(const unsigned int numDimensions, 
00347               const unsigned int* dimensions);
00348 
00355   void ComputeStrides();
00356 
00359   virtual unsigned int GetPixelSize() const;
00360 
00365   virtual unsigned int GetComponentSize() const;
00366 
00369   unsigned int GetComponentStride() const;
00370 
00373   unsigned int GetRowStride () const;
00374 
00377   unsigned int GetSliceStride () const;
00378 
00380   void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00381                           IOComponentType ctype,
00382                           unsigned int numComp);
00383 
00385   void ReadBufferAsASCII(std::istream& os, void *buffer,
00386                          IOComponentType ctype,
00387                          unsigned int numComp);
00388 
00390   bool ReadBufferAsBinary(std::istream& os, void *buffer,unsigned int numComp);
00391 
00392   
00393 private:
00394   ImageIOBase(const Self&); //purposely not implemented
00395   void operator=(const Self&); //purposely not implemented
00396 
00397 
00398 };
00399 
00400 } // end namespace itk
00401 
00402 #endif // __itkImageIOBase_h
00403 

Generated at Mon Mar 12 00:50:54 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000