Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkMRCImageIO_h
00019 #define __itkMRCImageIO_h
00020
00021 #include "itkStreamingImageIOBase.h"
00022 #include "itkMRCHeaderObject.h"
00023 #include <numeric>
00024
00025 namespace itk
00026 {
00027
00052 class ITK_EXPORT MRCImageIO
00053 : public StreamingImageIOBase
00054 {
00055 public:
00057 typedef MRCImageIO Self;
00058 typedef StreamingImageIOBase Superclass;
00059 typedef SmartPointer<Self> Pointer;
00060
00062 itkNewMacro(Self);
00063
00065 itkTypeMacro(MRCImageIO, StreamingImageIOBase);
00066
00067
00068
00069 virtual void WriteImageInformation( void ) {};
00070
00071
00072
00073
00074 virtual bool CanReadFile(const char*);
00075
00076
00077 virtual void ReadImageInformation();
00078
00079
00080 virtual void Read(void* buffer);
00081
00082
00083
00090 virtual bool CanWriteFile(const char*);
00091
00092
00093
00094 virtual void Write(const void* buffer);
00095
00100 static const char * m_MetaDataHeaderName;
00101
00102 protected:
00103 MRCImageIO();
00104
00105 void PrintSelf(std::ostream& os, Indent indent) const;
00106
00111 virtual SizeType GetHeaderSize( void ) const;
00112
00113 private:
00114
00115 MRCImageIO(const Self&);
00116 void operator=(const Self&);
00117
00118
00119
00120 template<typename TPixelType>
00121 void UpdateHeaderWithMinMaxMean( const TPixelType * bufferBegin)
00122 {
00123 typedef const TPixelType* ConstPixelPointer;
00124
00125 ConstPixelPointer bufferEnd = bufferBegin + m_IORegion.GetNumberOfPixels();
00126
00127
00128
00129 std::pair<ConstPixelPointer, ConstPixelPointer> mm =
00130 min_max_element(bufferBegin, bufferEnd);
00131
00132 double mean = std::accumulate( bufferBegin, bufferEnd, double(0.0) ) /
00133 std::distance( bufferBegin, bufferEnd );
00134
00135 m_MRCHeader->m_Header.amin = float(*mm.first);
00136 m_MRCHeader->m_Header.amax = float(*mm.second);
00137 m_MRCHeader->m_Header.amean = float(mean);
00138 }
00139
00140 void UpdateHeaderWithMinMaxMean( const void * bufferBegin );
00141
00142
00143
00144 void UpdateHeaderFromImageIO( void );
00145
00146
00147 void InternalReadImageInformation(std::ifstream& is);
00148
00149 virtual void WriteImageInformation( const void * bufferBegin );
00150
00151
00152 MRCHeaderObject::Pointer m_MRCHeader;
00153 };
00154
00155
00156 }
00157
00158
00159 #endif
00160