ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkLogicOpsFunctors.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 itkLogicOpsFunctors_h
19#define itkLogicOpsFunctors_h
20
21#include "itkNumericTraits.h"
22#include "itkMath.h"
23
24namespace itk::Functor
25{
26
55
56template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
57class ITK_TEMPLATE_EXPORT LogicOpBase
58{
59public:
62 : m_ForegroundValue(itk::NumericTraits<TOutput>::OneValue())
63 , m_BackgroundValue(TOutput{})
64 {}
65
66 ~LogicOpBase() = default;
67
68 bool
69 operator==(const Self &) const
70 {
71 return true;
72 }
73
75
76 void
77 SetForegroundValue(const TOutput & FG)
78 {
80 }
81 void
82 SetBackgroundValue(const TOutput & BG)
83 {
85 }
86
87 [[nodiscard]] TOutput
89 {
90 return (m_ForegroundValue);
91 }
92 [[nodiscard]] TOutput
94 {
95 return (m_BackgroundValue);
96 }
97
98protected:
101};
102
112
113template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
114class ITK_TEMPLATE_EXPORT Equal : public LogicOpBase<TInput1, TInput2, TOutput>
115{
116public:
117 using Self = Equal;
118
119 bool
120 operator==(const Self &) const
121 {
122 return true;
123 }
124
126
127 inline TOutput
128 operator()(const TInput1 & A, const TInput2 & B) const
129 {
130 if (Math::ExactlyEquals(A, static_cast<TInput1>(B)))
131 {
132 return this->m_ForegroundValue;
133 }
134 return this->m_BackgroundValue;
135 }
136};
137
146
147template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
148class ITK_TEMPLATE_EXPORT NotEqual : public LogicOpBase<TInput1, TInput2, TOutput>
149{
150public:
151 using Self = NotEqual;
152
153 bool
154 operator==(const Self &) const
155 {
156 return true;
157 }
158
160
161 inline TOutput
162 operator()(const TInput1 & A, const TInput2 & B) const
163 {
164 if (Math::NotExactlyEquals(A, B))
165 {
166 return this->m_ForegroundValue;
167 }
168 return this->m_BackgroundValue;
169 }
170};
171
181
182template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
183class ITK_TEMPLATE_EXPORT GreaterEqual : public LogicOpBase<TInput1, TInput2, TOutput>
184{
185public:
187
188 bool
189 operator==(const Self &) const
190 {
191 return true;
192 }
193
195
196 inline TOutput
197 operator()(const TInput1 & A, const TInput2 & B) const
198 {
199 if (A >= B)
200 {
201 return this->m_ForegroundValue;
202 }
203 return this->m_BackgroundValue;
204 }
205};
206
207
217template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
218class ITK_TEMPLATE_EXPORT Greater : public LogicOpBase<TInput1, TInput2, TOutput>
219{
220public:
221 using Self = Greater;
222
223 bool
224 operator==(const Self &) const
225 {
226 return true;
227 }
228
230
231 inline TOutput
232 operator()(const TInput1 & A, const TInput2 & B) const
233 {
234 if (A > B)
235 {
236 return this->m_ForegroundValue;
237 }
238 return this->m_BackgroundValue;
239 }
240};
241
242
252template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
253class ITK_TEMPLATE_EXPORT LessEqual : public LogicOpBase<TInput1, TInput2, TOutput>
254{
255public:
257
258 bool
259 operator==(const Self &) const
260 {
261 return true;
262 }
263
265
266 inline TOutput
267 operator()(const TInput1 & A, const TInput2 & B) const
268 {
269 if (A <= B)
270 {
271 return this->m_ForegroundValue;
272 }
273 return this->m_BackgroundValue;
274 }
275};
276
277
287template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
288class ITK_TEMPLATE_EXPORT Less : public LogicOpBase<TInput1, TInput2, TOutput>
289{
290public:
291 using Self = Less;
292
293 bool
294 operator==(const Self &) const
295 {
296 return true;
297 }
298
300
301 inline TOutput
302 operator()(const TInput1 & A, const TInput2 & B) const
303 {
304 if (A < B)
305 {
306 return this->m_ForegroundValue;
307 }
308 return this->m_BackgroundValue;
309 }
310};
311
312
318template <typename TInput, typename TOutput = TInput>
319class ITK_TEMPLATE_EXPORT NOT : public LogicOpBase<TInput, TInput, TOutput>
320{
321public:
322 bool
323 operator==(const NOT &) const
324 {
325 return true;
326 }
327
329
330 inline TOutput
331 operator()(const TInput & A) const
332 {
333 if (!A)
334 {
335 return this->m_ForegroundValue;
336 }
337 return this->m_BackgroundValue;
338 }
339};
340
346template <typename TInput1, typename TInput2, typename TInput3, typename TOutput>
347class ITK_TEMPLATE_EXPORT TernaryOperator
348{
349public:
350 bool
352 {
353 return true;
354 }
355
357
358 inline TOutput
359 operator()(const TInput1 & A, const TInput2 & B, const TInput3 & C) const
360 {
361 if (A)
362 {
363 return static_cast<TOutput>(B);
364 }
365
366 return static_cast<TOutput>(C);
367 }
368};
369
370} // namespace itk::Functor
371
372
373#endif
Functor for == operation on images and constants.
bool operator==(const Self &) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Functor for >= operation on images and constants.
bool operator==(const Self &) const
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Functor for > operation on images and constants.
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator==(const Self &) const
Functor for <= operation on images and constants.
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator==(const Self &) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
Functor for < operation on images and constants.
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator==(const Self &) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
bool operator==(const Self &) const
void SetForegroundValue(const TOutput &FG)
void SetBackgroundValue(const TOutput &BG)
Unary logical NOT functor.
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(NOT)
TOutput operator()(const TInput &A) const
bool operator==(const NOT &) const
Functor for != operation on images and constants.
bool operator==(const Self &) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Return argument 2 if argument 1 is false, and argument 3 otherwise.
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TernaryOperator)
bool operator==(const TernaryOperator &) const
TOutput operator()(const TInput1 &A, const TInput2 &B, const TInput3 &C) const
Define additional traits for native types such as int or float.
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:716
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition itkMath.h:727
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....