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();
00079 
00083   itkSetMacro(FileDimensionality, unsigned long);
00084   itkGetMacro(FileDimensionality, unsigned long);
00086 
00092   virtual bool SupportsDimension(unsigned long dim)
00093   {return (dim == m_FileDimensionality);}
00094 
00095   /*-------- This part of the interface deals with reading data. ------ */
00096 
00100   virtual bool CanReadFile(const char*) 
00101   {return false;}
00102 
00105   virtual void ReadImageInformation() 
00106   {return;}
00107 
00109   virtual void Read(void* buffer);
00110 
00112   itkGetConstReferenceMacro(ImageMask,unsigned short);
00113   void SetImageMask(unsigned long val) 
00114   {
00115     if (val == m_ImageMask) { return; }
00116     m_ImageMask = ((unsigned short)(val)); 
00117     this->Modified();
00118   }
00120 
00122   virtual void ReadHeader (const std::string = std::string()) {}
00123 
00124   /*-------- This part of the interfaces deals with writing data. ----- */
00125 
00129   virtual bool CanWriteFile(const char*);
00130 
00132   virtual void WriteImageInformation(void) 
00133   {return;}
00134 
00135 
00137   virtual void Write(const void* buffer);
00138 
00139 protected:
00140   RawImageIO();
00141   ~RawImageIO();
00142   void PrintSelf(std::ostream& os, Indent indent) const;
00143 
00144   //void ComputeInternalFileName(unsigned long slice);
00145   void OpenFileForReading(std::ifstream& is);
00146   void OpenFileForWriting(std::ofstream& os);
00147   
00148 private:
00149   RawImageIO(const Self&); //purposely not implemented
00150   void operator=(const Self&); //purposely not implemented
00151 
00152   std::string   m_InternalFileName;
00153 
00154   unsigned long  m_FileDimensionality;
00155   bool           m_ManualHeaderSize;
00156   unsigned long  m_HeaderSize;
00157   unsigned short m_ImageMask;
00158 };
00159 
00160 
00161 
00162 
00163 
00164 template <class TPixel, unsigned int VImageDimension>
00165 class ITK_EXPORT RawImageIOFactory : public ObjectFactoryBase
00166 {
00167 public:
00169   typedef RawImageIOFactory<TPixel,VImageDimension>   Self;
00170   typedef ObjectFactoryBase  Superclass;
00171   typedef SmartPointer<Self>  Pointer;
00172   typedef SmartPointer<const Self>  ConstPointer;
00173 
00175   const char* GetITKSourceVersion(void) const
00176   {
00177     return ITK_SOURCE_VERSION;
00178   }
00179 
00180   const char* GetDescription(void) const
00181   {
00182     return "Raw ImageIO Factory, allows the loading of Raw images into insight";
00183   }
00184 
00186   itkFactorylessNewMacro(Self);
00187 
00189   itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
00190 
00192   static void RegisterOneFactory(void)
00193   {
00194     ObjectFactoryBase::RegisterFactory( Self::New() );
00195   }
00196 
00197 
00198 protected:
00199   RawImageIOFactory() {};
00200   ~RawImageIOFactory() {};
00201   typedef RawImageIO<TPixel,VImageDimension> myProductType;
00202   const myProductType* m_MyProduct;
00203 
00204 private:
00205   RawImageIOFactory(const Self&); //purposely not implemented
00206   void operator=(const Self&); //purposely not implemented
00207 
00208 };
00209 
00210 } // namespace itk
00211 
00212 #ifndef ITK_MANUAL_INSTANTIATION
00213 #include "itkRawImageIO.txx"
00214 #endif
00215 
00216 #endif
00217 

Generated at Mon Mar 12 02:29:34 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000