ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkWeightedAddImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
25namespace itk
26{
27namespace Functor
28{
34template <typename TInput1, typename TInput2, typename TOutput>
36{
37public:
41 : m_Alpha(0.0)
42 , m_Beta(0.0)
43 {}
44 ~WeightedAdd2() = default;
46
47 bool
48 operator==(const WeightedAdd2 & other) const
49 {
50 return Math::ExactlyEquals(m_Alpha, other.m_Alpha);
51 }
52
54
55 inline TOutput
56 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
70
72 GetAlpha() const
73 {
74 return m_Alpha;
75 }
76
77private:
79 RealType m_Beta; // auxiliary var to avoid a subtraction at every pixel
80};
81} // namespace Functor
82
116template <typename TInputImage1, typename TInputImage2, typename TOutputImage>
117class ITK_TEMPLATE_EXPORT WeightedAddImageFilter
118 : public BinaryGeneratorImageFilter<TInputImage1, TInputImage2, TOutputImage>
119
120{
121public:
122 ITK_DISALLOW_COPY_AND_MOVE(WeightedAddImageFilter);
123
127
128
129 using FunctorType = Functor::
130 WeightedAdd2<typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType>;
131
134
135 using RealType = typename FunctorType::RealType;
136
138 itkNewMacro(Self);
139
141 itkOverrideGetNameOfClassMacro(WeightedAddImageFilter);
142
144 void
146 {
147 this->GetFunctor().SetAlpha(alpha);
148 this->Modified();
149 }
150
151
154 GetAlpha() const
155 {
156 return this->GetFunctor().GetAlpha();
157 }
158
160 itkConceptMacro(Input1RealTypeMultiplyCheck,
162 itkConceptMacro(Input2RealTypeMultiplyCheck,
164
165protected:
167 ~WeightedAddImageFilter() override = default;
168
169 void
171 {
172 this->SetFunctor(this->GetFunctor());
173 }
174
175private:
176 itkGetConstReferenceMacro(Functor, FunctorType);
179 {
180 return m_Functor;
181 }
182
184};
185} // end namespace itk
186
187#endif
void SetFunctor(const std::function< ConstRefFunctionType > &f)
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(WeightedAdd2)
bool operator==(const WeightedAdd2 &other) const
TOutput operator()(const TInput1 &A, const TInput2 &B) const
typename NumericTraits< TInput1 >::RealType RealType
typename NumericTraits< TInput1 >::AccumulateType AccumulatorType
virtual void Modified() const
Implements transparent reference counting.
BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage > Superclass
Functor:: WeightedAdd2< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > FunctorType
~WeightedAddImageFilter() override=default
typename FunctorType::RealType RealType
SmartPointer< const Self > ConstPointer
virtual const FunctorType & GetFunctor() const
#define itkConceptMacro(name, concept)
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition itkMath.h:720
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....