ITK  5.3.0
Insight Toolkit
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 
24 
25 namespace itk
26 {
27 namespace Functor
28 {
29 
58 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
59 class ITK_TEMPLATE_EXPORT LogicOpBase
60 {
61 public:
62  using Self = LogicOpBase;
64  {
65  m_ForegroundValue = itk::NumericTraits<TOutput>::OneValue();
66  m_BackgroundValue = itk::NumericTraits<TOutput>::ZeroValue();
67  }
70  ~LogicOpBase() = default;
71 
72  bool
73  operator==(const Self &) const
74  {
75  return true;
76  }
77 
78  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
79 
80  void
81  SetForegroundValue(const TOutput & FG)
82  {
83  m_ForegroundValue = FG;
84  }
85  void
86  SetBackgroundValue(const TOutput & BG)
87  {
88  m_BackgroundValue = BG;
89  }
90 
91  TOutput
93  {
94  return (m_ForegroundValue);
95  }
96  TOutput
98  {
99  return (m_BackgroundValue);
100  }
101 
102 protected:
105 };
106 
117 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
118 class ITK_TEMPLATE_EXPORT Equal : public LogicOpBase<TInput1, TInput2, TOutput>
119 {
120 public:
121  using Self = Equal;
122 
123  Equal() = default;
124  ~Equal() = default;
125 
126  bool
127  operator==(const Self &) const
128  {
129  return true;
130  }
131 
132  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
133 
134  inline TOutput
135  operator()(const TInput1 & A, const TInput2 & B) const
136  {
137  if (Math::ExactlyEquals(A, static_cast<TInput1>(B)))
138  {
139  return this->m_ForegroundValue;
140  }
141  return this->m_BackgroundValue;
142  }
143 };
154 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
155 class ITK_TEMPLATE_EXPORT NotEqual : public LogicOpBase<TInput1, TInput2, TOutput>
156 {
157 public:
158  using Self = NotEqual;
159 
160  NotEqual() = default;
161  ~NotEqual() = default;
162 
163  bool
164  operator==(const Self &) const
165  {
166  return true;
167  }
168 
169  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
170 
171  inline TOutput
172  operator()(const TInput1 & A, const TInput2 & B) const
173  {
174  if (Math::NotExactlyEquals(A, B))
175  {
176  return this->m_ForegroundValue;
177  }
178  return this->m_BackgroundValue;
179  }
180 };
181 
192 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
193 class ITK_TEMPLATE_EXPORT GreaterEqual : public LogicOpBase<TInput1, TInput2, TOutput>
194 {
195 public:
197  GreaterEqual() = default;
198  ~GreaterEqual() = default;
199 
200  bool
201  operator==(const Self &) const
202  {
203  return true;
204  }
205 
206  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
207 
208  inline TOutput
209  operator()(const TInput1 & A, const TInput2 & B) const
210  {
211  if (A >= B)
212  {
213  return this->m_ForegroundValue;
214  }
215  return this->m_BackgroundValue;
216  }
217 };
218 
219 
229 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
230 class ITK_TEMPLATE_EXPORT Greater : public LogicOpBase<TInput1, TInput2, TOutput>
231 {
232 public:
233  using Self = Greater;
234  Greater() = default;
235  ~Greater() = default;
238  bool
239  operator==(const Self &) const
240  {
241  return true;
242  }
243 
244  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
245 
246  inline TOutput
247  operator()(const TInput1 & A, const TInput2 & B) const
248  {
249  if (A > B)
250  {
251  return this->m_ForegroundValue;
252  }
253  return this->m_BackgroundValue;
254  }
255 };
256 
257 
267 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
268 class ITK_TEMPLATE_EXPORT LessEqual : public LogicOpBase<TInput1, TInput2, TOutput>
269 {
270 public:
271  using Self = LessEqual;
272 
273  LessEqual() = default;
274  ~LessEqual() = default;
275 
276  bool
277  operator==(const Self &) const
278  {
279  return true;
280  }
281 
282  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
283 
284  inline TOutput
285  operator()(const TInput1 & A, const TInput2 & B) const
286  {
287  if (A <= B)
288  {
289  return this->m_ForegroundValue;
290  }
291  return this->m_BackgroundValue;
292  }
293 };
294 
295 
305 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
306 class ITK_TEMPLATE_EXPORT Less : public LogicOpBase<TInput1, TInput2, TOutput>
307 {
308 public:
309  using Self = Less;
310  Less() = default;
311  ~Less() = default;
314  bool
315  operator==(const Self &) const
316  {
317  return true;
318  }
319 
320  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
321 
322  inline TOutput
323  operator()(const TInput1 & A, const TInput2 & B) const
324  {
325  if (A < B)
326  {
327  return this->m_ForegroundValue;
328  }
329  return this->m_BackgroundValue;
330  }
331 };
332 
333 
339 template <typename TInput, typename TOutput = TInput>
340 class ITK_TEMPLATE_EXPORT NOT : public LogicOpBase<TInput, TInput, TOutput>
341 {
342 public:
343  NOT() = default;
344  ~NOT() = default;
347  bool
348  operator==(const NOT &) const
349  {
350  return true;
351  }
352 
353  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(NOT);
354 
355  inline TOutput
356  operator()(const TInput & A) const
357  {
358  if (!A)
359  {
360  return this->m_ForegroundValue;
361  }
362  return this->m_BackgroundValue;
363  }
364 };
365 
371 template <typename TInput1, typename TInput2, typename TInput3, typename TOutput>
372 class ITK_TEMPLATE_EXPORT TernaryOperator
373 {
374 public:
375  TernaryOperator() = default;
376  ~TernaryOperator() = default;
379  bool
381  {
382  return true;
383  }
384 
385  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TernaryOperator);
386 
387  inline TOutput
388  operator()(const TInput1 & A, const TInput2 & B, const TInput3 & C) const
389  {
390  if (A)
391  {
392  return static_cast<TOutput>(B);
393  }
394  else
395  {
396  return static_cast<TOutput>(C);
397  }
398  }
399 };
400 
401 } // namespace Functor
402 } // namespace itk
403 
404 #endif
itk::Functor::Greater
Functor for > operation on images and constants.
Definition: itkLogicOpsFunctors.h:230
itk::Functor::Less::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:323
itk::Functor::GreaterEqual
Functor for >= operation on images and constants.
Definition: itkLogicOpsFunctors.h:193
itk::Functor::Greater::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:239
itk::Functor::TernaryOperator::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B, const TInput3 &C) const
Definition: itkLogicOpsFunctors.h:388
itk::Functor::NOT::operator()
TOutput operator()(const TInput &A) const
Definition: itkLogicOpsFunctors.h:356
itk::Functor::LogicOpBase::GetForegroundValue
TOutput GetForegroundValue() const
Definition: itkLogicOpsFunctors.h:92
itk::Functor::GreaterEqual::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:209
itk::Functor::LogicOpBase
Base class for some logic functors. Provides the Foreground and background setting methods.
Definition: itkLogicOpsFunctors.h:59
itk::Functor::NOT
Unary logical NOT functor.
Definition: itkLogicOpsFunctors.h:340
itk::Math::ExactlyEquals
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:723
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
itk::Functor::Less::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:315
itk::Functor::GreaterEqual::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:201
itk::Functor::NotEqual::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:164
itk::Functor::LogicOpBase::SetForegroundValue
void SetForegroundValue(const TOutput &FG)
Definition: itkLogicOpsFunctors.h:81
itk::Functor::LogicOpBase::m_ForegroundValue
TOutput m_ForegroundValue
Definition: itkLogicOpsFunctors.h:103
itk::Functor::LessEqual::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:277
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:156
itk::Functor::NOT::operator==
bool operator==(const NOT &) const
Definition: itkLogicOpsFunctors.h:348
itk::Functor::Greater::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:247
itk::Functor::LessEqual::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:285
itk::Functor::LogicOpBase::m_BackgroundValue
TOutput m_BackgroundValue
Definition: itkLogicOpsFunctors.h:104
itk::Functor::LessEqual
Functor for <= operation on images and constants.
Definition: itkLogicOpsFunctors.h:268
itk::Functor::Equal
Functor for == operation on images and constants.
Definition: itkLogicOpsFunctors.h:118
itk::Functor::Equal::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:127
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itk::Functor::TernaryOperator
Return argument 2 if argument 1 is false, and argument 3 otherwise.
Definition: itkLogicOpsFunctors.h:372
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Functor::NotEqual::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:172
itk::Functor::NotEqual
Functor for != operation on images and constants.
Definition: itkLogicOpsFunctors.h:155
itkNumericTraits.h
itk::Functor::Equal::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:135
itk::Functor::LogicOpBase::GetBackgroundValue
TOutput GetBackgroundValue() const
Definition: itkLogicOpsFunctors.h:97
AddImageFilter
Definition: itkAddImageFilter.h:80
itk::Functor::LogicOpBase::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:73
itk::Functor::Less
Functor for < operation on images and constants.
Definition: itkLogicOpsFunctors.h:306
itkMath.h
itk::Functor::LogicOpBase::LogicOpBase
LogicOpBase()
Definition: itkLogicOpsFunctors.h:63
itk::Functor::LogicOpBase::SetBackgroundValue
void SetBackgroundValue(const TOutput &BG)
Definition: itkLogicOpsFunctors.h:86
itk::Functor::TernaryOperator::operator==
bool operator==(const TernaryOperator &) const
Definition: itkLogicOpsFunctors.h:380