itkWeightedAddImageFilter.h
Go to the documentation of this file.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
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;
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&);
00159 void operator=(const Self&);
00160
00161 };
00162
00163 }
00164
00165
00166 #endif
00167