00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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;
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&);
00122 void operator=(const Self&);
00123
00124 };
00125
00126 }
00127
00128
00129 #endif