ITK  5.0.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) {}
41  ~WeightedAdd2() = default;
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 }
81 
115 template< typename TInputImage1, typename TInputImage2, typename TOutputImage >
117  public
118  BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage >
119 
120 {
121 public:
122  ITK_DISALLOW_COPY_AND_ASSIGN(WeightedAddImageFilter);
123 
127 
128 
129  using FunctorType = Functor::WeightedAdd2< typename TInputImage1::PixelType,
130  typename TInputImage2::PixelType,
131  typename TOutputImage::PixelType >;
132 
135 
136  using RealType = typename FunctorType::RealType;
137 
139  itkNewMacro(Self);
140 
142  itkTypeMacro(WeightedAddImageFilter,
144 
146  void SetAlpha(RealType alpha)
147  {
148  this->GetFunctor().SetAlpha(alpha);
149  this->Modified();
150  }
152 
155  {
156  return this->GetFunctor().GetAlpha();
157  }
158 
159 #ifdef ITK_USE_CONCEPT_CHECKING
160  // Begin concept checking
161  itkConceptMacro( Input1HasNumericTraitsCheck,
163  itkConceptMacro( Input1RealTypeMultiplyCheck,
164  ( Concept::MultiplyOperator< typename TInputImage1::PixelType,
165  RealType, RealType > ) );
166  itkConceptMacro( Input2RealTypeMultiplyCheck,
167  ( Concept::MultiplyOperator< typename TInputImage2::PixelType,
168  RealType, RealType > ) );
169  // End concept checking
170 #endif
171 
172 protected:
173  WeightedAddImageFilter() = default;
174  ~WeightedAddImageFilter() override = default;
175 
177  {
178  this->SetFunctor(this->GetFunctor());
179  }
180 
181 private:
182  itkGetConstReferenceMacro(Functor, FunctorType);
184 
186 };
187 } // end namespace itk
188 
189 #endif
typename FunctorType::RealType RealType
Define numeric traits for std::vector.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Computes a weighted sum of two images pixel-wise.
virtual const FunctorType & GetFunctor() const
Base class for all process objects that output image data.
Implements pixel-wise generic operation of two images, or of an image and a constant.
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:718
virtual void Modified() const
void SetFunctor(const std::function< ConstRefFunctionType > &f)
~WeightedAddImageFilter() override=default
bool operator!=(const WeightedAdd2 &other) const
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator==(const WeightedAdd2 &other) const
Functor::WeightedAdd2< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > FunctorType
#define itkConceptMacro(name, concept)