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: 2007/09/27 11:36:41 $
00007   Version:   $Revision: 1.4 $
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   bool operator!=( const WeightedAdd2 & other ) const
00064   {
00065     if( m_Alpha != other.m_Alpha)
00066       {
00067       return true;
00068       }
00069     return false;
00070    }
00071   bool operator==( const WeightedAdd2 & other ) const
00072   {
00073     return !(*this != other);
00074   }
00075 
00076   inline TOutput operator()( const TInput1 & A, const TInput2 & B)
00077   {
00078     const RealType sum1 = A * m_Alpha;
00079     const RealType sum2 = B * m_Beta;
00080     return static_cast<TOutput>( sum1 + sum2 );
00081   }
00082   void SetAlpha( RealType alpha ) { 
00083        m_Alpha = alpha; 
00084        m_Beta  = NumericTraits< RealType >::One - m_Alpha;
00085        }
00086   RealType GetAlpha() const { return m_Alpha; }
00087 private:
00088   RealType  m_Alpha;
00089   RealType  m_Beta;    // auxiliary var to avoid a subtraction at every pixel
00090 }; 
00091 
00092 }
00093 template <class TInputImage1, class TInputImage2, class TOutputImage>
00094 class ITK_EXPORT WeightedAddImageFilter :
00095     public
00096 BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage, 
00097                          Functor::WeightedAdd2< 
00098   typename TInputImage1::PixelType, 
00099   typename TInputImage2::PixelType,
00100   typename TOutputImage::PixelType>   >
00101 
00102 
00103 {
00104 public:
00106   typedef WeightedAddImageFilter  Self;
00107   typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage, 
00108                                    Functor::WeightedAdd2< 
00109     typename TInputImage1::PixelType, 
00110     typename TInputImage2::PixelType,
00111     typename TOutputImage::PixelType>   
00112   >  Superclass;
00113   typedef SmartPointer<Self>   Pointer;
00114   typedef SmartPointer<const Self>  ConstPointer;
00115 
00116   typedef typename Superclass::FunctorType    FunctorType;
00117   typedef typename FunctorType::RealType      RealType;
00118 
00120   itkNewMacro(Self);
00121 
00123   itkTypeMacro(WeightedAddImageFilter, 
00124                BinaryFunctorImageFilter);
00125 
00127   void SetAlpha( RealType alpha ) 
00128     {
00129     this->GetFunctor().SetAlpha( alpha );
00130     this->Modified();
00131     }
00133 
00134 #ifdef ITK_USE_CONCEPT_CHECKING
00135 
00136   itkConceptMacro(Input1HasNumericTraitsCheck,
00137     (Concept::HasNumericTraits<typename TInputImage1::PixelType>));
00138   itkConceptMacro(Input1RealTypeMultiplyCheck,
00139     (Concept::MultiplyOperator<typename TInputImage1::PixelType,
00140                                RealType, RealType>));
00141   itkConceptMacro(Input2RealTypeMultiplyCheck,
00142     (Concept::MultiplyOperator<typename TInputImage2::PixelType,
00143                                RealType, RealType>));
00144 
00146 #endif
00147 
00148 protected:
00149   WeightedAddImageFilter() {}
00150   virtual ~WeightedAddImageFilter() {}
00151 
00152 private:
00153   WeightedAddImageFilter(const Self&); //purposely not implemented
00154   void operator=(const Self&); //purposely not implemented
00155 
00156 };
00157 
00158 } // end namespace itk
00159 
00160 
00161 #endif
00162 

Generated at Tue Jul 29 23:59:25 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000