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 itkGetMacro(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*)
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
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
00145 void OpenFileForReading(std::ifstream& is);
00146 void OpenFileForWriting(std::ofstream& os);
00147
00148 private:
00149 RawImageIO(const Self&);
00150 void operator=(const Self&);
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&);
00206 void operator=(const Self&);
00207
00208 };
00209
00210 }
00211
00212 #ifndef ITK_MANUAL_INSTANTIATION
00213 #include "itkRawImageIO.txx"
00214 #endif
00215
00216 #endif
00217