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/03/06 04:49:18 $
00007   Version:   $Revision: 1.31 $
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 
00047 template <class TPixel, unsigned int VImageDimension=2>
00048 class ITK_EXPORT RawImageIO : public ImageIOBase
00049 {
00050 public:
00052   typedef RawImageIO Self;
00053   typedef ImageIOBase  Superclass;
00054   typedef SmartPointer<Self>  Pointer;
00055   
00057   itkNewMacro(Self);
00058 
00060   itkTypeMacro(RawImageIO, ImageIOBase);
00061 
00064   typedef TPixel PixelType;
00065 
00067   typedef typename PixelTraits<PixelType>::ValueType       ComponentType;
00068 
00070   typedef ByteSwapper<ComponentType>               ByteSwapperType;
00071 
00072 
00075   void SetHeaderSize(unsigned long size);
00076   unsigned long GetHeaderSize();
00077   
00081   itkSetMacro(FileDimensionality, unsigned long);
00082   itkGetMacro(FileDimensionality, unsigned long);
00083   
00089   virtual bool SupportsDimension(unsigned long dim)
00090   {return (dim == m_FileDimensionality);}
00091 
00092   /*-------- This part of the interface deals with reading data. ------ */
00093 
00097   virtual bool CanReadFile(const char*) 
00098   {return false;}
00099 
00102   virtual void ReadImageInformation() 
00103   {return;}
00104 
00106   virtual void Read(void* buffer);
00107 
00109   itkGetConstReferenceMacro(ImageMask,unsigned short);
00110   void SetImageMask(unsigned long val) 
00111   {
00112     if (val == m_ImageMask) { return; }
00113     m_ImageMask = ((unsigned short)(val)); 
00114     this->Modified();
00115   }
00116     
00118   virtual void ReadHeader (const std::string = std::string()) {}
00119 
00120   /*-------- This part of the interfaces deals with writing data. ----- */
00121 
00125   virtual bool CanWriteFile(const char*);
00126 
00128   virtual void WriteImageInformation(void) 
00129   {return;}
00130 
00131 
00133   virtual void Write(const void* buffer);
00134 
00135 protected:
00136   RawImageIO();
00137   ~RawImageIO();
00138   void PrintSelf(std::ostream& os, Indent indent) const;
00139 
00140   //void ComputeInternalFileName(unsigned long slice);
00141   void OpenFileForReading(std::ifstream& is);
00142   void OpenFileForWriting(std::ofstream& os);
00143   
00144 private:
00145   RawImageIO(const Self&); //purposely not implemented
00146   void operator=(const Self&); //purposely not implemented
00147 
00148   std::string   m_InternalFileName;
00149 
00150   unsigned long  m_FileDimensionality;
00151   bool           m_ManualHeaderSize;
00152   unsigned long  m_HeaderSize;
00153   unsigned short m_ImageMask;
00154 };
00155 
00156 
00157 
00158 
00159 
00160 template <class TPixel, unsigned int VImageDimension>
00161 class ITK_EXPORT RawImageIOFactory : public ObjectFactoryBase
00162 {
00163 public:
00165   typedef RawImageIOFactory<TPixel,VImageDimension>   Self;
00166   typedef ObjectFactoryBase  Superclass;
00167   typedef SmartPointer<Self>  Pointer;
00168   typedef SmartPointer<const Self>  ConstPointer;
00169 
00171   const char* GetITKSourceVersion(void) const
00172   {
00173     return ITK_SOURCE_VERSION;
00174   }
00175 
00176   const char* GetDescription(void) const
00177   {
00178     return "Raw ImageIO Factory, allows the loading of Raw images into insight";
00179   }
00180 
00182   itkFactorylessNewMacro(Self);
00183 
00185   itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
00186 
00188   static void RegisterOneFactory(void)
00189   {
00190     ObjectFactoryBase::RegisterFactory( Self::New() );
00191   }
00192 
00193 
00194 protected:
00195   RawImageIOFactory() {};
00196   ~RawImageIOFactory() {};
00197   typedef RawImageIO<TPixel,VImageDimension> myProductType;
00198   const myProductType* m_MyProduct;
00199 
00200 private:
00201   RawImageIOFactory(const Self&); //purposely not implemented
00202   void operator=(const Self&); //purposely not implemented
00203 
00204 };
00205 
00206 } // namespace itk
00207 
00208 #ifndef ITK_MANUAL_INSTANTIATION
00209 #include "itkRawImageIO.txx"
00210 #endif
00211 
00212 #endif

Generated at Tue Aug 30 16:45:57 2005 for ITK by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2000