DGtal 1.4.0
Loading...
Searching...
No Matches
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//-----------------------------------------------------------------------------
52template <typename TIterator, typename TInteger, unsigned short adjacency>
53inline
54DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
55ArithmeticalDSSComputer()
56 : myDSS( Point(0,0) ), myBegin(), myEnd()
57{
58}
59
60
61//-----------------------------------------------------------------------------
62template <typename TIterator, typename TInteger, unsigned short adjacency>
63inline
64DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
65ArithmeticalDSSComputer(const ConstIterator& it)
66 : myDSS( *it ), myBegin(it), myEnd(it)
67{
68 ++myEnd;
69}
70
71//-----------------------------------------------------------------------------
72template <typename TIterator, typename TInteger, unsigned short adjacency>
73inline
74void DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
75init(const ConstIterator& it)
76{
77 myBegin = it;
78 myEnd = it;
79 ++myEnd;
80 Point p = *it;
81 myDSS = DSS( p );
82}
83
84//-----------------------------------------------------------------------------
85template <typename TIterator, typename TInteger, unsigned short adjacency>
86inline
87DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
88ArithmeticalDSSComputer ( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency> & other )
89 : myDSS(other.myDSS), myBegin(other.myBegin), myEnd(other.myEnd)
90{
91}
92
93//-----------------------------------------------------------------------------
94template <typename TIterator, typename TInteger, unsigned short adjacency>
95inline
96typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>&
97DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
98operator=( 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//-----------------------------------------------------------------------------
110template <typename TIterator, typename TInteger, unsigned short adjacency>
111inline
112typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Reverse
113DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>
114::getReverse() const
115{
116 return Reverse();
117}
118
119//-----------------------------------------------------------------------------
120template <typename TIterator, typename TInteger, unsigned short adjacency>
121inline
122typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Self
123DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>
124::getSelf() const
125{
126 return Self();
127}
128
129//-----------------------------------------------------------------------------
130template <typename TIterator, typename TInteger, unsigned short adjacency>
131inline
132bool
133DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
134operator==( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency>& other ) const
135{
136 return ( (myBegin == other.myBegin)
137 && (myEnd == other.myEnd)
138 && (myDSS == other.myDSS) );
139}
140
141//-----------------------------------------------------------------------------
142template <typename TIterator, typename TInteger, unsigned short adjacency>
143inline
144bool
145DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::
146operator!=( const ArithmeticalDSSComputer<TIterator,TInteger,adjacency> & other ) const
147{
148 return (!(*this == other));
149}
150
151///////////////////////////////////////////////////////////////////////////////
152// Update methods //
153///////////////////////////////////////////////////////////////////////////////
154//--------------------------------------------------------------------
155template <typename TIterator, typename TInteger, unsigned short adjacency>
156inline
157bool
158DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isExtendableFront()
159{
160 return myDSS.isExtendableFront( *myEnd );
161}
162
163//--------------------------------------------------------------------
164template <typename TIterator, typename TInteger, unsigned short adjacency>
165inline
166bool
167DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isExtendableBack()
168{
169 ConstIterator it = myBegin;
170 --it;
171 return myDSS.isExtendableBack( *it );
172}
173
174//-----------------------------------------------------------------------------
175template <typename TIterator, typename TInteger, unsigned short adjacency>
176inline
177bool
178DGtal::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//--------------------------------------------------------------------
190template <typename TIterator, typename TInteger, unsigned short adjacency>
191inline
192bool
193DGtal::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//--------------------------------------------------------------------
207template <typename TIterator, typename TInteger, unsigned short adjacency>
208inline
209bool
210DGtal::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//--------------------------------------------------------------------
222template <typename TIterator, typename TInteger, unsigned short adjacency>
223inline
224bool
225DGtal::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//-------------------------------------------------------------------------
240template <typename TIterator, typename TInteger, unsigned short adjacency>
241inline
242const typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Primitive&
243DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::primitive() const
244{
245 return myDSS;
246}
247
248//-------------------------------------------------------------------------
249template <typename TIterator, typename TInteger, unsigned short adjacency>
250inline
251TInteger
252DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::remainder(const Point & aPoint) const
253{
254 return myDSS.remainder( aPoint );
255}
256
257//-------------------------------------------------------------------------
258template <typename TIterator, typename TInteger, unsigned short adjacency>
259inline
260TInteger
261DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::remainder(const ConstIterator & it) const
262{
263 return remainder(*it);
264}
265
266//-------------------------------------------------------------------------
267template <typename TIterator, typename TInteger, unsigned short adjacency>
268inline
269TInteger
270DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::position(const Point & aPoint) const
271{
272 return myDSS.position( aPoint );
273}
274
275//-------------------------------------------------------------------------
276template <typename TIterator, typename TInteger, unsigned short adjacency>
277inline
278TInteger
279DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::position(const ConstIterator & it) const
280{
281 return position(*it);
282}
283
284//-------------------------------------------------------------------------
285template <typename TIterator, typename TInteger, unsigned short adjacency>
286inline
287bool
288DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSL(const Point & aPoint) const
289{
290 return myDSS.isInDSL( aPoint );
291}
292
293//-------------------------------------------------------------------------
294template <typename TIterator, typename TInteger, unsigned short adjacency>
295inline
296bool
297DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSL(const ConstIterator & it) const
298{
299 return isInDSL(*it);
300}
301
302//-------------------------------------------------------------------------
303template <typename TIterator, typename TInteger, unsigned short adjacency>
304inline
305bool
306DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSS(const Point & aPoint) const
307{
308 return myDSS.isInDSS( aPoint );
309}
310
311//-------------------------------------------------------------------------
312template <typename TIterator, typename TInteger, unsigned short adjacency>
313inline
314bool
315DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isInDSS(const ConstIterator & it) const
316{
317 return isInDSS(*it);
318}
319
320//-------------------------------------------------------------------------
321template <typename TIterator, typename TInteger, unsigned short adjacency>
322inline
323TInteger
324DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::a() const
325{
326 return myDSS.a();
327}
328
329//-------------------------------------------------------------------------
330template <typename TIterator, typename TInteger, unsigned short adjacency>
331inline
332TInteger
333DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::b() const
334{
335 return myDSS.b();
336}
337
338//-------------------------------------------------------------------------
339template <typename TIterator, typename TInteger, unsigned short adjacency>
340inline
341TInteger
342DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::mu() const
343{
344 return myDSS.mu();
345}
346
347//-------------------------------------------------------------------------
348template <typename TIterator, typename TInteger, unsigned short adjacency>
349inline
350TInteger
351DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::omega() const
352{
353 return myDSS.omega();
354}
355
356//-------------------------------------------------------------------------
357template <typename TIterator, typename TInteger, unsigned short adjacency>
358inline
359typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
360DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Uf() const
361{
362 return myDSS.Uf();
363}
364
365//-------------------------------------------------------------------------
366template <typename TIterator, typename TInteger, unsigned short adjacency>
367inline
368typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
369DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Ul() const
370{
371 return myDSS.Ul();
372}
373
374//-------------------------------------------------------------------------
375template <typename TIterator, typename TInteger, unsigned short adjacency>
376inline
377typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
378DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Lf() const
379{
380 return myDSS.Lf();
381}
382
383//-------------------------------------------------------------------------
384template <typename TIterator, typename TInteger, unsigned short adjacency>
385inline
386typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
387DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Ll() const
388{
389 return myDSS.Ll();
390}
391
392//-------------------------------------------------------------------------
393template <typename TIterator, typename TInteger, unsigned short adjacency>
394inline
395typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
396DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::back() const
397{
398 return myDSS.back();
399}
400
401//-------------------------------------------------------------------------
402template <typename TIterator, typename TInteger, unsigned short adjacency>
403inline
404typename DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::Point
405DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::front() const
406{
407 return myDSS.front();
408}
409
410//-------------------------------------------------------------------------
411template <typename TIterator, typename TInteger, unsigned short adjacency>
412inline
413TIterator
414DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::begin() const
415{
416 return myBegin;
417}
418
419//-------------------------------------------------------------------------
420template <typename TIterator, typename TInteger, unsigned short adjacency>
421inline
422TIterator
423DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::end() const
424{
425 return myEnd;
426}
427
428//-----------------------------------------------------------------
429template <typename TIterator, typename TInteger, unsigned short adjacency>
430inline
431bool
432DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::isValid() const
433{
434 return ( (myDSS.isValid())&&(isNotEmpty(myBegin,myEnd)) );
435}
436
437//-----------------------------------------------------------------
438template <typename TIterator, typename TInteger, unsigned short adjacency>
439inline
440void
441DGtal::ArithmeticalDSSComputer<TIterator,TInteger,adjacency>::selfDisplay ( std::ostream & out) const
442{
443 out << "[ArithmeticalDSSComputer] " << myDSS;
444}
445