DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DigitalSurface2DSlice.ih
1 
30 
31 #include <cstdlib>
33 
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
44 template <typename TDigitalSurfaceTracker>
45 inline
48 {
49 }
50 //-----------------------------------------------------------------------------
51 template <typename TDigitalSurfaceTracker>
52 inline
55  Dimension i )
56 {
57  init( tracker, i );
58 }
59 //-----------------------------------------------------------------------------
60 template <typename TDigitalSurfaceTracker>
61 bool
64 {
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;
72  do
73  {
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 );
81  current_s = next_s;
82  }
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;
87  if ( ! myIsClosed )
88  { // open slice
89  tracker->move( start_s );
90  j = i;
91  current_s = start_s;
92  bool indirect = ! K.sDirect( current_s, j );
93  while ( ( code = tracker->adjacent( next_s, j, indirect ) ) )
94  { // valid movement;
95  mySurfels.push_front( next_s );
96  ++shift;
97  if ( code != 2 ) // 1 or 3, swap tracking dir and orthogonal dir.
98  j = K.sOrthDir( current_s );
99  tracker->move( next_s );
100  current_s = next_s;
101  indirect = ! K.sDirect( current_s, j );
102  }
103  }
104  myStart = begin() + shift;
105  return true;
106 }
107 //-----------------------------------------------------------------------------
108 template <typename TDigitalSurfaceTracker>
109 inline
112 size() const
113 {
114  return mySurfels.size();
115 }
116 //-----------------------------------------------------------------------------
117 template <typename TDigitalSurfaceTracker>
118 inline
119 bool
121 isClosed() const
122 {
123  return myIsClosed;
124 }
125 //-----------------------------------------------------------------------------
126 template <typename TDigitalSurfaceTracker>
127 inline
130 start() const
131 {
132  return myStart;
133 }
134 //-----------------------------------------------------------------------------
135 template <typename TDigitalSurfaceTracker>
136 inline
139 rstart() const
140 {
141  return ConstReverseIterator( myStart + 1 );
142 }
143 //-----------------------------------------------------------------------------
144 template <typename TDigitalSurfaceTracker>
145 inline
148 cstart() const
149 {
150  return ConstCirculator( myStart, begin(), end() );
151 }
152 //-----------------------------------------------------------------------------
153 template <typename TDigitalSurfaceTracker>
154 inline
157 rcstart() const
158 {
159  return ConstReverseCirculator( rstart(), rbegin(), rend() );
160 }
161 
162 //-----------------------------------------------------------------------------
163 template <typename TDigitalSurfaceTracker>
164 inline
167 begin() const
168 {
169  return mySurfels.begin();
170 }
171 //-----------------------------------------------------------------------------
172 template <typename TDigitalSurfaceTracker>
173 inline
176 end() const
177 {
178  return mySurfels.end();
179 }
180 //-----------------------------------------------------------------------------
181 template <typename TDigitalSurfaceTracker>
182 inline
185 rbegin() const
186 {
187  return mySurfels.rbegin();
188 }
189 //-----------------------------------------------------------------------------
190 template <typename TDigitalSurfaceTracker>
191 inline
194 rend() const
195 {
196  return mySurfels.rend();
197 }
198 //-----------------------------------------------------------------------------
199 template <typename TDigitalSurfaceTracker>
200 inline
203 c() const
204 {
205  return ConstCirculator( this->begin(), this->begin(), this->end() );
206 }
207 //-----------------------------------------------------------------------------
208 template <typename TDigitalSurfaceTracker>
209 inline
212 rc() const
213 {
214  return ConstReverseCirculator( ConstReverseIterator( begin() + 1 ),
215  rbegin(),
216  rend() );
217 }
218 
220 // Interface - public :
221 
226 template <typename TDigitalSurfaceTracker>
227 inline
228 void
230 {
231  out << "[DigitalSurface2DSlice]";
232 }
233 
238 template <typename TDigitalSurfaceTracker>
239 inline
240 bool
242 {
243  return true;
244 }
245 
246 
247 
249 // Implementation of inline functions //
250 
251 template <typename TDigitalSurfaceTracker>
252 inline
253 std::ostream&
254 DGtal::operator<< ( std::ostream & out,
256 {
257  object.selfDisplay( out );
258  return out;
259 }
260 
261 // //
263 
264