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

itkWeightedAddImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkWeightedAddImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2004/05/02 14:05:03 $
00007   Version:   $Revision: 1.1 $
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 #ifndef __itkWeightedAddImageFilter_h
00018 #define __itkWeightedAddImageFilter_h
00019 
00020 #include "itkBinaryFunctorImageFilter.h"
00021 #include "itkNumericTraits.h"
00022 
00023 
00024 namespace itk
00025 {
00026   
00053 namespace Functor {  
00054   
00055 template< class TInput1, class TInput2, class TOutput >
00056 class WeightedAdd2
00057 {
00058 public:
00059   typedef typename NumericTraits< TInput1 >::AccumulateType AccumulatorType;
00060   typedef typename NumericTraits< TInput1 >::RealType       RealType;
00061   WeightedAdd2() {};
00062   ~WeightedAdd2() {};
00063   inline TOutput operator()( const TInput1 & A, const TInput2 & B)
00064   {
00065     const RealType sum1 = A * m_Alpha;
00066     const RealType sum2 = B * m_Beta;
00067     return static_cast<TOutput>( sum1 + sum2 );
00068   }
00069   void SetAlpha( RealType alpha ) { 
00070        m_Alpha = alpha; 
00071        m_Beta  = NumericTraits< RealType >::One - m_Alpha;
00072        }
00073   RealType GetAlpha() const { return m_Alpha; }
00074 private:
00075   RealType  m_Alpha;
00076   RealType  m_Beta;    // auxiliary var to avoid a subtraction at every pixel
00077 }; 
00078 
00079 }
00080 template <class TInputImage1, class TInputImage2, class TOutputImage>
00081 class ITK_EXPORT WeightedAddImageFilter :
00082     public
00083 BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage, 
00084                          Functor::WeightedAdd2< 
00085   typename TInputImage1::PixelType, 
00086   typename TInputImage2::PixelType,
00087   typename TOutputImage::PixelType>   >
00088 
00089 
00090 {
00091 public:
00093   typedef WeightedAddImageFilter  Self;
00094   typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage, 
00095                                    Functor::WeightedAdd2< 
00096     typename TInputImage1::PixelType, 
00097     typename TInputImage2::PixelType,
00098     typename TOutputImage::PixelType>   
00099   >  Superclass;
00100   typedef SmartPointer<Self>   Pointer;
00101   typedef SmartPointer<const Self>  ConstPointer;
00102 
00103   typedef typename Superclass::FunctorType    FunctorType;
00104   typedef typename FunctorType::RealType      RealType;
00105 
00107   itkNewMacro(Self);
00108   
00110   void SetAlpha( RealType alpha ) 
00111     {
00112     this->GetFunctor().SetAlpha( alpha );
00113     this->Modified();
00114     }
00115 
00116 protected:
00117   WeightedAddImageFilter() {}
00118   virtual ~WeightedAddImageFilter() {}
00119 
00120 private:
00121   WeightedAddImageFilter(const Self&); //purposely not implemented
00122   void operator=(const Self&); //purposely not implemented
00123 
00124 };
00125 
00126 } // end namespace itk
00127 
00128 
00129 #endif

Generated at Thu May 25 00:18:18 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000