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
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
00089 virtual bool SupportsDimension(unsigned long dim)
00090 {return (dim == m_FileDimensionality);}
00091
00092
00093
00097 virtual bool CanReadFile(const char*)
00098 {return false;}
00099
00102 virtual void ReadImageInformation()
00103 {return;}
00104
00106 virtual void Read(void* buffer);
00107
00109 itkGetConstReferenceMacro(ImageMask,unsigned short);
00110 void SetImageMask(unsigned long val)
00111 {
00112 if (val == m_ImageMask) { return; }
00113 m_ImageMask = ((unsigned short)(val));
00114 this->Modified();
00115 }
00116
00118 virtual void ReadHeader (const std::string = std::string()) {}
00119
00120
00121
00125 virtual bool CanWriteFile(const char*);
00126
00128 virtual void WriteImageInformation(void)
00129 {return;}
00130
00131
00133 virtual void Write(const void* buffer);
00134
00135 protected:
00136 RawImageIO();
00137 ~RawImageIO();
00138 void PrintSelf(std::ostream& os, Indent indent) const;
00139
00140
00141 void OpenFileForReading(std::ifstream& is);
00142 void OpenFileForWriting(std::ofstream& os);
00143
00144 private:
00145 RawImageIO(const Self&);
00146 void operator=(const Self&);
00147
00148 std::string m_InternalFileName;
00149
00150 unsigned long m_FileDimensionality;
00151 bool m_ManualHeaderSize;
00152 unsigned long m_HeaderSize;
00153 unsigned short m_ImageMask;
00154 };
00155
00156
00157
00158
00159
00160 template <class TPixel, unsigned int VImageDimension>
00161 class ITK_EXPORT RawImageIOFactory : public ObjectFactoryBase
00162 {
00163 public:
00165 typedef RawImageIOFactory<TPixel,VImageDimension> Self;
00166 typedef ObjectFactoryBase Superclass;
00167 typedef SmartPointer<Self> Pointer;
00168 typedef SmartPointer<const Self> ConstPointer;
00169
00171 const char* GetITKSourceVersion(void) const
00172 {
00173 return ITK_SOURCE_VERSION;
00174 }
00175
00176 const char* GetDescription(void) const
00177 {
00178 return "Raw ImageIO Factory, allows the loading of Raw images into insight";
00179 }
00180
00182 itkFactorylessNewMacro(Self);
00183
00185 itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
00186
00188 static void RegisterOneFactory(void)
00189 {
00190 ObjectFactoryBase::RegisterFactory( Self::New() );
00191 }
00192
00193
00194 protected:
00195 RawImageIOFactory() {};
00196 ~RawImageIOFactory() {};
00197 typedef RawImageIO<TPixel,VImageDimension> myProductType;
00198 const myProductType* m_MyProduct;
00199
00200 private:
00201 RawImageIOFactory(const Self&);
00202 void operator=(const Self&);
00203
00204 };
00205
00206 }
00207
00208 #ifndef ITK_MANUAL_INSTANTIATION
00209 #include "itkRawImageIO.txx"
00210 #endif
00211
00212 #endif