Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 itkGetConstMacro(FileDimensionality, unsigned long);
00086
00092 virtual bool SupportsDimension(unsigned long dim)
00093 {return (dim == m_FileDimensionality);}
00094
00095
00096
00100 virtual bool CanReadFile(const char*) {return false;}
00101
00104 virtual void ReadImageInformation() {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 }
00118
00120 virtual void ReadHeader (const std::string = std::string()) {}
00121
00122
00123
00127 virtual bool CanWriteFile(const char*);
00128
00130 virtual void WriteImageInformation(void) {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
00142 void OpenFileForReading(std::ifstream& is);
00143 void OpenFileForWriting(std::ofstream& os);
00144
00145 private:
00146 RawImageIO(const Self&);
00147 void operator=(const Self&);
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 template <class TPixel, unsigned int VImageDimension>
00158 class ITK_EXPORT RawImageIOFactory : public ObjectFactoryBase
00159 {
00160 public:
00162 typedef RawImageIOFactory<TPixel,VImageDimension> Self;
00163 typedef ObjectFactoryBase Superclass;
00164 typedef SmartPointer<Self> Pointer;
00165 typedef SmartPointer<const Self> ConstPointer;
00166
00168 const char* GetITKSourceVersion(void) const
00169 {
00170 return ITK_SOURCE_VERSION;
00171 }
00172
00173 const char* GetDescription(void) const
00174 {
00175 return "Raw ImageIO Factory, allows the loading of Raw images into insight";
00176 }
00177
00179 itkFactorylessNewMacro(Self);
00180
00182 itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
00183
00185 static void RegisterOneFactory(void)
00186 {
00187 ObjectFactoryBase::RegisterFactory( Self::New() );
00188 }
00189
00190 protected:
00191 RawImageIOFactory() {};
00192 ~RawImageIOFactory() {};
00193 typedef RawImageIO<TPixel,VImageDimension> myProductType;
00194 const myProductType* m_MyProduct;
00195
00196 private:
00197 RawImageIOFactory(const Self&);
00198 void operator=(const Self&);
00199
00200 };
00201
00202 }
00203
00204 #ifndef ITK_MANUAL_INSTANTIATION
00205 #include "itkRawImageIO.txx"
00206 #endif
00207
00208 #endif
00209