DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImplicitDigitalSurface.ih
1 
30 
31 #include <cstdlib>
32 #include <iterator>
33 #include "DGtal/kernel/sets/SetPredicate.h"
34 #include "DGtal/topology/helpers/Surfaces.h"
36 
38 // IMPLEMENTATION of inline methods.
40 
41 //-----------------------------------------------------------------------------
42 template <typename TKSpace, typename TPointPredicate>
43 inline
46 {}
47 //-----------------------------------------------------------------------------
48 template <typename TKSpace, typename TPointPredicate>
49 inline
52  const Surfel & s )
53  : mySurface( aSurface ), myNeighborhood()
54 {
57  s );
58 }
59 //-----------------------------------------------------------------------------
60 template <typename TKSpace, typename TPointPredicate>
61 inline
63 ::Tracker( const Tracker & other )
64  : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
65 {
66 }
67 //-----------------------------------------------------------------------------
68 template <typename TKSpace, typename TPointPredicate>
69 inline
71 ::DigitalSurfaceContainer &
73 ::surface() const
74 {
75  return mySurface;
76 }
77 //-----------------------------------------------------------------------------
78 template <typename TKSpace, typename TPointPredicate>
79 inline
81 ::Surfel &
83 ::current() const
84 {
85  return myNeighborhood.surfel();
86 }
87 //-----------------------------------------------------------------------------
88 template <typename TKSpace, typename TPointPredicate>
89 inline
92 ::orthDir() const
93 {
94  return myNeighborhood().orthDir();
95 }
96 //-----------------------------------------------------------------------------
97 template <typename TKSpace, typename TPointPredicate>
98 inline
99 void
101 ::move( const Surfel & s )
102 {
103  ASSERT( surface().isInside( s ) );
104  myNeighborhood.setSurfel( s );
105 }
106 //-----------------------------------------------------------------------------
107 template <typename TKSpace, typename TPointPredicate>
108 inline
111 ::adjacent( Surfel & s, Dimension d, bool pos ) const
112 {
113  return static_cast<uint8_t>
114  ( myNeighborhood.getAdjacentOnPointPredicate( s, surface().pointPredicate(), d, pos ) );
115 }
116 
118 // ----------------------- Standard services ------------------------------
119 
120 //-----------------------------------------------------------------------------
121 template <typename TKSpace, typename TPointPredicate>
122 inline
124 {
125 }
126 //-----------------------------------------------------------------------------
127 template <typename TKSpace, typename TPointPredicate>
128 inline
130 ( const ImplicitDigitalSurface & other )
131  : myKSpace( other.myKSpace ),
134  mySurfels( other. mySurfels )
135 {
136 }
137 //-----------------------------------------------------------------------------
138 template <typename TKSpace, typename TPointPredicate>
139 inline
141 ( const KSpace & aKSpace,
142  const PointPredicate & aPP,
143  const Adjacency & adj,
144  const Surfel & s,
145  bool closed )
146  : myKSpace( aKSpace ), myPointPredicate( aPP ), mySurfelAdjacency( adj )
147 {
148  computeSurfels( s, closed );
149 }
150 //-----------------------------------------------------------------------------
151 template <typename TKSpace, typename TPointPredicate>
152 inline
153 const
156 {
157  return mySurfelAdjacency;
158 }
159 //-----------------------------------------------------------------------------
160 template <typename TKSpace, typename TPointPredicate>
161 inline
164 {
165  return mySurfelAdjacency;
166 }
167 //-----------------------------------------------------------------------------
168 template <typename TKSpace, typename TPointPredicate>
169 inline
170 const
173 {
174  return myPointPredicate;
175 }
176 
177 //-----------------------------------------------------------------------------
178 // --------- CDigitalSurfaceContainer realization -------------------------
179 //-----------------------------------------------------------------------------
180 template <typename TKSpace, typename TPointPredicate>
181 inline
184 {
185  return myKSpace;
186 }
187 //-----------------------------------------------------------------------------
188 template <typename TKSpace, typename TPointPredicate>
189 inline
190 bool
192 ( const Surfel & s ) const
193 {
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 ) )
197  return false;
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 ) )
202  {
203  SCell spel2 = myKSpace.sIndirectIncident( s, k );
204  Point p2 = myKSpace.sCoords( spel2 );
205  return ! myPointPredicate( p2 );
206  }
207  return false;
208 }
209 //-----------------------------------------------------------------------------
210 template <typename TKSpace, typename TPointPredicate>
211 inline
214 {
215  return mySurfels.begin();
216 }
217 //-----------------------------------------------------------------------------
218 template <typename TKSpace, typename TPointPredicate>
219 inline
222 {
223  return mySurfels.end();
224 }
225 //-----------------------------------------------------------------------------
226 template <typename TKSpace, typename TPointPredicate>
227 inline
230 {
231  return mySurfels.size();
232 }
233 //-----------------------------------------------------------------------------
234 template <typename TKSpace, typename TPointPredicate>
235 inline
236 bool
238 {
239  return mySurfels.empty();
240 }
241 //-----------------------------------------------------------------------------
242 template <typename TKSpace, typename TPointPredicate>
243 inline
246 ( const Surfel & s ) const
247 {
248  return new Tracker( *this, s );
249 }
250 //-----------------------------------------------------------------------------
251 template <typename TKSpace, typename TPointPredicate>
252 inline
255 {
256  return CONNECTED;
257 }
258 
259 // ------------------------- Hidden services ------------------------------
260 //-----------------------------------------------------------------------------
261 template <typename TKSpace, typename TPointPredicate>
262 inline
263 void
265 ( const Surfel & p, bool closed )
266 {
267  mySurfels.clear();
268  typename KSpace::SCellSet surface;
269  if ( closed )
271  myKSpace,
274  p );
275  else
277  myKSpace,
280  p );
281  for ( typename KSpace::SCellSet::const_iterator it = surface.begin(),
282  it_end = surface.end(); it != it_end; ++it )
283  mySurfels.push_back( *it );
284 }
285 
287 // Interface - public :
288 
293 template <typename TKSpace, typename TPointPredicate>
294 inline
295 void
297 {
298  out << "[ImplicitDigitalSurface]";
299 }
300 
305 template <typename TKSpace, typename TPointPredicate>
306 inline
307 bool
309 {
310  return true;
311 }
312 
313 
314 
316 // Implementation of inline functions //
317 
318 template <typename TKSpace, typename TPointPredicate>
319 inline
320 std::ostream&
321 DGtal::operator<< ( std::ostream & out,
323 {
324  object.selfDisplay( out );
325  return out;
326 }
327 
328 // //
330 
331