DGtal 1.3.0
Loading...
Searching...
No Matches
ImplicitDigitalSurface.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 ImplicitDigitalSurface.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 ImplicitDigitalSurface.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32#include <iterator>
33#include "DGtal/topology/helpers/Surfaces.h"
34//////////////////////////////////////////////////////////////////////////////
35
36///////////////////////////////////////////////////////////////////////////////
37// IMPLEMENTATION of inline methods.
38///////////////////////////////////////////////////////////////////////////////
39
40//-----------------------------------------------------------------------------
41template <typename TKSpace, typename TPointPredicate>
42inline
43DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
44::~Tracker()
45{}
46//-----------------------------------------------------------------------------
47template <typename TKSpace, typename TPointPredicate>
48inline
49DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
50::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
51 const Surfel & s )
52 : mySurface( aSurface ), myNeighborhood()
53{
54 myNeighborhood.init( & surface().space(),
55 & surface().surfelAdjacency(),
56 s );
57}
58//-----------------------------------------------------------------------------
59template <typename TKSpace, typename TPointPredicate>
60inline
61DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
62::Tracker( const Tracker & other )
63 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
64{
65}
66//-----------------------------------------------------------------------------
67template <typename TKSpace, typename TPointPredicate>
68inline
69const typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
70::DigitalSurfaceContainer &
71DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
72::surface() const
73{
74 return mySurface;
75}
76//-----------------------------------------------------------------------------
77template <typename TKSpace, typename TPointPredicate>
78inline
79const typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
80::Surfel &
81DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
82::current() const
83{
84 return myNeighborhood.surfel();
85}
86//-----------------------------------------------------------------------------
87template <typename TKSpace, typename TPointPredicate>
88inline
89DGtal::Dimension
90DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
91::orthDir() const
92{
93 return myNeighborhood.orthDir();
94}
95//-----------------------------------------------------------------------------
96template <typename TKSpace, typename TPointPredicate>
97inline
98void
99DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
100::move( const Surfel & s )
101{
102 ASSERT( surface().isInside( s ) );
103 myNeighborhood.setSurfel( s );
104}
105//-----------------------------------------------------------------------------
106template <typename TKSpace, typename TPointPredicate>
107inline
108DGtal::uint8_t
109DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
110::adjacent( Surfel & s, Dimension d, bool pos ) const
111{
112 return static_cast<uint8_t>
113 ( myNeighborhood.getAdjacentOnPointPredicate( s, surface().pointPredicate(), d, pos ) );
114}
115
116///////////////////////////////////////////////////////////////////////////////
117// ----------------------- Standard services ------------------------------
118
119//-----------------------------------------------------------------------------
120template <typename TKSpace, typename TPointPredicate>
121inline
122DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::~ImplicitDigitalSurface()
123{
124}
125//-----------------------------------------------------------------------------
126template <typename TKSpace, typename TPointPredicate>
127inline
128DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::ImplicitDigitalSurface
129( const ImplicitDigitalSurface & other )
130 : myKSpace( other.myKSpace ),
131 myPointPredicate( other.myPointPredicate ),
132 mySurfelAdjacency( other.mySurfelAdjacency ),
133 mySurfels( other. mySurfels )
134{
135}
136//-----------------------------------------------------------------------------
137template <typename TKSpace, typename TPointPredicate>
138inline
139DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::ImplicitDigitalSurface
140( ConstAlias<KSpace> aKSpace,
141 ConstAlias<PointPredicate> aPP,
142 const Adjacency & adj,
143 const Surfel & s,
144 bool closed )
145 : myKSpace( aKSpace ), myPointPredicate( aPP ), mySurfelAdjacency( adj )
146{
147 computeSurfels( s, closed );
148}
149//-----------------------------------------------------------------------------
150template <typename TKSpace, typename TPointPredicate>
151inline
152const
153typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
154DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency() const
155{
156 return mySurfelAdjacency;
157}
158//-----------------------------------------------------------------------------
159template <typename TKSpace, typename TPointPredicate>
160inline
161typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
162DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency()
163{
164 return mySurfelAdjacency;
165}
166//-----------------------------------------------------------------------------
167template <typename TKSpace, typename TPointPredicate>
168inline
169const
170typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::PointPredicate &
171DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::pointPredicate() const
172{
173 return myPointPredicate;
174}
175
176//-----------------------------------------------------------------------------
177// --------- CDigitalSurfaceContainer realization -------------------------
178//-----------------------------------------------------------------------------
179template <typename TKSpace, typename TPointPredicate>
180inline
181const typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::KSpace &
182DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::space() const
183{
184 return myKSpace;
185}
186//-----------------------------------------------------------------------------
187template <typename TKSpace, typename TPointPredicate>
188inline
189bool
190DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::isInside
191( const Surfel & s ) const
192{
193 Dimension k = myKSpace.sOrthDir( s );
194 // checks if the surfel is on the space boundary.
195 if ( myKSpace.sIsMax( s, k ) || myKSpace.sIsMin( s, k ) )
196 return false;
197 // p1 must be in the set and p2 must not be in the set.
198 SCell spel1 = myKSpace.sDirectIncident( s, k );
199 Point p1 = myKSpace.sCoords( spel1 );
200 if ( myPointPredicate( p1 ) )
201 {
202 SCell spel2 = myKSpace.sIndirectIncident( s, k );
203 Point p2 = myKSpace.sCoords( spel2 );
204 return ! myPointPredicate( p2 );
205 }
206 return false;
207}
208//-----------------------------------------------------------------------------
209template <typename TKSpace, typename TPointPredicate>
210inline
211typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
212DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::begin() const
213{
214 return mySurfels.begin();
215}
216//-----------------------------------------------------------------------------
217template <typename TKSpace, typename TPointPredicate>
218inline
219typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
220DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::end() const
221{
222 return mySurfels.end();
223}
224//-----------------------------------------------------------------------------
225template <typename TKSpace, typename TPointPredicate>
226inline
227typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Size
228DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::nbSurfels() const
229{
230 return static_cast<Size>(mySurfels.size());
231}
232//-----------------------------------------------------------------------------
233template <typename TKSpace, typename TPointPredicate>
234inline
235bool
236DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::empty() const
237{
238 return mySurfels.empty();
239}
240//-----------------------------------------------------------------------------
241template <typename TKSpace, typename TPointPredicate>
242inline
243typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::DigitalSurfaceTracker*
244DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::newTracker
245( const Surfel & s ) const
246{
247 return new Tracker( *this, s );
248}
249//-----------------------------------------------------------------------------
250template <typename TKSpace, typename TPointPredicate>
251inline
252DGtal::Connectedness
253DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::connectedness() const
254{
255 return CONNECTED;
256}
257
258// ------------------------- Hidden services ------------------------------
259//-----------------------------------------------------------------------------
260template <typename TKSpace, typename TPointPredicate>
261inline
262void
263DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::computeSurfels
264( const Surfel & p, bool closed )
265{
266 mySurfels.clear();
267 typename KSpace::SCellSet surface;
268 if ( closed )
269 Surfaces<KSpace>::trackClosedBoundary( surface,
270 myKSpace,
271 mySurfelAdjacency,
272 myPointPredicate,
273 p );
274 else
275 Surfaces<KSpace>::trackBoundary( surface,
276 myKSpace,
277 mySurfelAdjacency,
278 myPointPredicate,
279 p );
280 for ( typename KSpace::SCellSet::const_iterator it = surface.begin(),
281 it_end = surface.end(); it != it_end; ++it )
282 mySurfels.push_back( *it );
283}
284
285///////////////////////////////////////////////////////////////////////////////
286// Interface - public :
287
288/**
289 * Writes/Displays the object on an output stream.
290 * @param out the output stream where the object is written.
291 */
292template <typename TKSpace, typename TPointPredicate>
293inline
294void
295DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::selfDisplay ( std::ostream & out ) const
296{
297 out << "[ImplicitDigitalSurface]";
298}
299
300/**
301 * Checks the validity/consistency of the object.
302 * @return 'true' if the object is valid, 'false' otherwise.
303 */
304template <typename TKSpace, typename TPointPredicate>
305inline
306bool
307DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::isValid() const
308{
309 return true;
310}
311
312
313
314///////////////////////////////////////////////////////////////////////////////
315// Implementation of inline functions //
316
317template <typename TKSpace, typename TPointPredicate>
318inline
319std::ostream&
320DGtal::operator<< ( std::ostream & out,
321 const ImplicitDigitalSurface<TKSpace,TPointPredicate> & object )
322{
323 object.selfDisplay( out );
324 return out;
325}
326
327// //
328///////////////////////////////////////////////////////////////////////////////
329
330