DGtal 1.4.0
Loading...
Searching...
No Matches
BasicPointFunctors.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 BasicPointFunctors.ih
19 * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21 * @date 2012/02/02
22 *
23 * Implementation of inline methods defined in BasicPointFunctors.h
24 *
25 * This file is part of the DGtal library.
26 */
27
28
29//////////////////////////////////////////////////////////////////////////////
30#include <cstdlib>
31//////////////////////////////////////////////////////////////////////////////
32
33
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
37template <typename S>
38inline
39DGtal::functors::Projector<S>::Projector(const Integer& aDefaultInteger)
40 : myDims(), myDefaultInteger(aDefaultInteger)
41{ //default projection
42 Dimension k = 0;
43 for ( ; k < dimension; ++k)
44 {
45 myDims[k] = k;
46 }
47}
48
49
50template <typename S>
51template <typename TIterator>
52inline
53void
54DGtal::functors::Projector<S>::init( const TIterator& itb, const TIterator& ite )
55{
56 BOOST_STATIC_ASSERT ((boost::is_same< Dimension,
57 typename std::iterator_traits<TIterator>::value_type >::value));
58
59 TIterator it = itb;
60 Dimension k = 0;
61 for ( ; ( (k < dimension)&&(it != ite) ); ++it, ++k)
62 {
63 myDims[k] = *it;
64 }
65 for ( ; k < dimension; ++k)
66 {
67 myDims[k] = dimension;
68 }
69}
70
71
72template <typename S>
73inline
74void
75DGtal::functors::Projector<S>::initRemoveOneDim(const Dimension &dimRemoved)
76{
77 std::vector<Dimension> vectDims;
78 Dimension aCurrentPos = 0;
79 Dimension k=0;
80 for ( ; k < dimension; ++k)
81 {
82 if(k!=dimRemoved){
83 vectDims.push_back(aCurrentPos);
84 }
85 aCurrentPos++;
86 }
87 init(vectDims.begin(), vectDims.end());
88}
89
90
91
92
93template <typename S>
94inline
95void
96DGtal::functors::Projector<S>::initAddOneDim( const Dimension &newDim)
97{
98 std::vector<Dimension> vectDims;
99 Dimension maxIndex = dimension;
100 Dimension aCurrentPos = 0;
101 Dimension k=0;
102 for ( ; k < dimension; ++k)
103 {
104 if(k==newDim){
105 vectDims.push_back(maxIndex);
106 }else{
107 vectDims.push_back(aCurrentPos);
108 aCurrentPos++;
109 }
110 }
111 init(vectDims.begin(), vectDims.end());
112}
113
114
115
116template <typename S>
117template <typename TInputPoint>
118inline
119typename DGtal::functors::Projector<S>::Point
120DGtal::functors::Projector<S>::operator()( const TInputPoint& aPoint ) const
121{
122 BOOST_STATIC_ASSERT ((boost::is_same< typename TInputPoint::Coordinate,
123 Integer >::value));
124
125 Point res;
126
127 typename std::array<Dimension,dimension>::const_iterator it = myDims.begin();
128 typename std::array<Dimension,dimension>::const_iterator itEnd = myDims.end();
129
130 Dimension k = 0;
131 for ( ; it != itEnd; ++it, ++k)
132 {
133 Dimension l = *it;
134 if (l < TInputPoint::dimension)
135 res[k] = aPoint[l];
136 else
137 res[k] = myDefaultInteger;
138 }
139
140 return res;
141}
142//------------------------------------------------------------------------------
143
144template< typename TP, typename TD, typename TV >
145inline
146DGtal::functors::PointFunctorFromPointPredicateAndDomain< TP, TD, TV >::PointFunctorFromPointPredicateAndDomain
147( ConstAlias< PointPredicate > aPtrPredicate,
148 ConstAlias< Domain > aDomain,
149 const Value aTrueValue,
150 const Value aFalseValue )
151 : myPtrPredicate( &aPtrPredicate ), myDomain( &aDomain), myTrueValue( aTrueValue ), myFalseValue( aFalseValue )
152{
153
154}
155
156template< typename TP, typename TD, typename TV >
157inline
158DGtal::functors::PointFunctorFromPointPredicateAndDomain< TP, TD, TV >::PointFunctorFromPointPredicateAndDomain( const PointFunctorFromPointPredicateAndDomain & other )
159 : myPtrPredicate( other.myPtrPredicate ), myDomain( other.myDomain), myTrueValue( other.myTrueValue ), myFalseValue( other.myFalseValue )
160{
161}
162
163template< typename TP, typename TD, typename TV >
164inline
165typename DGtal::functors::PointFunctorFromPointPredicateAndDomain< TP, TD, TV >::Value
166DGtal::functors::PointFunctorFromPointPredicateAndDomain< TP, TD, TV >::operator()( const Point& aPoint ) const
167{
168 if( myDomain->isInside( aPoint ))
169 {
170 if( myPtrPredicate->operator()( aPoint ) )
171 return myTrueValue;
172 else
173 return myFalseValue;
174 }
175 return myFalseValue;
176}
177
178template <typename TP, typename TD, typename TV>
179inline
180DGtal::functors::PointFunctorFromPointPredicateAndDomain<TP,TD, TV> &
181DGtal::functors::PointFunctorFromPointPredicateAndDomain<TP,TD, TV>::operator=( const PointFunctorFromPointPredicateAndDomain<TP,TD,TV> &other)
182{
183 ASSERT( ( myDomain->lowerBound() <= other.myDomain->lowerBound() )
184 && ( myDomain->upperBound() >= other.myDomain->upperBound() )
185 && "This domain should include the domain of the other set in case of assignment." );
186
187 myPtrPredicate = other.myPtrPredicate;
188 myDomain = other.myDomain;
189 myTrueValue = other.myTrueValue;
190 myFalseValue = other.myFalseValue;
191
192 return *this;
193}
194
195// //
196///////////////////////////////////////////////////////////////////////////////
197
198