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 //-----------------------------------------------------------------------------
41 template <typename TKSpace, typename TDigitalSet>
43 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
46 //-----------------------------------------------------------------------------
47 template <typename TKSpace, typename TDigitalSet>
49 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
50 ::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
52 : mySurface( aSurface ), myNeighborhood()
54 myNeighborhood.init( & surface().space(),
55 & surface().surfelAdjacency(),
58 //-----------------------------------------------------------------------------
59 template <typename TKSpace, typename TDigitalSet>
61 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
62 ::Tracker( const Tracker & other )
63 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
66 //-----------------------------------------------------------------------------
67 template <typename TKSpace, typename TDigitalSet>
69 const typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
70 ::DigitalSurfaceContainer &
71 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
76 //-----------------------------------------------------------------------------
77 template <typename TKSpace, typename TDigitalSet>
79 const typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
81 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
84 return myNeighborhood.surfel();
86 //-----------------------------------------------------------------------------
87 template <typename TKSpace, typename TDigitalSet>
90 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
93 return myNeighborhood.orthDir();
95 //-----------------------------------------------------------------------------
96 template <typename TKSpace, typename TDigitalSet>
99 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Tracker
100 ::move( const Surfel & s )
102 ASSERT( surface().isInside( s ) );
103 myNeighborhood.setSurfel( s );
105 //-----------------------------------------------------------------------------
106 template <typename TKSpace, typename TDigitalSet>
109 DGtal::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 //-----------------------------------------------------------------------------
120 template <typename TKSpace, typename TDigitalSet>
122 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::~DigitalSetBoundary()
125 //-----------------------------------------------------------------------------
126 template <typename TKSpace, typename TDigitalSet>
128 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::DigitalSetBoundary
129 ( const DigitalSetBoundary & other )
130 : myKSpace( other.myKSpace ), myDigitalSet( other.myDigitalSet ),
131 mySurfelAdjacency( other.mySurfelAdjacency ),
132 mySurfels( other. mySurfels )
135 //-----------------------------------------------------------------------------
136 template <typename TKSpace, typename TDigitalSet>
138 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::DigitalSetBoundary
139 ( ConstAlias<KSpace> aKSpace,
140 const DigitalSet & aSet,
141 const Adjacency & adj )
142 : myKSpace( aKSpace ), myDigitalSet( aSet ), mySurfelAdjacency( adj )
146 //-----------------------------------------------------------------------------
147 template <typename TKSpace, typename TDigitalSet>
150 typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Adjacency &
151 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::surfelAdjacency() const
153 return mySurfelAdjacency;
155 //-----------------------------------------------------------------------------
156 template <typename TKSpace, typename TDigitalSet>
158 typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Adjacency &
159 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::surfelAdjacency()
161 return mySurfelAdjacency;
163 //-----------------------------------------------------------------------------
164 template <typename TKSpace, typename TDigitalSet>
167 typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::DigitalSet &
168 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::digitalSet() const
173 //-----------------------------------------------------------------------------
174 // --------- CDigitalSurfaceContainer realization -------------------------
175 //-----------------------------------------------------------------------------
176 template <typename TKSpace, typename TDigitalSet>
178 const typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::KSpace &
179 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::space() const
183 //-----------------------------------------------------------------------------
184 template <typename TKSpace, typename TDigitalSet>
187 DGtal::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 //-----------------------------------------------------------------------------
206 template <typename TKSpace, typename TDigitalSet>
208 typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::SurfelConstIterator
209 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::begin() const
211 return mySurfels.begin();
213 //-----------------------------------------------------------------------------
214 template <typename TKSpace, typename TDigitalSet>
216 typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::SurfelConstIterator
217 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::end() const
219 return mySurfels.end();
221 //-----------------------------------------------------------------------------
222 template <typename TKSpace, typename TDigitalSet>
224 typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::Size
225 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::nbSurfels() const
227 return (unsigned int)mySurfels.size();
229 //-----------------------------------------------------------------------------
230 template <typename TKSpace, typename TDigitalSet>
233 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::empty() const
235 return mySurfels.empty();
237 //-----------------------------------------------------------------------------
238 template <typename TKSpace, typename TDigitalSet>
240 typename DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::DigitalSurfaceTracker*
241 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::newTracker
242 ( const Surfel & s ) const
244 return new Tracker( *this, s );
246 //-----------------------------------------------------------------------------
247 template <typename TKSpace, typename TDigitalSet>
250 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::connectedness() const
255 // ------------------------- Hidden services ------------------------------
256 //-----------------------------------------------------------------------------
257 template <typename TKSpace, typename TDigitalSet>
260 DGtal::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.
281 template <typename TKSpace, typename TDigitalSet>
284 DGtal::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.
293 template <typename TKSpace, typename TDigitalSet>
296 DGtal::DigitalSetBoundary<TKSpace,TDigitalSet>::isValid() const
303 ///////////////////////////////////////////////////////////////////////////////
304 // Implementation of inline functions //
306 template <typename TKSpace, typename TDigitalSet>
309 DGtal::operator<< ( std::ostream & out,
310 const DigitalSetBoundary<TKSpace,TDigitalSet> & object )
312 object.selfDisplay( out );
317 ///////////////////////////////////////////////////////////////////////////////