DGtal 1.3.0
Loading...
Searching...
No Matches
LightExplicitDigitalSurface.ih
1/**
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.
6 *
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.
11 *
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/>.
14 *
15 **/
16
17/**
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
21 *
22 * @date 2011/09/01
23 *
24 * Implementation of inline methods defined in LightExplicitDigitalSurface.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32#include <iterator>
33#include "DGtal/graph/CVertexPredicate.h"
34#include "DGtal/topology/helpers/Surfaces.h"
35//////////////////////////////////////////////////////////////////////////////
36
37///////////////////////////////////////////////////////////////////////////////
38// IMPLEMENTATION of inline methods.
39///////////////////////////////////////////////////////////////////////////////
40
41//-----------------------------------------------------------------------------
42template <typename TKSpace, typename TSurfelPredicate>
43inline
44DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
45::~Tracker()
46{}
47//-----------------------------------------------------------------------------
48template <typename TKSpace, typename TSurfelPredicate>
49inline
50DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
51::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
52 const Surfel & s )
53 : mySurface( aSurface ), myNeighborhood()
54{
55 myNeighborhood.init( & surface().space(),
56 & surface().surfelAdjacency(),
57 s );
58}
59//-----------------------------------------------------------------------------
60template <typename TKSpace, typename TSurfelPredicate>
61inline
62DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
63::Tracker( const Tracker & other )
64 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
65{
66}
67//-----------------------------------------------------------------------------
68template <typename TKSpace, typename TSurfelPredicate>
69inline
70const typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
71::DigitalSurfaceContainer &
72DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
73::surface() const
74{
75 return mySurface;
76}
77//-----------------------------------------------------------------------------
78template <typename TKSpace, typename TSurfelPredicate>
79inline
80const typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
81::Surfel &
82DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
83::current() const
84{
85 return myNeighborhood.surfel();
86}
87//-----------------------------------------------------------------------------
88template <typename TKSpace, typename TSurfelPredicate>
89inline
90DGtal::Dimension
91DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
92::orthDir() const
93{
94 return myNeighborhood.orthDir();
95}
96//-----------------------------------------------------------------------------
97template <typename TKSpace, typename TSurfelPredicate>
98inline
99void
100DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
101::move( const Surfel & s )
102{
103 ASSERT( surface().isInside( s ) );
104 myNeighborhood.setSurfel( s );
105}
106//-----------------------------------------------------------------------------
107template <typename TKSpace, typename TSurfelPredicate>
108inline
109DGtal::uint8_t
110DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
111::adjacent( Surfel & s, Dimension d, bool pos ) const
112{
113 return static_cast<uint8_t>
114 ( myNeighborhood.getAdjacentOnSurfelPredicate
115 ( s, surface().surfelPredicate(), d, pos ) );
116}
117
118///////////////////////////////////////////////////////////////////////////////
119// ----------------------- Standard services ------------------------------
120
121//-----------------------------------------------------------------------------
122template <typename TKSpace, typename TSurfelPredicate>
123inline
124DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::~LightExplicitDigitalSurface()
125{
126}
127//-----------------------------------------------------------------------------
128template <typename TKSpace, typename TSurfelPredicate>
129inline
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 )
137{
138}
139//-----------------------------------------------------------------------------
140template <typename TKSpace, typename TSurfelPredicate>
141inline
142DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::LightExplicitDigitalSurface
143( ConstAlias<KSpace> aKSpace,
144 ConstAlias<SurfelPredicate> aSP,
145 const Adjacency & adj,
146 const Surfel & s )
147 : myKSpace( aKSpace ), mySurfelPredicate( aSP ), mySurfelAdjacency( adj ),
148 mySurfel( s ), myTracker( *this, s )
149{
150}
151//-----------------------------------------------------------------------------
152template <typename TKSpace, typename TSurfelPredicate>
153inline
154const
155typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
156DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency() const
157{
158 return mySurfelAdjacency;
159}
160//-----------------------------------------------------------------------------
161template <typename TKSpace, typename TSurfelPredicate>
162inline
163typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
164DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency()
165{
166 return mySurfelAdjacency;
167}
168//-----------------------------------------------------------------------------
169template <typename TKSpace, typename TSurfelPredicate>
170inline
171const
172typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelPredicate &
173DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelPredicate() const
174{
175 return mySurfelPredicate;
176}
177//-----------------------------------------------------------------------------
178template <typename TKSpace, typename TSurfelPredicate>
179inline
180const
181typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Surfel &
182DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfel() const
183{
184 return mySurfel;
185}
186//-----------------------------------------------------------------------------
187template <typename TKSpace, typename TSurfelPredicate>
188inline
189void
190DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::setSurfel(const Surfel& aSurfel)
191{
192 mySurfel = aSurfel;
193 ASSERT( myKSpace.sIsSurfel( mySurfel ) );
194 ASSERT( mySurfelPredicate( mySurfel ) );
195
196 myTracker = Tracker( *this, mySurfel );
197}
198
199//-----------------------------------------------------------------------------
200// --------- CDigitalSurfaceContainer realization -------------------------
201//-----------------------------------------------------------------------------
202template <typename TKSpace, typename TSurfelPredicate>
203inline
204const typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::KSpace &
205DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::space() const
206{
207 return myKSpace;
208}
209//-----------------------------------------------------------------------------
210template <typename TKSpace, typename TSurfelPredicate>
211inline
212bool
213DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isInside
214( const Surfel & s ) const
215{
216 return surfelPredicate()( s );
217}
218//-----------------------------------------------------------------------------
219template <typename TKSpace, typename TSurfelPredicate>
220inline
221typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
222DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::begin() const
223{
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 );
229}
230//-----------------------------------------------------------------------------
231template <typename TKSpace, typename TSurfelPredicate>
232inline
233typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
234DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::end() const
235{
236 return SurfelConstIterator();
237}
238//-----------------------------------------------------------------------------
239template <typename TKSpace, typename TSurfelPredicate>
240inline
241typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
242DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::nbSurfels() const
243{
244 Size nb = 0;
245 for ( SurfelConstIterator it = begin(), it_end = end(); it != it_end; ++it )
246 ++nb;
247 return nb;
248}
249//-----------------------------------------------------------------------------
250template <typename TKSpace, typename TSurfelPredicate>
251inline
252bool
253DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::empty() const
254{
255 return false;
256}
257//-----------------------------------------------------------------------------
258template <typename TKSpace, typename TSurfelPredicate>
259inline
260typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::DigitalSurfaceTracker*
261DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::newTracker
262( const Surfel & s ) const
263{
264 return new Tracker( *this, s );
265}
266//-----------------------------------------------------------------------------
267template <typename TKSpace, typename TSurfelPredicate>
268inline
269DGtal::Connectedness
270DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::connectedness() const
271{
272 return CONNECTED;
273}
274//-----------------------------------------------------------------------------
275// ----------------- UndirectedSimplePreGraph realization --------------------
276//-----------------------------------------------------------------------------
277template <typename TKSpace, typename TSurfelPredicate>
278inline
279typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
280DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>
281::degree( const Vertex & v ) const
282{
283 Size d = 0;
284 Vertex s;
285 myTracker.move( v );
286 for ( typename KSpace::DirIterator q = space().sDirs( v );
287 q != 0; ++q )
288 {
289 if ( myTracker.adjacent( s, *q, true ) )
290 ++d;
291 if ( myTracker.adjacent( s, *q, false ) )
292 ++d;
293 }
294 return d;
295}
296//-----------------------------------------------------------------------------
297template <typename TKSpace, typename TSurfelPredicate>
298template <typename OutputIterator>
299inline
300void
301DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>
302::writeNeighbors( OutputIterator & it,
303 const Vertex & v ) const
304{
305 Vertex s;
306 myTracker.move( v );
307 for ( typename KSpace::DirIterator q = space().sDirs( v );
308 q != 0; ++q )
309 {
310 if ( myTracker.adjacent( s, *q, true ) )
311 *it++ = s;
312 if ( myTracker.adjacent( s, *q, false ) )
313 *it++ = s;
314 }
315}
316//-----------------------------------------------------------------------------
317template <typename TKSpace, typename TSurfelPredicate>
318template <typename OutputIterator, typename VertexPredicate>
319inline
320void
321DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>
322::writeNeighbors( OutputIterator & it,
323 const Vertex & v,
324 const VertexPredicate & pred ) const
325{
326 BOOST_CONCEPT_ASSERT(( concepts::CVertexPredicate< VertexPredicate > ));
327 Vertex s;
328 myTracker.move( v );
329 for ( typename KSpace::DirIterator q = space().sDirs( v );
330 q != 0; ++q )
331 {
332 if ( myTracker.adjacent( s, *q, true ) )
333 {
334 if ( pred( s ) ) *it++ = s;
335 }
336 if ( myTracker.adjacent( s, *q, false ) )
337 {
338 if ( pred( s ) ) *it++ = s;
339 }
340 }
341}
342//-----------------------------------------------------------------------------
343template <typename TKSpace, typename TSurfelPredicate>
344inline
345typename DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
346DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>
347::bestCapacity() const
348{
349 return KSpace::dimension * 2 - 2;
350}
351
352
353// ------------------------- Hidden services ------------------------------
354
355///////////////////////////////////////////////////////////////////////////////
356// Interface - public :
357
358/**
359 * Writes/Displays the object on an output stream.
360 * @param out the output stream where the object is written.
361 */
362template <typename TKSpace, typename TSurfelPredicate>
363inline
364void
365DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::selfDisplay ( std::ostream & out ) const
366{
367 out << "[LightExplicitDigitalSurface]";
368}
369
370/**
371 * Checks the validity/consistency of the object.
372 * @return 'true' if the object is valid, 'false' otherwise.
373 */
374template <typename TKSpace, typename TSurfelPredicate>
375inline
376bool
377DGtal::LightExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isValid() const
378{
379 return true;
380}
381
382
383
384///////////////////////////////////////////////////////////////////////////////
385// Implementation of inline functions //
386
387template <typename TKSpace, typename TSurfelPredicate>
388inline
389std::ostream&
390DGtal::operator<< ( std::ostream & out,
391 const LightExplicitDigitalSurface< TKSpace, TSurfelPredicate > & object )
392{
393 object.selfDisplay( out );
394 return out;
395}
396
397// //
398///////////////////////////////////////////////////////////////////////////////
399
400