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-01-21 17:11:44 $
00007   Version:   $Revision: 1.48 $
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 
00337 
00338 protected:
00339   ImageIOBase();
00340   ~ImageIOBase();
00341   void PrintSelf(std::ostream& os, Indent indent) const;
00342 
00344   IOPixelType m_PixelType;
00345 
00348   IOComponentType m_ComponentType;
00349 
00351   ByteOrder      m_ByteOrder;
00352   FileType       m_FileType;
00353 
00355   bool m_Initialized;
00356 
00358   std::string m_FileName;
00359 
00362   unsigned int m_NumberOfComponents;
00363 
00365   unsigned int m_NumberOfDimensions;
00366 
00368   bool m_UseCompression;
00369 
00371   bool m_UseStreamedReading;
00372 
00374   bool m_UseStreamedWriting;
00375 
00378   ImageIORegion m_IORegion;
00379 
00381   std::vector<unsigned int> m_Dimensions;
00382 
00385   std::vector<double> m_Spacing;
00386 
00388   std::vector<double> m_Origin;
00389 
00391   std::vector<std::vector<double> > m_Direction;
00392 
00395   std::vector< SizeType > m_Strides;
00396 
00398   virtual void Reset(const bool freeDynamic = true);
00399 
00401   void Resize(const unsigned int numDimensions, 
00402               const unsigned int* dimensions);
00403 
00410   void ComputeStrides();
00411 
00414   virtual unsigned int GetPixelSize() const;
00415 
00420   virtual unsigned int GetComponentSize() const;
00421 
00424   SizeType GetComponentStride() const;
00425 
00428   SizeType GetRowStride () const;
00429 
00432   SizeType GetSliceStride () const;
00433 
00435   void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00436                           IOComponentType ctype,
00437                           SizeType numberOfBytesToWrite);
00438 
00440   void ReadBufferAsASCII(std::istream& os, void *buffer,
00441                          IOComponentType ctype,
00442                          SizeType numberOfBytesToBeRead);
00443 
00445   bool ReadBufferAsBinary(std::istream& os, void *buffer, SizeType numberOfBytesToBeRead);
00446 
00447   
00448 private:
00449   ImageIOBase(const Self&); //purposely not implemented
00450   void operator=(const Self&); //purposely not implemented
00451 
00452 
00453 };
00454 
00455 } // end namespace itk
00456 
00457 #endif // __itkImageIOBase_h
00458 

Generated at Mon Apr 14 12:50:38 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000