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;
45
46 bool
47 operator==(const WeightedAdd2 & other) const
48 {
49 return Math::ExactlyEquals(m_Alpha, other.m_Alpha);
50 }
51
53
54 inline TOutput
55 operator()(const TInput1 & A, const TInput2 & B) const
56 {
57 const RealType sum1 = A * m_Alpha;
58 const RealType sum2 = B * m_Beta;
59
60 return static_cast<TOutput>(sum1 + sum2);
61 }
62
63 void
69
70 [[nodiscard]] RealType
71 GetAlpha() const
72 {
73 return m_Alpha;
74 }
75
76private:
78 RealType m_Beta; // auxiliary var to avoid a subtraction at every pixel
79};
80} // namespace Functor
81
115template <typename TInputImage1, typename TInputImage2, typename TOutputImage>
116class ITK_TEMPLATE_EXPORT WeightedAddImageFilter
117 : public BinaryGeneratorImageFilter<TInputImage1, TInputImage2, TOutputImage>
118{
119public:
120 ITK_DISALLOW_COPY_AND_MOVE(WeightedAddImageFilter);
121
125
126
127 using FunctorType = Functor::
128 WeightedAdd2<typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType>;
129
132
133 using RealType = typename FunctorType::RealType;
134
136 itkNewMacro(Self);
137
139 itkOverrideGetNameOfClassMacro(WeightedAddImageFilter);
140
142 void
144 {
145 this->GetFunctor().SetAlpha(alpha);
146 this->Modified();
147 }
148
151 GetAlpha() const
152 {
153 return this->GetFunctor().GetAlpha();
154 }
155
157 itkConceptMacro(Input1RealTypeMultiplyCheck,
159 itkConceptMacro(Input2RealTypeMultiplyCheck,
161
162protected:
164 ~WeightedAddImageFilter() override = default;
165
166 void
168 {
169 this->SetFunctor(this->GetFunctor());
170 }
171
172private:
173 itkGetConstReferenceMacro(Functor, FunctorType);
176 {
177 return m_Functor;
178 }
179
181};
182} // end namespace itk
183
184#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)
constexpr 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:743
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....