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.
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.
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/>.
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
23 * Implementation of inline methods defined in BasicPointFunctors.h
25 * This file is part of the DGtal library.
29//////////////////////////////////////////////////////////////////////////////
31//////////////////////////////////////////////////////////////////////////////
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
39DGtal::functors::Projector<S>::Projector(const Integer& aDefaultInteger)
40 : myDims(), myDefaultInteger(aDefaultInteger)
43 for ( ; k < dimension; ++k)
51template <typename TIterator>
54DGtal::functors::Projector<S>::init( const TIterator& itb, const TIterator& ite )
56 BOOST_STATIC_ASSERT ((boost::is_same< Dimension,
57 typename std::iterator_traits<TIterator>::value_type >::value));
61 for ( ; ( (k < dimension)&&(it != ite) ); ++it, ++k)
65 for ( ; k < dimension; ++k)
67 myDims[k] = dimension;
75DGtal::functors::Projector<S>::initRemoveOneDim(const Dimension &dimRemoved)
77 std::vector<Dimension> vectDims;
78 Dimension aCurrentPos = 0;
80 for ( ; k < dimension; ++k)
83 vectDims.push_back(aCurrentPos);
87 init(vectDims.begin(), vectDims.end());
96DGtal::functors::Projector<S>::initAddOneDim( const Dimension &newDim)
98 std::vector<Dimension> vectDims;
99 Dimension maxIndex = dimension;
100 Dimension aCurrentPos = 0;
102 for ( ; k < dimension; ++k)
105 vectDims.push_back(maxIndex);
107 vectDims.push_back(aCurrentPos);
111 init(vectDims.begin(), vectDims.end());
117template <typename TInputPoint>
119typename DGtal::functors::Projector<S>::Point
120DGtal::functors::Projector<S>::operator()( const TInputPoint& aPoint ) const
122 BOOST_STATIC_ASSERT ((boost::is_same< typename TInputPoint::Coordinate,
127 typename std::array<Dimension,dimension>::const_iterator it = myDims.begin();
128 typename std::array<Dimension,dimension>::const_iterator itEnd = myDims.end();
131 for ( ; it != itEnd; ++it, ++k)
134 if (l < TInputPoint::dimension)
137 res[k] = myDefaultInteger;
142//------------------------------------------------------------------------------
144template< typename TP, typename TD, typename TV >
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 )
156template< typename TP, typename TD, typename TV >
158DGtal::functors::PointFunctorFromPointPredicateAndDomain< TP, TD, TV >::PointFunctorFromPointPredicateAndDomain( const PointFunctorFromPointPredicateAndDomain & other )
159 : myPtrPredicate( other.myPtrPredicate ), myDomain( other.myDomain), myTrueValue( other.myTrueValue ), myFalseValue( other.myFalseValue )
163template< typename TP, typename TD, typename TV >
165typename DGtal::functors::PointFunctorFromPointPredicateAndDomain< TP, TD, TV >::Value
166DGtal::functors::PointFunctorFromPointPredicateAndDomain< TP, TD, TV >::operator()( const Point& aPoint ) const
168 if( myDomain->isInside( aPoint ))
170 if( myPtrPredicate->operator()( aPoint ) )
178template <typename TP, typename TD, typename TV>
180DGtal::functors::PointFunctorFromPointPredicateAndDomain<TP,TD, TV> &
181DGtal::functors::PointFunctorFromPointPredicateAndDomain<TP,TD, TV>::operator=( const PointFunctorFromPointPredicateAndDomain<TP,TD,TV> &other)
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." );
187 myPtrPredicate = other.myPtrPredicate;
188 myDomain = other.myDomain;
189 myTrueValue = other.myTrueValue;
190 myFalseValue = other.myFalseValue;
196///////////////////////////////////////////////////////////////////////////////