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 ImplicitDigitalSurface.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 ImplicitDigitalSurface.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 TPointPredicate>
43 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
46 //-----------------------------------------------------------------------------
47 template <typename TKSpace, typename TPointPredicate>
49 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
50 ::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
52 : mySurface( aSurface ), myNeighborhood()
54 myNeighborhood.init( & surface().space(),
55 & surface().surfelAdjacency(),
58 //-----------------------------------------------------------------------------
59 template <typename TKSpace, typename TPointPredicate>
61 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
62 ::Tracker( const Tracker & other )
63 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
66 //-----------------------------------------------------------------------------
67 template <typename TKSpace, typename TPointPredicate>
69 const typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
70 ::DigitalSurfaceContainer &
71 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
76 //-----------------------------------------------------------------------------
77 template <typename TKSpace, typename TPointPredicate>
79 const typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
81 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
84 return myNeighborhood.surfel();
86 //-----------------------------------------------------------------------------
87 template <typename TKSpace, typename TPointPredicate>
90 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
93 return myNeighborhood.orthDir();
95 //-----------------------------------------------------------------------------
96 template <typename TKSpace, typename TPointPredicate>
99 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
100 ::move( const Surfel & s )
102 ASSERT( surface().isInside( s ) );
103 myNeighborhood.setSurfel( s );
105 //-----------------------------------------------------------------------------
106 template <typename TKSpace, typename TPointPredicate>
109 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Tracker
110 ::adjacent( Surfel & s, Dimension d, bool pos ) const
112 return static_cast<uint8_t>
113 ( myNeighborhood.getAdjacentOnPointPredicate( s, surface().pointPredicate(), d, pos ) );
116 ///////////////////////////////////////////////////////////////////////////////
117 // ----------------------- Standard services ------------------------------
119 //-----------------------------------------------------------------------------
120 template <typename TKSpace, typename TPointPredicate>
122 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::~ImplicitDigitalSurface()
125 //-----------------------------------------------------------------------------
126 template <typename TKSpace, typename TPointPredicate>
128 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::ImplicitDigitalSurface
129 ( const ImplicitDigitalSurface & other )
130 : myKSpace( other.myKSpace ),
131 myPointPredicate( other.myPointPredicate ),
132 mySurfelAdjacency( other.mySurfelAdjacency ),
133 mySurfels( other. mySurfels )
136 //-----------------------------------------------------------------------------
137 template <typename TKSpace, typename TPointPredicate>
139 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::ImplicitDigitalSurface
140 ( ConstAlias<KSpace> aKSpace,
141 ConstAlias<PointPredicate> aPP,
142 const Adjacency & adj,
145 : myKSpace( aKSpace ), myPointPredicate( aPP ), mySurfelAdjacency( adj )
147 computeSurfels( s, closed );
149 //-----------------------------------------------------------------------------
150 template <typename TKSpace, typename TPointPredicate>
153 typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
154 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency() const
156 return mySurfelAdjacency;
158 //-----------------------------------------------------------------------------
159 template <typename TKSpace, typename TPointPredicate>
161 typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Adjacency &
162 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::surfelAdjacency()
164 return mySurfelAdjacency;
166 //-----------------------------------------------------------------------------
167 template <typename TKSpace, typename TPointPredicate>
170 typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::PointPredicate &
171 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::pointPredicate() const
173 return myPointPredicate;
176 //-----------------------------------------------------------------------------
177 // --------- CDigitalSurfaceContainer realization -------------------------
178 //-----------------------------------------------------------------------------
179 template <typename TKSpace, typename TPointPredicate>
181 const typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::KSpace &
182 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::space() const
186 //-----------------------------------------------------------------------------
187 template <typename TKSpace, typename TPointPredicate>
190 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::isInside
191 ( const Surfel & s ) const
193 Dimension k = myKSpace.sOrthDir( s );
194 // checks if the surfel is on the space boundary.
195 if ( myKSpace.sIsMax( s, k ) || myKSpace.sIsMin( s, k ) )
197 // p1 must be in the set and p2 must not be in the set.
198 SCell spel1 = myKSpace.sDirectIncident( s, k );
199 Point p1 = myKSpace.sCoords( spel1 );
200 if ( myPointPredicate( p1 ) )
202 SCell spel2 = myKSpace.sIndirectIncident( s, k );
203 Point p2 = myKSpace.sCoords( spel2 );
204 return ! myPointPredicate( p2 );
208 //-----------------------------------------------------------------------------
209 template <typename TKSpace, typename TPointPredicate>
211 typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
212 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::begin() const
214 return mySurfels.begin();
216 //-----------------------------------------------------------------------------
217 template <typename TKSpace, typename TPointPredicate>
219 typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::SurfelConstIterator
220 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::end() const
222 return mySurfels.end();
224 //-----------------------------------------------------------------------------
225 template <typename TKSpace, typename TPointPredicate>
227 typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::Size
228 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::nbSurfels() const
230 return static_cast<Size>(mySurfels.size());
232 //-----------------------------------------------------------------------------
233 template <typename TKSpace, typename TPointPredicate>
236 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::empty() const
238 return mySurfels.empty();
240 //-----------------------------------------------------------------------------
241 template <typename TKSpace, typename TPointPredicate>
243 typename DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::DigitalSurfaceTracker*
244 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::newTracker
245 ( const Surfel & s ) const
247 return new Tracker( *this, s );
249 //-----------------------------------------------------------------------------
250 template <typename TKSpace, typename TPointPredicate>
253 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::connectedness() const
258 // ------------------------- Hidden services ------------------------------
259 //-----------------------------------------------------------------------------
260 template <typename TKSpace, typename TPointPredicate>
263 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::computeSurfels
264 ( const Surfel & p, bool closed )
267 typename KSpace::SCellSet surface;
269 Surfaces<KSpace>::trackClosedBoundary( surface,
275 Surfaces<KSpace>::trackBoundary( surface,
280 for ( typename KSpace::SCellSet::const_iterator it = surface.begin(),
281 it_end = surface.end(); it != it_end; ++it )
282 mySurfels.push_back( *it );
285 ///////////////////////////////////////////////////////////////////////////////
286 // Interface - public :
289 * Writes/Displays the object on an output stream.
290 * @param out the output stream where the object is written.
292 template <typename TKSpace, typename TPointPredicate>
295 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::selfDisplay ( std::ostream & out ) const
297 out << "[ImplicitDigitalSurface]";
301 * Checks the validity/consistency of the object.
302 * @return 'true' if the object is valid, 'false' otherwise.
304 template <typename TKSpace, typename TPointPredicate>
307 DGtal::ImplicitDigitalSurface<TKSpace,TPointPredicate>::isValid() const
314 ///////////////////////////////////////////////////////////////////////////////
315 // Implementation of inline functions //
317 template <typename TKSpace, typename TPointPredicate>
320 DGtal::operator<< ( std::ostream & out,
321 const ImplicitDigitalSurface<TKSpace,TPointPredicate> & object )
323 object.selfDisplay( out );
328 ///////////////////////////////////////////////////////////////////////////////