DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DigitalSetBoundary.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 TDigitalSet>
43 inline
46 {}
47 //-----------------------------------------------------------------------------
48 template <typename TKSpace, typename TDigitalSet>
49 inline
52  const Surfel & s )
53  : mySurface( aSurface ), myNeighborhood()
54 {
57  s );
58 }
59 //-----------------------------------------------------------------------------
60 template <typename TKSpace, typename TDigitalSet>
61 inline
63 ::Tracker( const Tracker & other )
64  : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
65 {
66 }
67 //-----------------------------------------------------------------------------
68 template <typename TKSpace, typename TDigitalSet>
69 inline
71 ::DigitalSurfaceContainer &
73 ::surface() const
74 {
75  return mySurface;
76 }
77 //-----------------------------------------------------------------------------
78 template <typename TKSpace, typename TDigitalSet>
79 inline
81 ::Surfel &
83 ::current() const
84 {
85  return myNeighborhood.surfel();
86 }
87 //-----------------------------------------------------------------------------
88 template <typename TKSpace, typename TDigitalSet>
89 inline
92 ::orthDir() const
93 {
94  return myNeighborhood.orthDir();
95 }
96 //-----------------------------------------------------------------------------
97 template <typename TKSpace, typename TDigitalSet>
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 TDigitalSet>
108 inline
111 ::adjacent( Surfel & s, Dimension d, bool pos ) const
112 {
113  SetPredicate<DigitalSet> isInSet( surface().digitalSet() );
114  return static_cast<uint8_t>
115  ( myNeighborhood.getAdjacentOnPointPredicate( s, isInSet, d, pos ) );
116 }
117 
119 // ----------------------- Standard services ------------------------------
120 
121 //-----------------------------------------------------------------------------
122 template <typename TKSpace, typename TDigitalSet>
123 inline
125 {
126 }
127 //-----------------------------------------------------------------------------
128 template <typename TKSpace, typename TDigitalSet>
129 inline
131 ( const DigitalSetBoundary & other )
132  : myKSpace( other.myKSpace ), myDigitalSet( other.myDigitalSet ),
134  mySurfels( other. mySurfels )
135 {
136 }
137 //-----------------------------------------------------------------------------
138 template <typename TKSpace, typename TDigitalSet>
139 inline
141 ( const KSpace & aKSpace,
142  const DigitalSet & aSet,
143  const Adjacency & adj )
144  : myKSpace( aKSpace ), myDigitalSet( aSet ), mySurfelAdjacency( adj )
145 {
146  computeSurfels();
147 }
148 //-----------------------------------------------------------------------------
149 template <typename TKSpace, typename TDigitalSet>
150 inline
151 const
154 {
155  return mySurfelAdjacency;
156 }
157 //-----------------------------------------------------------------------------
158 template <typename TKSpace, typename TDigitalSet>
159 inline
162 {
163  return mySurfelAdjacency;
164 }
165 //-----------------------------------------------------------------------------
166 template <typename TKSpace, typename TDigitalSet>
167 inline
168 const
171 {
172  return myDigitalSet;
173 }
174 
175 //-----------------------------------------------------------------------------
176 // --------- CDigitalSurfaceContainer realization -------------------------
177 //-----------------------------------------------------------------------------
178 template <typename TKSpace, typename TDigitalSet>
179 inline
182 {
183  return myKSpace;
184 }
185 //-----------------------------------------------------------------------------
186 template <typename TKSpace, typename TDigitalSet>
187 inline
188 bool
190 ( const Surfel & s ) const
191 {
192  Dimension k = myKSpace.sOrthDir( s );
193  // checks if the surfel is on the space boundary.
194  if ( myKSpace.sIsMax( s, k ) || myKSpace.sIsMin( s, k ) )
195  return false;
196  // p1 must be in the set and p2 must not be in the set.
197  SCell spel1 = myKSpace.sDirectIncident( s, k );
198  Point p1 = myKSpace.sCoords( spel1 );
199  if ( myDigitalSet.find( p1 ) != myDigitalSet.end() )
200  {
201  SCell spel2 = myKSpace.sIndirectIncident( s, k );
202  Point p2 = myKSpace.sCoords( spel2 );
203  return ! ( myDigitalSet.find( p2 ) != myDigitalSet.end() );
204  }
205  return false;
206 }
207 //-----------------------------------------------------------------------------
208 template <typename TKSpace, typename TDigitalSet>
209 inline
212 {
213  return mySurfels.begin();
214 }
215 //-----------------------------------------------------------------------------
216 template <typename TKSpace, typename TDigitalSet>
217 inline
220 {
221  return mySurfels.end();
222 }
223 //-----------------------------------------------------------------------------
224 template <typename TKSpace, typename TDigitalSet>
225 inline
228 {
229  return (unsigned int)mySurfels.size();
230 }
231 //-----------------------------------------------------------------------------
232 template <typename TKSpace, typename TDigitalSet>
233 inline
234 bool
236 {
237  return mySurfels.empty();
238 }
239 //-----------------------------------------------------------------------------
240 template <typename TKSpace, typename TDigitalSet>
241 inline
244 ( const Surfel & s ) const
245 {
246  return new Tracker( *this, s );
247 }
248 //-----------------------------------------------------------------------------
249 template <typename TKSpace, typename TDigitalSet>
250 inline
253 {
254  return UNKNOWN;
255 }
256 
257 // ------------------------- Hidden services ------------------------------
258 //-----------------------------------------------------------------------------
259 template <typename TKSpace, typename TDigitalSet>
260 inline
261 void
263 {
265  mySurfels.clear();
266  std::back_insert_iterator<SurfelStorage> output_it =
267  std::back_inserter( mySurfels );
269  myKSpace,
270  isInSet,
271  myKSpace.lowerBound(),
272  myKSpace.upperBound() );
273 }
274 
276 // Interface - public :
277 
282 template <typename TKSpace, typename TDigitalSet>
283 inline
284 void
286 {
287  out << "[DigitalSetBoundary]";
288 }
289 
294 template <typename TKSpace, typename TDigitalSet>
295 inline
296 bool
298 {
299  return true;
300 }
301 
302 
303 
305 // Implementation of inline functions //
306 
307 template <typename TKSpace, typename TDigitalSet>
308 inline
309 std::ostream&
310 DGtal::operator<< ( std::ostream & out,
312 {
313  object.selfDisplay( out );
314  return out;
315 }
316 
317 // //
319 
320