ITK  6.0.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 = TOutput{};
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  bool
124  operator==(const Self &) const
125  {
126  return true;
127  }
128 
129  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
130 
131  inline TOutput
132  operator()(const TInput1 & A, const TInput2 & B) const
133  {
134  if (Math::ExactlyEquals(A, static_cast<TInput1>(B)))
135  {
136  return this->m_ForegroundValue;
137  }
138  return this->m_BackgroundValue;
139  }
140 };
151 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
152 class ITK_TEMPLATE_EXPORT NotEqual : public LogicOpBase<TInput1, TInput2, TOutput>
153 {
154 public:
155  using Self = NotEqual;
156 
157  bool
158  operator==(const Self &) const
159  {
160  return true;
161  }
162 
163  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
164 
165  inline TOutput
166  operator()(const TInput1 & A, const TInput2 & B) const
167  {
168  if (Math::NotExactlyEquals(A, B))
169  {
170  return this->m_ForegroundValue;
171  }
172  return this->m_BackgroundValue;
173  }
174 };
175 
186 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
187 class ITK_TEMPLATE_EXPORT GreaterEqual : public LogicOpBase<TInput1, TInput2, TOutput>
188 {
189 public:
191 
192  bool
193  operator==(const Self &) const
194  {
195  return true;
196  }
197 
198  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
199 
200  inline TOutput
201  operator()(const TInput1 & A, const TInput2 & B) const
202  {
203  if (A >= B)
204  {
205  return this->m_ForegroundValue;
206  }
207  return this->m_BackgroundValue;
208  }
209 };
210 
211 
221 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
222 class ITK_TEMPLATE_EXPORT Greater : public LogicOpBase<TInput1, TInput2, TOutput>
223 {
224 public:
225  using Self = Greater;
226 
227  bool
228  operator==(const Self &) const
229  {
230  return true;
231  }
232 
233  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
234 
235  inline TOutput
236  operator()(const TInput1 & A, const TInput2 & B) const
237  {
238  if (A > B)
239  {
240  return this->m_ForegroundValue;
241  }
242  return this->m_BackgroundValue;
243  }
244 };
245 
246 
256 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
257 class ITK_TEMPLATE_EXPORT LessEqual : public LogicOpBase<TInput1, TInput2, TOutput>
258 {
259 public:
260  using Self = LessEqual;
261 
262  bool
263  operator==(const Self &) const
264  {
265  return true;
266  }
267 
268  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
269 
270  inline TOutput
271  operator()(const TInput1 & A, const TInput2 & B) const
272  {
273  if (A <= B)
274  {
275  return this->m_ForegroundValue;
276  }
277  return this->m_BackgroundValue;
278  }
279 };
280 
281 
291 template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
292 class ITK_TEMPLATE_EXPORT Less : public LogicOpBase<TInput1, TInput2, TOutput>
293 {
294 public:
295  using Self = Less;
296 
297  bool
298  operator==(const Self &) const
299  {
300  return true;
301  }
302 
303  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
304 
305  inline TOutput
306  operator()(const TInput1 & A, const TInput2 & B) const
307  {
308  if (A < B)
309  {
310  return this->m_ForegroundValue;
311  }
312  return this->m_BackgroundValue;
313  }
314 };
315 
316 
322 template <typename TInput, typename TOutput = TInput>
323 class ITK_TEMPLATE_EXPORT NOT : public LogicOpBase<TInput, TInput, TOutput>
324 {
325 public:
326  bool
327  operator==(const NOT &) const
328  {
329  return true;
330  }
331 
332  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(NOT);
333 
334  inline TOutput
335  operator()(const TInput & A) const
336  {
337  if (!A)
338  {
339  return this->m_ForegroundValue;
340  }
341  return this->m_BackgroundValue;
342  }
343 };
344 
350 template <typename TInput1, typename TInput2, typename TInput3, typename TOutput>
351 class ITK_TEMPLATE_EXPORT TernaryOperator
352 {
353 public:
354  bool
356  {
357  return true;
358  }
359 
360  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TernaryOperator);
361 
362  inline TOutput
363  operator()(const TInput1 & A, const TInput2 & B, const TInput3 & C) const
364  {
365  if (A)
366  {
367  return static_cast<TOutput>(B);
368  }
369  else
370  {
371  return static_cast<TOutput>(C);
372  }
373  }
374 };
375 
376 } // namespace Functor
377 } // namespace itk
378 
379 #endif
itk::Functor::Greater
Functor for > operation on images and constants.
Definition: itkLogicOpsFunctors.h:222
itk::Functor::Less::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:306
itk::Functor::GreaterEqual
Functor for >= operation on images and constants.
Definition: itkLogicOpsFunctors.h:187
itk::Functor::Greater::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:228
itk::Functor::TernaryOperator::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B, const TInput3 &C) const
Definition: itkLogicOpsFunctors.h:363
itk::Functor::NOT::operator()
TOutput operator()(const TInput &A) const
Definition: itkLogicOpsFunctors.h:335
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:201
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:323
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:726
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:737
itk::Functor::Less::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:298
itk::Functor::GreaterEqual::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:193
itk::Functor::NotEqual::operator==
bool operator==(const Self &) const
Definition: itkLogicOpsFunctors.h:158
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:263
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:157
itk::Functor::NOT::operator==
bool operator==(const NOT &) const
Definition: itkLogicOpsFunctors.h:327
itk::Functor::Greater::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:236
itk::Functor::LessEqual::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:271
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:257
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:124
itk::Functor::TernaryOperator
Return argument 2 if argument 1 is false, and argument 3 otherwise.
Definition: itkLogicOpsFunctors.h:351
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:166
itk::Functor::NotEqual
Functor for != operation on images and constants.
Definition: itkLogicOpsFunctors.h:152
itkNumericTraits.h
itk::Functor::Equal::operator()
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Definition: itkLogicOpsFunctors.h:132
itk::Functor::LogicOpBase::GetBackgroundValue
TOutput GetBackgroundValue() const
Definition: itkLogicOpsFunctors.h:97
AddImageFilter
Definition: itkAddImageFilter.h:81
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:292
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:355