ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkWeightedAddImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkWeightedAddImageFilter_h
19 #define __itkWeightedAddImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 
24 namespace itk
25 {
26 namespace Functor
27 {
33 template< class TInput1, class TInput2, class TOutput >
35 {
36 public:
41  bool operator!=(const WeightedAdd2 & other) const
42  {
43  if ( m_Alpha != other.m_Alpha )
44  {
45  return true;
46  }
47  return false;
48  }
50 
51  bool operator==(const WeightedAdd2 & other) const
52  {
53  return !( *this != other );
54  }
55 
56  inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
57  {
58  const RealType sum1 = A * m_Alpha;
59  const RealType sum2 = B * m_Beta;
60 
61  return static_cast< TOutput >( sum1 + sum2 );
62  }
63 
64  void SetAlpha(RealType alpha)
65  {
66  m_Alpha = alpha;
68  }
69 
71  {
72  return m_Alpha;
73  }
74 
75 private:
77  RealType m_Beta; // auxiliary var to avoid a subtraction at every pixel
78 };
79 }
113 template< class TInputImage1, class TInputImage2, class TOutputImage >
114 class ITK_EXPORT WeightedAddImageFilter:
115  public
116  BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
117  Functor::WeightedAdd2<
118  typename TInputImage1::PixelType,
119  typename TInputImage2::PixelType,
120  typename TOutputImage::PixelType > >
121 
122 {
123 public:
126  typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
128  typename TInputImage1::PixelType,
129  typename TInputImage2::PixelType,
130  typename TOutputImage::PixelType >
132 
135 
136  typedef typename Superclass::FunctorType FunctorType;
137  typedef typename FunctorType::RealType RealType;
138 
140  itkNewMacro(Self);
141 
143  itkTypeMacro(WeightedAddImageFilter,
145 
147  void SetAlpha(RealType alpha)
148  {
149  this->GetFunctor().SetAlpha(alpha);
150  this->Modified();
151  }
153 
155  RealType GetAlpha() const
156  {
157  return this->GetFunctor().GetAlpha();
158  }
159 
160 #ifdef ITK_USE_CONCEPT_CHECKING
161 
162  itkConceptMacro( Input1HasNumericTraitsCheck,
164  itkConceptMacro( Input1RealTypeMultiplyCheck,
165  ( Concept::MultiplyOperator< typename TInputImage1::PixelType,
166  RealType, RealType > ) );
167  itkConceptMacro( Input2RealTypeMultiplyCheck,
168  ( Concept::MultiplyOperator< typename TInputImage2::PixelType,
169  RealType, RealType > ) );
170 
172 #endif
173 
174 protected:
177 
178 private:
179  WeightedAddImageFilter(const Self &); //purposely not implemented
180  void operator=(const Self &); //purposely not implemented
181 };
182 } // end namespace itk
183 
184 #endif
185