Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkMRCImageIO.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMRCImageIO.h,v $
00005   Language:  C++
00006   Date:      $Date: 2010-06-23 16:11:17 $
00007   Version:   $Revision: 1.5 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
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   // we don't use this method
00069   virtual void WriteImageInformation( void ) {};
00070 
00071   //-------- This part of the interface deals with reading data. ------ 
00072 
00073   // See super class for documentation
00074   virtual bool CanReadFile(const char*);
00075 
00076   // See super class for documentation
00077   virtual void ReadImageInformation();
00078 
00079   // See super class for documentation
00080   virtual void Read(void* buffer);
00081 
00082   // -------- This part of the interfaces deals with writing data. -----
00083 
00090   virtual bool CanWriteFile(const char*);
00091 
00092 
00093   // see super class for documentation
00094   virtual void Write(const void* buffer);
00095 
00100   static const char * m_MetaDataHeaderName;
00101 
00102 protected:
00103   MRCImageIO();
00104   // ~MRCImageIO(); // default works
00105   void PrintSelf(std::ostream& os, Indent indent) const;
00106 
00111   virtual SizeType GetHeaderSize( void ) const;
00112 
00113 private:
00114 
00115   MRCImageIO(const Self&); //purposely not implemented
00116   void operator=(const Self&); //purposely not implemented
00117   
00118   // internal methods to update the min and max in the header based on
00119   // the data, in the image buffer to be written
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     // this could be replaced with std::min_element and
00128     // std::max_element, but that is slighlty less efficient
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   // internal methods to update the header object from the ImageIO's
00143   // set member variables
00144   void UpdateHeaderFromImageIO( void );
00145   
00146   // reimplemented
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 } // namespace itk
00157 
00158 
00159 #endif
00160 

Generated at Mon Jul 12 2010 19:11:17 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000