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 //-----------------------------------------------------------------------------
42 template <typename TKSpace, typename TPointPredicate>
44 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
47 //-----------------------------------------------------------------------------
48 template <typename TKSpace, typename TPointPredicate>
50 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
51 ::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
53 : mySurface( aSurface ), myNeighborhood()
55 myNeighborhood.init( & surface().space(),
56 & surface().surfelAdjacency(),
59 //-----------------------------------------------------------------------------
60 template <typename TKSpace, typename TPointPredicate>
62 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
63 ::Tracker( const Tracker & other )
64 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
67 //-----------------------------------------------------------------------------
68 template <typename TKSpace, typename TPointPredicate>
70 const typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
71 ::DigitalSurfaceContainer &
72 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
77 //-----------------------------------------------------------------------------
78 template <typename TKSpace, typename TPointPredicate>
80 const typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
82 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
85 return myNeighborhood.surfel();
87 //-----------------------------------------------------------------------------
88 template <typename TKSpace, typename TPointPredicate>
91 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
94 return myNeighborhood.orthDir();
96 //-----------------------------------------------------------------------------
97 template <typename TKSpace, typename TPointPredicate>
100 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
101 ::move( const Surfel & s )
103 ASSERT( surface().isInside( s ) );
104 myNeighborhood.setSurfel( s );
106 //-----------------------------------------------------------------------------
107 template <typename TKSpace, typename TPointPredicate>
110 DGtal::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 //-----------------------------------------------------------------------------
121 template <typename TKSpace, typename TPointPredicate>
123 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::~LightImplicitDigitalSurface()
126 //-----------------------------------------------------------------------------
127 template <typename TKSpace, typename TPointPredicate>
129 DGtal::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 //-----------------------------------------------------------------------------
139 template <typename TKSpace, typename TPointPredicate>
141 DGtal::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 //-----------------------------------------------------------------------------
151 template <typename TKSpace, typename TPointPredicate>
154 typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
155 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency() const
157 return mySurfelAdjacency;
159 //-----------------------------------------------------------------------------
160 template <typename TKSpace, typename TPointPredicate>
162 typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
163 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency()
165 return mySurfelAdjacency;
167 //-----------------------------------------------------------------------------
168 template <typename TKSpace, typename TPointPredicate>
171 typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::PointPredicate &
172 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::pointPredicate() const
174 return myPointPredicate;
177 //-----------------------------------------------------------------------------
178 // --------- CDigitalSurfaceContainer realization -------------------------
179 //-----------------------------------------------------------------------------
180 template <typename TKSpace, typename TPointPredicate>
182 const typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::KSpace &
183 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::space() const
187 //-----------------------------------------------------------------------------
188 template <typename TKSpace, typename TPointPredicate>
191 DGtal::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 //-----------------------------------------------------------------------------
210 template <typename TKSpace, typename TPointPredicate>
212 typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
213 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::begin() const
215 SelfVisitorRange range( new SelfVisitor( *this, mySurfel ) );
216 return range.begin();
218 //-----------------------------------------------------------------------------
219 template <typename TKSpace, typename TPointPredicate>
221 typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
222 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::end() const
224 return SurfelConstIterator();
226 //-----------------------------------------------------------------------------
227 template <typename TKSpace, typename TPointPredicate>
229 typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Size
230 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::nbSurfels() const
233 for ( SurfelConstIterator it = begin(), it_end = end(); it != it_end; ++it )
237 //-----------------------------------------------------------------------------
238 template <typename TKSpace, typename TPointPredicate>
241 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::empty() const
245 //-----------------------------------------------------------------------------
246 template <typename TKSpace, typename TPointPredicate>
248 typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::DigitalSurfaceTracker*
249 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::newTracker
250 ( const Surfel & s ) const
252 return new Tracker( *this, s );
254 //-----------------------------------------------------------------------------
255 template <typename TKSpace, typename TPointPredicate>
258 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::connectedness() const
262 //-----------------------------------------------------------------------------
263 // ----------------- UndirectedSimplePreGraph realization --------------------
264 //-----------------------------------------------------------------------------
265 template <typename TKSpace, typename TPointPredicate>
267 typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Size
268 DGtal::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 //-----------------------------------------------------------------------------
285 template <typename TKSpace, typename TPointPredicate>
286 template <typename OutputIterator>
289 DGtal::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 //-----------------------------------------------------------------------------
305 template <typename TKSpace, typename TPointPredicate>
306 template <typename OutputIterator, typename VertexPredicate>
309 DGtal::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 //-----------------------------------------------------------------------------
331 template <typename TKSpace, typename TPointPredicate>
333 typename DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::Size
334 DGtal::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.
350 template <typename TKSpace, typename TPointPredicate>
353 DGtal::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.
362 template <typename TKSpace, typename TPointPredicate>
365 DGtal::LightImplicitDigitalSurface<TKSpace,TPointPredicate>::isValid() const
372 ///////////////////////////////////////////////////////////////////////////////
373 // Implementation of inline functions //
375 template <typename TKSpace, typename TPointPredicate>
378 DGtal::operator<< ( std::ostream & out,
379 const LightImplicitDigitalSurface< TKSpace, TPointPredicate > & object )
381 object.selfDisplay( out );
386 ///////////////////////////////////////////////////////////////////////////////