DGtal 1.4.0
Loading...
Searching...
No Matches
SimpleIncremental2x2DetComputer.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 SimpleIncremental2x2DetComputer.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 2013/11/18
23 *
24 * Implementation of inline methods defined in SimpleIncremental2x2DetComputer.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32//////////////////////////////////////////////////////////////////////////////
33
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
37
38///////////////////////////////////////////////////////////////////////////////
39// ---------------------------------------------------------------------------
40template <typename TI, typename TO>
41inline
42DGtal::SimpleIncremental2x2DetComputer<TI,TO>::SimpleIncremental2x2DetComputer()
43 : myA (NumberTraits<ResultInteger>::ZERO),
44 myB (NumberTraits<ResultInteger>::ZERO),
45 myAY (NumberTraits<ResultInteger>::ZERO),
46 myBX (NumberTraits<ResultInteger>::ZERO),
47 myDet (NumberTraits<ResultInteger>::ZERO),
48 myX (NumberTraits<ResultInteger>::ZERO),
49 myY (NumberTraits<ResultInteger>::ZERO),
50 myDX (NumberTraits<ResultInteger>::ZERO),
51 myDY (NumberTraits<ResultInteger>::ZERO),
52 myADY (NumberTraits<ResultInteger>::ZERO),
53 myBDX (NumberTraits<ResultInteger>::ZERO),
54 myDDet (NumberTraits<ResultInteger>::ZERO),
55 myZero (NumberTraits<ResultInteger>::ZERO)
56{
57}
58
59// ---------------------------------------------------------------------------
60template <typename TI, typename TO>
61inline
62DGtal::SimpleIncremental2x2DetComputer<TI,TO>::SimpleIncremental2x2DetComputer(const DGtal::SimpleIncremental2x2DetComputer<TI,TO>& aOther)
63 : myA (aOther.myA),
64 myB (aOther.myB),
65 myAY (aOther.myAY),
66 myBX (aOther.myBX),
67 myDet (aOther.myDet),
68 myX (aOther.myX),
69 myY (aOther.myY),
70 myDX (aOther.myDX),
71 myDY (aOther.myDY),
72 myADY (aOther.myADY),
73 myBDX (aOther.myBDX),
74 myDDet (aOther.myDDet),
75 myZero (aOther.myZero)
76{
77}
78
79// ---------------------------------------------------------------------------
80template <typename TI, typename TO>
81inline
82DGtal::SimpleIncremental2x2DetComputer<TI,TO>&
83DGtal::SimpleIncremental2x2DetComputer<TI,TO>::operator=(const DGtal::SimpleIncremental2x2DetComputer<TI,TO>& aOther)
84{
85 if (this != &aOther)
86 {
87 myA = aOther.myA;
88 myB = aOther.myB;
89 myAY = aOther.myAY;
90 myBX = aOther.myBX;
91 myDet = aOther.myDet;
92 myX = aOther.myX;
93 myY = aOther.myY;
94 myDX = aOther.myDX;
95 myDY = aOther.myDY;
96 myADY = aOther.myADY;
97 myBDX = aOther.myBDX;
98 myDDet = aOther.myDDet;
99 }
100 return *this;
101}
102
103// ---------------------------------------------------------------------------
104template <typename TI, typename TO>
105inline
106DGtal::SimpleIncremental2x2DetComputer<TI,TO>::~SimpleIncremental2x2DetComputer()
107{
108}
109
110// ---------------------------------------------------------------------------
111template <typename TI, typename TO>
112inline
113void
114DGtal::SimpleIncremental2x2DetComputer<TI,TO>::init(const ArgumentInteger& aA, const ArgumentInteger& aB)
115{
116 //memorize the first column vector
117 myA = static_cast<ResultInteger>(aA);
118 myB = static_cast<ResultInteger>(aB);
119 //clear members used to memorize old values
120 myX = NumberTraits<ResultInteger>::ZERO;
121 myY = NumberTraits<ResultInteger>::ZERO;
122 myDet = NumberTraits<ResultInteger>::ZERO;
123}
124
125// ---------------------------------------------------------------------------
126template <typename TI, typename TO>
127inline
128typename DGtal::SimpleIncremental2x2DetComputer<TI,TO>::ResultInteger
129DGtal::SimpleIncremental2x2DetComputer<TI,TO>::operator()(const ArgumentInteger& aX, const ArgumentInteger& aY) const
130{
131 //compute the difference with the last second column vector
132 myDX = aX - static_cast<ResultInteger>(myX);
133 myDY = aY - static_cast<ResultInteger>(myY);
134
135 //memorize the second column vector for the next computation
136 myX = aX;
137 myY = aY;
138
139 if (myDX == NumberTraits<ResultInteger>::ZERO)
140 {
141 partialComputation();
142 }
143 else if (myDX == NumberTraits<ResultInteger>::ONE)
144 {
145 myDet -= myB;
146 partialComputation();
147 }
148 else if (myDX == -NumberTraits<ResultInteger>::ONE)
149 {
150 myDet += myB;
151 partialComputation();
152 }
153 else
154 {
155 myBDX = myB * myDX;
156 myDet -= myBDX;
157 partialComputation();
158 }
159 return myDet;
160}
161
162// ---------------------------------------------------------------------------
163template <typename TI, typename TO>
164inline
165typename DGtal::SimpleIncremental2x2DetComputer<TI,TO>::ResultInteger
166DGtal::SimpleIncremental2x2DetComputer<TI,TO>::operator()(const ArgumentInteger& aA, const ArgumentInteger& aB,
167 const ArgumentInteger& aX, const ArgumentInteger& aY)
168{
169 init(aA,aB);
170 return operator()(aX, aY);
171}
172
173
174// ---------------------------------------------------------------------------
175template <typename TI, typename TO>
176inline
177void
178DGtal::SimpleIncremental2x2DetComputer<TI,TO>::partialComputation() const
179{
180 if (myDY != NumberTraits<ResultInteger>::ZERO)
181 {
182 if (myDY == NumberTraits<ResultInteger>::ONE)
183 {
184 myDet += myA;
185 }
186 else if (myDY == -NumberTraits<ResultInteger>::ONE)
187 {
188 myDet -= myA;
189 }
190 else
191 {
192 myADY = myA * myDY;
193 myDet += myADY;
194 }
195 }
196}
197
198// ---------------------------------------------------------------------------
199template <typename TI, typename TO>
200inline
201void
202DGtal::SimpleIncremental2x2DetComputer<TI,TO>::selfDisplay ( std::ostream & out ) const
203{
204 out << "[SimpleIncremental2x2DetComputer]";
205}
206
207// ---------------------------------------------------------------------------
208template <typename TI, typename TO>
209inline
210bool
211DGtal::SimpleIncremental2x2DetComputer<TI,TO>::isValid() const
212{
213 return true;
214}
215
216
217
218///////////////////////////////////////////////////////////////////////////////
219// Implementation of inline functions //
220
221template <typename TI, typename TO>
222inline
223std::ostream&
224DGtal::operator<< ( std::ostream & out,
225 const SimpleIncremental2x2DetComputer<TI,TO> & object )
226{
227 object.selfDisplay( out );
228 return out;
229}
230
231// //
232///////////////////////////////////////////////////////////////////////////////
233
234