DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LightExplicitDigitalSurface.ih
1 
30 
31 #include <cstdlib>
32 #include <iterator>
33 #include "DGtal/kernel/sets/SetPredicate.h"
34 #include "DGtal/topology/CVertexPredicate.h"
35 #include "DGtal/topology/helpers/Surfaces.h"
37 
39 // IMPLEMENTATION of inline methods.
41 
42 //-----------------------------------------------------------------------------
43 template <typename TKSpace, typename TSurfelPredicate>
44 inline
47 {}
48 //-----------------------------------------------------------------------------
49 template <typename TKSpace, typename TSurfelPredicate>
50 inline
53  const Surfel & s )
54  : mySurface( aSurface ), myNeighborhood()
55 {
58  s );
59 }
60 //-----------------------------------------------------------------------------
61 template <typename TKSpace, typename TSurfelPredicate>
62 inline
64 ::Tracker( const Tracker & other )
65  : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
66 {
67 }
68 //-----------------------------------------------------------------------------
69 template <typename TKSpace, typename TSurfelPredicate>
70 inline
72 ::DigitalSurfaceContainer &
74 ::surface() const
75 {
76  return mySurface;
77 }
78 //-----------------------------------------------------------------------------
79 template <typename TKSpace, typename TSurfelPredicate>
80 inline
82 ::Surfel &
84 ::current() const
85 {
86  return myNeighborhood.surfel();
87 }
88 //-----------------------------------------------------------------------------
89 template <typename TKSpace, typename TSurfelPredicate>
90 inline
93 ::orthDir() const
94 {
95  return myNeighborhood.orthDir();
96 }
97 //-----------------------------------------------------------------------------
98 template <typename TKSpace, typename TSurfelPredicate>
99 inline
100 void
102 ::move( const Surfel & s )
103 {
104  ASSERT( surface().isInside( s ) );
105  myNeighborhood.setSurfel( s );
106 }
107 //-----------------------------------------------------------------------------
108 template <typename TKSpace, typename TSurfelPredicate>
109 inline
112 ::adjacent( Surfel & s, Dimension d, bool pos ) const
113 {
114  return static_cast<uint8_t>
115  ( myNeighborhood.getAdjacentOnSurfelPredicate
116  ( s, surface().surfelPredicate(), d, pos ) );
117 }
118 
120 // ----------------------- Standard services ------------------------------
121 
122 //-----------------------------------------------------------------------------
123 template <typename TKSpace, typename TSurfelPredicate>
124 inline
126 {
127 }
128 //-----------------------------------------------------------------------------
129 template <typename TKSpace, typename TSurfelPredicate>
130 inline
133  : myKSpace( other.myKSpace ),
136  mySurfel( other.mySurfel ),
137  myTracker( *this, other.mySurfel )
138 {
139 }
140 //-----------------------------------------------------------------------------
141 template <typename TKSpace, typename TSurfelPredicate>
142 inline
144 ( const KSpace & aKSpace,
145  const SurfelPredicate & aSP,
146  const Adjacency & adj,
147  const Surfel & s )
148  : myKSpace( aKSpace ), mySurfelPredicate( aSP ), mySurfelAdjacency( adj ),
149  mySurfel( s ), myTracker( *this, s )
150 {
151 }
152 //-----------------------------------------------------------------------------
153 template <typename TKSpace, typename TSurfelPredicate>
154 inline
155 const
158 {
159  return mySurfelAdjacency;
160 }
161 //-----------------------------------------------------------------------------
162 template <typename TKSpace, typename TSurfelPredicate>
163 inline
166 {
167  return mySurfelAdjacency;
168 }
169 //-----------------------------------------------------------------------------
170 template <typename TKSpace, typename TSurfelPredicate>
171 inline
172 const
175 {
176  return mySurfelPredicate;
177 }
178 //-----------------------------------------------------------------------------
179 template <typename TKSpace, typename TSurfelPredicate>
180 inline
181 const
184 {
185  return mySurfel;
186 }
187 //-----------------------------------------------------------------------------
188 template <typename TKSpace, typename TSurfelPredicate>
189 inline
190 void
192 {
193  mySurfel = aSurfel;
194  ASSERT( myKSpace.sIsSurfel( mySurfel ) );
195  ASSERT( mySurfelPredicate( mySurfel ) );
196 
197  myTracker = Tracker( *this, mySurfel );
198 }
199 
200 //-----------------------------------------------------------------------------
201 // --------- CDigitalSurfaceContainer realization -------------------------
202 //-----------------------------------------------------------------------------
203 template <typename TKSpace, typename TSurfelPredicate>
204 inline
207 {
208  return myKSpace;
209 }
210 //-----------------------------------------------------------------------------
211 template <typename TKSpace, typename TSurfelPredicate>
212 inline
213 bool
215 ( const Surfel & s ) const
216 {
217  return surfelPredicate()( s );
218 }
219 //-----------------------------------------------------------------------------
220 template <typename TKSpace, typename TSurfelPredicate>
221 inline
224 {
225  SelfVisitor* ptrVisitor = new SelfVisitor( *this, mySurfel );
226  ASSERT( ptrVisitor != 0 );
227  return SurfelConstIterator( ptrVisitor );
228 }
229 //-----------------------------------------------------------------------------
230 template <typename TKSpace, typename TSurfelPredicate>
231 inline
234 {
235  return SurfelConstIterator( 0 );
236 }
237 //-----------------------------------------------------------------------------
238 template <typename TKSpace, typename TSurfelPredicate>
239 inline
242 {
243  Size nb = 0;
244  for ( SurfelConstIterator it = begin(), it_end = end(); it != it_end; ++it )
245  ++nb;
246  return nb;
247 }
248 //-----------------------------------------------------------------------------
249 template <typename TKSpace, typename TSurfelPredicate>
250 inline
251 bool
253 {
254  return false;
255 }
256 //-----------------------------------------------------------------------------
257 template <typename TKSpace, typename TSurfelPredicate>
258 inline
261 ( const Surfel & s ) const
262 {
263  return new Tracker( *this, s );
264 }
265 //-----------------------------------------------------------------------------
266 template <typename TKSpace, typename TSurfelPredicate>
267 inline
270 {
271  return CONNECTED;
272 }
273 //-----------------------------------------------------------------------------
274 // ----------------- UndirectedSimplePreGraph realization --------------------
275 //-----------------------------------------------------------------------------
276 template <typename TKSpace, typename TSurfelPredicate>
277 inline
280 ::degree( const Vertex & v ) const
281 {
282  Size d = 0;
283  Vertex s;
284  myTracker.move( v );
285  for ( typename KSpace::DirIterator q = space().sDirs( v );
286  q != 0; ++q )
287  {
288  if ( myTracker.adjacent( s, *q, true ) )
289  ++d;
290  if ( myTracker.adjacent( s, *q, false ) )
291  ++d;
292  }
293  return d;
294 }
295 //-----------------------------------------------------------------------------
296 template <typename TKSpace, typename TSurfelPredicate>
297 template <typename OutputIterator>
298 inline
299 void
301 ::writeNeighbors( OutputIterator & it,
302  const Vertex & v ) const
303 {
304  Vertex s;
305  myTracker.move( v );
306  for ( typename KSpace::DirIterator q = space().sDirs( v );
307  q != 0; ++q )
308  {
309  if ( myTracker.adjacent( s, *q, true ) )
310  *it++ = s;
311  if ( myTracker.adjacent( s, *q, false ) )
312  *it++ = s;
313  }
314 }
315 //-----------------------------------------------------------------------------
316 template <typename TKSpace, typename TSurfelPredicate>
317 template <typename OutputIterator, typename VertexPredicate>
318 inline
319 void
321 ::writeNeighbors( OutputIterator & it,
322  const Vertex & v,
323  const VertexPredicate & pred ) const
324 {
326  Vertex s;
327  myTracker.move( v );
328  for ( typename KSpace::DirIterator q = space().sDirs( v );
329  q != 0; ++q )
330  {
331  if ( myTracker.adjacent( s, *q, true ) )
332  {
333  if ( pred( s ) ) *it++ = s;
334  }
335  if ( myTracker.adjacent( s, *q, false ) )
336  {
337  if ( pred( s ) ) *it++ = s;
338  }
339  }
340 }
341 //-----------------------------------------------------------------------------
342 template <typename TKSpace, typename TSurfelPredicate>
343 inline
347 {
348  return KSpace::dimension * 2 - 2;
349 }
350 
351 
352 // ------------------------- Hidden services ------------------------------
353 
355 // Interface - public :
356 
361 template <typename TKSpace, typename TSurfelPredicate>
362 inline
363 void
365 {
366  out << "[LightExplicitDigitalSurface]";
367 }
368 
373 template <typename TKSpace, typename TSurfelPredicate>
374 inline
375 bool
377 {
378  return true;
379 }
380 
381 
382 
384 // Implementation of inline functions //
385 
386 template <typename TKSpace, typename TSurfelPredicate>
387 inline
388 std::ostream&
389 DGtal::operator<< ( std::ostream & out,
391 {
392  object.selfDisplay( out );
393  return out;
394 }
395 
396 // //
398 
399