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 LightExplicitDigitalSurface.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 LightExplicitDigitalSurface.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
33#include "DGtal/graph/CVertexPredicate.h"
34#include "DGtal/topology/helpers/Surfaces.h"
35//////////////////////////////////////////////////////////////////////////////
37///////////////////////////////////////////////////////////////////////////////
38// IMPLEMENTATION of inline methods.
39///////////////////////////////////////////////////////////////////////////////
41//-----------------------------------------------------------------------------
42template <typename TKSpace, typename TSurfelPredicate>
44DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
47//-----------------------------------------------------------------------------
48template <typename TKSpace, typename TSurfelPredicate>
50DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
51::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
53 : mySurface( aSurface ), myNeighborhood()
55 myNeighborhood.init( & surface().space(),
56 & surface().surfelAdjacency(),
59//-----------------------------------------------------------------------------
60template <typename TKSpace, typename TSurfelPredicate>
62DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
63::Tracker( const Tracker & other )
64 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
67//-----------------------------------------------------------------------------
68template <typename TKSpace, typename TSurfelPredicate>
70const typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
71::DigitalSurfaceContainer &
72DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
77//-----------------------------------------------------------------------------
78template <typename TKSpace, typename TSurfelPredicate>
80const typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
82DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
85 return myNeighborhood.surfel();
87//-----------------------------------------------------------------------------
88template <typename TKSpace, typename TSurfelPredicate>
91DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
94 return myNeighborhood.orthDir();
96//-----------------------------------------------------------------------------
97template <typename TKSpace, typename TSurfelPredicate>
100DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
101::move( const Surfel & s )
103 ASSERT( surface().isInside( s ) );
104 myNeighborhood.setSurfel( s );
106//-----------------------------------------------------------------------------
107template <typename TKSpace, typename TSurfelPredicate>
110DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
111::adjacent( Surfel & s, Dimension d, bool pos ) const
113 return static_cast<uint8_t>
114 ( myNeighborhood.getAdjacentOnSurfelPredicate
115 ( s, surface().surfelPredicate(), d, pos ) );
118///////////////////////////////////////////////////////////////////////////////
119// ----------------------- Standard services ------------------------------
121//-----------------------------------------------------------------------------
122template <typename TKSpace, typename TSurfelPredicate>
124DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::~LightExplicitDigitalSurface()
127//-----------------------------------------------------------------------------
128template <typename TKSpace, typename TSurfelPredicate>
130DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::LightExplicitDigitalSurface
131( const LightExplicitDigitalSurface & other )
132 : myKSpace( other.myKSpace ),
133 mySurfelPredicate( other.mySurfelPredicate ),
134 mySurfelAdjacency( other.mySurfelAdjacency ),
135 mySurfel( other.mySurfel ),
136 myTracker( *this, other.mySurfel )
139//-----------------------------------------------------------------------------
140template <typename TKSpace, typename TSurfelPredicate>
142DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::LightExplicitDigitalSurface
143( ConstAlias<KSpace> aKSpace,
144 ConstAlias<SurfelPredicate> aSP,
145 const Adjacency & adj,
147 : myKSpace( aKSpace ), mySurfelPredicate( aSP ), mySurfelAdjacency( adj ),
148 mySurfel( s ), myTracker( *this, s )
151//-----------------------------------------------------------------------------
152template <typename TKSpace, typename TSurfelPredicate>
155typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
156DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency() const
158 return mySurfelAdjacency;
160//-----------------------------------------------------------------------------
161template <typename TKSpace, typename TSurfelPredicate>
163typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
164DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency()
166 return mySurfelAdjacency;
168//-----------------------------------------------------------------------------
169template <typename TKSpace, typename TSurfelPredicate>
172typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelPredicate &
173DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelPredicate() const
175 return mySurfelPredicate;
177//-----------------------------------------------------------------------------
178template <typename TKSpace, typename TSurfelPredicate>
181typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Surfel &
182DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfel() const
186//-----------------------------------------------------------------------------
187template <typename TKSpace, typename TSurfelPredicate>
190DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::setSurfel(const Surfel& aSurfel)
193 ASSERT( myKSpace.sIsSurfel( mySurfel ) );
194 ASSERT( mySurfelPredicate( mySurfel ) );
196 myTracker = Tracker( *this, mySurfel );
199//-----------------------------------------------------------------------------
200// --------- CDigitalSurfaceContainer realization -------------------------
201//-----------------------------------------------------------------------------
202template <typename TKSpace, typename TSurfelPredicate>
204const typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::KSpace &
205DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::space() const
209//-----------------------------------------------------------------------------
210template <typename TKSpace, typename TSurfelPredicate>
213DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isInside
214( const Surfel & s ) const
216 return surfelPredicate()( s );
218//-----------------------------------------------------------------------------
219template <typename TKSpace, typename TSurfelPredicate>
221typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
222DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::begin() const
224 SelfVisitorRange range( new SelfVisitor( *this, mySurfel ) );
225 return range.begin();
226 // SelfVisitor* ptrVisitor = new SelfVisitor( *this, mySurfel );
227 // ASSERT( ptrVisitor != 0 );
228 // return SurfelConstIterator( ptrVisitor );
230//-----------------------------------------------------------------------------
231template <typename TKSpace, typename TSurfelPredicate>
233typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
234DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::end() const
236 return SurfelConstIterator();
238//-----------------------------------------------------------------------------
239template <typename TKSpace, typename TSurfelPredicate>
241typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
242DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::nbSurfels() const
245 for ( SurfelConstIterator it = begin(), it_end = end(); it != it_end; ++it )
249//-----------------------------------------------------------------------------
250template <typename TKSpace, typename TSurfelPredicate>
253DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::empty() const
257//-----------------------------------------------------------------------------
258template <typename TKSpace, typename TSurfelPredicate>
260typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::DigitalSurfaceTracker*
261DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::newTracker
262( const Surfel & s ) const
264 return new Tracker( *this, s );
266//-----------------------------------------------------------------------------
267template <typename TKSpace, typename TSurfelPredicate>
270DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::connectedness() const
274//-----------------------------------------------------------------------------
275// ----------------- UndirectedSimplePreGraph realization --------------------
276//-----------------------------------------------------------------------------
277template <typename TKSpace, typename TSurfelPredicate>
279typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
280DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>
281::degree( const Vertex & v ) const
286 for ( typename KSpace::DirIterator q = space().sDirs( v );
289 if ( myTracker.adjacent( s, *q, true ) )
291 if ( myTracker.adjacent( s, *q, false ) )
296//-----------------------------------------------------------------------------
297template <typename TKSpace, typename TSurfelPredicate>
298template <typename OutputIterator>
301DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>
302::writeNeighbors( OutputIterator & it,
303 const Vertex & v ) const
307 for ( typename KSpace::DirIterator q = space().sDirs( v );
310 if ( myTracker.adjacent( s, *q, true ) )
312 if ( myTracker.adjacent( s, *q, false ) )
316//-----------------------------------------------------------------------------
317template <typename TKSpace, typename TSurfelPredicate>
318template <typename OutputIterator, typename VertexPredicate>
321DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>
322::writeNeighbors( OutputIterator & it,
324 const VertexPredicate & pred ) const
326 BOOST_CONCEPT_ASSERT(( concepts::CVertexPredicate< VertexPredicate > ));
329 for ( typename KSpace::DirIterator q = space().sDirs( v );
332 if ( myTracker.adjacent( s, *q, true ) )
334 if ( pred( s ) ) *it++ = s;
336 if ( myTracker.adjacent( s, *q, false ) )
338 if ( pred( s ) ) *it++ = s;
342//-----------------------------------------------------------------------------
343template <typename TKSpace, typename TSurfelPredicate>
345typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
346DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>
347::bestCapacity() const
349 return KSpace::dimension * 2 - 2;
353// ------------------------- Hidden services ------------------------------
355///////////////////////////////////////////////////////////////////////////////
356// Interface - public :
359 * Writes/Displays the object on an output stream.
360 * @param out the output stream where the object is written.
362template <typename TKSpace, typename TSurfelPredicate>
365DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::selfDisplay ( std::ostream & out ) const
367 out << "[LightExplicitDigitalSurface]";
371 * Checks the validity/consistency of the object.
372 * @return 'true' if the object is valid, 'false' otherwise.
374template <typename TKSpace, typename TSurfelPredicate>
377DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isValid() const
384///////////////////////////////////////////////////////////////////////////////
385// Implementation of inline functions //
387template <typename TKSpace, typename TSurfelPredicate>
390DGtal::operator<< ( std::ostream & out,
391 const LightExplicitDigitalSurface< TKSpace, TSurfelPredicate > & object )
393 object.selfDisplay( out );
398///////////////////////////////////////////////////////////////////////////////