DGtal  0.9.2
SetOfSurfels.ih
1 /**
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.
6  *
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.
11  *
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/>.
14  *
15  **/
16 
17 /**
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
21  *
22  * @date 2011/11/27
23  *
24  * Implementation of inline methods defined in SetOfSurfels.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 
30 //////////////////////////////////////////////////////////////////////////////
31 #include <cstdlib>
32 #include <iterator>
33 #include "DGtal/topology/helpers/Surfaces.h"
34 //////////////////////////////////////////////////////////////////////////////
35 
36 ///////////////////////////////////////////////////////////////////////////////
37 // IMPLEMENTATION of inline methods.
38 ///////////////////////////////////////////////////////////////////////////////
39 
40 //-----------------------------------------------------------------------------
41 template <typename TKSpace, typename TSurfelSet>
42 inline
43 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
44 ::~Tracker()
45 {}
46 //-----------------------------------------------------------------------------
47 template <typename TKSpace, typename TSurfelSet>
48 inline
49 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
50 ::Tracker( ConstAlias<DigitalSurfaceContainer> aSurface,
51  const Surfel & s )
52  : mySurface( aSurface ), myNeighborhood()
53 {
54  myNeighborhood.init( & surface().space(),
55  & surface().surfelAdjacency(),
56  s );
57 }
58 //-----------------------------------------------------------------------------
59 template <typename TKSpace, typename TSurfelSet>
60 inline
61 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
62 ::Tracker( const Tracker & other )
63  : mySurface( other.mySurface ), myNeighborhood( other.myNeighborhood )
64 {
65 }
66 //-----------------------------------------------------------------------------
67 template <typename TKSpace, typename TSurfelSet>
68 inline
69 const typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker::DigitalSurfaceContainer &
70 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
71 ::surface() const
72 {
73  return mySurface;
74 }
75 //-----------------------------------------------------------------------------
76 template <typename TKSpace, typename TSurfelSet>
77 inline
78 const typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker::Surfel &
79 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker::current() const
80 {
81  return myNeighborhood.surfel();
82 }
83 //-----------------------------------------------------------------------------
84 template <typename TKSpace, typename TSurfelSet>
85 inline
86 DGtal::Dimension
87 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
88 ::orthDir() const
89 {
90  return myNeighborhood.orthDir();
91 }
92 //-----------------------------------------------------------------------------
93 template <typename TKSpace, typename TSurfelSet>
94 inline
95 void
96 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
97 ::move( const Surfel & s )
98 {
99  ASSERT( surface().isInside( s ) );
100  myNeighborhood.setSurfel( s );
101 }
102 //-----------------------------------------------------------------------------
103 template <typename TKSpace, typename TSurfelSet>
104 inline
105 DGtal::uint8_t
106 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Tracker
107 ::adjacent( Surfel & s, Dimension d, bool pos ) const
108 {
109  return static_cast<uint8_t>
110  ( myNeighborhood.getAdjacentOnSurfelPredicate( s, surface().surfelPredicate(), d, pos ) );
111 }
112 
113 ///////////////////////////////////////////////////////////////////////////////
114 // ----------------------- Standard services ------------------------------
115 
116 //-----------------------------------------------------------------------------
117 template <typename TKSpace, typename TSurfelSet>
118 inline
119 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::~SetOfSurfels()
120 {
121 }
122 //-----------------------------------------------------------------------------
123 template <typename TKSpace, typename TSurfelSet>
124 inline
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 )
131 {
132 }
133 //-----------------------------------------------------------------------------
134 template <typename TKSpace, typename TSurfelSet>
135 inline
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 )
143 {
144 }
145 //-----------------------------------------------------------------------------
146 template <typename TKSpace, typename TSurfelSet>
147 inline
148 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelSet &
149 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelSet()
150 {
151  return mySurfelSet;
152 }
153 //-----------------------------------------------------------------------------
154 template <typename TKSpace, typename TSurfelSet>
155 inline
156 const
157 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelSet &
158 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelSet() const
159 {
160  return mySurfelSet;
161 }
162 //-----------------------------------------------------------------------------
163 template <typename TKSpace, typename TSurfelSet>
164 inline
165 const
166 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Adjacency &
167 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelAdjacency() const
168 {
169  return mySurfelAdjacency;
170 }
171 //-----------------------------------------------------------------------------
172 template <typename TKSpace, typename TSurfelSet>
173 inline
174 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Adjacency &
175 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelAdjacency()
176 {
177  return mySurfelAdjacency;
178 }
179 //-----------------------------------------------------------------------------
180 template <typename TKSpace, typename TSurfelSet>
181 inline
182 const
183 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelPredicate &
184 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::surfelPredicate() const
185 {
186  return mySurfelPredicate;
187 }
188 
189 //-----------------------------------------------------------------------------
190 // --------- CDigitalSurfaceContainer realization -------------------------
191 //-----------------------------------------------------------------------------
192 template <typename TKSpace, typename TSurfelSet>
193 inline
194 const typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::KSpace &
195 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::space() const
196 {
197  return myKSpace;
198 }
199 //-----------------------------------------------------------------------------
200 template <typename TKSpace, typename TSurfelSet>
201 inline
202 bool
203 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::isInside
204 ( const Surfel & s ) const
205 {
206  return mySurfelPredicate( s );
207 }
208 //-----------------------------------------------------------------------------
209 template <typename TKSpace, typename TSurfelSet>
210 inline
211 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelConstIterator
212 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::begin() const
213 {
214  return mySurfelSet.begin();
215 }
216 //-----------------------------------------------------------------------------
217 template <typename TKSpace, typename TSurfelSet>
218 inline
219 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::SurfelConstIterator
220 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::end() const
221 {
222  return mySurfelSet.end();
223 }
224 //-----------------------------------------------------------------------------
225 template <typename TKSpace, typename TSurfelSet>
226 inline
227 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::Size
228 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::nbSurfels() const
229 {
230  return (unsigned int)mySurfelSet.size();
231 }
232 //-----------------------------------------------------------------------------
233 template <typename TKSpace, typename TSurfelSet>
234 inline
235 bool
236 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::empty() const
237 {
238  return mySurfelSet.empty();
239 }
240 //-----------------------------------------------------------------------------
241 template <typename TKSpace, typename TSurfelSet>
242 inline
243 typename DGtal::SetOfSurfels<TKSpace,TSurfelSet>::DigitalSurfaceTracker*
244 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::newTracker
245 ( const Surfel & s ) const
246 {
247  return new Tracker( *this, s );
248 }
249 //-----------------------------------------------------------------------------
250 template <typename TKSpace, typename TSurfelSet>
251 inline
252 DGtal::Connectedness
253 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::connectedness() const
254 {
255  return UNKNOWN;
256 }
257 
258 // ------------------------- Hidden services ------------------------------
259 
260 ///////////////////////////////////////////////////////////////////////////////
261 // Interface - public :
262 
263 /**
264  * Writes/Displays the object on an output stream.
265  * @param out the output stream where the object is written.
266  */
267 template <typename TKSpace, typename TSurfelSet>
268 inline
269 void
270 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::selfDisplay ( std::ostream & out ) const
271 {
272  out << "[SetOfSurfels]";
273 }
274 
275 /**
276  * Checks the validity/consistency of the object.
277  * @return 'true' if the object is valid, 'false' otherwise.
278  */
279 template <typename TKSpace, typename TSurfelSet>
280 inline
281 bool
282 DGtal::SetOfSurfels<TKSpace,TSurfelSet>::isValid() const
283 {
284  return true;
285 }
286 
287 
288 
289 ///////////////////////////////////////////////////////////////////////////////
290 // Implementation of inline functions //
291 
292 template <typename TKSpace, typename TSurfelSet>
293 inline
294 std::ostream&
295 DGtal::operator<< ( std::ostream & out,
296  const SetOfSurfels<TKSpace,TSurfelSet> & object )
297 {
298  object.selfDisplay( out );
299  return out;
300 }
301 
302 // //
303 ///////////////////////////////////////////////////////////////////////////////
304 
305