DGtal  1.4.beta
BasicPointPredicates.ih
1 /**
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU Lesser General Public License as
4  * published by the Free Software Foundation, either version 3 of the
5  * License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  **/
16 
17 /**
18  * @file BasicPointPredicates.ih
19  * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20  * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
21  *
22  * @date 2010/07/10
23  *
24  * Implementation of inline methods defined in BasicPointPredicates.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 
30 //////////////////////////////////////////////////////////////////////////////
31 #include <cstdlib>
32 //////////////////////////////////////////////////////////////////////////////
33 
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
37 template <typename TPoint, bool boolCst>
38 inline
39 bool
40 DGtal::functors::ConstantPointPredicate<TPoint,boolCst>
41 ::operator()( const Point & p ) const
42 {
43  boost::ignore_unused_variable_warning(p);
44  return boolCst;
45 }
46 //------------------------------------------------------------------------------
47 template <typename TPoint>
48 inline
49 DGtal::functors::IsLowerPointPredicate<TPoint>
50 ::IsLowerPointPredicate( const Point & upperBound )
51  : myUpperBound( upperBound )
52 {
53 }
54 //------------------------------------------------------------------------------
55 template <typename TPoint>
56 inline
57 bool
58 DGtal::functors::IsLowerPointPredicate<TPoint>
59 ::operator()( const Point & p ) const
60 {
61  return p.isLower( myUpperBound );
62 }
63 
64 //------------------------------------------------------------------------------
65 template <typename TPoint>
66 inline
67 DGtal::functors::IsUpperPointPredicate<TPoint>
68 ::IsUpperPointPredicate( const Point & lowerBound )
69  : myLowerBound( lowerBound )
70 {
71 }
72 //------------------------------------------------------------------------------
73 template <typename TPoint>
74 inline
75 bool
76 DGtal::functors::IsUpperPointPredicate<TPoint>
77 ::operator()( const Point & p ) const
78 {
79  return p.isUpper( myLowerBound );
80 }
81 
82 //------------------------------------------------------------------------------
83 template <typename TPoint>
84 inline
85 DGtal::functors::IsWithinPointPredicate<TPoint>
86 ::IsWithinPointPredicate( const Point & lowerBound,
87  const Point & upperBound )
88  : myLowerBound( lowerBound ), myUpperBound( upperBound )
89 {
90 }
91 //------------------------------------------------------------------------------
92 template <typename TPoint>
93 inline
94 bool
95 DGtal::functors::IsWithinPointPredicate<TPoint>
96 ::operator()( const Point & p ) const
97 {
98  return p.isUpper( myLowerBound )
99  && p.isLower( myUpperBound );
100 }
101 
102 //------------------------------------------------------------------------------
103 template <typename TPointPredicate>
104 inline
105 DGtal::functors::NotPointPredicate<TPointPredicate>
106 ::NotPointPredicate( ConstAlias<PointPredicate> pred )
107  : myPred( &pred )
108 {
109 }
110 //------------------------------------------------------------------------------
111 template <typename TPointPredicate>
112 inline
113 bool
114 DGtal::functors::NotPointPredicate<TPointPredicate>
115 ::operator()( const Point & p ) const
116 {
117  return !(*myPred)( p );
118 }
119 //------------------------------------------------------------------------------
120 template <typename TPointPredicate>
121 inline
122 DGtal::functors::EqualPointPredicate<TPointPredicate>
123 ::EqualPointPredicate( const Point & aPoint )
124  : myPoint( aPoint )
125 {
126 }
127 //------------------------------------------------------------------------------
128 template <typename TPointPredicate>
129 inline
130 bool
131 DGtal::functors::EqualPointPredicate<TPointPredicate>
132 ::operator()( const Point & p ) const
133 {
134  return (myPoint == p);
135 }
136 //------------------------------------------------------------------------------
137 template <typename TPointPredicate1, typename TPointPredicate2, typename TBinaryFunctor>
138 inline
139 DGtal::functors::BinaryPointPredicate<TPointPredicate1,TPointPredicate2,TBinaryFunctor>
140 ::BinaryPointPredicate( ConstAlias<PointPredicate1> pred1, ConstAlias<PointPredicate2> pred2, ConstAlias<TBinaryFunctor> boolFunctor )
141  : myPred1( &pred1 ), myPred2( &pred2 ), myBoolFunctor( &boolFunctor )
142 {
143 }
144 //------------------------------------------------------------------------------
145 template <typename TPointPredicate1, typename TPointPredicate2, typename TBinaryFunctor>
146 inline
147 bool
148 DGtal::functors::BinaryPointPredicate<TPointPredicate1,TPointPredicate2,TBinaryFunctor>
149 ::operator()( const Point & p ) const
150 {
151  return myBoolFunctor->operator()( myPred1->operator()( p ),
152  myPred2->operator()( p ) );
153 }
154 //------------------------------------------------------------------------------
155 template <typename TPointPredicate1, typename TPointPredicate2>
156 inline
157 DGtal::functors::BinaryPointPredicate<TPointPredicate1,TPointPredicate2,DGtal::functors::AndBoolFct2>
158 ::BinaryPointPredicate( ConstAlias<PointPredicate1> pred1, ConstAlias<PointPredicate2> pred2, ConstAlias<DGtal::functors::AndBoolFct2> boolFunctor )
159  : myPred1( &pred1 ), myPred2( &pred2 ), myBoolFunctor( &boolFunctor )
160 {
161 }
162 //------------------------------------------------------------------------------
163 template <typename TPointPredicate1, typename TPointPredicate2>
164 inline
165 bool
166 DGtal::functors::BinaryPointPredicate<TPointPredicate1,TPointPredicate2,DGtal::functors::AndBoolFct2>
167 ::operator()( const Point & p ) const
168 {
169  return ( (myPred1->operator()( p )) && (myPred2->operator()( p )) );
170 }
171 //------------------------------------------------------------------------------
172 template <typename TPointPredicate1, typename TPointPredicate2>
173 inline
174 DGtal::functors::BinaryPointPredicate<TPointPredicate1,TPointPredicate2,DGtal::functors::OrBoolFct2>
175 ::BinaryPointPredicate( ConstAlias<PointPredicate1> pred1, ConstAlias<PointPredicate2> pred2, ConstAlias<DGtal::functors::OrBoolFct2> boolFunctor )
176  : myPred1( &pred1 ), myPred2( &pred2 ), myBoolFunctor( &boolFunctor )
177 {
178 }
179 //------------------------------------------------------------------------------
180 template <typename TPointPredicate1, typename TPointPredicate2>
181 inline
182 bool
183 DGtal::functors::BinaryPointPredicate<TPointPredicate1,TPointPredicate2,DGtal::functors::OrBoolFct2>
184 ::operator()( const Point & p ) const
185 {
186  return ( (myPred1->operator()( p )) || (myPred2->operator()( p )) );
187 }
188 //------------------------------------------------------------------------------
189 template <typename TPointFunctor, typename TPredicate>
190 inline
191 DGtal::functors::PointFunctorPredicate<TPointFunctor, TPredicate>
192 ::PointFunctorPredicate( ConstAlias<PointFunctor> aFun, ConstAlias<Predicate> aPred )
193  : myFun(&aFun), myPred(&aPred)
194 {
195 }
196 //------------------------------------------------------------------------------
197 template <typename TPointFunctor, typename TPredicate>
198 inline
199 bool
200 DGtal::functors::PointFunctorPredicate<TPointFunctor, TPredicate>
201 ::operator()( const Point & p ) const
202 {
203  return (*myPred)( (*myFun)( p ) );
204 }
205 // //
206 ///////////////////////////////////////////////////////////////////////////////