ITK  4.8.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 
23 
24 namespace itk
25 {
26 namespace Functor
27 {
28 
57 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
59 {
60 public:
61  typedef LogicOpBase Self;
63  {
66  }
67 
69 
70 
71  bool operator!=( const Self & ) const
72  {
73  return false;
74  }
75  bool operator==( const Self & other ) const
76  {
77  return !(*this != other);
78  }
79 
80  void SetForegroundValue(const TOutput &FG)
81  {
83  }
84  void SetBackgroundValue(const TOutput &BG)
85  {
87  }
88 
89  TOutput GetForegroundValue() const
90  {
91  return(m_ForegroundValue);
92  }
93  TOutput GetBackgroundValue() const
94  {
95  return(m_BackgroundValue);
96  }
97 
98 protected:
101 
102 };
103 
113 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
114 class Equal : public LogicOpBase<TInput1, TInput2, TOutput>
115 {
116 public:
117  typedef Equal Self;
118 
120  {};
122  {};
123 
124  bool operator!=( const Self & ) const
125  {
126  return false;
127  }
128  bool operator==( const Self & other ) const
129  {
130  return !(*this != other);
131  }
132  inline TOutput operator()( const TInput1 & A, const TInput2 & B)
133  {
134  if( A == static_cast<TInput1>(B) )
135  {
136  return this->m_ForegroundValue;
137  }
138  return this->m_BackgroundValue;
139  }
140 
141 };
151 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
152 class NotEqual : public LogicOpBase<TInput1, TInput2, TOutput>
153 {
154 public:
155  typedef NotEqual Self;
156 
157  NotEqual() {};
158  ~NotEqual() {};
159  bool operator!=( const Self & ) const
160  {
161  return false;
162  }
163  bool operator==( const Self & other ) const
164  {
165  return !(*this != other);
166  }
167  inline TOutput operator()( const TInput1 & A, const TInput2 & B)
168  {
169  if( A != B )
170  {
171  return this->m_ForegroundValue;
172  }
173  return this->m_BackgroundValue;
174  }
175 
176 };
177 
187 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
188 class GreaterEqual : public LogicOpBase<TInput1, TInput2, TOutput>
189 {
190 public:
194 
195  bool operator!=( const Self & ) const
196  {
197  return false;
198  }
199  bool operator==( const Self & other ) const
200  {
201  return !(*this != other);
202  }
203  inline TOutput operator()( const TInput1 & A, const TInput2 & B)
204  {
205  if( A >= B )
206  {
207  return this->m_ForegroundValue;
208  }
209  return this->m_BackgroundValue;
210  }
211 
212 };
222 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
223 class Greater : public LogicOpBase<TInput1, TInput2, TOutput>
224 {
225 public:
226  typedef Greater Self;
227  Greater() {};
228  ~Greater() {};
229  bool operator!=( const Self & ) const
230  {
231  return false;
232  }
233  bool operator==( const Self & other ) const
234  {
235  return !(*this != other);
236  }
237  inline TOutput operator()( const TInput1 & A, const TInput2 & B)
238  {
239  if( A > B )
240  {
241  return this->m_ForegroundValue;
242  }
243  return this->m_BackgroundValue;
244  }
245 };
255 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
256 class LessEqual : public LogicOpBase<TInput1, TInput2, TOutput>
257 {
258 public:
259  typedef LessEqual Self;
260 
263  bool operator!=( const Self & ) const
264  {
265  return false;
266  }
267  bool operator==( const Self & other ) const
268  {
269  return !(*this != other);
270  }
271  inline TOutput operator()( const TInput1 & A, const TInput2 & B)
272  {
273  if( A <= B )
274  {
275  return this->m_ForegroundValue;
276  }
277  return this->m_BackgroundValue;
278  }
279 
280 };
290 template< typename TInput1, typename TInput2=TInput1, typename TOutput=TInput1 >
291 class Less : public LogicOpBase<TInput1, TInput2, TOutput>
292 {
293 public:
294  typedef Less Self;
295  Less() {};
296  ~Less() {};
297  bool operator!=( const Self & ) const
298  {
299  return false;
300  }
301  bool operator==( const Self & other ) const
302  {
303  return !(*this != other);
304  }
305  inline TOutput operator()( const TInput1 & A, const TInput2 & B)
306  {
307  if( A < B )
308  {
309  return this->m_ForegroundValue;
310  }
311  return this->m_BackgroundValue;
312  }
313 
314 };
315 
316 
317 }
318 }
319 
320 #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
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
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