ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkLogicOpsFunctors.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  typedef LogicOpBase Self;
64  {
65  m_ForegroundValue=itk::NumericTraits<TOutput>::OneValue();
66  m_BackgroundValue=itk::NumericTraits<TOutput>::ZeroValue();
67  }
68 
70 
71 
72  bool operator!=( const Self & ) const
73  {
74  return false;
75  }
76  bool operator==( const Self & other ) const
77  {
78  return !(*this != other);
79  }
80 
81  void SetForegroundValue(const TOutput &FG)
82  {
83  m_ForegroundValue=FG;
84  }
85  void SetBackgroundValue(const TOutput &BG)
86  {
87  m_BackgroundValue=BG;
88  }
89 
90  TOutput GetForegroundValue() const
91  {
92  return(m_ForegroundValue);
93  }
94  TOutput GetBackgroundValue() const
95  {
96  return(m_BackgroundValue);
97  }
98 
99 protected:
102 
103 };
104 
114 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
115 class ITK_TEMPLATE_EXPORT Equal : public LogicOpBase<TInput1, TInput2, TOutput>
116 {
117 public:
118  typedef Equal Self;
119 
121  {};
123  {};
124 
125  bool operator!=( const Self & ) const
126  {
127  return false;
128  }
129  bool operator==( const Self & other ) const
130  {
131  return !(*this != other);
132  }
133  inline TOutput operator()( const TInput1 & A, const TInput2 & B) const
134  {
135  if( Math::ExactlyEquals(A, static_cast<TInput1>(B)) )
136  {
137  return this->m_ForegroundValue;
138  }
139  return this->m_BackgroundValue;
140  }
141 
142 };
152 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
153 class ITK_TEMPLATE_EXPORT NotEqual : public LogicOpBase<TInput1, TInput2, TOutput>
154 {
155 public:
156  typedef NotEqual Self;
157 
158  NotEqual() {};
159  ~NotEqual() {};
160  bool operator!=( const Self & ) const
161  {
162  return false;
163  }
164  bool operator==( const Self & other ) const
165  {
166  return !(*this != other);
167  }
168  inline TOutput operator()( const TInput1 & A, const TInput2 & B) const
169  {
170  if( Math::NotExactlyEquals(A, B) )
171  {
172  return this->m_ForegroundValue;
173  }
174  return this->m_BackgroundValue;
175  }
176 
177 };
178 
188 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
189 class ITK_TEMPLATE_EXPORT GreaterEqual : public LogicOpBase<TInput1, TInput2, TOutput>
190 {
191 public:
195 
196  bool operator!=( const Self & ) const
197  {
198  return false;
199  }
200  bool operator==( const Self & other ) const
201  {
202  return !(*this != other);
203  }
204  inline TOutput operator()( const TInput1 & A, const TInput2 & B) const
205  {
206  if( A >= B )
207  {
208  return this->m_ForegroundValue;
209  }
210  return this->m_BackgroundValue;
211  }
212 
213 };
214 
215 
224 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
225 class ITK_TEMPLATE_EXPORT Greater : public LogicOpBase<TInput1, TInput2, TOutput>
226 {
227 public:
228  typedef Greater Self;
229  Greater() {};
230  ~Greater() {};
231  bool operator!=( const Self & ) const
232  {
233  return false;
234  }
235  bool operator==( const Self & other ) const
236  {
237  return !(*this != other);
238  }
239  inline TOutput operator()( const TInput1 & A, const TInput2 & B) const
240  {
241  if( A > B )
242  {
243  return this->m_ForegroundValue;
244  }
245  return this->m_BackgroundValue;
246  }
247 };
248 
249 
258 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
259 class ITK_TEMPLATE_EXPORT LessEqual : public LogicOpBase<TInput1, TInput2, TOutput>
260 {
261 public:
262  typedef LessEqual Self;
263 
266  bool operator!=( const Self & ) const
267  {
268  return false;
269  }
270  bool operator==( const Self & other ) const
271  {
272  return !(*this != other);
273  }
274  inline TOutput operator()( const TInput1 & A, const TInput2 & B) const
275  {
276  if( A <= B )
277  {
278  return this->m_ForegroundValue;
279  }
280  return this->m_BackgroundValue;
281  }
282 
283 };
284 
285 
294 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
295 class ITK_TEMPLATE_EXPORT Less : public LogicOpBase<TInput1, TInput2, TOutput>
296 {
297 public:
298  typedef Less Self;
299  Less() {};
300  ~Less() {};
301  bool operator!=( const Self & ) const
302  {
303  return false;
304  }
305  bool operator==( const Self & other ) const
306  {
307  return !(*this != other);
308  }
309  inline TOutput operator()( const TInput1 & A, const TInput2 & B) const
310  {
311  if( A < B )
312  {
313  return this->m_ForegroundValue;
314  }
315  return this->m_BackgroundValue;
316  }
317 
318 };
319 
320 
326 template< typename TInput, typename TOutput = TInput >
327 class ITK_TEMPLATE_EXPORT NOT : public LogicOpBase<TInput, TInput, TOutput>
328 {
329 public:
330  NOT() {}
331  ~NOT() {}
332  bool operator!=(const NOT &) const
333  {
334  return false;
335  }
337 
338  bool operator==(const NOT & other) const
339  {
340  return !( *this != other );
341  }
342 
343  inline TOutput operator()(const TInput & A) const
344  {
345  if( !A )
346  {
347  return this->m_ForegroundValue;
348  }
349  return this->m_BackgroundValue;
350  }
351 };
352 
358 template< typename TInput1, typename TInput2, typename TInput3, typename TOutput >
359 class ITK_TEMPLATE_EXPORT TernaryOperator
360 {
361 public:
364  bool operator!=(const TernaryOperator &) const
365  {
366  return false;
367  }
369 
370  bool operator==(const TernaryOperator & other) const
371  {
372  return !( *this != other );
373  }
374 
375  inline TOutput operator()(const TInput1 & A,
376  const TInput2 & B,
377  const TInput3 & C) const
378  {
379  if (A)
380  {
381  return static_cast<TOutput>( B );
382  }
383  else
384  {
385  return static_cast<TOutput>( C );
386  }
387  }
388 };
389 
390 }
391 }
392 
393 #endif
bool operator!=(const Self &) const
bool operator==(const Self &other) const
bool operator!=(const Self &) const
void SetBackgroundValue(const TOutput &BG)
bool operator!=(const Self &) const
bool operator==(const Self &other) const
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potetially different types...
Definition: itkMath.h:710
Functor for != operation on images and constants.
bool operator!=(const Self &) const
Return argument 2 if argument 1 is false, and argument 3 otherwise.
TOutput operator()(const TInput1 &A, const TInput2 &B) const
TOutput operator()(const TInput1 &A, const TInput2 &B) const
TOutput operator()(const TInput1 &A, const TInput2 &B) const
TOutput operator()(const TInput &A) const
bool operator!=(const TernaryOperator &) const
Functor for == operation on images and constants.
bool operator!=(const Self &) const
TOutput GetBackgroundValue() const
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:721
Functor for &gt; operation on images and constants.
Functor for &gt;= operation on images and constants.
bool operator!=(const Self &) const
bool operator==(const TernaryOperator &other) const
Functor for &lt; operation on images and constants.
bool operator==(const Self &other) const
Unary logical NOT functor.
void SetForegroundValue(const TOutput &FG)
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Base class for some logic functors. Provides the Foreground and background setting methods...
TOutput operator()(const TInput1 &A, const TInput2 &B) const
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator==(const Self &other) const
bool operator==(const Self &other) const
bool operator==(const Self &other) const
Functor for &lt;= operation on images and constants.
bool operator==(const NOT &other) const
bool operator!=(const NOT &) const
bool operator==(const Self &other) const
TOutput GetForegroundValue() const
bool operator!=(const Self &) const
TOutput operator()(const TInput1 &A, const TInput2 &B, const TInput3 &C) const