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 SetOfSurfels.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 SetOfSurfels.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 TSurfelSet>
43 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
46 //-----------------------------------------------------------------------------
47 template <typename TKSpace, typename TSurfelSet>
49 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
50 ::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
52 : mySurface( aSurface ), myNeighborhood()
54 myNeighborhood.init( & surface().space(),
55 & surface().surfelAdjacency(),
58 //-----------------------------------------------------------------------------
59 template <typename TKSpace, typename TSurfelSet>
61 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
62 ::Tracker( const Tracker & other )
63 : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
66 //-----------------------------------------------------------------------------
67 template <typename TKSpace, typename TSurfelSet>
69 const typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker::DigitalSurfaceContainer &
70 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
75 //-----------------------------------------------------------------------------
76 template <typename TKSpace, typename TSurfelSet>
78 const typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker::Surfel &
79 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker::current() const
81 return myNeighborhood.surfel();
83 //-----------------------------------------------------------------------------
84 template <typename TKSpace, typename TSurfelSet>
87 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
90 return myNeighborhood.orthDir();
92 //-----------------------------------------------------------------------------
93 template <typename TKSpace, typename TSurfelSet>
96 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
97 ::move( const Surfel & s )
99 ASSERT( surface().isInside( s ) );
100 myNeighborhood.setSurfel( s );
102 //-----------------------------------------------------------------------------
103 template <typename TKSpace, typename TSurfelSet>
106 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
107 ::adjacent( Surfel & s, Dimension d, bool pos ) const
109 return static_cast<uint8_t>
110 ( myNeighborhood.getAdjacentOnSurfelPredicate( s, surface().surfelPredicate(), d, pos ) );
113 ///////////////////////////////////////////////////////////////////////////////
114 // ----------------------- Standard services ------------------------------
116 //-----------------------------------------------------------------------------
117 template <typename TKSpace, typename TSurfelSet>
119 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::~SetOfSurfels()
122 //-----------------------------------------------------------------------------
123 template <typename TKSpace, typename TSurfelSet>
125 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SetOfSurfels
126 ( const SetOfSurfels & other )
127 : myKSpace( other.myKSpace ),
128 mySurfelSet( other.mySurfelSet ),
129 mySurfelPredicate( other.mySurfelPredicate ),
130 mySurfelAdjacency( other.mySurfelAdjacency )
133 //-----------------------------------------------------------------------------
134 template <typename TKSpace, typename TSurfelSet>
136 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SetOfSurfels
137 ( ConstAlias<KSpace> aKSpace,
138 const Adjacency & adj,
139 SurfelSet aSetOfSurfels )
140 : myKSpace( aKSpace ), mySurfelSet( aSetOfSurfels ),
141 mySurfelPredicate( mySurfelSet ),
142 mySurfelAdjacency( adj )
145 //-----------------------------------------------------------------------------
146 template <typename TKSpace, typename TSurfelSet>
148 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelSet &
149 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelSet()
153 //-----------------------------------------------------------------------------
154 template <typename TKSpace, typename TSurfelSet>
157 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelSet &
158 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelSet() const
162 //-----------------------------------------------------------------------------
163 template <typename TKSpace, typename TSurfelSet>
166 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Adjacency &
167 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelAdjacency() const
169 return mySurfelAdjacency;
171 //-----------------------------------------------------------------------------
172 template <typename TKSpace, typename TSurfelSet>
174 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Adjacency &
175 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelAdjacency()
177 return mySurfelAdjacency;
179 //-----------------------------------------------------------------------------
180 template <typename TKSpace, typename TSurfelSet>
183 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelPredicate &
184 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelPredicate() const
186 return mySurfelPredicate;
189 //-----------------------------------------------------------------------------
190 // --------- CDigitalSurfaceContainer realization -------------------------
191 //-----------------------------------------------------------------------------
192 template <typename TKSpace, typename TSurfelSet>
194 const typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::KSpace &
195 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::space() const
199 //-----------------------------------------------------------------------------
200 template <typename TKSpace, typename TSurfelSet>
203 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::isInside
204 ( const Surfel & s ) const
206 return mySurfelPredicate( s );
208 //-----------------------------------------------------------------------------
209 template <typename TKSpace, typename TSurfelSet>
211 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelConstIterator
212 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::begin() const
214 return mySurfelSet.begin();
216 //-----------------------------------------------------------------------------
217 template <typename TKSpace, typename TSurfelSet>
219 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelConstIterator
220 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::end() const
222 return mySurfelSet.end();
224 //-----------------------------------------------------------------------------
225 template <typename TKSpace, typename TSurfelSet>
227 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Size
228 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::nbSurfels() const
230 return (unsigned int)mySurfelSet.size();
232 //-----------------------------------------------------------------------------
233 template <typename TKSpace, typename TSurfelSet>
236 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::empty() const
238 return mySurfelSet.empty();
240 //-----------------------------------------------------------------------------
241 template <typename TKSpace, typename TSurfelSet>
243 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::DigitalSurfaceTracker*
244 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::newTracker
245 ( const Surfel & s ) const
247 return new Tracker( *this, s );
249 //-----------------------------------------------------------------------------
250 template <typename TKSpace, typename TSurfelSet>
253 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::connectedness() const
258 // ------------------------- Hidden services ------------------------------
260 ///////////////////////////////////////////////////////////////////////////////
261 // Interface - public :
264 * Writes/Displays the object on an output stream.
265 * @param out the output stream where the object is written.
267 template <typename TKSpace, typename TSurfelSet>
270 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::selfDisplay ( std::ostream & out ) const
272 out << "[SetOfSurfels]";
276 * Checks the validity/consistency of the object.
277 * @return 'true' if the object is valid, 'false' otherwise.
279 template <typename TKSpace, typename TSurfelSet>
282 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::isValid() const
289 ///////////////////////////////////////////////////////////////////////////////
290 // Implementation of inline functions //
292 template <typename TKSpace, typename TSurfelSet>
295 DGtal::operator<< ( std::ostream & out,
296 const SetOfSurfels<TKSpace,TSurfelSet> & object )
298 object.selfDisplay( out );
303 ///////////////////////////////////////////////////////////////////////////////