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 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;
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&);
00154 void operator=(const Self&);
00155
00156 };
00157
00158 }
00159
00160
00161 #endif
00162