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: 2003/02/26 23:20:32 $
00007   Version:   $Revision: 1.21 $
00008 
00009   Copyright (c) 2002 Insight 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   
00085   virtual const std::type_info& GetPixelType() const
00086     {return typeid(PixelType);}
00087 
00091   virtual unsigned int GetComponentSize() const
00092     {return sizeof(typename PixelTraits<PixelType>::ValueType);}
00093 
00094   /*-------- This part of the interface deals with reading data. ------ */
00095 
00099   virtual bool CanReadFile(const char*) 
00100     {return false;}
00101 
00104   virtual void ReadImageInformation() 
00105     {return;}
00106 
00108   virtual void Read(void* buffer);
00109 
00111   itkGetConstMacro(ImageMask,unsigned short);
00112   void SetImageMask(unsigned long val) 
00113     {
00114       if (val == m_ImageMask) { return; }
00115       m_ImageMask = ((unsigned short)(val)); 
00116       this->Modified();
00117     }
00118     
00120   virtual void ReadHeader (const std::string = std::string()) {}
00121 
00122   /*-------- This part of the interfaces deals with writing data. ----- */
00123 
00127   virtual bool CanWriteFile(const char*);
00128 
00130   virtual void WriteImageInformation(void) 
00131     {return;}
00132 
00133 
00135   virtual void Write(const void* buffer);
00136 
00137 protected:
00138   RawImageIO();
00139   ~RawImageIO();
00140   void PrintSelf(std::ostream& os, Indent indent) const;
00141 
00142   //void ComputeInternalFileName(unsigned long slice);
00143   void OpenFileForReading(std::ifstream& is);
00144   void OpenFileForWriting(std::ofstream& os);
00145   
00146 private:
00147   RawImageIO(const Self&); //purposely not implemented
00148   void operator=(const Self&); //purposely not implemented
00149 
00150   std::string   m_FilePrefix;
00151   std::string   m_FilePattern;
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

Generated at Fri May 21 01:15:14 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000