DGtal 1.4.0
Loading...
Searching...
No Matches
ArithDSSIterator.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 ArithDSSIterator.ih
19 * @author Isabelle Sivignon (\c isabelle.sivignon@gipsa-lab.grenoble-inp.fr )
20 * gipsa-lab Grenoble Images Parole Signal Automatique (CNRS, UMR 5216), CNRS, France
21 *
22 * @date 2012/11/26
23 *
24 * Implementation of inline methods defined in ArithDSSIterator.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//////////////////////////////////////////////////////////////////////////////
36
37
38
39///////////////////////////////////////////////////////////////////////////////
40// Implementation of inline methods //
41
42template<typename TInteger, int c>
43inline
44DGtal::ArithDSSIterator<TInteger,c>::ArithDSSIterator(const Integer a, const Integer b, const Integer mu, const Point & p)
45{
46 myA = a;
47 myB = b;
48 myMu = mu;
49 myP = p;
50}
51
52template<typename TInteger, int c>
53inline
54DGtal::ArithDSSIterator<TInteger,c>::ArithDSSIterator(const ArithDSSIterator<TInteger,c> &other):myA(other.myA),myB(other.myB),myMu(other.myMu),myP(other.myP)
55{
56
57}
58
59
60
61template<typename TInteger, int c>
62inline
63typename DGtal::ArithDSSIterator<TInteger,c>::Self & DGtal::ArithDSSIterator<TInteger,c>::operator=(const ArithDSSIterator<TInteger,c> & other)
64{
65 if (this != &other)
66 {
67 myA = other.myA;
68 myB = other.myB;
69 myMu = other.myMu;
70 myP = other.myP;
71 }
72 return *this;
73}
74
75
76
77
78
79template<typename TInteger, int c>
80inline
81TInteger DGtal::ArithDSSIterator<TInteger,c>::remainder(const Point &Q)
82{
83 return myA*Q[0] - myB*Q[1];
84}
85
86template<typename TInteger, int c>
87inline
88typename DGtal::ArithDSSIterator<TInteger,c>::reference DGtal::ArithDSSIterator<TInteger,c>::operator*() const
89{
90 return myP;
91}
92
93
94template<typename TInteger, int c>
95inline
96typename DGtal::ArithDSSIterator<TInteger,c>::Self & DGtal::ArithDSSIterator<TInteger,c>::operator++()
97{
98 Integer r = remainder(myP);
99 if(c == 8)
100 {
101 if(r + myA >= myB + myMu)
102 ++(myP[1]);
103 ++(myP[0]);
104 }
105 else // connectivity = 4
106 {
107 if(r - myB >=myMu)
108 ++(myP[1]);
109 else
110 ++(myP[0]);
111 }
112 return *this;
113}
114
115template<typename TInteger, int c>
116inline
117typename DGtal::ArithDSSIterator<TInteger,c>::Self DGtal::ArithDSSIterator<TInteger,c>::operator++(int)
118{
119 Self _tmp = *this;
120 this->operator++();
121 return _tmp;
122}
123
124
125template<typename TInteger, int c>
126inline
127bool DGtal::ArithDSSIterator<TInteger,c>::operator==(const ArithDSSIterator<TInteger,c> & other) const
128{
129 return myP == other.myP;
130}
131
132
133template<typename TInteger, int c>
134inline
135bool DGtal::ArithDSSIterator<TInteger,c>::operator!=(const ArithDSSIterator<TInteger, c> & other) const
136{
137 return ! (this->operator==(other));
138}
139
140
141
142
143
144
145
146
147///////////////////////////////////////////////////////////////////////////////
148// Implementation of inline functions and external operators //
149
150/**
151 * Overloads 'operator<<' for displaying objects of class 'ArithDSSIterator'.
152 * @param out the output stream where the object is written.
153 * @param object the object of class 'ArithDSSIterator' to write.
154 * @return the output stream after the writing.
155 */
156// inline
157// std::ostream&
158// DGtal::operator<< ( std::ostream & out,
159// const ArithDSSIterator & object )
160// {
161// object.selfDisplay ( out );
162// return out;
163// }
164
165// //
166///////////////////////////////////////////////////////////////////////////////