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