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-02-22 05:53:41 $
00007   Version:   $Revision: 1.51 $
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   itkGetConstMacro(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 
00139   virtual std::vector<double> GetDefaultDirection(unsigned int i) const;
00140 
00147   itkSetMacro(IORegion, ImageIORegion);
00148   itkGetConstReferenceMacro(IORegion, ImageIORegion);
00150 
00156   itkSetEnumMacro(PixelType, IOPixelType);
00157   itkGetEnumMacro(PixelType, IOPixelType);
00159 
00166   virtual bool SetPixelTypeInfo(const std::type_info& ptype);
00167 
00170   itkSetEnumMacro(ComponentType,IOComponentType);
00171   itkGetEnumMacro(ComponentType,IOComponentType);
00172   virtual const std::type_info& GetComponentTypeInfo() const;
00174 
00179   itkSetMacro(NumberOfComponents,unsigned int);
00180   itkGetConstReferenceMacro(NumberOfComponents,unsigned int);
00182 
00184   itkSetMacro(UseCompression,bool);
00185   itkGetMacro(UseCompression,bool);
00186   itkBooleanMacro(UseCompression);
00188 
00190   itkSetMacro(UseStreamedReading,bool);
00191   itkGetMacro(UseStreamedReading,bool);
00192   itkBooleanMacro(UseStreamedReading);
00194 
00196   itkSetMacro(UseStreamedWriting,bool);
00197   itkGetMacro(UseStreamedWriting,bool);
00198   itkBooleanMacro(UseStreamedWriting);
00200 
00201 
00204   std::string GetComponentTypeAsString(IOComponentType) const;
00205 
00208   std::string GetPixelTypeAsString(IOPixelType) const;
00209 
00212   typedef  enum {ASCII,Binary,TypeNotApplicable} FileType;
00213 
00216   typedef  enum {BigEndian,LittleEndian,OrderNotApplicable} ByteOrder;
00217 
00220   itkSetEnumMacro(FileType,FileType);
00221   itkGetEnumMacro(FileType,FileType);
00222   void SetFileTypeToASCII()
00223     {
00224     this->SetFileType(ASCII);
00225     }
00226   void SetFileTypeToBinary()
00227     {
00228     this->SetFileType(Binary);
00229     }
00231 
00243   itkSetEnumMacro(ByteOrder,ByteOrder);
00244   itkGetEnumMacro(ByteOrder,ByteOrder);
00245   void SetByteOrderToBigEndian()
00246     {
00247     this->SetByteOrder(BigEndian);
00248     }
00249   void SetByteOrderToLittleEndian()
00250     {
00251     this->SetByteOrder(LittleEndian);
00252     }
00254 
00257   std::string GetFileTypeAsString(FileType) const;
00258 
00261   std::string GetByteOrderAsString(ByteOrder) const;
00262 
00264   typedef std::streamoff SizeType;
00265 
00268   virtual SizeType GetPixelStride () const;
00269 
00271   SizeType GetImageSizeInPixels() const;
00272 
00274   SizeType GetImageSizeInBytes() const;
00275 
00278   SizeType GetImageSizeInComponents() const;
00279 
00280   /*-------- This part of the interfaces deals with reading data ----- */
00281 
00284   virtual bool CanReadFile(const char*) = 0;
00285 
00288   virtual bool CanStreamRead()
00289     {
00290     return false;
00291     }
00292 
00295   virtual void ReadImageInformation() = 0;
00296 
00298   virtual void Read(void* buffer) = 0;
00299 
00300 
00301   /*-------- This part of the interfaces deals with writing data ----- */
00302 
00305   virtual bool CanWriteFile(const char*)  = 0;
00306 
00312   virtual bool CanStreamWrite()
00313     {
00314     return false;
00315     }
00316 
00319   virtual void WriteImageInformation() = 0;
00320 
00324   virtual void Write( const void* buffer) = 0;
00325 
00326   /* --- Support reading and writing data as a series of files. --- */
00327 
00333   virtual bool SupportsDimension(unsigned long dim)
00334     {
00335     return (dim == 2);
00336     }
00337 
00342   virtual ImageIORegion 
00343   GenerateStreamableReadRegionFromRequestedRegion( const ImageIORegion & requested ) const;
00344 
00345   
00346   
00359   virtual unsigned int GetActualNumberOfSplitsForWriting(unsigned int numberOfRequestedSplits,
00360                                                          const ImageIORegion &pasteRegion,
00361                                                          const ImageIORegion &largestPossibleRegion);
00362 
00369   virtual ImageIORegion GetSplitRegionForWriting(unsigned int ithPiece, 
00370                                                  unsigned int numberOfActualSplits,
00371                                                  const ImageIORegion &pasteRegion,
00372                                                  const ImageIORegion &largestPossibleRegion);
00373 
00375   typedef  std::vector< std::string >    ArrayOfExtensionsType;
00376 
00381   const ArrayOfExtensionsType & GetSupportedReadExtensions() const;
00382 
00387   const ArrayOfExtensionsType & GetSupportedWriteExtensions() const;
00388 
00389 
00390 protected:
00391   ImageIOBase();
00392   ~ImageIOBase();
00393   void PrintSelf(std::ostream& os, Indent indent) const;
00394 
00396   IOPixelType m_PixelType;
00397 
00400   IOComponentType m_ComponentType;
00401 
00403   ByteOrder      m_ByteOrder;
00404   FileType       m_FileType;
00405 
00407   bool m_Initialized;
00408 
00410   std::string m_FileName;
00411 
00414   unsigned int m_NumberOfComponents;
00415 
00417   unsigned int m_NumberOfDimensions;
00418 
00420   bool m_UseCompression;
00421 
00423   bool m_UseStreamedReading;
00424 
00426   bool m_UseStreamedWriting;
00427 
00430   ImageIORegion m_IORegion;
00431 
00433   std::vector<unsigned int> m_Dimensions;
00434 
00437   std::vector<double> m_Spacing;
00438 
00440   std::vector<double> m_Origin;
00441 
00443   std::vector<std::vector<double> > m_Direction;
00444 
00447   std::vector< SizeType > m_Strides;
00448 
00450   virtual void Reset(const bool freeDynamic = true);
00451 
00453   void Resize(const unsigned int numDimensions, 
00454               const unsigned int* dimensions);
00455 
00462   void ComputeStrides();
00463 
00466   virtual unsigned int GetPixelSize() const;
00467 
00472   virtual unsigned int GetComponentSize() const;
00473 
00476   SizeType GetComponentStride() const;
00477 
00480   SizeType GetRowStride () const;
00481 
00484   SizeType GetSliceStride () const;
00485 
00487   void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00488                           IOComponentType ctype,
00489                           SizeType numberOfBytesToWrite);
00490 
00492   void ReadBufferAsASCII(std::istream& os, void *buffer,
00493                          IOComponentType ctype,
00494                          SizeType numberOfBytesToBeRead);
00495 
00497   bool ReadBufferAsBinary(std::istream& os, void *buffer, SizeType numberOfBytesToBeRead);
00498 
00499   
00501   void AddSupportedReadExtension( const char * extension );
00502 
00504   void AddSupportedWriteExtension( const char * extension );
00505 
00508   virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(unsigned int numberOfRequestedSplits,
00509                                                                        const ImageIORegion &pasteRegion) const;
00510 
00513   virtual ImageIORegion GetSplitRegionForWritingCanStreamWrite(unsigned int ithPiece, 
00514                                                                unsigned int numberOfActualSplits,
00515                                                                const ImageIORegion &pasteRegion) const;
00516 
00517 private:
00518   ImageIOBase(const Self&); //purposely not implemented
00519   void operator=(const Self&); //purposely not implemented
00520 
00521   ArrayOfExtensionsType    m_SupportedReadExtensions;
00522   ArrayOfExtensionsType    m_SupportedWriteExtensions;
00523 
00524 };
00525 
00526 } // end namespace itk
00527 
00528 #endif // __itkImageIOBase_h
00529 

Generated at Sat Feb 28 12:39:11 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000