Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkRawImageIO.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkRawImageIO.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/09/28 15:41:55 $
00007   Version:   $Revision: 1.32 $
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 __itkRawImageIO_h
00018 #define __itkRawImageIO_h
00019 
00020 #include <fstream>
00021 #include "itkImageIOBase.h"
00022 #include "itkIndex.h"
00023 #include "itkImageRegion.h"
00024 #include "itkPixelTraits.h"
00025 #include "itkByteSwapper.h"
00026 #include "itkVersion.h"
00027 #include <string>
00028 
00029 
00030 namespace itk
00031 {
00032 
00048 template <class TPixel, unsigned int VImageDimension=2>
00049 class ITK_EXPORT RawImageIO : public ImageIOBase
00050 {
00051 public:
00053   typedef RawImageIO Self;
00054   typedef ImageIOBase  Superclass;
00055   typedef SmartPointer<Self>  Pointer;
00056   
00058   itkNewMacro(Self);
00059 
00061   itkTypeMacro(RawImageIO, ImageIOBase);
00062 
00065   typedef TPixel PixelType;
00066 
00068   typedef typename PixelTraits<PixelType>::ValueType       ComponentType;
00069 
00071   typedef ByteSwapper<ComponentType>               ByteSwapperType;
00072 
00073 
00076   void SetHeaderSize(unsigned long size);
00077   unsigned long GetHeaderSize();
00078   
00082   itkSetMacro(FileDimensionality, unsigned long);
00083   itkGetMacro(FileDimensionality, unsigned long);
00084   
00090   virtual bool SupportsDimension(unsigned long dim)
00091   {return (dim == m_FileDimensionality);}
00092 
00093   /*-------- This part of the interface deals with reading data. ------ */
00094 
00098   virtual bool CanReadFile(const char*) 
00099   {return false;}
00100 
00103   virtual void ReadImageInformation() 
00104   {return;}
00105 
00107   virtual void Read(void* buffer);
00108 
00110   itkGetConstReferenceMacro(ImageMask,unsigned short);
00111   void SetImageMask(unsigned long val) 
00112   {
00113     if (val == m_ImageMask) { return; }
00114     m_ImageMask = ((unsigned short)(val)); 
00115     this->Modified();
00116   }
00117     
00119   virtual void ReadHeader (const std::string = std::string()) {}
00120 
00121   /*-------- This part of the interfaces deals with writing data. ----- */
00122 
00126   virtual bool CanWriteFile(const char*);
00127 
00129   virtual void WriteImageInformation(void) 
00130   {return;}
00131 
00132 
00134   virtual void Write(const void* buffer);
00135 
00136 protected:
00137   RawImageIO();
00138   ~RawImageIO();
00139   void PrintSelf(std::ostream& os, Indent indent) const;
00140 
00141   //void ComputeInternalFileName(unsigned long slice);
00142   void OpenFileForReading(std::ifstream& is);
00143   void OpenFileForWriting(std::ofstream& os);
00144   
00145 private:
00146   RawImageIO(const Self&); //purposely not implemented
00147   void operator=(const Self&); //purposely not implemented
00148 
00149   std::string   m_InternalFileName;
00150 
00151   unsigned long  m_FileDimensionality;
00152   bool           m_ManualHeaderSize;
00153   unsigned long  m_HeaderSize;
00154   unsigned short m_ImageMask;
00155 };
00156 
00157 
00158 
00159 
00160 
00161 template <class TPixel, unsigned int VImageDimension>
00162 class ITK_EXPORT RawImageIOFactory : public ObjectFactoryBase
00163 {
00164 public:
00166   typedef RawImageIOFactory<TPixel,VImageDimension>   Self;
00167   typedef ObjectFactoryBase  Superclass;
00168   typedef SmartPointer<Self>  Pointer;
00169   typedef SmartPointer<const Self>  ConstPointer;
00170 
00172   const char* GetITKSourceVersion(void) const
00173   {
00174     return ITK_SOURCE_VERSION;
00175   }
00176 
00177   const char* GetDescription(void) const
00178   {
00179     return "Raw ImageIO Factory, allows the loading of Raw images into insight";
00180   }
00181 
00183   itkFactorylessNewMacro(Self);
00184 
00186   itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
00187 
00189   static void RegisterOneFactory(void)
00190   {
00191     ObjectFactoryBase::RegisterFactory( Self::New() );
00192   }
00193 
00194 
00195 protected:
00196   RawImageIOFactory() {};
00197   ~RawImageIOFactory() {};
00198   typedef RawImageIO<TPixel,VImageDimension> myProductType;
00199   const myProductType* m_MyProduct;
00200 
00201 private:
00202   RawImageIOFactory(const Self&); //purposely not implemented
00203   void operator=(const Self&); //purposely not implemented
00204 
00205 };
00206 
00207 } // namespace itk
00208 
00209 #ifndef ITK_MANUAL_INSTANTIATION
00210 #include "itkRawImageIO.txx"
00211 #endif
00212 
00213 #endif

Generated at Wed May 24 23:54:29 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000