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.
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.
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/>.
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
24 * Implementation of inline methods defined in SimpleIncremental2x2DetComputer.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
32//////////////////////////////////////////////////////////////////////////////
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
38///////////////////////////////////////////////////////////////////////////////
39// ---------------------------------------------------------------------------
40template <typename TI, typename TO>
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)
59// ---------------------------------------------------------------------------
60template <typename TI, typename TO>
62DGtal::SimpleIncremental2x2DetComputer<TI,TO>::SimpleIncremental2x2DetComputer(const DGtal::SimpleIncremental2x2DetComputer<TI,TO>& aOther)
74 myDDet (aOther.myDDet),
75 myZero (aOther.myZero)
79// ---------------------------------------------------------------------------
80template <typename TI, typename TO>
82DGtal::SimpleIncremental2x2DetComputer<TI,TO>&
83DGtal::SimpleIncremental2x2DetComputer<TI,TO>::operator=(const DGtal::SimpleIncremental2x2DetComputer<TI,TO>& aOther)
98 myDDet = aOther.myDDet;
103// ---------------------------------------------------------------------------
104template <typename TI, typename TO>
106DGtal::SimpleIncremental2x2DetComputer<TI,TO>::~SimpleIncremental2x2DetComputer()
110// ---------------------------------------------------------------------------
111template <typename TI, typename TO>
114DGtal::SimpleIncremental2x2DetComputer<TI,TO>::init(const ArgumentInteger& aA, const ArgumentInteger& aB)
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;
125// ---------------------------------------------------------------------------
126template <typename TI, typename TO>
128typename DGtal::SimpleIncremental2x2DetComputer<TI,TO>::ResultInteger
129DGtal::SimpleIncremental2x2DetComputer<TI,TO>::operator()(const ArgumentInteger& aX, const ArgumentInteger& aY) const
131 //compute the difference with the last second column vector
132 myDX = aX - static_cast<ResultInteger>(myX);
133 myDY = aY - static_cast<ResultInteger>(myY);
135 //memorize the second column vector for the next computation
139 if (myDX == NumberTraits<ResultInteger>::ZERO)
141 partialComputation();
143 else if (myDX == NumberTraits<ResultInteger>::ONE)
146 partialComputation();
148 else if (myDX == -NumberTraits<ResultInteger>::ONE)
151 partialComputation();
157 partialComputation();
162// ---------------------------------------------------------------------------
163template <typename TI, typename TO>
165typename DGtal::SimpleIncremental2x2DetComputer<TI,TO>::ResultInteger
166DGtal::SimpleIncremental2x2DetComputer<TI,TO>::operator()(const ArgumentInteger& aA, const ArgumentInteger& aB,
167 const ArgumentInteger& aX, const ArgumentInteger& aY)
170 return operator()(aX, aY);
174// ---------------------------------------------------------------------------
175template <typename TI, typename TO>
178DGtal::SimpleIncremental2x2DetComputer<TI,TO>::partialComputation() const
180 if (myDY != NumberTraits<ResultInteger>::ZERO)
182 if (myDY == NumberTraits<ResultInteger>::ONE)
186 else if (myDY == -NumberTraits<ResultInteger>::ONE)
198// ---------------------------------------------------------------------------
199template <typename TI, typename TO>
202DGtal::SimpleIncremental2x2DetComputer<TI,TO>::selfDisplay ( std::ostream & out ) const
204 out << "[SimpleIncremental2x2DetComputer]";
207// ---------------------------------------------------------------------------
208template <typename TI, typename TO>
211DGtal::SimpleIncremental2x2DetComputer<TI,TO>::isValid() const
218///////////////////////////////////////////////////////////////////////////////
219// Implementation of inline functions //
221template <typename TI, typename TO>
224DGtal::operator<< ( std::ostream & out,
225 const SimpleIncremental2x2DetComputer<TI,TO> & object )
227 object.selfDisplay( out );
232///////////////////////////////////////////////////////////////////////////////