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: 2004/11/04 20:40:41 $
00007   Version:   $Revision: 1.30 $
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   
00085   virtual const std::type_info& GetComponentTypeInfo() const
00086   {return typeid(ComponentType);}
00087   
00091   virtual unsigned int GetComponentSize() const
00092   {return sizeof(typename PixelTraits<PixelType>::ValueType);}
00093 
00099   virtual bool SupportsDimension(unsigned long dim)
00100   {return (dim == m_FileDimensionality);}
00101 
00102   /*-------- This part of the interface deals with reading data. ------ */
00103 
00107   virtual bool CanReadFile(const char*) 
00108   {return false;}
00109 
00112   virtual void ReadImageInformation() 
00113   {return;}
00114 
00116   virtual void Read(void* buffer);
00117 
00119   itkGetConstReferenceMacro(ImageMask,unsigned short);
00120   void SetImageMask(unsigned long val) 
00121   {
00122     if (val == m_ImageMask) { return; }
00123     m_ImageMask = ((unsigned short)(val)); 
00124     this->Modified();
00125   }
00126     
00128   virtual void ReadHeader (const std::string = std::string()) {}
00129 
00130   /*-------- This part of the interfaces deals with writing data. ----- */
00131 
00135   virtual bool CanWriteFile(const char*);
00136 
00138   virtual void WriteImageInformation(void) 
00139   {return;}
00140 
00141 
00143   virtual void Write(const void* buffer);
00144 
00145 
00146   virtual bool SetPixelType(const std::type_info& )
00147   { return true; }
00148 
00149   virtual void SetPixelType(const IOPixelType ) {}
00150   virtual void SetComponentType(const IOComponentType ) {}
00151 protected:
00152   RawImageIO();
00153   ~RawImageIO();
00154   void PrintSelf(std::ostream& os, Indent indent) const;
00155 
00156   //void ComputeInternalFileName(unsigned long slice);
00157   void OpenFileForReading(std::ifstream& is);
00158   void OpenFileForWriting(std::ofstream& os);
00159   
00160 private:
00161   RawImageIO(const Self&); //purposely not implemented
00162   void operator=(const Self&); //purposely not implemented
00163 
00164   std::string   m_InternalFileName;
00165 
00166   unsigned long  m_FileDimensionality;
00167   bool           m_ManualHeaderSize;
00168   unsigned long  m_HeaderSize;
00169   unsigned short m_ImageMask;
00170 };
00171 
00172 
00173 
00174 
00175 
00176 template <class TPixel, unsigned int VImageDimension>
00177 class ITK_EXPORT RawImageIOFactory : public ObjectFactoryBase
00178 {
00179 public:
00181   typedef RawImageIOFactory<TPixel,VImageDimension>   Self;
00182   typedef ObjectFactoryBase  Superclass;
00183   typedef SmartPointer<Self>  Pointer;
00184   typedef SmartPointer<const Self>  ConstPointer;
00185 
00187   const char* GetITKSourceVersion(void) const
00188   {
00189     return ITK_SOURCE_VERSION;
00190   }
00191 
00192   const char* GetDescription(void) const
00193   {
00194     return "Raw ImageIO Factory, allows the loading of Raw images into insight";
00195   }
00196 
00198   itkFactorylessNewMacro(Self);
00199 
00201   itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
00202 
00204   static void RegisterOneFactory(void)
00205   {
00206     ObjectFactoryBase::RegisterFactory( Self::New() );
00207   }
00208 
00209 
00210 protected:
00211   RawImageIOFactory() {};
00212   ~RawImageIOFactory() {};
00213   typedef RawImageIO<TPixel,VImageDimension> myProductType;
00214   const myProductType* m_MyProduct;
00215 
00216 private:
00217   RawImageIOFactory(const Self&); //purposely not implemented
00218   void operator=(const Self&); //purposely not implemented
00219 
00220 };
00221 
00222 } // namespace itk
00223 
00224 #ifndef ITK_MANUAL_INSTANTIATION
00225 #include "itkRawImageIO.txx"
00226 #endif
00227 
00228 #endif

Generated at Wed Mar 30 00:08:16 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000