DGtal  0.9.2
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/math/common_factor_rt.hpp>
36 //////////////////////////////////////////////////////////////////////////////
37 
38 
39 
40 
41 
42 ///////////////////////////////////////////////////////////////////////////////
43 // Implementation of inline methods //
44 
45 //-----------------------------------------------------------------------------
46 template <typename TIterator, typename TInteger, unsigned short adjacency>
47 inline
48 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
49 ArithmeticalDSSComputer()
50  : myDSS( Point(0,0) ), myBegin(), myEnd()
51 {
52 }
53 
54 
55 //-----------------------------------------------------------------------------
56 template <typename TIterator, typename TInteger, unsigned short adjacency>
57 inline
58 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
59 ArithmeticalDSSComputer(const ConstIterator& it)
60  : myDSS( *it ), myBegin(it), myEnd(it)
61 {
62  ++myEnd;
63 }
64 
65 //-----------------------------------------------------------------------------
66 template <typename TIterator, typename TInteger, unsigned short adjacency>
67 inline
68 void DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
69 init(const ConstIterator& it)
70 {
71  myBegin = it;
72  myEnd = it;
73  ++myEnd;
74  Point p = *it;
75  myDSS = DSS( p );
76 }
77 
78 //-----------------------------------------------------------------------------
79 template <typename TIterator, typename TInteger, unsigned short adjacency>
80 inline
81 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
82 ArithmeticalDSSComputer ( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency> & other )
83  : myDSS(other.myDSS), myBegin(other.myBegin), myEnd(other.myEnd)
84 {
85 }
86 
87 //-----------------------------------------------------------------------------
88 template <typename TIterator, typename TInteger, unsigned short adjacency>
89 inline
90 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>&
91 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
92 operator=( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency> & other )
93 {
94  if ( this != &other )
95  {
96  myDSS = other.myDSS;
97  myBegin = other.myBegin;
98  myEnd = other.myEnd;
99  }
100  return *this;
101 }
102 
103 //-----------------------------------------------------------------------------
104 template <typename TIterator, typename TInteger, unsigned short adjacency>
105 inline
106 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Reverse
107 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>
108 ::getReverse() const
109 {
110  return Reverse();
111 }
112 
113 //-----------------------------------------------------------------------------
114 template <typename TIterator, typename TInteger, unsigned short adjacency>
115 inline
116 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Self
117 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>
118 ::getSelf() const
119 {
120  return Self();
121 }
122 
123 //-----------------------------------------------------------------------------
124 template <typename TIterator, typename TInteger, unsigned short adjacency>
125 inline
126 bool
127 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
128 operator==( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency>& other ) const
129 {
130  return ( (myBegin == other.myBegin)
131  && (myEnd == other.myEnd)
132  && (myDSS == other.myDSS) );
133 }
134 
135 //-----------------------------------------------------------------------------
136 template <typename TIterator, typename TInteger, unsigned short adjacency>
137 inline
138 bool
139 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
140 operator!=( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency> & other ) const
141 {
142  return (!(*this == other));
143 }
144 
145 ///////////////////////////////////////////////////////////////////////////////
146 // Update methods //
147 ///////////////////////////////////////////////////////////////////////////////
148 //--------------------------------------------------------------------
149 template <typename TIterator, typename TInteger, unsigned short adjacency>
150 inline
151 bool
152 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isExtendableFront()
153 {
154  return myDSS.isExtendableFront( *myEnd );
155 }
156 
157 //--------------------------------------------------------------------
158 template <typename TIterator, typename TInteger, unsigned short adjacency>
159 inline
160 bool
161 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isExtendableBack()
162 {
163  ConstIterator it = myBegin;
164  --it;
165  return myDSS.isExtendableBack( *it );
166 }
167 
168 //-----------------------------------------------------------------------------
169 template <typename TIterator, typename TInteger, unsigned short adjacency>
170 inline
171 bool
172 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::extendFront()
173 {
174  if (myDSS.extendFront(*myEnd))
175  {
176  ++myEnd;
177  return true;
178  }
179  else
180  return false;
181 }
182 
183 //--------------------------------------------------------------------
184 template <typename TIterator, typename TInteger, unsigned short adjacency>
185 inline
186 bool
187 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::extendBack()
188 {
189  ConstIterator it = myBegin;
190  --it;
191  if (myDSS.extendBack(*it))
192  {
193  myBegin = it;
194  return true;
195  }
196  else
197  return false;
198 }
199 
200 //--------------------------------------------------------------------
201 template <typename TIterator, typename TInteger, unsigned short adjacency>
202 inline
203 bool
204 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::retractFront()
205 {
206  if (myDSS.retractFront())
207  {
208  --myEnd;
209  return true;
210  }
211  else
212  return false;
213 }
214 
215 //--------------------------------------------------------------------
216 template <typename TIterator, typename TInteger, unsigned short adjacency>
217 inline
218 bool
219 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::retractBack()
220 {
221  if (myDSS.retractBack())
222  {
223  ++myBegin;
224  return true;
225  }
226  else
227  return false;
228 }
229 
230 ///////////////////////////////////////////////////////////////////////////////
231 // Accessors //
232 ///////////////////////////////////////////////////////////////////////////////
233 //-------------------------------------------------------------------------
234 template <typename TIterator, typename TInteger, unsigned short adjacency>
235 inline
236 const typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Primitive&
237 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::primitive() const
238 {
239  return myDSS;
240 }
241 
242 //-------------------------------------------------------------------------
243 template <typename TIterator, typename TInteger, unsigned short adjacency>
244 inline
245 TInteger
246 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::remainder(const Point & aPoint) const
247 {
248  return myDSS.remainder( aPoint );
249 }
250 
251 //-------------------------------------------------------------------------
252 template <typename TIterator, typename TInteger, unsigned short adjacency>
253 inline
254 TInteger
255 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::remainder(const ConstIterator & it) const
256 {
257  return remainder(*it);
258 }
259 
260 //-------------------------------------------------------------------------
261 template <typename TIterator, typename TInteger, unsigned short adjacency>
262 inline
263 TInteger
264 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::position(const Point & aPoint) const
265 {
266  return myDSS.position( aPoint );
267 }
268 
269 //-------------------------------------------------------------------------
270 template <typename TIterator, typename TInteger, unsigned short adjacency>
271 inline
272 TInteger
273 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::position(const ConstIterator & it) const
274 {
275  return position(*it);
276 }
277 
278 //-------------------------------------------------------------------------
279 template <typename TIterator, typename TInteger, unsigned short adjacency>
280 inline
281 bool
282 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSL(const Point & aPoint) const
283 {
284  return myDSS.isInDSL( aPoint );
285 }
286 
287 //-------------------------------------------------------------------------
288 template <typename TIterator, typename TInteger, unsigned short adjacency>
289 inline
290 bool
291 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSL(const ConstIterator & it) const
292 {
293  return isInDSL(*it);
294 }
295 
296 //-------------------------------------------------------------------------
297 template <typename TIterator, typename TInteger, unsigned short adjacency>
298 inline
299 bool
300 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSS(const Point & aPoint) const
301 {
302  return myDSS.isInDSS( aPoint );
303 }
304 
305 //-------------------------------------------------------------------------
306 template <typename TIterator, typename TInteger, unsigned short adjacency>
307 inline
308 bool
309 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSS(const ConstIterator & it) const
310 {
311  return isInDSS(*it);
312 }
313 
314 //-------------------------------------------------------------------------
315 template <typename TIterator, typename TInteger, unsigned short adjacency>
316 inline
317 TInteger
318 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::a() const
319 {
320  return myDSS.a();
321 }
322 
323 //-------------------------------------------------------------------------
324 template <typename TIterator, typename TInteger, unsigned short adjacency>
325 inline
326 TInteger
327 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::b() const
328 {
329  return myDSS.b();
330 }
331 
332 //-------------------------------------------------------------------------
333 template <typename TIterator, typename TInteger, unsigned short adjacency>
334 inline
335 TInteger
336 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::mu() const
337 {
338  return myDSS.mu();
339 }
340 
341 //-------------------------------------------------------------------------
342 template <typename TIterator, typename TInteger, unsigned short adjacency>
343 inline
344 TInteger
345 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::omega() const
346 {
347  return myDSS.omega();
348 }
349 
350 //-------------------------------------------------------------------------
351 template <typename TIterator, typename TInteger, unsigned short adjacency>
352 inline
353 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
354 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Uf() const
355 {
356  return myDSS.Uf();
357 }
358 
359 //-------------------------------------------------------------------------
360 template <typename TIterator, typename TInteger, unsigned short adjacency>
361 inline
362 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
363 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Ul() const
364 {
365  return myDSS.Ul();
366 }
367 
368 //-------------------------------------------------------------------------
369 template <typename TIterator, typename TInteger, unsigned short adjacency>
370 inline
371 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
372 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Lf() const
373 {
374  return myDSS.Lf();
375 }
376 
377 //-------------------------------------------------------------------------
378 template <typename TIterator, typename TInteger, unsigned short adjacency>
379 inline
380 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
381 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Ll() const
382 {
383  return myDSS.Ll();
384 }
385 
386 //-------------------------------------------------------------------------
387 template <typename TIterator, typename TInteger, unsigned short adjacency>
388 inline
389 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
390 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::back() const
391 {
392  return myDSS.back();
393 }
394 
395 //-------------------------------------------------------------------------
396 template <typename TIterator, typename TInteger, unsigned short adjacency>
397 inline
398 typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
399 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::front() const
400 {
401  return myDSS.front();
402 }
403 
404 //-------------------------------------------------------------------------
405 template <typename TIterator, typename TInteger, unsigned short adjacency>
406 inline
407 TIterator
408 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::begin() const
409 {
410  return myBegin;
411 }
412 
413 //-------------------------------------------------------------------------
414 template <typename TIterator, typename TInteger, unsigned short adjacency>
415 inline
416 TIterator
417 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::end() const
418 {
419  return myEnd;
420 }
421 
422 //-----------------------------------------------------------------
423 template <typename TIterator, typename TInteger, unsigned short adjacency>
424 inline
425 bool
426 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isValid() const
427 {
428  return ( (myDSS.isValid())&&(isNotEmpty(myBegin,myEnd)) );
429 }
430 
431 //-----------------------------------------------------------------
432 template <typename TIterator, typename TInteger, unsigned short adjacency>
433 inline
434 void
435 DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::selfDisplay ( std::ostream & out) const
436 {
437  out << "[ArithmeticalDSSComputer] " << myDSS;
438 }
439 
440 ///////////////////////////////////////////////////////////////////////////////
441 // Alias //
442 ///////////////////////////////////////////////////////////////////////////////
443 //-----------------------------------------------------------------------------
444 template <typename TIterator, typename TInteger>
445 inline
446 DGtal::StandardDSS4Computer<TIterator,TInteger>::
447 StandardDSS4Computer()
448  : Super()
449 {
450 }
451 
452 
453 //-----------------------------------------------------------------------------
454 template <typename TIterator, typename TInteger>
455 inline
456 DGtal::StandardDSS4Computer<TIterator,TInteger>::
457 StandardDSS4Computer(const ConstIterator& it)
458  : Super(it)
459 {
460 }
461 
462 //-----------------------------------------------------------------------------
463 template <typename TIterator, typename TInteger>
464 inline
465 DGtal::StandardDSS4Computer<TIterator,TInteger>::
466 StandardDSS4Computer ( const StandardDSS4Computer<TIterator,TInteger> & other )
467  : Super(other)
468 {
469 }
470 
471 //-----------------------------------------------------------------------------
472 template <typename TIterator, typename TInteger>
473 inline
474 typename DGtal::StandardDSS4Computer<TIterator,TInteger>&
475 DGtal::StandardDSS4Computer<TIterator,TInteger>::
476 operator=( const StandardDSS4Computer<TIterator,TInteger> & other )
477 {
478  if (this != & other)
479  Super::operator=( other );
480  return *this;
481 }
482 
483 //-----------------------------------------------------------------------------
484 template <typename TIterator, typename TInteger>
485 inline
486 DGtal::NaiveDSS8Computer<TIterator,TInteger>::
487 NaiveDSS8Computer()
488  : Super()
489 {
490 }
491 
492 
493 //-----------------------------------------------------------------------------
494 template <typename TIterator, typename TInteger>
495 inline
496 DGtal::NaiveDSS8Computer<TIterator,TInteger>::
497 NaiveDSS8Computer(const ConstIterator& it)
498  : Super(it)
499 {
500 }
501 
502 //-----------------------------------------------------------------------------
503 template <typename TIterator, typename TInteger>
504 inline
505 DGtal::NaiveDSS8Computer<TIterator,TInteger>::
506 NaiveDSS8Computer ( const NaiveDSS8Computer<TIterator,TInteger> & other )
507  : Super(other)
508 {
509 }
510 
511 //-----------------------------------------------------------------------------
512 template <typename TIterator, typename TInteger>
513 inline
514 typename DGtal::NaiveDSS8Computer<TIterator,TInteger>&
515 DGtal::NaiveDSS8Computer<TIterator,TInteger>::
516 operator=( const NaiveDSS8Computer<TIterator,TInteger> & other )
517 {
518  if (this != & other)
519  Super::operator=( other );
520  return *this;
521 }