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 ImplicitDigitalSurface.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
24 * Implementation of inline methods defined in ImplicitDigitalSurface.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
33#include "DGtal/topology/helpers/Surfaces.h"
34//////////////////////////////////////////////////////////////////////////////
36///////////////////////////////////////////////////////////////////////////////
37// IMPLEMENTATION of inline methods.
38///////////////////////////////////////////////////////////////////////////////
40//-----------------------------------------------------------------------------
41template <typename TKSpace, typename TPointPredicate>
43DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
46//-----------------------------------------------------------------------------
47template <typename TKSpace, typename TPointPredicate>
49DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
50::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
52 : mySurface( aSurface ), myNeighborhood()
54 myNeighborhood.init( & surface().space(),
55 & surface().surfelAdjacency(),
58//-----------------------------------------------------------------------------
59template <typename TKSpace, typename TPointPredicate>
61DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
62::Tracker( const Tracker & other )
63 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
66//-----------------------------------------------------------------------------
67template <typename TKSpace, typename TPointPredicate>
69const typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
70::DigitalSurfaceContainer &
71DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
76//-----------------------------------------------------------------------------
77template <typename TKSpace, typename TPointPredicate>
79const typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
81DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
84 return myNeighborhood.surfel();
86//-----------------------------------------------------------------------------
87template <typename TKSpace, typename TPointPredicate>
90DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
93 return myNeighborhood.orthDir();
95//-----------------------------------------------------------------------------
96template <typename TKSpace, typename TPointPredicate>
99DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
100::move( const Surfel & s )
102 ASSERT( surface().isInside( s ) );
103 myNeighborhood.setSurfel( s );
105//-----------------------------------------------------------------------------
106template <typename TKSpace, typename TPointPredicate>
109DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
110::adjacent( Surfel & s, Dimension d, bool pos ) const
112 return static_cast<uint8_t>
113 ( myNeighborhood.getAdjacentOnPointPredicate( s, surface().pointPredicate(), d, pos ) );
116///////////////////////////////////////////////////////////////////////////////
117// ----------------------- Standard services ------------------------------
119//-----------------------------------------------------------------------------
120template <typename TKSpace, typename TPointPredicate>
122DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::~ImplicitDigitalSurface()
125//-----------------------------------------------------------------------------
126template <typename TKSpace, typename TPointPredicate>
128DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::ImplicitDigitalSurface
129( const ImplicitDigitalSurface & other )
130 : myKSpace( other.myKSpace ),
131 myPointPredicate( other.myPointPredicate ),
132 mySurfelAdjacency( other.mySurfelAdjacency ),
133 mySurfels( other. mySurfels )
136//-----------------------------------------------------------------------------
137template <typename TKSpace, typename TPointPredicate>
139DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::ImplicitDigitalSurface
140( ConstAlias<KSpace> aKSpace,
141 ConstAlias<PointPredicate> aPP,
142 const Adjacency & adj,
145 : myKSpace( aKSpace ), myPointPredicate( aPP ), mySurfelAdjacency( adj )
147 computeSurfels( s, closed );
149//-----------------------------------------------------------------------------
150template <typename TKSpace, typename TPointPredicate>
153typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
154DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency() const
156 return mySurfelAdjacency;
158//-----------------------------------------------------------------------------
159template <typename TKSpace, typename TPointPredicate>
161typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
162DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency()
164 return mySurfelAdjacency;
166//-----------------------------------------------------------------------------
167template <typename TKSpace, typename TPointPredicate>
170typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::PointPredicate &
171DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::pointPredicate() const
173 return myPointPredicate;
176//-----------------------------------------------------------------------------
177// --------- CDigitalSurfaceContainer realization -------------------------
178//-----------------------------------------------------------------------------
179template <typename TKSpace, typename TPointPredicate>
181const typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::KSpace &
182DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::space() const
186//-----------------------------------------------------------------------------
187template <typename TKSpace, typename TPointPredicate>
190DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::isInside
191( const Surfel & s ) const
193 Dimension k = myKSpace.sOrthDir( s );
194 // checks if the surfel is on the space boundary.
195 if ( myKSpace.sIsMax( s, k ) || myKSpace.sIsMin( s, k ) )
197 // p1 must be in the set and p2 must not be in the set.
198 SCell spel1 = myKSpace.sDirectIncident( s, k );
199 Point p1 = myKSpace.sCoords( spel1 );
200 if ( myPointPredicate( p1 ) )
202 SCell spel2 = myKSpace.sIndirectIncident( s, k );
203 Point p2 = myKSpace.sCoords( spel2 );
204 return ! myPointPredicate( p2 );
208//-----------------------------------------------------------------------------
209template <typename TKSpace, typename TPointPredicate>
211typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
212DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::begin() const
214 return mySurfels.begin();
216//-----------------------------------------------------------------------------
217template <typename TKSpace, typename TPointPredicate>
219typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
220DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::end() const
222 return mySurfels.end();
224//-----------------------------------------------------------------------------
225template <typename TKSpace, typename TPointPredicate>
227typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Size
228DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::nbSurfels() const
230 return static_cast<Size>(mySurfels.size());
232//-----------------------------------------------------------------------------
233template <typename TKSpace, typename TPointPredicate>
236DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::empty() const
238 return mySurfels.empty();
240//-----------------------------------------------------------------------------
241template <typename TKSpace, typename TPointPredicate>
243typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::DigitalSurfaceTracker*
244DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::newTracker
245( const Surfel & s ) const
247 return new Tracker( *this, s );
249//-----------------------------------------------------------------------------
250template <typename TKSpace, typename TPointPredicate>
253DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::connectedness() const
258// ------------------------- Hidden services ------------------------------
259//-----------------------------------------------------------------------------
260template <typename TKSpace, typename TPointPredicate>
263DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::computeSurfels
264( const Surfel & p, bool closed )
267 typename KSpace::SCellSet surface;
269 Surfaces<KSpace>::trackClosedBoundary( surface,
275 Surfaces<KSpace>::trackBoundary( surface,
280 for ( typename KSpace::SCellSet::const_iterator it = surface.begin(),
281 it_end = surface.end(); it != it_end; ++it )
282 mySurfels.push_back( *it );
285///////////////////////////////////////////////////////////////////////////////
286// Interface - public :
289 * Writes/Displays the object on an output stream.
290 * @param out the output stream where the object is written.
292template <typename TKSpace, typename TPointPredicate>
295DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::selfDisplay ( std::ostream & out ) const
297 out << "[ImplicitDigitalSurface]";
301 * Checks the validity/consistency of the object.
302 * @return 'true' if the object is valid, 'false' otherwise.
304template <typename TKSpace, typename TPointPredicate>
307DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::isValid() const
314///////////////////////////////////////////////////////////////////////////////
315// Implementation of inline functions //
317template <typename TKSpace, typename TPointPredicate>
320DGtal::operator<< ( std::ostream & out,
321 const ImplicitDigitalSurface<TKSpace,TPointPredicate> & object )
323 object.selfDisplay( out );
328///////////////////////////////////////////////////////////////////////////////