DGtal  1.5.beta
ArithmeticalDSSComputer.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 ArithmeticalDSSComputer.ih
19  * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
20  * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21  *
22  * @date 2010/07/01
23  *
24  * Implementation of inline methods defined in ArithmeticalDSSComputer.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 // IMPLEMENTATION of inline methods.
31 ///////////////////////////////////////////////////////////////////////////////
32 
33 //////////////////////////////////////////////////////////////////////////////
34 #include <cstdlib>
35 #include <boost/version.hpp>
36 #if BOOST_VERSION < 105800
37 #include <boost/math/common_factor_rt.hpp>
38 #else
39 #include <boost/integer/common_factor_rt.hpp>
40 #endif
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 
45 
46 
47 
48 ///////////////////////////////////////////////////////////////////////////////
49 // Implementation of inline methods //
50 
51 //-----------------------------------------------------------------------------
52 template <typename TIterator, typename TInteger, unsigned short adjacency>
53 inline
54 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
55 ArithmeticalDSSComputer()
56  : myDSS( Point(0,0) ), myBegin(), myEnd()
57 {
58 }
59 
60 
61 //-----------------------------------------------------------------------------
62 template <typename TIterator, typename TInteger, unsigned short adjacency>
63 inline
64 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
65 ArithmeticalDSSComputer(const ConstIterator& it)
66  : myDSS( *it ), myBegin(it), myEnd(it)
67 {
68  ++myEnd;
69 }
70 
71 //-----------------------------------------------------------------------------
72 template <typename TIterator, typename TInteger, unsigned short adjacency>
73 inline
74 void DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
75 init(const ConstIterator& it)
76 {
77  myBegin = it;
78  myEnd = it;
79  ++myEnd;
80  Point p = *it;
81  myDSS = DSS( p );
82 }
83 
84 //-----------------------------------------------------------------------------
85 template <typename TIterator, typename TInteger, unsigned short adjacency>
86 inline
87 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
88 ArithmeticalDSSComputer ( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency> & other )
89  : myDSS(other.myDSS), myBegin(other.myBegin), myEnd(other.myEnd)
90 {
91 }
92 
93 //-----------------------------------------------------------------------------
94 template <typename TIterator, typename TInteger, unsigned short adjacency>
95 inline
96 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>&
97 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
98 operator=( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency> & other )
99 {
100  if ( this != &other )
101  {
102  myDSS = other.myDSS;
103  myBegin = other.myBegin;
104  myEnd = other.myEnd;
105  }
106  return *this;
107 }
108 
109 //-----------------------------------------------------------------------------
110 template <typename TIterator, typename TInteger, unsigned short adjacency>
111 inline
112 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Reverse
113 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>
114 ::getReverse() const
115 {
116  return Reverse();
117 }
118 
119 //-----------------------------------------------------------------------------
120 template <typename TIterator, typename TInteger, unsigned short adjacency>
121 inline
122 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Self
123 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>
124 ::getSelf() const
125 {
126  return Self();
127 }
128 
129 //-----------------------------------------------------------------------------
130 template <typename TIterator, typename TInteger, unsigned short adjacency>
131 inline
132 bool
133 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
134 operator==( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency>& other ) const
135 {
136  return ( (myBegin == other.myBegin)
137  && (myEnd == other.myEnd)
138  && (myDSS == other.myDSS) );
139 }
140 
141 //-----------------------------------------------------------------------------
142 template <typename TIterator, typename TInteger, unsigned short adjacency>
143 inline
144 bool
145 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
146 operator!=( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency> & other ) const
147 {
148  return (!(*this == other));
149 }
150 
151 ///////////////////////////////////////////////////////////////////////////////
152 // Update methods //
153 ///////////////////////////////////////////////////////////////////////////////
154 //--------------------------------------------------------------------
155 template <typename TIterator, typename TInteger, unsigned short adjacency>
156 inline
157 bool
158 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isExtendableFront()
159 {
160  return myDSS.isExtendableFront( *myEnd );
161 }
162 
163 //--------------------------------------------------------------------
164 template <typename TIterator, typename TInteger, unsigned short adjacency>
165 inline
166 bool
167 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isExtendableBack()
168 {
169  ConstIterator it = myBegin;
170  --it;
171  return myDSS.isExtendableBack( *it );
172 }
173 
174 //-----------------------------------------------------------------------------
175 template <typename TIterator, typename TInteger, unsigned short adjacency>
176 inline
177 bool
178 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::extendFront()
179 {
180  if (myDSS.extendFront(*myEnd))
181  {
182  ++myEnd;
183  return true;
184  }
185  else
186  return false;
187 }
188 
189 //--------------------------------------------------------------------
190 template <typename TIterator, typename TInteger, unsigned short adjacency>
191 inline
192 bool
193 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::extendBack()
194 {
195  ConstIterator it = myBegin;
196  --it;
197  if (myDSS.extendBack(*it))
198  {
199  myBegin = it;
200  return true;
201  }
202  else
203  return false;
204 }
205 
206 //--------------------------------------------------------------------
207 template <typename TIterator, typename TInteger, unsigned short adjacency>
208 inline
209 bool
210 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::retractFront()
211 {
212  if (myDSS.retractFront())
213  {
214  --myEnd;
215  return true;
216  }
217  else
218  return false;
219 }
220 
221 //--------------------------------------------------------------------
222 template <typename TIterator, typename TInteger, unsigned short adjacency>
223 inline
224 bool
225 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::retractBack()
226 {
227  if (myDSS.retractBack())
228  {
229  ++myBegin;
230  return true;
231  }
232  else
233  return false;
234 }
235 
236 ///////////////////////////////////////////////////////////////////////////////
237 // Accessors //
238 ///////////////////////////////////////////////////////////////////////////////
239 //-------------------------------------------------------------------------
240 template <typename TIterator, typename TInteger, unsigned short adjacency>
241 inline
242 const typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Primitive&
243 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::primitive() const
244 {
245  return myDSS;
246 }
247 
248 //-------------------------------------------------------------------------
249 template <typename TIterator, typename TInteger, unsigned short adjacency>
250 inline
251 TInteger
252 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::remainder(const Point & aPoint) const
253 {
254  return myDSS.remainder( aPoint );
255 }
256 
257 //-------------------------------------------------------------------------
258 template <typename TIterator, typename TInteger, unsigned short adjacency>
259 inline
260 TInteger
261 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::remainder(const ConstIterator & it) const
262 {
263  return remainder(*it);
264 }
265 
266 //-------------------------------------------------------------------------
267 template <typename TIterator, typename TInteger, unsigned short adjacency>
268 inline
269 TInteger
270 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::position(const Point & aPoint) const
271 {
272  return myDSS.position( aPoint );
273 }
274 
275 //-------------------------------------------------------------------------
276 template <typename TIterator, typename TInteger, unsigned short adjacency>
277 inline
278 TInteger
279 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::position(const ConstIterator & it) const
280 {
281  return position(*it);
282 }
283 
284 //-------------------------------------------------------------------------
285 template <typename TIterator, typename TInteger, unsigned short adjacency>
286 inline
287 bool
288 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSL(const Point & aPoint) const
289 {
290  return myDSS.isInDSL( aPoint );
291 }
292 
293 //-------------------------------------------------------------------------
294 template <typename TIterator, typename TInteger, unsigned short adjacency>
295 inline
296 bool
297 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSL(const ConstIterator & it) const
298 {
299  return isInDSL(*it);
300 }
301 
302 //-------------------------------------------------------------------------
303 template <typename TIterator, typename TInteger, unsigned short adjacency>
304 inline
305 bool
306 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSS(const Point & aPoint) const
307 {
308  return myDSS.isInDSS( aPoint );
309 }
310 
311 //-------------------------------------------------------------------------
312 template <typename TIterator, typename TInteger, unsigned short adjacency>
313 inline
314 bool
315 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSS(const ConstIterator & it) const
316 {
317  return isInDSS(*it);
318 }
319 
320 //-------------------------------------------------------------------------
321 template <typename TIterator, typename TInteger, unsigned short adjacency>
322 inline
323 TInteger
324 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::a() const
325 {
326  return myDSS.a();
327 }
328 
329 //-------------------------------------------------------------------------
330 template <typename TIterator, typename TInteger, unsigned short adjacency>
331 inline
332 TInteger
333 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::b() const
334 {
335  return myDSS.b();
336 }
337 
338 //-------------------------------------------------------------------------
339 template <typename TIterator, typename TInteger, unsigned short adjacency>
340 inline
341 TInteger
342 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::mu() const
343 {
344  return myDSS.mu();
345 }
346 
347 //-------------------------------------------------------------------------
348 template <typename TIterator, typename TInteger, unsigned short adjacency>
349 inline
350 TInteger
351 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::omega() const
352 {
353  return myDSS.omega();
354 }
355 
356 //-------------------------------------------------------------------------
357 template <typename TIterator, typename TInteger, unsigned short adjacency>
358 inline
359 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
360 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Uf() const
361 {
362  return myDSS.Uf();
363 }
364 
365 //-------------------------------------------------------------------------
366 template <typename TIterator, typename TInteger, unsigned short adjacency>
367 inline
368 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
369 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Ul() const
370 {
371  return myDSS.Ul();
372 }
373 
374 //-------------------------------------------------------------------------
375 template <typename TIterator, typename TInteger, unsigned short adjacency>
376 inline
377 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
378 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Lf() const
379 {
380  return myDSS.Lf();
381 }
382 
383 //-------------------------------------------------------------------------
384 template <typename TIterator, typename TInteger, unsigned short adjacency>
385 inline
386 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
387 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Ll() const
388 {
389  return myDSS.Ll();
390 }
391 
392 //-------------------------------------------------------------------------
393 template <typename TIterator, typename TInteger, unsigned short adjacency>
394 inline
395 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
396 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::back() const
397 {
398  return myDSS.back();
399 }
400 
401 //-------------------------------------------------------------------------
402 template <typename TIterator, typename TInteger, unsigned short adjacency>
403 inline
404 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
405 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::front() const
406 {
407  return myDSS.front();
408 }
409 
410 //-------------------------------------------------------------------------
411 template <typename TIterator, typename TInteger, unsigned short adjacency>
412 inline
413 TIterator
414 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::begin() const
415 {
416  return myBegin;
417 }
418 
419 //-------------------------------------------------------------------------
420 template <typename TIterator, typename TInteger, unsigned short adjacency>
421 inline
422 TIterator
423 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::end() const
424 {
425  return myEnd;
426 }
427 
428 //-----------------------------------------------------------------
429 template <typename TIterator, typename TInteger, unsigned short adjacency>
430 inline
431 bool
432 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isValid() const
433 {
434  return ( (myDSS.isValid())&&(isNotEmpty(myBegin,myEnd)) );
435 }
436 
437 //-----------------------------------------------------------------
438 template <typename TIterator, typename TInteger, unsigned short adjacency>
439 inline
440 void
441 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::selfDisplay ( std::ostream & out) const
442 {
443  out << "[ArithmeticalDSSComputer] " << myDSS;
444 }
445