ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkRawImageIO_h 00019 #define __itkRawImageIO_h 00020 00021 #include "itkImageIOBase.h" 00022 #include "itkImageRegion.h" 00023 #include "itkPixelTraits.h" 00024 #include "itkByteSwapper.h" 00025 #include "itkVersion.h" 00026 #include <string> 00027 #include <fstream> 00028 00029 namespace itk 00030 { 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 Superclass::SizeValueType SizeValueType; 00068 00070 typedef typename PixelTraits< PixelType >::ValueType ComponentType; 00071 00073 typedef ByteSwapper< ComponentType > ByteSwapperType; 00074 00077 void SetHeaderSize(SizeValueType size); 00078 00079 SizeValueType GetHeaderSize(); 00080 00084 itkSetMacro(FileDimensionality, unsigned long); 00085 itkGetConstMacro(FileDimensionality, unsigned long); 00087 00093 virtual bool SupportsDimension(unsigned long dim) 00094 { return ( dim == m_FileDimensionality ); } 00095 00096 /*-------- This part of the interface deals with reading data. ------ */ 00097 00101 virtual bool CanReadFile(const char *) { return false; } 00102 00105 virtual void ReadImageInformation() { return; } 00106 00108 virtual void Read(void *buffer); 00109 00111 itkGetConstReferenceMacro(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 } 00119 00121 virtual void ReadHeader( const std::string = std::string() ) {} 00122 00123 /*-------- This part of the interfaces deals with writing data. ----- */ 00124 00128 virtual bool CanWriteFile(const char *); 00129 00131 virtual void WriteImageInformation(void) { return; } 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 //void ComputeInternalFileName(unsigned long slice); 00142 void OpenFileForReading(std::ifstream & is); 00143 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_InternalFileName; 00151 00152 unsigned long m_FileDimensionality; 00153 bool m_ManualHeaderSize; 00154 SizeValueType m_HeaderSize; 00155 unsigned short m_ImageMask; 00156 }; 00157 00158 template< class TPixel, unsigned int VImageDimension > 00159 class ITK_EXPORT RawImageIOFactory:public ObjectFactoryBase 00160 { 00161 public: 00163 typedef RawImageIOFactory< TPixel, VImageDimension > Self; 00164 typedef ObjectFactoryBase Superclass; 00165 typedef SmartPointer< Self > Pointer; 00166 typedef SmartPointer< const Self > ConstPointer; 00167 00169 const char * GetITKSourceVersion(void) const 00170 { 00171 return ITK_SOURCE_VERSION; 00172 } 00173 00174 const char * GetDescription(void) const 00175 { 00176 return "Raw ImageIO Factory, allows the loading of Raw images into insight"; 00177 } 00178 00180 itkFactorylessNewMacro(Self); 00181 00183 itkTypeMacro(RawImageIOFactory, ObjectFactoryBase); 00184 00186 static void RegisterOneFactory(void) 00187 { 00188 ObjectFactoryBase::RegisterFactory( Self::New() ); 00189 } 00190 00191 protected: 00192 RawImageIOFactory() {} 00193 ~RawImageIOFactory() {} 00194 typedef RawImageIO< TPixel, VImageDimension > myProductType; 00195 const myProductType *m_MyProduct; 00196 private: 00197 RawImageIOFactory(const Self &); //purposely not implemented 00198 void operator=(const Self &); //purposely not implemented 00199 }; 00200 } // namespace itk 00201 00202 #ifndef ITK_MANUAL_INSTANTIATION 00203 #include "itkRawImageIO.hxx" 00204 #endif 00205 00206 #endif 00207