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 LightImplicitDigitalSurface.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 LightImplicitDigitalSurface.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 TPointPredicate>
44DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
47//-----------------------------------------------------------------------------
48template <typename TKSpace, typename TPointPredicate>
50DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
51::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
53 : mySurface( aSurface ), myNeighborhood()
55 myNeighborhood.init( & surface().space(),
56 & surface().surfelAdjacency(),
59//-----------------------------------------------------------------------------
60template <typename TKSpace, typename TPointPredicate>
62DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
63::Tracker( const Tracker & other )
64 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
67//-----------------------------------------------------------------------------
68template <typename TKSpace, typename TPointPredicate>
70const typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
71::DigitalSurfaceContainer &
72DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
77//-----------------------------------------------------------------------------
78template <typename TKSpace, typename TPointPredicate>
80const typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
82DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
85 return myNeighborhood.surfel();
87//-----------------------------------------------------------------------------
88template <typename TKSpace, typename TPointPredicate>
91DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
94 return myNeighborhood.orthDir();
96//-----------------------------------------------------------------------------
97template <typename TKSpace, typename TPointPredicate>
100DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
101::move( const Surfel & s )
103 ASSERT( surface().isInside( s ) );
104 myNeighborhood.setSurfel( s );
106//-----------------------------------------------------------------------------
107template <typename TKSpace, typename TPointPredicate>
110DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
111::adjacent( Surfel & s, Dimension d, bool pos ) const
113 return static_cast<uint8_t>
114 ( myNeighborhood.getAdjacentOnPointPredicate( s, surface().pointPredicate(), d, pos ) );
117///////////////////////////////////////////////////////////////////////////////
118// ----------------------- Standard services ------------------------------
120//-----------------------------------------------------------------------------
121template <typename TKSpace, typename TPointPredicate>
123DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::~LightImplicitDigitalSurface()
126//-----------------------------------------------------------------------------
127template <typename TKSpace, typename TPointPredicate>
129DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::LightImplicitDigitalSurface
130( const LightImplicitDigitalSurface & other )
131 : myKSpace( other.myKSpace ),
132 myPointPredicate( other.myPointPredicate ),
133 mySurfelAdjacency( other.mySurfelAdjacency ),
134 mySurfel( other.mySurfel ),
135 myTracker( *this, other.mySurfel )
138//-----------------------------------------------------------------------------
139template <typename TKSpace, typename TPointPredicate>
141DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::LightImplicitDigitalSurface
142( ConstAlias<KSpace> aKSpace,
143 ConstAlias<PointPredicate> aPP,
144 const Adjacency & adj,
146 : myKSpace( aKSpace ), myPointPredicate( aPP ), mySurfelAdjacency( adj ),
147 mySurfel( s ), myTracker( *this, s )
150//-----------------------------------------------------------------------------
151template <typename TKSpace, typename TPointPredicate>
154typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
155DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency() const
157 return mySurfelAdjacency;
159//-----------------------------------------------------------------------------
160template <typename TKSpace, typename TPointPredicate>
162typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
163DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency()
165 return mySurfelAdjacency;
167//-----------------------------------------------------------------------------
168template <typename TKSpace, typename TPointPredicate>
171typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::PointPredicate &
172DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::pointPredicate() const
174 return myPointPredicate;
177//-----------------------------------------------------------------------------
178// --------- CDigitalSurfaceContainer realization -------------------------
179//-----------------------------------------------------------------------------
180template <typename TKSpace, typename TPointPredicate>
182const typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::KSpace &
183DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::space() const
187//-----------------------------------------------------------------------------
188template <typename TKSpace, typename TPointPredicate>
191DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::isInside
192( const Surfel & s ) const
194 Dimension k = myKSpace.sOrthDir( s );
195 // checks if the surfel is on the space boundary.
196 if ( myKSpace.sIsMax( s, k ) || myKSpace.sIsMin( s, k ) )
198 // p1 must be in the set and p2 must not be in the set.
199 SCell spel1 = myKSpace.sDirectIncident( s, k );
200 Point p1 = myKSpace.sCoords( spel1 );
201 if ( myPointPredicate( p1 ) )
203 SCell spel2 = myKSpace.sIndirectIncident( s, k );
204 Point p2 = myKSpace.sCoords( spel2 );
205 return ! myPointPredicate( p2 );
209//-----------------------------------------------------------------------------
210template <typename TKSpace, typename TPointPredicate>
212typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
213DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::begin() const
215 SelfVisitorRange range( new SelfVisitor( *this, mySurfel ) );
216 return range.begin();
218//-----------------------------------------------------------------------------
219template <typename TKSpace, typename TPointPredicate>
221typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
222DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::end() const
224 return SurfelConstIterator();
226//-----------------------------------------------------------------------------
227template <typename TKSpace, typename TPointPredicate>
229typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Size
230DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::nbSurfels() const
233 for ( SurfelConstIterator it = begin(), it_end = end(); it != it_end; ++it )
237//-----------------------------------------------------------------------------
238template <typename TKSpace, typename TPointPredicate>
241DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::empty() const
245//-----------------------------------------------------------------------------
246template <typename TKSpace, typename TPointPredicate>
248typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::DigitalSurfaceTracker*
249DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::newTracker
250( const Surfel & s ) const
252 return new Tracker( *this, s );
254//-----------------------------------------------------------------------------
255template <typename TKSpace, typename TPointPredicate>
258DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::connectedness() const
262//-----------------------------------------------------------------------------
263// ----------------- UndirectedSimplePreGraph realization --------------------
264//-----------------------------------------------------------------------------
265template <typename TKSpace, typename TPointPredicate>
267typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Size
268DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>
269::degree( const Vertex & v ) const
274 for ( typename KSpace::DirIterator q = space().sDirs( v );
277 if ( myTracker.adjacent( s, *q, true ) )
279 if ( myTracker.adjacent( s, *q, false ) )
284//-----------------------------------------------------------------------------
285template <typename TKSpace, typename TPointPredicate>
286template <typename OutputIterator>
289DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>
290::writeNeighbors( OutputIterator & it,
291 const Vertex & v ) const
295 for ( typename KSpace::DirIterator q = space().sDirs( v );
298 if ( myTracker.adjacent( s, *q, true ) )
300 if ( myTracker.adjacent( s, *q, false ) )
304//-----------------------------------------------------------------------------
305template <typename TKSpace, typename TPointPredicate>
306template <typename OutputIterator, typename VertexPredicate>
309DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>
310::writeNeighbors( OutputIterator & it,
312 const VertexPredicate & pred ) const
314 BOOST_CONCEPT_ASSERT(( concepts::CVertexPredicate< VertexPredicate > ));
317 for ( typename KSpace::DirIterator q = space().sDirs( v );
320 if ( myTracker.adjacent( s, *q, true ) )
322 if ( pred( s ) ) *it++ = s;
324 if ( myTracker.adjacent( s, *q, false ) )
326 if ( pred( s ) ) *it++ = s;
330//-----------------------------------------------------------------------------
331template <typename TKSpace, typename TPointPredicate>
333typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Size
334DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>
335::bestCapacity() const
337 return KSpace::dimension * 2 - 2;
341// ------------------------- Hidden services ------------------------------
343///////////////////////////////////////////////////////////////////////////////
344// Interface - public :
347 * Writes/Displays the object on an output stream.
348 * @param out the output stream where the object is written.
350template <typename TKSpace, typename TPointPredicate>
353DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::selfDisplay ( std::ostream & out ) const
355 out << "[LightImplicitDigitalSurface]";
359 * Checks the validity/consistency of the object.
360 * @return 'true' if the object is valid, 'false' otherwise.
362template <typename TKSpace, typename TPointPredicate>
365DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::isValid() const
372///////////////////////////////////////////////////////////////////////////////
373// Implementation of inline functions //
375template <typename TKSpace, typename TPointPredicate>
378DGtal::operator<< ( std::ostream & out,
379 const LightImplicitDigitalSurface< TKSpace, TPointPredicate > & object )
381 object.selfDisplay( out );
386///////////////////////////////////////////////////////////////////////////////