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 //-----------------------------------------------------------------------------
42 template <typename TKSpace, typename TSurfelPredicate>
44 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
47 //-----------------------------------------------------------------------------
48 template <typename TKSpace, typename TSurfelPredicate>
50 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
51 ::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
53 : mySurface( aSurface ), myNeighborhood()
55 myNeighborhood.init( & surface().space(),
56 & surface().surfelAdjacency(),
59 //-----------------------------------------------------------------------------
60 template <typename TKSpace, typename TSurfelPredicate>
62 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
63 ::Tracker( const Tracker & other )
64 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
67 //-----------------------------------------------------------------------------
68 template <typename TKSpace, typename TSurfelPredicate>
70 const typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
71 ::DigitalSurfaceContainer &
72 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
77 //-----------------------------------------------------------------------------
78 template <typename TKSpace, typename TSurfelPredicate>
80 const typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
82 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
85 return myNeighborhood.surfel();
87 //-----------------------------------------------------------------------------
88 template <typename TKSpace, typename TSurfelPredicate>
91 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
94 return myNeighborhood.orthDir();
96 //-----------------------------------------------------------------------------
97 template <typename TKSpace, typename TSurfelPredicate>
100 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
101 ::move( const Surfel & s )
103 ASSERT( surface().isInside( s ) );
104 myNeighborhood.setSurfel( s );
106 //-----------------------------------------------------------------------------
107 template <typename TKSpace, typename TSurfelPredicate>
110 DGtal::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 //-----------------------------------------------------------------------------
122 template <typename TKSpace, typename TSurfelPredicate>
124 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::~LightExplicitDigitalSurface()
127 //-----------------------------------------------------------------------------
128 template <typename TKSpace, typename TSurfelPredicate>
130 DGtal::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 //-----------------------------------------------------------------------------
140 template <typename TKSpace, typename TSurfelPredicate>
142 DGtal::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 //-----------------------------------------------------------------------------
152 template <typename TKSpace, typename TSurfelPredicate>
155 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
156 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency() const
158 return mySurfelAdjacency;
160 //-----------------------------------------------------------------------------
161 template <typename TKSpace, typename TSurfelPredicate>
163 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
164 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency()
166 return mySurfelAdjacency;
168 //-----------------------------------------------------------------------------
169 template <typename TKSpace, typename TSurfelPredicate>
172 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelPredicate &
173 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelPredicate() const
175 return mySurfelPredicate;
177 //-----------------------------------------------------------------------------
178 template <typename TKSpace, typename TSurfelPredicate>
181 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Surfel &
182 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfel() const
186 //-----------------------------------------------------------------------------
187 template <typename TKSpace, typename TSurfelPredicate>
190 DGtal::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 //-----------------------------------------------------------------------------
202 template <typename TKSpace, typename TSurfelPredicate>
204 const typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::KSpace &
205 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::space() const
209 //-----------------------------------------------------------------------------
210 template <typename TKSpace, typename TSurfelPredicate>
213 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isInside
214 ( const Surfel & s ) const
216 return surfelPredicate()( s );
218 //-----------------------------------------------------------------------------
219 template <typename TKSpace, typename TSurfelPredicate>
221 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
222 DGtal::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 //-----------------------------------------------------------------------------
231 template <typename TKSpace, typename TSurfelPredicate>
233 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
234 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::end() const
236 return SurfelConstIterator();
238 //-----------------------------------------------------------------------------
239 template <typename TKSpace, typename TSurfelPredicate>
241 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
242 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::nbSurfels() const
245 for ( SurfelConstIterator it = begin(), it_end = end(); it != it_end; ++it )
249 //-----------------------------------------------------------------------------
250 template <typename TKSpace, typename TSurfelPredicate>
253 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::empty() const
257 //-----------------------------------------------------------------------------
258 template <typename TKSpace, typename TSurfelPredicate>
260 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::DigitalSurfaceTracker*
261 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::newTracker
262 ( const Surfel & s ) const
264 return new Tracker( *this, s );
266 //-----------------------------------------------------------------------------
267 template <typename TKSpace, typename TSurfelPredicate>
270 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::connectedness() const
274 //-----------------------------------------------------------------------------
275 // ----------------- UndirectedSimplePreGraph realization --------------------
276 //-----------------------------------------------------------------------------
277 template <typename TKSpace, typename TSurfelPredicate>
279 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
280 DGtal::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 //-----------------------------------------------------------------------------
297 template <typename TKSpace, typename TSurfelPredicate>
298 template <typename OutputIterator>
301 DGtal::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 //-----------------------------------------------------------------------------
317 template <typename TKSpace, typename TSurfelPredicate>
318 template <typename OutputIterator, typename VertexPredicate>
321 DGtal::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 //-----------------------------------------------------------------------------
343 template <typename TKSpace, typename TSurfelPredicate>
345 typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
346 DGtal::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.
362 template <typename TKSpace, typename TSurfelPredicate>
365 DGtal::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.
374 template <typename TKSpace, typename TSurfelPredicate>
377 DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isValid() const
384 ///////////////////////////////////////////////////////////////////////////////
385 // Implementation of inline functions //
387 template <typename TKSpace, typename TSurfelPredicate>
390 DGtal::operator<< ( std::ostream & out,
391 const LightExplicitDigitalSurface< TKSpace, TSurfelPredicate > & object )
393 object.selfDisplay( out );
398 ///////////////////////////////////////////////////////////////////////////////