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

Generated at Mon Jul 12 2010 20:18:58 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000