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 ArithmeticalDSSCheck.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 functions defined in ArithmeticalDSSCheck.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
33 #include "ArithmeticalDSLKernel.h"
34 #include "DGtal/kernel/NumberTraits.h"
35 #include "DGtal/arithmetic/IntegerComputer.h"
36 //////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // Implementation of inline functions //
42 //-----------------------------------------------------------------------------
43 template <typename TCoordinate, typename TInteger, unsigned short adjacency>
47 checkOnePoint(const ArithmeticalDSS<TCoordinate,TInteger,adjacency>& aDSS)
49 ASSERT(aDSS.front()==aDSS.back());
51 //Vector type redefinition
52 typedef typename ArithmeticalDSS<TCoordinate,TInteger,adjacency>::Vector V;
54 return ( (aDSS.a()==NumberTraits<TCoordinate>::ZERO)
55 &&(aDSS.b()==NumberTraits<TCoordinate>::ZERO)
56 &&(aDSS.mu()==NumberTraits<TInteger>::ZERO)
57 &&(aDSS.omega()==NumberTraits<TInteger>::ZERO)
58 &&(aDSS.Uf()==aDSS.back())
59 &&(aDSS.Lf()==aDSS.back())
60 &&(aDSS.Ul()==aDSS.front())
61 &&(aDSS.Ll()==aDSS.front())
62 &&(aDSS.shift()==V(NumberTraits<TCoordinate>::ZERO,NumberTraits<TCoordinate>::ZERO))
63 &&(aDSS.steps().first==V(NumberTraits<TCoordinate>::ZERO,NumberTraits<TCoordinate>::ZERO))
64 &&(aDSS.steps().second==V(NumberTraits<TCoordinate>::ZERO,NumberTraits<TCoordinate>::ZERO)) );
67 //-----------------------------------------------------------------------------
68 template <typename TCoordinate, typename TInteger, unsigned short adjacency>
72 checkPointsRemainder(const ArithmeticalDSS<TCoordinate,TInteger,adjacency>& aDSS)
74 ASSERT(aDSS.front()!=aDSS.back());
76 //'true' if valid, 'false' otherwise
79 if (aDSS.remainder(aDSS.Uf()) != aDSS.mu())
81 else if (aDSS.remainder(aDSS.Ul()) != aDSS.mu())
83 else if (aDSS.remainder(aDSS.Lf()) != aDSS.mu()+aDSS.omega()-1)
84 { isValid = false; std::cout << aDSS.remainder(aDSS.Lf()) << " " << aDSS.mu()+aDSS.omega()-1 << std::endl;}
85 else if (aDSS.remainder(aDSS.Ll()) != aDSS.mu()+aDSS.omega()-1)
86 { isValid = false; std::cout << aDSS.remainder(aDSS.Ll()) << " " << aDSS.mu()+aDSS.omega()-1 << std::endl;}
87 else if (aDSS.isInDSL(aDSS.front()))
89 else if (aDSS.isInDSL(aDSS.back()))
97 //-----------------------------------------------------------------------------
98 template <typename TCoordinate, typename TInteger, unsigned short adjacency>
102 checkPointsPosition(const ArithmeticalDSS<TCoordinate,TInteger,adjacency>& aDSS)
104 ASSERT(aDSS.front()!=aDSS.back());
106 //Vector type redefinition
107 typedef typename ArithmeticalDSS<TCoordinate,TInteger,adjacency>::Vector V;
108 V v(aDSS.b(), aDSS.a());
109 //Length of direction vector
110 TInteger lv = aDSS.position(v);
112 //Position of end points and leaning points
113 TInteger posBack = aDSS.position(aDSS.back());
114 TInteger posUf = aDSS.position(aDSS.Uf());
115 TInteger posLf = aDSS.position(aDSS.Lf());
116 TInteger posUl = aDSS.position(aDSS.Ul());
117 TInteger posLl = aDSS.position(aDSS.Ll());
118 TInteger posFront = aDSS.position(aDSS.front());
120 bool isValid = ( ((posUf - posBack) < lv)
121 && ((posLf - posBack) < lv)
122 && ((posFront - posUl) < lv)
123 && ((posFront - posLl) < lv)
124 && ((posUl - posUf)%lv == 0)
125 && ( ( ((posUl - posUf) >= 0) && (lv >= 0) )
126 || ( ((posUl - posUf) < 0) && (lv < 0) ) )
127 && ((posLl - posLf)%lv == 0)
128 && ( ( ((posLl - posLf) >= 0) && (lv >= 0) )
129 || ( ((posLl - posLf) < 0) && (lv < 0) ) )
135 //-----------------------------------------------------------------------------
136 template <typename TCoordinate, typename TInteger, unsigned short adjacency>
140 checkAll(const ArithmeticalDSS<TCoordinate,TInteger,adjacency>& aDSS)
142 //'true' if valid, 'false' otherwise
145 //special case with one point
146 if (aDSS.front() == aDSS.back())
147 isValid = checkOnePoint(aDSS);
153 if (!aDSS.dsl().isValid())
155 else if (!checkPointsRemainder(aDSS))
157 else if (!checkPointsPosition(aDSS))
168 ///////////////////////////////////////////////////////////////////////////////