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: 2009-11-29 15:51:11 $
00007   Version:   $Revision: 1.56 $
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   typedef   long              IndexValueType;
00076   typedef   unsigned long     SizeValueType;
00077 
00082   class UnknownType {};
00083 
00087   typedef  enum {UNKNOWNPIXELTYPE,SCALAR,RGB,RGBA,OFFSET,VECTOR,
00088                  POINT,COVARIANTVECTOR,SYMMETRICSECONDRANKTENSOR,
00089                  DIFFUSIONTENSOR3D,COMPLEX,FIXEDARRAY,MATRIX}  IOPixelType;
00090 
00095   typedef  enum {UNKNOWNCOMPONENTTYPE,UCHAR,CHAR,USHORT,SHORT,UINT,INT,
00096                  ULONG,LONG, FLOAT,DOUBLE} IOComponentType;
00097 
00101   void SetNumberOfDimensions(unsigned int);
00102   itkGetConstMacro(NumberOfDimensions, unsigned int);
00104 
00108   virtual void SetDimensions(unsigned int i, unsigned int dim);
00109   virtual unsigned int GetDimensions(unsigned int i) const
00110   { return m_Dimensions[i]; }
00112 
00115   virtual void SetOrigin(unsigned int i, double origin);
00116   virtual double GetOrigin(unsigned int i) const
00117     {
00118     return m_Origin[i];
00119     }
00121 
00124   virtual void SetSpacing(unsigned int i, double spacing);
00125   virtual double GetSpacing(unsigned int i) const
00126     {
00127     return m_Spacing[i];
00128     }
00130 
00133   virtual void SetDirection(unsigned int i, std::vector<double> &direction);
00134   virtual void SetDirection(unsigned int i, vnl_vector<double> &direction);
00135   virtual std::vector<double> GetDirection(unsigned int i) const
00136     {
00137     return m_Direction[i];
00138     }
00140 
00143   virtual std::vector<double> GetDefaultDirection(unsigned int i) const;
00144 
00151   itkSetMacro(IORegion, ImageIORegion);
00152   itkGetConstReferenceMacro(IORegion, ImageIORegion);
00154 
00160   itkSetEnumMacro(PixelType, IOPixelType);
00161   itkGetEnumMacro(PixelType, IOPixelType);
00163 
00170   virtual bool SetPixelTypeInfo(const std::type_info& ptype);
00171 
00174   itkSetEnumMacro(ComponentType,IOComponentType);
00175   itkGetEnumMacro(ComponentType,IOComponentType);
00176   virtual const std::type_info& GetComponentTypeInfo() const;
00178 
00183   itkSetMacro(NumberOfComponents,unsigned int);
00184   itkGetConstReferenceMacro(NumberOfComponents,unsigned int);
00186 
00188   itkSetMacro(UseCompression,bool);
00189   itkGetConstMacro(UseCompression,bool);
00190   itkBooleanMacro(UseCompression);
00192 
00194   itkSetMacro(UseStreamedReading,bool);
00195   itkGetConstMacro(UseStreamedReading,bool);
00196   itkBooleanMacro(UseStreamedReading);
00198 
00200   itkSetMacro(UseStreamedWriting,bool);
00201   itkGetConstMacro(UseStreamedWriting,bool);
00202   itkBooleanMacro(UseStreamedWriting);
00204 
00205 
00208   std::string GetComponentTypeAsString(IOComponentType) const;
00209 
00212   std::string GetPixelTypeAsString(IOPixelType) const;
00213 
00216   typedef  enum {ASCII,Binary,TypeNotApplicable} FileType;
00217 
00220   typedef  enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00221 
00224   itkSetEnumMacro(FileType,FileType);
00225   itkGetEnumMacro(FileType,FileType);
00226   void SetFileTypeToASCII()
00227     {
00228     this->SetFileType(ASCII);
00229     }
00230   void SetFileTypeToBinary()
00231     {
00232     this->SetFileType(Binary);
00233     }
00235 
00247   itkSetEnumMacro(ByteOrder,ByteOrder);
00248   itkGetEnumMacro(ByteOrder,ByteOrder);
00249   void SetByteOrderToBigEndian()
00250     {
00251     this->SetByteOrder(BigEndian);
00252     }
00253   void SetByteOrderToLittleEndian()
00254     {
00255     this->SetByteOrder(LittleEndian);
00256     }
00258 
00261   std::string GetFileTypeAsString(FileType) const;
00262 
00265   std::string GetByteOrderAsString(ByteOrder) const;
00266 
00268   typedef std::streamoff SizeType;
00269 
00271   typedef size_t    BufferSizeType;
00272 
00279   virtual SizeType GetPixelStride () const;
00280 
00282   SizeType GetImageSizeInPixels() const;
00283 
00285   SizeType GetImageSizeInBytes() const;
00286 
00289   SizeType GetImageSizeInComponents() const;
00290 
00291 
00296   virtual unsigned int GetComponentSize() const;
00297 
00298 
00299   /*-------- This part of the interfaces deals with reading data ----- */
00300 
00303   virtual bool CanReadFile(const char*) = 0;
00304 
00307   virtual bool CanStreamRead()
00308     {
00309     return false;
00310     }
00311 
00314   virtual void ReadImageInformation() = 0;
00315 
00317   virtual void Read(void* buffer) = 0;
00318 
00319 
00320   /*-------- This part of the interfaces deals with writing data ----- */
00321 
00324   virtual bool CanWriteFile(const char*)  = 0;
00325 
00331   virtual bool CanStreamWrite()
00332     {
00333     return false;
00334     }
00335 
00338   virtual void WriteImageInformation() = 0;
00339 
00343   virtual void Write( const void* buffer) = 0;
00344 
00345   /* --- Support reading and writing data as a series of files. --- */
00346 
00352   virtual bool SupportsDimension(unsigned long dim)
00353     {
00354     return (dim == 2);
00355     }
00356 
00368   virtual ImageIORegion 
00369   GenerateStreamableReadRegionFromRequestedRegion( const ImageIORegion & requested ) const;
00370 
00371   
00372   
00387   virtual unsigned int GetActualNumberOfSplitsForWriting(unsigned int numberOfRequestedSplits,
00388                                                          const ImageIORegion &pasteRegion,
00389                                                          const ImageIORegion &largestPossibleRegion);
00390 
00397   virtual ImageIORegion GetSplitRegionForWriting(unsigned int ithPiece, 
00398                                                  unsigned int numberOfActualSplits,
00399                                                  const ImageIORegion &pasteRegion,
00400                                                  const ImageIORegion &largestPossibleRegion);
00401 
00403   typedef  std::vector< std::string >    ArrayOfExtensionsType;
00404 
00409   const ArrayOfExtensionsType & GetSupportedReadExtensions() const;
00410 
00415   const ArrayOfExtensionsType & GetSupportedWriteExtensions() const;
00416 
00417 
00418 protected:
00419   ImageIOBase();
00420   ~ImageIOBase();
00421   void PrintSelf(std::ostream& os, Indent indent) const;
00422 
00424   IOPixelType m_PixelType;
00425 
00428   IOComponentType m_ComponentType;
00429 
00431   ByteOrder      m_ByteOrder;
00432   FileType       m_FileType;
00433 
00435   bool m_Initialized;
00436 
00438   std::string m_FileName;
00439 
00442   unsigned int m_NumberOfComponents;
00443 
00445   unsigned int m_NumberOfDimensions;
00446 
00448   bool m_UseCompression;
00449 
00451   bool m_UseStreamedReading;
00452 
00454   bool m_UseStreamedWriting;
00455 
00458   ImageIORegion m_IORegion;
00459 
00461   std::vector< SizeValueType > m_Dimensions;
00462 
00465   std::vector<double> m_Spacing;
00466 
00468   std::vector<double> m_Origin;
00469 
00471   std::vector<std::vector<double> > m_Direction;
00472 
00475   std::vector< SizeType > m_Strides;
00476 
00478   virtual void Reset(const bool freeDynamic = true);
00479 
00481   void Resize(const unsigned int numDimensions, 
00482               const unsigned int* dimensions);
00483 
00486   virtual unsigned int GetPixelSize() const;
00487 
00494   void ComputeStrides();
00495 
00498   SizeType GetComponentStride() const;
00499 
00502   SizeType GetRowStride () const;
00503 
00506   SizeType GetSliceStride () const;
00507 
00509   void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00510                           IOComponentType ctype,
00511                           SizeType numberOfBytesToWrite);
00512 
00514   void ReadBufferAsASCII(std::istream& os, void *buffer,
00515                          IOComponentType ctype,
00516                          SizeType numberOfBytesToBeRead);
00517 
00519   bool ReadBufferAsBinary(std::istream& os, void *buffer, SizeType numberOfBytesToBeRead);
00520 
00521   
00523   void AddSupportedReadExtension( const char * extension );
00524 
00526   void AddSupportedWriteExtension( const char * extension );
00527 
00530   virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(unsigned int numberOfRequestedSplits,
00531                                                                        const ImageIORegion &pasteRegion) const;
00532 
00535   virtual ImageIORegion GetSplitRegionForWritingCanStreamWrite(unsigned int ithPiece, 
00536                                                                unsigned int numberOfActualSplits,
00537                                                                const ImageIORegion &pasteRegion) const;
00538 
00539 private:
00540   ImageIOBase(const Self&); //purposely not implemented
00541   void operator=(const Self&); //purposely not implemented
00542 
00543   ArrayOfExtensionsType    m_SupportedReadExtensions;
00544   ArrayOfExtensionsType    m_SupportedWriteExtensions;
00545 
00546 };
00547 
00548 } // end namespace itk
00549 
00550 #endif // __itkImageIOBase_h
00551 

Generated at Fri Apr 16 18:34:25 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000