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 DigitalSurface2DSlice.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 DigitalSurface2DSlice.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
44 template <typename TDigitalSurfaceTracker>
46 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
47 ~DigitalSurface2DSlice()
50 //-----------------------------------------------------------------------------
51 template <typename TDigitalSurfaceTracker>
53 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
54 DigitalSurface2DSlice( DigitalSurfaceTracker* tracker,
59 //-----------------------------------------------------------------------------
60 template <typename TDigitalSurfaceTracker>
62 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
63 init( DigitalSurfaceTracker* tracker, Dimension i )
65 const KSpace & K = tracker->surface().space();
66 Surfel start_s = tracker->current(); // the start surfel
67 Surfel current_s = start_s; // the current surfel during the extraction
68 Surfel next_s; // the surfel after the current surfel during the extraction
69 uint8_t code = 0;// the code turn when going to the next surfel.
70 Dimension j = i; // the current tracking direction.
71 if ( K.sOrthDir( start_s ) == i ) return false;
74 mySurfels.push_back( current_s );
75 bool direct = K.sDirect( current_s, j );
76 code = tracker->adjacent( next_s, j, direct );
77 if ( code == 0 ) break; // slice is open
78 if ( code != 2 ) // 1 or 3, swap tracking dir and orthogonal dir.
79 j = K.sOrthDir( current_s );
80 tracker->move( next_s );
83 while ( next_s != start_s );
84 // Test if we have looped or if the slice is open.
85 myIsClosed = code != 0;
86 unsigned int shift = 0;
89 tracker->move( start_s );
92 bool indirect = ! K.sDirect( current_s, j );
93 while ( ( code = tracker->adjacent( next_s, j, indirect ) ) )
95 mySurfels.push_front( next_s );
97 if ( code != 2 ) // 1 or 3, swap tracking dir and orthogonal dir.
98 j = K.sOrthDir( current_s );
99 tracker->move( next_s );
101 indirect = ! K.sDirect( current_s, j );
104 myStart = begin() + shift;
107 //-----------------------------------------------------------------------------
108 template <typename TDigitalSurfaceTracker>
110 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::Size
111 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
114 return static_cast<Size>(mySurfels.size());
116 //-----------------------------------------------------------------------------
117 template <typename TDigitalSurfaceTracker>
120 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
125 //-----------------------------------------------------------------------------
126 template <typename TDigitalSurfaceTracker>
128 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstIterator
129 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
134 //-----------------------------------------------------------------------------
135 template <typename TDigitalSurfaceTracker>
137 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseIterator
138 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
141 return ConstReverseIterator( myStart + 1 );
143 //-----------------------------------------------------------------------------
144 template <typename TDigitalSurfaceTracker>
146 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstCirculator
147 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
150 return ConstCirculator( myStart, begin(), end() );
152 //-----------------------------------------------------------------------------
153 template <typename TDigitalSurfaceTracker>
155 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseCirculator
156 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
159 return ConstReverseCirculator( rstart(), rbegin(), rend() );
162 //-----------------------------------------------------------------------------
163 template <typename TDigitalSurfaceTracker>
165 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstIterator
166 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
169 return mySurfels.begin();
171 //-----------------------------------------------------------------------------
172 template <typename TDigitalSurfaceTracker>
174 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstIterator
175 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
178 return mySurfels.end();
180 //-----------------------------------------------------------------------------
181 template <typename TDigitalSurfaceTracker>
183 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseIterator
184 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
187 return mySurfels.rbegin();
189 //-----------------------------------------------------------------------------
190 template <typename TDigitalSurfaceTracker>
192 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseIterator
193 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
196 return mySurfels.rend();
198 //-----------------------------------------------------------------------------
199 template <typename TDigitalSurfaceTracker>
201 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstCirculator
202 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
205 return ConstCirculator( this->begin(), this->begin(), this->end() );
207 //-----------------------------------------------------------------------------
208 template <typename TDigitalSurfaceTracker>
210 typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseCirculator
211 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
214 return ConstReverseCirculator( ConstReverseIterator( begin() + 1 ),
219 ///////////////////////////////////////////////////////////////////////////////
220 // Interface - public :
223 * Writes/Displays the object on an output stream.
224 * @param out the output stream where the object is written.
226 template <typename TDigitalSurfaceTracker>
229 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::selfDisplay ( std::ostream & out ) const
231 out << "[DigitalSurface2DSlice]";
235 * Checks the validity/consistency of the object.
236 * @return 'true' if the object is valid, 'false' otherwise.
238 template <typename TDigitalSurfaceTracker>
241 DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::isValid() const
248 ///////////////////////////////////////////////////////////////////////////////
249 // Implementation of inline functions //
251 template <typename TDigitalSurfaceTracker>
254 DGtal::operator<< ( std::ostream & out,
255 const DigitalSurface2DSlice<TDigitalSurfaceTracker> & object )
257 object.selfDisplay( out );
262 ///////////////////////////////////////////////////////////////////////////////