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/>.
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
24 * Implementation of inline methods defined in Shapes.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
32//////////////////////////////////////////////////////////////////////////////
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
38///////////////////////////////////////////////////////////////////////////////
39// ----------------------- Standard services ------------------------------
44template <typename TDomain>
46DGtal::Shapes<TDomain>::~Shapes()
52 * Removes the discrete ball (norm-1) of center [aCenter] and radius
53 * [aRadius] to the (perhaps non empty) set [aSet].
55 * @tparam TDigitalSet the type chosen for the digital set.
56 * @param aSet the set (modified) which will contain the discrete ball.
57 * @param aCenter the center of the ball.
58 * @param aRadius the radius of the ball.
60template <typename TDomain>
61template <typename TDigitalSet>
64DGtal::Shapes<TDomain>::removeNorm1Ball
66 const Point & aCenter,
67 UnsignedInteger aRadius )
69 Point v1( aCenter.diagonal( aRadius ) );
74 const Domain & domain = aSet.domain();
75 typedef DGtal::HyperRectDomain<Space> LocalSpace;
76 LocalSpace ballDomain( p1, p2 );
77 for ( typename LocalSpace::ConstIterator it = ballDomain.begin();
78 it != ballDomain.end();
81 if ( domain.isInside( *it )
82 && ( (*it - aCenter ).norm1() <= aRadius ) )
87 * Adds the discrete ball (norm-1) of center [aCenter] and radius
88 * [aRadius] to the (perhaps non empty) set [aSet].
90 * @tparam TDigitalSet the type chosen for the digital set.
91 * @param aSet the set (modified) which will contain the discrete ball.
92 * @param aCenter the center of the ball.
93 * @param aRadius the radius of the ball.
95template <typename TDomain>
96template <typename TDigitalSet>
99DGtal::Shapes<TDomain>::addNorm1Ball
101 const Point & aCenter,
102 UnsignedInteger aRadius )
104 Point v1( aCenter.diagonal( aRadius ) );
109 const Domain & domain = aSet.domain();
110 typedef DGtal::HyperRectDomain<Space> LocalSpace;
111 LocalSpace ballDomain( p1, p2 );
112 for ( typename LocalSpace::ConstIterator it = ballDomain.begin();
113 it != ballDomain.end();
116 if ( domain.isInside( *it )
117 && ( (*it - aCenter ).norm1() <= aRadius ) )
124 * Removes the discrete ball (norm-2) of center [aCenter] and radius
125 * [aRadius] to the (perhaps non empty) set [aSet].
127 * @tparam TDigitalSet the type chosen for the digital set.
128 * @param aSet the set (modified) which will contain the discrete ball.
129 * @param aCenter the center of the ball.
130 * @param aRadius the radius of the ball.
132template <typename TDomain>
133template <typename TDigitalSet>
136DGtal::Shapes<TDomain>::removeNorm2Ball
138 const Point & aCenter,
139 UnsignedInteger aRadius )
141 Point v1( aCenter.diagonal( aRadius ) );
146 const Domain & domain = aSet.domain();
147 typedef DGtal::HyperRectDomain<Space> LocalSpace;
148 LocalSpace ballDomain( p1, p2 );
149 for ( typename LocalSpace::ConstIterator it = ballDomain.begin();
150 it != ballDomain.end();
153 if ( domain.isInside( *it )
154 && ( (*it - aCenter ).norm() <= aRadius ) )
161 * Adds the discrete ball (norm-2) of center [aCenter] and radius
162 * [aRadius] to the (perhaps non empty) set [aSet].
164 * @tparam TDigitalSet the type chosen for the digital set.
165 * @param aSet the set (modified) which will contain the discrete ball.
166 * @param aCenter the center of the ball.
167 * @param aRadius the radius of the ball.
169template <typename TDomain>
170template <typename TDigitalSet>
173DGtal::Shapes<TDomain>::addNorm2Ball
175 const Point & aCenter,
176 UnsignedInteger aRadius )
178 Point v1( aCenter.diagonal( aRadius ) );
183 const Domain & domain = aSet.domain();
184 typedef DGtal::HyperRectDomain<Space> LocalSpace;
185 LocalSpace ballDomain( p1, p2 );
186 for ( typename LocalSpace::ConstIterator it = ballDomain.begin();
187 it != ballDomain.end();
190 if ( domain.isInside( *it )
191 && ( (*it - aCenter ).norm() <= aRadius ) )
196template <typename TDomain>
197template <typename TDigitalSet, typename ShapeFunctor>
199DGtal::Shapes<TDomain>::digitalShaper( TDigitalSet & aSet,
200 const ShapeFunctor & aFunctor)
202 typedef DGtal::HyperRectDomain<Space> LocalSpace;
204 BOOST_CONCEPT_ASSERT((concepts::CDigitalBoundedShape<ShapeFunctor>));
205 BOOST_CONCEPT_ASSERT((concepts::CDigitalOrientedShape<ShapeFunctor>));
208 Point pLow = aFunctor.getLowerBound();
209 Point pUpp = aFunctor.getUpperBound();
211 LocalSpace implicitDomain( pLow, pUpp );
212 for ( typename LocalSpace::ConstIterator it = implicitDomain.begin();
213 it != implicitDomain.end();
216 if ( aFunctor.orientation( *it ) == INSIDE || aFunctor.orientation( *it ) == ON )
222template <typename TDomain>
223template <typename TDigitalSet, typename ShapeFunctor>
225DGtal::Shapes<TDomain>::euclideanShaper( TDigitalSet & aSet,
226 const ShapeFunctor & aFunctor,
230 BOOST_CONCEPT_ASSERT((concepts::CEuclideanBoundedShape<ShapeFunctor>));
231 BOOST_CONCEPT_ASSERT((concepts::CEuclideanOrientedShape<ShapeFunctor>));
233 RealPoint pLow = aFunctor.getLowerBound();
234 RealPoint pUpp = aFunctor.getUpperBound();
235 GaussDigitizer<Space,ShapeFunctor> dig;
236 dig.attach( aFunctor ); // attaches the shape.
237 dig.init( pLow, pUpp, h);
239 // Creates a set from the digitizer.
240 Shapes<Domain>::digitalShaper( aSet, dig );
243template <typename TDomain>
244template <typename DigitalSet, typename PointPredicate>
246DGtal::Shapes<TDomain>::makeSetFromPointPredicate
248 const PointPredicate & aPP )
251 BOOST_CONCEPT_ASSERT(( concepts::CDigitalSet< DigitalSet > ));
252 BOOST_CONCEPT_ASSERT(( concepts::CPointPredicate< PointPredicate > ));
254 (( concepts::ConceptUtils::SameType< Domain, typename DigitalSet::Domain >::value ));
256 (( concepts::ConceptUtils::SameType< Point, typename PointPredicate::Point >::value ));
258 for ( ConstIterator it = aSet.domain().begin(),
259 it_end = aSet.domain().end(); it != it_end; ++it )
260 if ( aPP( *it ) ) aSet.insert( *it );
266///////////////////////////////////////////////////////////////////////////////
267// Interface - public :
270 * Writes/Displays the object on an output stream.
271 * @param out the output stream where the object is written.
273template <typename TDomain>
276DGtal::Shapes<TDomain>::selfDisplay ( std::ostream & out ) const
282 * Checks the validity/consistency of the object.
283 * @return 'true' if the object is valid, 'false' otherwise.
285template <typename TDomain>
288DGtal::Shapes<TDomain>::isValid() const
295///////////////////////////////////////////////////////////////////////////////
296// Implementation of inline functions //
298template <typename TDomain>
301DGtal::operator<< ( std::ostream & out,
302 const Shapes<TDomain> & object )
304 object.selfDisplay( out );
309///////////////////////////////////////////////////////////////////////////////