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.
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.
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/>.
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
24 * Implementation of inline methods defined in DigitalSetBoundary.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
33#include "DGtal/topology/helpers/Surfaces.h"
34//////////////////////////////////////////////////////////////////////////////
36///////////////////////////////////////////////////////////////////////////////
37// IMPLEMENTATION of inline methods.
38///////////////////////////////////////////////////////////////////////////////
40//-----------------------------------------------------------------------------
41template <typename TKSpace, typename TDigitalSet>
43DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
46//-----------------------------------------------------------------------------
47template <typename TKSpace, typename TDigitalSet>
49DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
50::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
52 : mySurface( aSurface ), myNeighborhood()
54 myNeighborhood.init( & surface().space(),
55 & surface().surfelAdjacency(),
58//-----------------------------------------------------------------------------
59template <typename TKSpace, typename TDigitalSet>
61DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
62::Tracker( const Tracker & other )
63 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
66//-----------------------------------------------------------------------------
67template <typename TKSpace, typename TDigitalSet>
69const typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
70::DigitalSurfaceContainer &
71DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
76//-----------------------------------------------------------------------------
77template <typename TKSpace, typename TDigitalSet>
79const typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
81DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
84 return myNeighborhood.surfel();
86//-----------------------------------------------------------------------------
87template <typename TKSpace, typename TDigitalSet>
90DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
93 return myNeighborhood.orthDir();
95//-----------------------------------------------------------------------------
96template <typename TKSpace, typename TDigitalSet>
99DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
100::move( const Surfel & s )
102 ASSERT( surface().isInside( s ) );
103 myNeighborhood.setSurfel( s );
105//-----------------------------------------------------------------------------
106template <typename TKSpace, typename TDigitalSet>
109DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
110::adjacent( Surfel & s, Dimension d, bool pos ) const
112 return static_cast<uint8_t>
113 ( myNeighborhood.getAdjacentOnPointPredicate( s, surface().digitalSet(), d, pos ) );
116///////////////////////////////////////////////////////////////////////////////
117// ----------------------- Standard services ------------------------------
119//-----------------------------------------------------------------------------
120template <typename TKSpace, typename TDigitalSet>
122DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::~DigitalSetBoundary()
125//-----------------------------------------------------------------------------
126template <typename TKSpace, typename TDigitalSet>
128DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::DigitalSetBoundary
129( const DigitalSetBoundary & other )
130 : myKSpace( other.myKSpace ), myDigitalSet( other.myDigitalSet ),
131 mySurfelAdjacency( other.mySurfelAdjacency ),
132 mySurfels( other. mySurfels )
135//-----------------------------------------------------------------------------
136template <typename TKSpace, typename TDigitalSet>
138DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::DigitalSetBoundary
139( ConstAlias<KSpace> aKSpace,
140 const DigitalSet & aSet,
141 const Adjacency & adj )
142 : myKSpace( aKSpace ), myDigitalSet( aSet ), mySurfelAdjacency( adj )
146//-----------------------------------------------------------------------------
147template <typename TKSpace, typename TDigitalSet>
150typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Adjacency &
151DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::surfelAdjacency() const
153 return mySurfelAdjacency;
155//-----------------------------------------------------------------------------
156template <typename TKSpace, typename TDigitalSet>
158typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Adjacency &
159DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::surfelAdjacency()
161 return mySurfelAdjacency;
163//-----------------------------------------------------------------------------
164template <typename TKSpace, typename TDigitalSet>
167typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::DigitalSet &
168DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::digitalSet() const
173//-----------------------------------------------------------------------------
174// --------- CDigitalSurfaceContainer realization -------------------------
175//-----------------------------------------------------------------------------
176template <typename TKSpace, typename TDigitalSet>
178const typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::KSpace &
179DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::space() const
183//-----------------------------------------------------------------------------
184template <typename TKSpace, typename TDigitalSet>
187DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::isInside
188( const Surfel & s ) const
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 ) )
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() )
199 SCell spel2 = myKSpace.sIndirectIncident( s, k );
200 Point p2 = myKSpace.sCoords( spel2 );
201 return ! ( myDigitalSet.find( p2 ) != myDigitalSet.end() );
205//-----------------------------------------------------------------------------
206template <typename TKSpace, typename TDigitalSet>
208typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::SurfelConstIterator
209DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::begin() const
211 return mySurfels.begin();
213//-----------------------------------------------------------------------------
214template <typename TKSpace, typename TDigitalSet>
216typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::SurfelConstIterator
217DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::end() const
219 return mySurfels.end();
221//-----------------------------------------------------------------------------
222template <typename TKSpace, typename TDigitalSet>
224typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Size
225DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::nbSurfels() const
227 return (unsigned int)mySurfels.size();
229//-----------------------------------------------------------------------------
230template <typename TKSpace, typename TDigitalSet>
233DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::empty() const
235 return mySurfels.empty();
237//-----------------------------------------------------------------------------
238template <typename TKSpace, typename TDigitalSet>
240typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::DigitalSurfaceTracker*
241DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::newTracker
242( const Surfel & s ) const
244 return new Tracker( *this, s );
246//-----------------------------------------------------------------------------
247template <typename TKSpace, typename TDigitalSet>
250DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::connectedness() const
255// ------------------------- Hidden services ------------------------------
256//-----------------------------------------------------------------------------
257template <typename TKSpace, typename TDigitalSet>
260DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::computeSurfels()
262 // Since 0.6, models of CDigitalSet are models of concepts::CPointPredicate.
263 // SetPredicate<DigitalSet> isInSet( myDigitalSet );
265 std::back_insert_iterator<SurfelStorage> output_it =
266 std::back_inserter( mySurfels );
267 Surfaces<KSpace>::sWriteBoundary( output_it,
270 myKSpace.lowerBound(),
271 myKSpace.upperBound() );
274///////////////////////////////////////////////////////////////////////////////
275// Interface - public :
278 * Writes/Displays the object on an output stream.
279 * @param out the output stream where the object is written.
281template <typename TKSpace, typename TDigitalSet>
284DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::selfDisplay ( std::ostream & out ) const
286 out << "[DigitalSetBoundary]";
290 * Checks the validity/consistency of the object.
291 * @return 'true' if the object is valid, 'false' otherwise.
293template <typename TKSpace, typename TDigitalSet>
296DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::isValid() const
303///////////////////////////////////////////////////////////////////////////////
304// Implementation of inline functions //
306template <typename TKSpace, typename TDigitalSet>
309DGtal::operator<< ( std::ostream & out,
310 const DigitalSetBoundary<TKSpace,TDigitalSet> & object )
312 object.selfDisplay( out );
317///////////////////////////////////////////////////////////////////////////////