ITK  4.9.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 >
60 {
61 public:
62  typedef LogicOpBase Self;
64  {
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  {
84  }
85  void SetBackgroundValue(const TOutput &BG)
86  {
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 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)
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 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)
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 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)
205  {
206  if( A >= B )
207  {
208  return this->m_ForegroundValue;
209  }
210  return this->m_BackgroundValue;
211  }
212 
213 };
223 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
224 class Greater : public LogicOpBase<TInput1, TInput2, TOutput>
225 {
226 public:
227  typedef Greater Self;
228  Greater() {};
229  ~Greater() {};
230  bool operator!=( const Self & ) const
231  {
232  return false;
233  }
234  bool operator==( const Self & other ) const
235  {
236  return !(*this != other);
237  }
238  inline TOutput operator()( const TInput1 & A, const TInput2 & B)
239  {
240  if( A > B )
241  {
242  return this->m_ForegroundValue;
243  }
244  return this->m_BackgroundValue;
245  }
246 };
256 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
257 class LessEqual : public LogicOpBase<TInput1, TInput2, TOutput>
258 {
259 public:
260  typedef LessEqual Self;
261 
264  bool operator!=( const Self & ) const
265  {
266  return false;
267  }
268  bool operator==( const Self & other ) const
269  {
270  return !(*this != other);
271  }
272  inline TOutput operator()( const TInput1 & A, const TInput2 & B)
273  {
274  if( A <= B )
275  {
276  return this->m_ForegroundValue;
277  }
278  return this->m_BackgroundValue;
279  }
280 
281 };
291 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
292 class Less : public LogicOpBase<TInput1, TInput2, TOutput>
293 {
294 public:
295  typedef Less Self;
296  Less() {};
297  ~Less() {};
298  bool operator!=( const Self & ) const
299  {
300  return false;
301  }
302  bool operator==( const Self & other ) const
303  {
304  return !(*this != other);
305  }
306  inline TOutput operator()( const TInput1 & A, const TInput2 & B)
307  {
308  if( A < B )
309  {
310  return this->m_ForegroundValue;
311  }
312  return this->m_BackgroundValue;
313  }
314 
315 };
316 
317 
318 }
319 }
320 
321 #endif
TOutput operator()(const TInput1 &A, const TInput2 &B)
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:665
Functor for != operation on images and constants.
TOutput operator()(const TInput1 &A, const TInput2 &B)
bool operator!=(const Self &) const
TOutput operator()(const TInput1 &A, const TInput2 &B)
TOutput operator()(const TInput1 &A, const TInput2 &B)
TOutput operator()(const TInput1 &A, const TInput2 &B)
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:676
Functor for &gt; operation on images and constants.
Functor for &gt;= operation on images and constants.
bool operator!=(const Self &) const
Functor for &lt; operation on images and constants.
bool operator==(const Self &other) const
void SetForegroundValue(const TOutput &FG)
Base class for some logic functors. Provides the Foreground and background setting methods...
TOutput operator()(const TInput1 &A, const TInput2 &B)
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 Self &other) const
TOutput GetForegroundValue() const
bool operator!=(const Self &) const