DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LightImplicitDigitalSurface.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 TPointPredicate>
44 inline
47 {}
48 //-----------------------------------------------------------------------------
49 template <typename TKSpace, typename TPointPredicate>
50 inline
53  const Surfel & s )
54  : mySurface( aSurface ), myNeighborhood()
55 {
58  s );
59 }
60 //-----------------------------------------------------------------------------
61 template <typename TKSpace, typename TPointPredicate>
62 inline
64 ::Tracker( const Tracker & other )
65  : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
66 {
67 }
68 //-----------------------------------------------------------------------------
69 template <typename TKSpace, typename TPointPredicate>
70 inline
72 ::DigitalSurfaceContainer &
74 ::surface() const
75 {
76  return mySurface;
77 }
78 //-----------------------------------------------------------------------------
79 template <typename TKSpace, typename TPointPredicate>
80 inline
82 ::Surfel &
84 ::current() const
85 {
86  return myNeighborhood.surfel();
87 }
88 //-----------------------------------------------------------------------------
89 template <typename TKSpace, typename TPointPredicate>
90 inline
93 ::orthDir() const
94 {
95  return myNeighborhood.orthDir();
96 }
97 //-----------------------------------------------------------------------------
98 template <typename TKSpace, typename TPointPredicate>
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 TPointPredicate>
109 inline
112 ::adjacent( Surfel & s, Dimension d, bool pos ) const
113 {
114  return static_cast<uint8_t>
115  ( myNeighborhood.getAdjacentOnPointPredicate( s, surface().pointPredicate(), d, pos ) );
116 }
117 
119 // ----------------------- Standard services ------------------------------
120 
121 //-----------------------------------------------------------------------------
122 template <typename TKSpace, typename TPointPredicate>
123 inline
125 {
126 }
127 //-----------------------------------------------------------------------------
128 template <typename TKSpace, typename TPointPredicate>
129 inline
132  : myKSpace( other.myKSpace ),
135  mySurfel( other.mySurfel ),
136  myTracker( *this, other.mySurfel )
137 {
138 }
139 //-----------------------------------------------------------------------------
140 template <typename TKSpace, typename TPointPredicate>
141 inline
143 ( const KSpace & aKSpace,
144  const PointPredicate & aPP,
145  const Adjacency & adj,
146  const Surfel & s )
147  : myKSpace( aKSpace ), myPointPredicate( aPP ), mySurfelAdjacency( adj ),
148  mySurfel( s ), myTracker( *this, s )
149 {
150 }
151 //-----------------------------------------------------------------------------
152 template <typename TKSpace, typename TPointPredicate>
153 inline
154 const
157 {
158  return mySurfelAdjacency;
159 }
160 //-----------------------------------------------------------------------------
161 template <typename TKSpace, typename TPointPredicate>
162 inline
165 {
166  return mySurfelAdjacency;
167 }
168 //-----------------------------------------------------------------------------
169 template <typename TKSpace, typename TPointPredicate>
170 inline
171 const
174 {
175  return myPointPredicate;
176 }
177 
178 //-----------------------------------------------------------------------------
179 // --------- CDigitalSurfaceContainer realization -------------------------
180 //-----------------------------------------------------------------------------
181 template <typename TKSpace, typename TPointPredicate>
182 inline
185 {
186  return myKSpace;
187 }
188 //-----------------------------------------------------------------------------
189 template <typename TKSpace, typename TPointPredicate>
190 inline
191 bool
193 ( const Surfel & s ) const
194 {
195  Dimension k = myKSpace.sOrthDir( s );
196  // checks if the surfel is on the space boundary.
197  if ( myKSpace.sIsMax( s, k ) || myKSpace.sIsMin( s, k ) )
198  return false;
199  // p1 must be in the set and p2 must not be in the set.
200  SCell spel1 = myKSpace.sDirectIncident( s, k );
201  Point p1 = myKSpace.sCoords( spel1 );
202  if ( myPointPredicate( p1 ) )
203  {
204  SCell spel2 = myKSpace.sIndirectIncident( s, k );
205  Point p2 = myKSpace.sCoords( spel2 );
206  return ! myPointPredicate( p2 );
207  }
208  return false;
209 }
210 //-----------------------------------------------------------------------------
211 template <typename TKSpace, typename TPointPredicate>
212 inline
215 {
216  SelfVisitor* ptrVisitor = new SelfVisitor( *this, mySurfel );
217  ASSERT( ptrVisitor != 0 );
218  return SurfelConstIterator( ptrVisitor );
219 }
220 //-----------------------------------------------------------------------------
221 template <typename TKSpace, typename TPointPredicate>
222 inline
225 {
226  return SurfelConstIterator( 0 );
227 }
228 //-----------------------------------------------------------------------------
229 template <typename TKSpace, typename TPointPredicate>
230 inline
233 {
234  Size nb = 0;
235  for ( SurfelConstIterator it = begin(), it_end = end(); it != it_end; ++it )
236  ++nb;
237  return nb;
238 }
239 //-----------------------------------------------------------------------------
240 template <typename TKSpace, typename TPointPredicate>
241 inline
242 bool
244 {
245  return false;
246 }
247 //-----------------------------------------------------------------------------
248 template <typename TKSpace, typename TPointPredicate>
249 inline
252 ( const Surfel & s ) const
253 {
254  return new Tracker( *this, s );
255 }
256 //-----------------------------------------------------------------------------
257 template <typename TKSpace, typename TPointPredicate>
258 inline
261 {
262  return CONNECTED;
263 }
264 //-----------------------------------------------------------------------------
265 // ----------------- UndirectedSimplePreGraph realization --------------------
266 //-----------------------------------------------------------------------------
267 template <typename TKSpace, typename TPointPredicate>
268 inline
271 ::degree( const Vertex & v ) const
272 {
273  Size d = 0;
274  Vertex s;
275  myTracker.move( v );
276  for ( typename KSpace::DirIterator q = space().sDirs( v );
277  q != 0; ++q )
278  {
279  if ( myTracker.adjacent( s, *q, true ) )
280  ++d;
281  if ( myTracker.adjacent( s, *q, false ) )
282  ++d;
283  }
284  return d;
285 }
286 //-----------------------------------------------------------------------------
287 template <typename TKSpace, typename TPointPredicate>
288 template <typename OutputIterator>
289 inline
290 void
292 ::writeNeighbors( OutputIterator & it,
293  const Vertex & v ) const
294 {
295  Vertex s;
296  myTracker.move( v );
297  for ( typename KSpace::DirIterator q = space().sDirs( v );
298  q != 0; ++q )
299  {
300  if ( myTracker.adjacent( s, *q, true ) )
301  *it++ = s;
302  if ( myTracker.adjacent( s, *q, false ) )
303  *it++ = s;
304  }
305 }
306 //-----------------------------------------------------------------------------
307 template <typename TKSpace, typename TPointPredicate>
308 template <typename OutputIterator, typename VertexPredicate>
309 inline
310 void
312 ::writeNeighbors( OutputIterator & it,
313  const Vertex & v,
314  const VertexPredicate & pred ) const
315 {
317  Vertex s;
318  myTracker.move( v );
319  for ( typename KSpace::DirIterator q = space().sDirs( v );
320  q != 0; ++q )
321  {
322  if ( myTracker.adjacent( s, *q, true ) )
323  {
324  if ( pred( s ) ) *it++ = s;
325  }
326  if ( myTracker.adjacent( s, *q, false ) )
327  {
328  if ( pred( s ) ) *it++ = s;
329  }
330  }
331 }
332 //-----------------------------------------------------------------------------
333 template <typename TKSpace, typename TPointPredicate>
334 inline
338 {
339  return KSpace::dimension * 2 - 2;
340 }
341 
342 
343 // ------------------------- Hidden services ------------------------------
344 
346 // Interface - public :
347 
352 template <typename TKSpace, typename TPointPredicate>
353 inline
354 void
356 {
357  out << "[LightImplicitDigitalSurface]";
358 }
359 
364 template <typename TKSpace, typename TPointPredicate>
365 inline
366 bool
368 {
369  return true;
370 }
371 
372 
373 
375 // Implementation of inline functions //
376 
377 template <typename TKSpace, typename TPointPredicate>
378 inline
379 std::ostream&
380 DGtal::operator<< ( std::ostream & out,
382 {
383  object.selfDisplay( out );
384  return out;
385 }
386 
387 // //
389 
390