ITK  4.2.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 
154 #ifdef ITK_USE_CONCEPT_CHECKING
155 
156  itkConceptMacro( Input1HasNumericTraitsCheck,
158  itkConceptMacro( Input1RealTypeMultiplyCheck,
159  ( Concept::MultiplyOperator< typename TInputImage1::PixelType,
160  RealType, RealType > ) );
161  itkConceptMacro( Input2RealTypeMultiplyCheck,
162  ( Concept::MultiplyOperator< typename TInputImage2::PixelType,
163  RealType, RealType > ) );
164 
166 #endif
167 protected:
170 private:
171  WeightedAddImageFilter(const Self &); //purposely not implemented
172  void operator=(const Self &); //purposely not implemented
173 };
174 } // end namespace itk
176 
177 #endif
178