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//-----------------------------------------------------------------------------
41template <typename TKSpace, typename TSurfelPredicate>
43DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
46//-----------------------------------------------------------------------------
47template <typename TKSpace, typename TSurfelPredicate>
49DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
50::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
52 : mySurface( aSurface ), myNeighborhood()
54 myNeighborhood.init( & surface().space(),
55 & surface().surfelAdjacency(),
58//-----------------------------------------------------------------------------
59template <typename TKSpace, typename TSurfelPredicate>
61DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
62::Tracker( const Tracker & other )
63 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
66//-----------------------------------------------------------------------------
67template <typename TKSpace, typename TSurfelPredicate>
69const typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
70::DigitalSurfaceContainer &
71DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
76//-----------------------------------------------------------------------------
77template <typename TKSpace, typename TSurfelPredicate>
79const typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
81DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
84 return myNeighborhood.surfel();
86//-----------------------------------------------------------------------------
87template <typename TKSpace, typename TSurfelPredicate>
90DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
93 return myNeighborhood.orthDir();
95//-----------------------------------------------------------------------------
96template <typename TKSpace, typename TSurfelPredicate>
99DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Tracker
100::move( const Surfel & s )
102 ASSERT( surface().isInside( s ) );
103 myNeighborhood.setSurfel( s );
105//-----------------------------------------------------------------------------
106template <typename TKSpace, typename TSurfelPredicate>
109DGtal::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//-----------------------------------------------------------------------------
121template <typename TKSpace, typename TSurfelPredicate>
123DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::~ExplicitDigitalSurface()
126//-----------------------------------------------------------------------------
127template <typename TKSpace, typename TSurfelPredicate>
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 )
137//-----------------------------------------------------------------------------
138template <typename TKSpace, typename TSurfelPredicate>
140DGtal::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//-----------------------------------------------------------------------------
151template <typename TKSpace, typename TSurfelPredicate>
154typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
155DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency() const
157 return mySurfelAdjacency;
159//-----------------------------------------------------------------------------
160template <typename TKSpace, typename TSurfelPredicate>
162typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Adjacency &
163DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelAdjacency()
165 return mySurfelAdjacency;
167//-----------------------------------------------------------------------------
168template <typename TKSpace, typename TSurfelPredicate>
171typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelPredicate &
172DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::surfelPredicate() const
174 return mySurfelPredicate;
177//-----------------------------------------------------------------------------
178// --------- CDigitalSurfaceContainer realization -------------------------
179//-----------------------------------------------------------------------------
180template <typename TKSpace, typename TSurfelPredicate>
182const typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::KSpace &
183DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::space() const
187//-----------------------------------------------------------------------------
188template <typename TKSpace, typename TSurfelPredicate>
191DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isInside
192( const Surfel & s ) const
194 return surfelPredicate()( s );
196//-----------------------------------------------------------------------------
197template <typename TKSpace, typename TSurfelPredicate>
199typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
200DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::begin() const
202 return mySurfels.begin();
204//-----------------------------------------------------------------------------
205template <typename TKSpace, typename TSurfelPredicate>
207typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::SurfelConstIterator
208DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::end() const
210 return mySurfels.end();
212//-----------------------------------------------------------------------------
213template <typename TKSpace, typename TSurfelPredicate>
215typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::Size
216DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::nbSurfels() const
218 return (Size)mySurfels.size();
220//-----------------------------------------------------------------------------
221template <typename TKSpace, typename TSurfelPredicate>
224DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::empty() const
226 return mySurfels.empty();
228//-----------------------------------------------------------------------------
229template <typename TKSpace, typename TSurfelPredicate>
231typename DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::DigitalSurfaceTracker*
232DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::newTracker
233( const Surfel & s ) const
235 return new Tracker( *this, s );
237//-----------------------------------------------------------------------------
238template <typename TKSpace, typename TSurfelPredicate>
241DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::connectedness() const
246// ------------------------- Hidden services ------------------------------
247//-----------------------------------------------------------------------------
248template <typename TKSpace, typename TSurfelPredicate>
251DGtal::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.
296template <typename TKSpace, typename TSurfelPredicate>
299DGtal::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.
308template <typename TKSpace, typename TSurfelPredicate>
311DGtal::ExplicitDigitalSurface<TKSpace,TSurfelPredicate>::isValid() const
318///////////////////////////////////////////////////////////////////////////////
319// Implementation of inline functions //
321template <typename TKSpace, typename TSurfelPredicate>
324DGtal::operator<< ( std::ostream & out,
325 const ExplicitDigitalSurface<TKSpace,TSurfelPredicate> & object )
327 object.selfDisplay( out );
332///////////////////////////////////////////////////////////////////////////////