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