DGtal 1.3.0
Loading...
Searching...
No Matches
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///////////////////////////////////////////////////////////////////////////////
37template <typename TPoint, bool boolCst>
38inline
39bool
40DGtal::functors::ConstantPointPredicate<TPoint,boolCst>
41::operator()( const Point & p ) const
42{
43 boost::ignore_unused_variable_warning(p);
44 return boolCst;
45}
46//------------------------------------------------------------------------------
47template <typename TPoint>
48inline
49DGtal::functors::IsLowerPointPredicate<TPoint>
50::IsLowerPointPredicate( const Point & upperBound )
51 : myUpperBound( upperBound )
52{
53}
54//------------------------------------------------------------------------------
55template <typename TPoint>
56inline
57bool
58DGtal::functors::IsLowerPointPredicate<TPoint>
59::operator()( const Point & p ) const
60{
61 return p.isLower( myUpperBound );
62}
63
64//------------------------------------------------------------------------------
65template <typename TPoint>
66inline
67DGtal::functors::IsUpperPointPredicate<TPoint>
68::IsUpperPointPredicate( const Point & lowerBound )
69 : myLowerBound( lowerBound )
70{
71}
72//------------------------------------------------------------------------------
73template <typename TPoint>
74inline
75bool
76DGtal::functors::IsUpperPointPredicate<TPoint>
77::operator()( const Point & p ) const
78{
79 return p.isUpper( myLowerBound );
80}
81
82//------------------------------------------------------------------------------
83template <typename TPoint>
84inline
85DGtal::functors::IsWithinPointPredicate<TPoint>
86::IsWithinPointPredicate( const Point & lowerBound,
87 const Point & upperBound )
88 : myLowerBound( lowerBound ), myUpperBound( upperBound )
89{
90}
91//------------------------------------------------------------------------------
92template <typename TPoint>
93inline
94bool
95DGtal::functors::IsWithinPointPredicate<TPoint>
96::operator()( const Point & p ) const
97{
98 return p.isUpper( myLowerBound )
99 && p.isLower( myUpperBound );
100}
101
102//------------------------------------------------------------------------------
103template <typename TPointPredicate>
104inline
105DGtal::functors::NotPointPredicate<TPointPredicate>
106::NotPointPredicate( ConstAlias<PointPredicate> pred )
107 : myPred( &pred )
108{
109}
110//------------------------------------------------------------------------------
111template <typename TPointPredicate>
112inline
113bool
114DGtal::functors::NotPointPredicate<TPointPredicate>
115::operator()( const Point & p ) const
116{
117 return !(*myPred)( p );
118}
119//------------------------------------------------------------------------------
120template <typename TPointPredicate>
121inline
122DGtal::functors::EqualPointPredicate<TPointPredicate>
123::EqualPointPredicate( const Point & aPoint )
124 : myPoint( aPoint )
125{
126}
127//------------------------------------------------------------------------------
128template <typename TPointPredicate>
129inline
130bool
131DGtal::functors::EqualPointPredicate<TPointPredicate>
132::operator()( const Point & p ) const
133{
134 return (myPoint == p);
135}
136//------------------------------------------------------------------------------
137template <typename TPointPredicate1, typename TPointPredicate2, typename TBinaryFunctor>
138inline
139DGtal::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//------------------------------------------------------------------------------
145template <typename TPointPredicate1, typename TPointPredicate2, typename TBinaryFunctor>
146inline
147bool
148DGtal::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//------------------------------------------------------------------------------
155template <typename TPointPredicate1, typename TPointPredicate2>
156inline
157DGtal::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//------------------------------------------------------------------------------
163template <typename TPointPredicate1, typename TPointPredicate2>
164inline
165bool
166DGtal::functors::BinaryPointPredicate<TPointPredicate1,TPointPredicate2,DGtal::functors::AndBoolFct2>
167::operator()( const Point & p ) const
168{
169 return ( (myPred1->operator()( p )) && (myPred2->operator()( p )) );
170}
171//------------------------------------------------------------------------------
172template <typename TPointPredicate1, typename TPointPredicate2>
173inline
174DGtal::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//------------------------------------------------------------------------------
180template <typename TPointPredicate1, typename TPointPredicate2>
181inline
182bool
183DGtal::functors::BinaryPointPredicate<TPointPredicate1,TPointPredicate2,DGtal::functors::OrBoolFct2>
184::operator()( const Point & p ) const
185{
186 return ( (myPred1->operator()( p )) || (myPred2->operator()( p )) );
187}
188//------------------------------------------------------------------------------
189template <typename TPointFunctor, typename TPredicate>
190inline
191DGtal::functors::PointFunctorPredicate<TPointFunctor, TPredicate>
192::PointFunctorPredicate( ConstAlias<PointFunctor> aFun, ConstAlias<Predicate> aPred )
193 : myFun(&aFun), myPred(&aPred)
194{
195}
196//------------------------------------------------------------------------------
197template <typename TPointFunctor, typename TPredicate>
198inline
199bool
200DGtal::functors::PointFunctorPredicate<TPointFunctor, TPredicate>
201::operator()( const Point & p ) const
202{
203 return (*myPred)( (*myFun)( p ) );
204}
205// //
206///////////////////////////////////////////////////////////////////////////////