ITK  4.9.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 #include "itkMath.h"
24 
25 namespace itk
26 {
27 namespace Functor
28 {
34 template< typename TInput1, typename TInput2, typename TOutput >
36 {
37 public:
40  WeightedAdd2() : m_Alpha(0.0), m_Beta(0.0) {}
42  bool operator!=(const WeightedAdd2 & other) const
43  {
45  {
46  return true;
47  }
48  return false;
49  }
51 
52  bool operator==(const WeightedAdd2 & other) const
53  {
54  return !( *this != other );
55  }
56 
57  inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
58  {
59  const RealType sum1 = A * m_Alpha;
60  const RealType sum2 = B * m_Beta;
61 
62  return static_cast< TOutput >( sum1 + sum2 );
63  }
64 
65  void SetAlpha(RealType alpha)
66  {
67  m_Alpha = alpha;
69  }
70 
72  {
73  return m_Alpha;
74  }
75 
76 private:
78  RealType m_Beta; // auxiliary var to avoid a subtraction at every pixel
79 };
80 }
114 template< typename TInputImage1, typename TInputImage2, typename TOutputImage >
116  public
117  BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
118  Functor::WeightedAdd2<
119  typename TInputImage1::PixelType,
120  typename TInputImage2::PixelType,
121  typename TOutputImage::PixelType > >
122 
123 {
124 public:
127  typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
129  typename TInputImage1::PixelType,
130  typename TInputImage2::PixelType,
131  typename TOutputImage::PixelType >
133 
136 
138  typedef typename FunctorType::RealType RealType;
139 
141  itkNewMacro(Self);
142 
144  itkTypeMacro(WeightedAddImageFilter,
146 
148  void SetAlpha(RealType alpha)
149  {
150  this->GetFunctor().SetAlpha(alpha);
151  this->Modified();
152  }
154 
157  {
158  return this->GetFunctor().GetAlpha();
159  }
160 
161 #ifdef ITK_USE_CONCEPT_CHECKING
162  // Begin concept checking
163  itkConceptMacro( Input1HasNumericTraitsCheck,
165  itkConceptMacro( Input1RealTypeMultiplyCheck,
166  ( Concept::MultiplyOperator< typename TInputImage1::PixelType,
167  RealType, RealType > ) );
168  itkConceptMacro( Input2RealTypeMultiplyCheck,
169  ( Concept::MultiplyOperator< typename TInputImage2::PixelType,
170  RealType, RealType > ) );
171  // End concept checking
172 #endif
173 
174 protected:
177 
178 private:
179  WeightedAddImageFilter(const Self &) ITK_DELETE_FUNCTION;
180  void operator=(const Self &) ITK_DELETE_FUNCTION;
181 };
182 } // end namespace itk
183 
184 #endif
NumericTraits< TInput1 >::RealType RealType
SmartPointer< const Self > ConstPointer
Computes a weighted sum of two images pixel-wise.
Base class for all process objects that output image data.
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:676
virtual void Modified() const
bool operator!=(const WeightedAdd2 &other) const
NumericTraits< TInput1 >::AccumulateType AccumulatorType
BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::WeightedAdd2< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > > Superclass
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator==(const WeightedAdd2 &other) const
Define additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)
Implements pixel-wise generic operation of two images, or of an image and a constant.