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: 2006/03/31 14:31:04 $
00007   Version:   $Revision: 1.3 $
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   void SetAlpha( RealType alpha ) 
00124     {
00125     this->GetFunctor().SetAlpha( alpha );
00126     this->Modified();
00127     }
00129 
00130 #ifdef ITK_USE_CONCEPT_CHECKING
00131 
00132   itkConceptMacro(Input1HasNumericTraitsCheck,
00133     (Concept::HasNumericTraits<typename TInputImage1::PixelType>));
00134   itkConceptMacro(Input1RealTypeMultiplyCheck,
00135     (Concept::MultiplyOperator<typename TInputImage1::PixelType,
00136                                RealType, RealType>));
00137   itkConceptMacro(Input2RealTypeMultiplyCheck,
00138     (Concept::MultiplyOperator<typename TInputImage2::PixelType,
00139                                RealType, RealType>));
00140 
00142 #endif
00143 
00144 protected:
00145   WeightedAddImageFilter() {}
00146   virtual ~WeightedAddImageFilter() {}
00147 
00148 private:
00149   WeightedAddImageFilter(const Self&); //purposely not implemented
00150   void operator=(const Self&); //purposely not implemented
00151 
00152 };
00153 
00154 } // end namespace itk
00155 
00156 
00157 #endif
00158 

Generated at Mon Mar 12 03:31:25 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000