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 ------------------------------
44template <typename TDigitalSurfaceTracker>
46DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
47~DigitalSurface2DSlice()
50//-----------------------------------------------------------------------------
51template <typename TDigitalSurfaceTracker>
53DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
54DigitalSurface2DSlice( DigitalSurfaceTracker* tracker,
59//-----------------------------------------------------------------------------
60template <typename TDigitalSurfaceTracker>
62DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
63init( 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//-----------------------------------------------------------------------------
108template <typename TDigitalSurfaceTracker>
110typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::Size
111DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
114 return static_cast<Size>(mySurfels.size());
116//-----------------------------------------------------------------------------
117template <typename TDigitalSurfaceTracker>
120DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
125//-----------------------------------------------------------------------------
126template <typename TDigitalSurfaceTracker>
128typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstIterator
129DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
134//-----------------------------------------------------------------------------
135template <typename TDigitalSurfaceTracker>
137typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseIterator
138DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
141 return ConstReverseIterator( myStart + 1 );
143//-----------------------------------------------------------------------------
144template <typename TDigitalSurfaceTracker>
146typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstCirculator
147DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
150 return ConstCirculator( myStart, begin(), end() );
152//-----------------------------------------------------------------------------
153template <typename TDigitalSurfaceTracker>
155typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseCirculator
156DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
159 return ConstReverseCirculator( rstart(), rbegin(), rend() );
162//-----------------------------------------------------------------------------
163template <typename TDigitalSurfaceTracker>
165typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstIterator
166DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
169 return mySurfels.begin();
171//-----------------------------------------------------------------------------
172template <typename TDigitalSurfaceTracker>
174typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstIterator
175DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
178 return mySurfels.end();
180//-----------------------------------------------------------------------------
181template <typename TDigitalSurfaceTracker>
183typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseIterator
184DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
187 return mySurfels.rbegin();
189//-----------------------------------------------------------------------------
190template <typename TDigitalSurfaceTracker>
192typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseIterator
193DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
196 return mySurfels.rend();
198//-----------------------------------------------------------------------------
199template <typename TDigitalSurfaceTracker>
201typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstCirculator
202DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::
205 return ConstCirculator( this->begin(), this->begin(), this->end() );
207//-----------------------------------------------------------------------------
208template <typename TDigitalSurfaceTracker>
210typename DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::ConstReverseCirculator
211DGtal::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.
226template <typename TDigitalSurfaceTracker>
229DGtal::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.
238template <typename TDigitalSurfaceTracker>
241DGtal::DigitalSurface2DSlice<TDigitalSurfaceTracker>::isValid() const
248///////////////////////////////////////////////////////////////////////////////
249// Implementation of inline functions //
251template <typename TDigitalSurfaceTracker>
254DGtal::operator<< ( std::ostream & out,
255 const DigitalSurface2DSlice<TDigitalSurfaceTracker> & object )
257 object.selfDisplay( out );
262///////////////////////////////////////////////////////////////////////////////