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-07-02 13:16:48 $
00007   Version:   $Revision: 1.54 $
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   itkGetConstMacro(UseCompression,bool);
00186   itkBooleanMacro(UseCompression);
00188 
00190   itkSetMacro(UseStreamedReading,bool);
00191   itkGetConstMacro(UseStreamedReading,bool);
00192   itkBooleanMacro(UseStreamedReading);
00194 
00196   itkSetMacro(UseStreamedWriting,bool);
00197   itkGetConstMacro(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 
00272   virtual SizeType GetPixelStride () const;
00273 
00275   SizeType GetImageSizeInPixels() const;
00276 
00278   SizeType GetImageSizeInBytes() const;
00279 
00282   SizeType GetImageSizeInComponents() const;
00283 
00284 
00289   virtual unsigned int GetComponentSize() const;
00290 
00291 
00292   /*-------- This part of the interfaces deals with reading data ----- */
00293 
00296   virtual bool CanReadFile(const char*) = 0;
00297 
00300   virtual bool CanStreamRead()
00301     {
00302     return false;
00303     }
00304 
00307   virtual void ReadImageInformation() = 0;
00308 
00310   virtual void Read(void* buffer) = 0;
00311 
00312 
00313   /*-------- This part of the interfaces deals with writing data ----- */
00314 
00317   virtual bool CanWriteFile(const char*)  = 0;
00318 
00324   virtual bool CanStreamWrite()
00325     {
00326     return false;
00327     }
00328 
00331   virtual void WriteImageInformation() = 0;
00332 
00336   virtual void Write( const void* buffer) = 0;
00337 
00338   /* --- Support reading and writing data as a series of files. --- */
00339 
00345   virtual bool SupportsDimension(unsigned long dim)
00346     {
00347     return (dim == 2);
00348     }
00349 
00361   virtual ImageIORegion 
00362   GenerateStreamableReadRegionFromRequestedRegion( const ImageIORegion & requested ) const;
00363 
00364   
00365   
00380   virtual unsigned int GetActualNumberOfSplitsForWriting(unsigned int numberOfRequestedSplits,
00381                                                          const ImageIORegion &pasteRegion,
00382                                                          const ImageIORegion &largestPossibleRegion);
00383 
00390   virtual ImageIORegion GetSplitRegionForWriting(unsigned int ithPiece, 
00391                                                  unsigned int numberOfActualSplits,
00392                                                  const ImageIORegion &pasteRegion,
00393                                                  const ImageIORegion &largestPossibleRegion);
00394 
00396   typedef  std::vector< std::string >    ArrayOfExtensionsType;
00397 
00402   const ArrayOfExtensionsType & GetSupportedReadExtensions() const;
00403 
00408   const ArrayOfExtensionsType & GetSupportedWriteExtensions() const;
00409 
00410 
00411 protected:
00412   ImageIOBase();
00413   ~ImageIOBase();
00414   void PrintSelf(std::ostream& os, Indent indent) const;
00415 
00417   IOPixelType m_PixelType;
00418 
00421   IOComponentType m_ComponentType;
00422 
00424   ByteOrder      m_ByteOrder;
00425   FileType       m_FileType;
00426 
00428   bool m_Initialized;
00429 
00431   std::string m_FileName;
00432 
00435   unsigned int m_NumberOfComponents;
00436 
00438   unsigned int m_NumberOfDimensions;
00439 
00441   bool m_UseCompression;
00442 
00444   bool m_UseStreamedReading;
00445 
00447   bool m_UseStreamedWriting;
00448 
00451   ImageIORegion m_IORegion;
00452 
00454   std::vector<unsigned int> m_Dimensions;
00455 
00458   std::vector<double> m_Spacing;
00459 
00461   std::vector<double> m_Origin;
00462 
00464   std::vector<std::vector<double> > m_Direction;
00465 
00468   std::vector< SizeType > m_Strides;
00469 
00471   virtual void Reset(const bool freeDynamic = true);
00472 
00474   void Resize(const unsigned int numDimensions, 
00475               const unsigned int* dimensions);
00476 
00479   virtual unsigned int GetPixelSize() const;
00480 
00487   void ComputeStrides();
00488 
00491   SizeType GetComponentStride() const;
00492 
00495   SizeType GetRowStride () const;
00496 
00499   SizeType GetSliceStride () const;
00500 
00502   void WriteBufferAsASCII(std::ostream& os, const void *buffer,
00503                           IOComponentType ctype,
00504                           SizeType numberOfBytesToWrite);
00505 
00507   void ReadBufferAsASCII(std::istream& os, void *buffer,
00508                          IOComponentType ctype,
00509                          SizeType numberOfBytesToBeRead);
00510 
00512   bool ReadBufferAsBinary(std::istream& os, void *buffer, SizeType numberOfBytesToBeRead);
00513 
00514   
00516   void AddSupportedReadExtension( const char * extension );
00517 
00519   void AddSupportedWriteExtension( const char * extension );
00520 
00523   virtual unsigned int GetActualNumberOfSplitsForWritingCanStreamWrite(unsigned int numberOfRequestedSplits,
00524                                                                        const ImageIORegion &pasteRegion) const;
00525 
00528   virtual ImageIORegion GetSplitRegionForWritingCanStreamWrite(unsigned int ithPiece, 
00529                                                                unsigned int numberOfActualSplits,
00530                                                                const ImageIORegion &pasteRegion) const;
00531 
00532 private:
00533   ImageIOBase(const Self&); //purposely not implemented
00534   void operator=(const Self&); //purposely not implemented
00535 
00536   ArrayOfExtensionsType    m_SupportedReadExtensions;
00537   ArrayOfExtensionsType    m_SupportedWriteExtensions;
00538 
00539 };
00540 
00541 } // end namespace itk
00542 
00543 #endif // __itkImageIOBase_h
00544 

Generated at Tue Sep 15 03:18:02 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000