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  * 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 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  }
69 
70  ~LogicOpBase() = default;
71 
72 
73  bool
74  operator!=(const Self &) const
75  {
76  return false;
77  }
78  bool
79  operator==(const Self & other) const
80  {
81  return !(*this != other);
82  }
83 
84  void
85  SetForegroundValue(const TOutput & FG)
86  {
87  m_ForegroundValue = FG;
88  }
89  void
90  SetBackgroundValue(const TOutput & BG)
91  {
92  m_BackgroundValue = BG;
93  }
94 
95  TOutput
97  {
98  return (m_ForegroundValue);
99  }
100  TOutput
102  {
103  return (m_BackgroundValue);
104  }
105 
106 protected:
109 };
110 
121 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
122 class ITK_TEMPLATE_EXPORT Equal : public LogicOpBase<TInput1, TInput2, TOutput>
123 {
124 public:
125  using Self = Equal;
126 
127  Equal() = default;
128  ~Equal() = default;
129 
130  bool
131  operator!=(const Self &) const
132  {
133  return false;
134  }
135  bool
136  operator==(const Self & other) const
137  {
138  return !(*this != other);
139  }
140  inline TOutput
141  operator()(const TInput1 & A, const TInput2 & B) const
142  {
143  if (Math::ExactlyEquals(A, static_cast<TInput1>(B)))
144  {
145  return this->m_ForegroundValue;
146  }
147  return this->m_BackgroundValue;
148  }
149 };
160 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
161 class ITK_TEMPLATE_EXPORT NotEqual : public LogicOpBase<TInput1, TInput2, TOutput>
162 {
163 public:
164  using Self = NotEqual;
165 
166  NotEqual() = default;
167  ~NotEqual() = default;
168  bool
169  operator!=(const Self &) const
170  {
171  return false;
172  }
173  bool
174  operator==(const Self & other) const
175  {
176  return !(*this != other);
177  }
178  inline TOutput
179  operator()(const TInput1 & A, const TInput2 & B) const
180  {
181  if (Math::NotExactlyEquals(A, B))
182  {
183  return this->m_ForegroundValue;
184  }
185  return this->m_BackgroundValue;
186  }
187 };
188 
199 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
200 class ITK_TEMPLATE_EXPORT GreaterEqual : public LogicOpBase<TInput1, TInput2, TOutput>
201 {
202 public:
204  GreaterEqual() = default;
205  ~GreaterEqual() = default;
206 
207  bool
208  operator!=(const Self &) const
209  {
210  return false;
211  }
212  bool
213  operator==(const Self & other) const
214  {
215  return !(*this != other);
216  }
217  inline TOutput
218  operator()(const TInput1 & A, const TInput2 & B) const
219  {
220  if (A >= B)
221  {
222  return this->m_ForegroundValue;
223  }
224  return this->m_BackgroundValue;
225  }
226 };
227 
228 
238 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
239 class ITK_TEMPLATE_EXPORT Greater : public LogicOpBase<TInput1, TInput2, TOutput>
240 {
241 public:
242  using Self = Greater;
243  Greater() = default;
244  ~Greater() = default;
245  bool
246  operator!=(const Self &) const
247  {
248  return false;
249  }
250  bool
251  operator==(const Self & other) const
252  {
253  return !(*this != other);
254  }
255  inline TOutput
256  operator()(const TInput1 & A, const TInput2 & B) const
257  {
258  if (A > B)
259  {
260  return this->m_ForegroundValue;
261  }
262  return this->m_BackgroundValue;
263  }
264 };
266 
267 
277 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
278 class ITK_TEMPLATE_EXPORT LessEqual : public LogicOpBase<TInput1, TInput2, TOutput>
279 {
280 public:
281  using Self = LessEqual;
282 
283  LessEqual() = default;
284  ~LessEqual() = default;
285  bool
286  operator!=(const Self &) const
287  {
288  return false;
289  }
290  bool
291  operator==(const Self & other) const
292  {
293  return !(*this != other);
294  }
295  inline TOutput
296  operator()(const TInput1 & A, const TInput2 & B) const
297  {
298  if (A <= B)
299  {
300  return this->m_ForegroundValue;
301  }
302  return this->m_BackgroundValue;
303  }
304 };
305 
306 
316 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
317 class ITK_TEMPLATE_EXPORT Less : public LogicOpBase<TInput1, TInput2, TOutput>
318 {
319 public:
320  using Self = Less;
321  Less() = default;
322  ~Less() = default;
323  bool
324  operator!=(const Self &) const
325  {
326  return false;
327  }
328  bool
329  operator==(const Self & other) const
330  {
331  return !(*this != other);
332  }
333  inline TOutput
334  operator()(const TInput1 & A, const TInput2 & B) const
335  {
336  if (A < B)
337  {
338  return this->m_ForegroundValue;
339  }
340  return this->m_BackgroundValue;
341  }
342 };
344 
345 
351 template <typename TInput, typename TOutput = TInput>
352 class ITK_TEMPLATE_EXPORT NOT : public LogicOpBase<TInput, TInput, TOutput>
353 {
354 public:
355  NOT() = default;
356  ~NOT() = default;
357  bool
358  operator!=(const NOT &) const
359  {
360  return false;
361  }
363 
364  bool
365  operator==(const NOT & other) const
366  {
367  return !(*this != other);
368  }
369 
370  inline TOutput
371  operator()(const TInput & A) const
372  {
373  if (!A)
374  {
375  return this->m_ForegroundValue;
376  }
377  return this->m_BackgroundValue;
378  }
379 };
380 
386 template <typename TInput1, typename TInput2, typename TInput3, typename TOutput>
387 class ITK_TEMPLATE_EXPORT TernaryOperator
388 {
389 public:
390  TernaryOperator() = default;
391  ~TernaryOperator() = default;
392  bool
394  {
395  return false;
396  }
398 
399  bool
400  operator==(const TernaryOperator & other) const
401  {
402  return !(*this != other);
403  }
404 
405  inline TOutput
406  operator()(const TInput1 & A, const TInput2 & B, const TInput3 & C) const
407  {
408  if (A)
409  {
410  return static_cast<TOutput>(B);
411  }
412  else
413  {
414  return static_cast<TOutput>(C);
415  }
416  }
417 };
418 
419 } // namespace Functor
420 } // namespace itk
421 
422 #endif
itk::Functor::Greater
Functor for > operation on images and constants.
Definition: itkLogicOpsFunctors.h:239
itk::Functor::Less::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:334
itk::Functor::GreaterEqual
Functor for >= operation on images and constants.
Definition: itkLogicOpsFunctors.h:200
itk::Functor::NotEqual::operator!=
bool operator!=(const Self &) const
Definition: itkLogicOpsFunctors.h:169
itk::Functor::NotEqual::operator==
bool operator==(const Self &other) const
Definition: itkLogicOpsFunctors.h:174
itk::Functor::TernaryOperator::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B, const TInput3 &C) const
Definition: itkLogicOpsFunctors.h:406
itk::Functor::NOT::operator()
TOutput operator()(const TInput &A) const
Definition: itkLogicOpsFunctors.h:371
itk::Functor::LogicOpBase::GetForegroundValue
TOutput GetForegroundValue() const
Definition: itkLogicOpsFunctors.h:96
itk::Functor::TernaryOperator::operator!=
bool operator!=(const TernaryOperator &) const
Definition: itkLogicOpsFunctors.h:393
itk::Functor::GreaterEqual::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:218
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:352
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::Functor::GreaterEqual::operator!=
bool operator!=(const Self &) const
Definition: itkLogicOpsFunctors.h:208
itk::Functor::GreaterEqual::operator==
bool operator==(const Self &other) const
Definition: itkLogicOpsFunctors.h:213
itk::Functor::Equal::operator==
bool operator==(const Self &other) const
Definition: itkLogicOpsFunctors.h:136
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
itk::Functor::LogicOpBase::SetForegroundValue
void SetForegroundValue(const TOutput &FG)
Definition: itkLogicOpsFunctors.h:85
itk::Functor::Greater::operator!=
bool operator!=(const Self &) const
Definition: itkLogicOpsFunctors.h:246
itk::Functor::Less::operator!=
bool operator!=(const Self &) const
Definition: itkLogicOpsFunctors.h:324
itk::Functor::LogicOpBase::m_ForegroundValue
TOutput m_ForegroundValue
Definition: itkLogicOpsFunctors.h:107
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:156
itk::Functor::Greater::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:256
itk::Functor::LessEqual::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:296
itk::Functor::LogicOpBase::m_BackgroundValue
TOutput m_BackgroundValue
Definition: itkLogicOpsFunctors.h:108
itk::Functor::LessEqual
Functor for <= operation on images and constants.
Definition: itkLogicOpsFunctors.h:278
itk::Functor::Equal
Functor for == operation on images and constants.
Definition: itkLogicOpsFunctors.h:122
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:387
itk::Functor::NOT::operator!=
bool operator!=(const NOT &) const
Definition: itkLogicOpsFunctors.h:358
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:179
itk::Functor::LogicOpBase::operator==
bool operator==(const Self &other) const
Definition: itkLogicOpsFunctors.h:79
itk::Functor::LessEqual::operator!=
bool operator!=(const Self &) const
Definition: itkLogicOpsFunctors.h:286
itk::Functor::NotEqual
Functor for != operation on images and constants.
Definition: itkLogicOpsFunctors.h:161
itkNumericTraits.h
itk::Functor::Equal::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:141
itk::Functor::LogicOpBase::GetBackgroundValue
TOutput GetBackgroundValue() const
Definition: itkLogicOpsFunctors.h:101
itk::Functor::Equal::operator!=
bool operator!=(const Self &) const
Definition: itkLogicOpsFunctors.h:131
itk::Functor::LessEqual::operator==
bool operator==(const Self &other) const
Definition: itkLogicOpsFunctors.h:291
itk::Functor::Less
Functor for < operation on images and constants.
Definition: itkLogicOpsFunctors.h:317
itk::Functor::NOT::operator==
bool operator==(const NOT &other) const
Definition: itkLogicOpsFunctors.h:365
itk::Functor::LogicOpBase::operator!=
bool operator!=(const Self &) const
Definition: itkLogicOpsFunctors.h:74
itkMath.h
itk::Functor::TernaryOperator::operator==
bool operator==(const TernaryOperator &other) const
Definition: itkLogicOpsFunctors.h:400
itk::Functor::LogicOpBase::LogicOpBase
LogicOpBase()
Definition: itkLogicOpsFunctors.h:63
itk::Functor::LogicOpBase::SetBackgroundValue
void SetBackgroundValue(const TOutput &BG)
Definition: itkLogicOpsFunctors.h:90
itk::Functor::Greater::operator==
bool operator==(const Self &other) const
Definition: itkLogicOpsFunctors.h:251
itk::Functor::Less::operator==
bool operator==(const Self &other) const
Definition: itkLogicOpsFunctors.h:329