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 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
24 * Implementation of inline methods defined in ExplicitDigitalSurface.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 TSurfelPredicate>
43 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
46 //-----------------------------------------------------------------------------
47 template <typename TKSpace, typename TSurfelPredicate>
49 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
50 ::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
52 : mySurface( aSurface ), myNeighborhood()
54 myNeighborhood.init( & surface().space(),
55 & surface().surfelAdjacency(),
58 //-----------------------------------------------------------------------------
59 template <typename TKSpace, typename TSurfelPredicate>
61 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
62 ::Tracker( const Tracker & other )
63 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
66 //-----------------------------------------------------------------------------
67 template <typename TKSpace, typename TSurfelPredicate>
69 const typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
70 ::DigitalSurfaceContainer &
71 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
76 //-----------------------------------------------------------------------------
77 template <typename TKSpace, typename TSurfelPredicate>
79 const typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
81 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
84 return myNeighborhood.surfel();
86 //-----------------------------------------------------------------------------
87 template <typename TKSpace, typename TSurfelPredicate>
90 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
93 return myNeighborhood.orthDir();
95 //-----------------------------------------------------------------------------
96 template <typename TKSpace, typename TSurfelPredicate>
99 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
100 ::move( const Surfel & s )
102 ASSERT( surface().isInside( s ) );
103 myNeighborhood.setSurfel( s );
105 //-----------------------------------------------------------------------------
106 template <typename TKSpace, typename TSurfelPredicate>
109 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
110 ::adjacent( Surfel & s, Dimension d, bool pos ) const
112 return static_cast<uint8_t>
113 ( myNeighborhood.getAdjacentOnSurfelPredicate
114 ( s, surface().surfelPredicate(), d, pos ) );
117 ///////////////////////////////////////////////////////////////////////////////
118 // ----------------------- Standard services ------------------------------
120 //-----------------------------------------------------------------------------
121 template <typename TKSpace, typename TSurfelPredicate>
123 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::~ExplicitDigitalSurface()
126 //-----------------------------------------------------------------------------
127 template <typename TKSpace, typename TSurfelPredicate>
129 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::ExplicitDigitalSurface
130 ( const ExplicitDigitalSurface & other )
131 : myKSpace( other.myKSpace ),
132 mySurfelPredicate( other.mySurfelPredicate ),
133 mySurfelAdjacency( other.mySurfelAdjacency ),
134 mySurfels( other.mySurfels )
137 //-----------------------------------------------------------------------------
138 template <typename TKSpace, typename TSurfelPredicate>
140 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::ExplicitDigitalSurface
141 ( ConstAlias<KSpace> aKSpace,
142 const SurfelPredicate & aPP,
143 const Adjacency & adj,
146 : myKSpace( aKSpace ), mySurfelPredicate( aPP ), mySurfelAdjacency( adj )
148 computeSurfels( s, closed );
150 //-----------------------------------------------------------------------------
151 template <typename TKSpace, typename TSurfelPredicate>
154 typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
155 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency() const
157 return mySurfelAdjacency;
159 //-----------------------------------------------------------------------------
160 template <typename TKSpace, typename TSurfelPredicate>
162 typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
163 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency()
165 return mySurfelAdjacency;
167 //-----------------------------------------------------------------------------
168 template <typename TKSpace, typename TSurfelPredicate>
171 typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelPredicate &
172 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelPredicate() const
174 return mySurfelPredicate;
177 //-----------------------------------------------------------------------------
178 // --------- CDigitalSurfaceContainer realization -------------------------
179 //-----------------------------------------------------------------------------
180 template <typename TKSpace, typename TSurfelPredicate>
182 const typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::KSpace &
183 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::space() const
187 //-----------------------------------------------------------------------------
188 template <typename TKSpace, typename TSurfelPredicate>
191 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isInside
192 ( const Surfel & s ) const
194 return surfelPredicate()( s );
196 //-----------------------------------------------------------------------------
197 template <typename TKSpace, typename TSurfelPredicate>
199 typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
200 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::begin() const
202 return mySurfels.begin();
204 //-----------------------------------------------------------------------------
205 template <typename TKSpace, typename TSurfelPredicate>
207 typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
208 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::end() const
210 return mySurfels.end();
212 //-----------------------------------------------------------------------------
213 template <typename TKSpace, typename TSurfelPredicate>
215 typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
216 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::nbSurfels() const
218 return (Size)mySurfels.size();
220 //-----------------------------------------------------------------------------
221 template <typename TKSpace, typename TSurfelPredicate>
224 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::empty() const
226 return mySurfels.empty();
228 //-----------------------------------------------------------------------------
229 template <typename TKSpace, typename TSurfelPredicate>
231 typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::DigitalSurfaceTracker*
232 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::newTracker
233 ( const Surfel & s ) const
235 return new Tracker( *this, s );
237 //-----------------------------------------------------------------------------
238 template <typename TKSpace, typename TSurfelPredicate>
241 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::connectedness() const
246 // ------------------------- Hidden services ------------------------------
247 //-----------------------------------------------------------------------------
248 template <typename TKSpace, typename TSurfelPredicate>
251 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::computeSurfels
252 ( const Surfel & p, bool closed )
255 if ( KSpace::dimension > 2 )
257 typename KSpace::SCellSet surface;
259 Surfaces<KSpace>::trackClosedSurface( surface,
266 Surfaces<KSpace>::trackSurface( surface,
273 for ( typename KSpace::SCellSet::const_iterator it = surface.begin(),
274 it_end = surface.end(); it != it_end; ++it )
275 mySurfels.push_back( *it );
279 ASSERT( KSpace::dimension == 2 );
280 Surfaces<KSpace>::track2DSurface( mySurfels,
289 ///////////////////////////////////////////////////////////////////////////////
290 // Interface - public :
293 * Writes/Displays the object on an output stream.
294 * @param out the output stream where the object is written.
296 template <typename TKSpace, typename TSurfelPredicate>
299 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::selfDisplay ( std::ostream & out ) const
301 out << "[ExplicitDigitalSurface]";
305 * Checks the validity/consistency of the object.
306 * @return 'true' if the object is valid, 'false' otherwise.
308 template <typename TKSpace, typename TSurfelPredicate>
311 DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isValid() const
318 ///////////////////////////////////////////////////////////////////////////////
319 // Implementation of inline functions //
321 template <typename TKSpace, typename TSurfelPredicate>
324 DGtal::operator<< ( std::ostream & out,
325 const ExplicitDigitalSurface<TKSpace,TSurfelPredicate> & object )
327 object.selfDisplay( out );
332 ///////////////////////////////////////////////////////////////////////////////