DGtal 1.3.0
Loading...
Searching...
No Matches
PlaneProbingEstimatorHelper.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
19 * @author Jocelyn Meyron (\c jocelyn.meyron@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21 *
22 * @date 2020/09/15
23 *
24 * Implementation of inline methods defined in PlaneProbingEstimatorHelper.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 functions.
36///////////////////////////////////////////////////////////////////////////////
37
38// ------------------------------------------------------------------------
39template < typename Point >
40inline
41typename Point::Coordinate
42DGtal::detail::squaredNorm (Point const& aPoint)
43{
44 using Integer = typename Point::Coordinate;
45 Integer res = DGtal::NumberTraits<Integer>::ZERO;
46
47 for (typename Point::Dimension i = 0; i < aPoint.size(); ++i)
48 {
49 res += aPoint[i] * aPoint[i];
50 }
51
52 return res;
53}
54
55// ------------------------------------------------------------------------
56template < int N, typename T >
57inline
58T
59DGtal::detail::determinant (const T aMatrix[N][N])
60{
61 DGtal::SimpleMatrix<T, N, N> m;
62
63 for (int i = 0; i < N; ++i)
64 {
65 for (int j = 0; j < N; ++j)
66 {
67 m.setComponent(i, j, aMatrix[i][j]);
68 }
69 }
70
71 return m.determinant();
72}
73
74// ------------------------------------------------------------------------
75template < typename Point >
76inline
77typename Point::Coordinate
78DGtal::detail::distToSphere (std::array<Point, 5> const& aPoints)
79{
80 using Integer = typename Point::Coordinate;
81 Integer one = DGtal::NumberTraits<Integer>::ONE,
82 zero = DGtal::NumberTraits<Integer>::ZERO;
83
84 Integer M0[4][4] = { { aPoints[0][0], aPoints[0][1], aPoints[0][2], one },
85 { aPoints[1][0], aPoints[1][1], aPoints[1][2], one },
86 { aPoints[2][0], aPoints[2][1], aPoints[2][2], one },
87 { aPoints[3][0], aPoints[3][1], aPoints[3][2], one } };
88
89 if ( DGtal::detail::determinant<4, Integer>(M0) == zero)
90 {
91 throw std::runtime_error("4 coplanar points in distToSphere");
92 }
93 Integer M[5][5] = { { aPoints[0][0], aPoints[0][1], aPoints[0][2], squaredNorm(aPoints[0]), one },
94 { aPoints[1][0], aPoints[1][1], aPoints[1][2], squaredNorm(aPoints[1]), one },
95 { aPoints[2][0], aPoints[2][1], aPoints[2][2], squaredNorm(aPoints[2]), one },
96 { aPoints[3][0], aPoints[3][1], aPoints[3][2], squaredNorm(aPoints[3]), one },
97 { aPoints[4][0], aPoints[4][1], aPoints[4][2], squaredNorm(aPoints[4]), one } };
98 return DGtal::detail::determinant<5, Integer>(M);
99}
100
101// ------------------------------------------------------------------------
102template < typename Point >
103inline
104bool
105DGtal::detail::isBasisReduced (Point const& aU, Point const& aV)
106{
107 Point w = aU + aV, x = aU - aV;
108 return (squaredNorm(aU) <= squaredNorm(w)) &&
109 (squaredNorm(aU) <= squaredNorm(x)) &&
110 (squaredNorm(aV) <= squaredNorm(w)) &&
111 (squaredNorm(aV) <= squaredNorm(x));
112}
113
114///////////////////////////////////////////////////////////////////////////////
115// IMPLEMENTATION of inline methods.
116///////////////////////////////////////////////////////////////////////////////
117
118///////////////////////////////////////////////////////////////////////////////
119// ----------------------- Standard services ------------------------------
120
121// ------------------------------------------------------------------------
122template < typename Integer >
123inline
124DGtal::detail::PointOnProbingRay<Integer>::
125PointOnProbingRay (Permutation const& aSigma, Integer const& aIndex)
126 : mySigma(aSigma), myIndex(aIndex)
127{
128}
129
130
131// ------------------------------------------------------------------------
132template < typename Integer >
133inline
134DGtal::detail::PointOnProbingRay<Integer>
135DGtal::detail::PointOnProbingRay<Integer>::getBase () const
136{
137 return PointOnProbingRay(mySigma, 0);
138}
139
140// ------------------------------------------------------------------------
141template < typename Integer >
142inline
143typename DGtal::detail::PointOnProbingRay<Integer>::Permutation const&
144DGtal::detail::PointOnProbingRay<Integer>::sigma () const
145{
146 return mySigma;
147}
148
149// ------------------------------------------------------------------------
150template < typename Integer >
151inline
152int
153DGtal::detail::PointOnProbingRay<Integer>::sigma (int aIndex) const
154{
155 assert(aIndex >= 0 && aIndex <= 2);
156 return mySigma[aIndex];
157}
158
159// ------------------------------------------------------------------------
160template < typename Integer >
161inline
162Integer const&
163DGtal::detail::PointOnProbingRay<Integer>::index () const
164{
165 return myIndex;
166}
167
168// ------------------------------------------------------------------------
169template < typename Integer >
170inline
171bool
172DGtal::detail::PointOnProbingRay<Integer>::operator== (PointOnProbingRay const& aRay) const
173{
174 return (mySigma == aRay.mySigma) && (myIndex == aRay.index());
175}
176
177
178// ------------------------------------------------------------------------
179template < typename Integer >
180inline
181bool
182DGtal::detail::PointOnProbingRay<Integer>::operator!= (PointOnProbingRay const& aRay) const
183{
184 return !(*this == aRay);
185}
186
187// ------------------------------------------------------------------------
188template < typename Integer >
189inline
190bool
191DGtal::detail::PointOnProbingRay<Integer>::operator<= (PointOnProbingRay const& aRay) const
192{
193 return (mySigma == aRay.mySigma) && (myIndex <= aRay.index());
194}
195
196// ------------------------------------------------------------------------
197template < typename Integer >
198inline
199DGtal::detail::PointOnProbingRay<Integer>
200DGtal::detail::PointOnProbingRay<Integer>::next (Integer const& aInc) const
201{
202 return PointOnProbingRay(mySigma, myIndex + aInc);
203}
204
205// ------------------------------------------------------------------------
206template < typename Integer >
207inline
208DGtal::detail::PointOnProbingRay<Integer>
209DGtal::detail::PointOnProbingRay<Integer>::previous (Integer const& aDec) const
210{
211 return PointOnProbingRay(mySigma, myIndex - aDec);
212}
213
214// ------------------------------------------------------------------------
215template < typename Integer >
216inline
217std::ostream&
218DGtal::detail::operator<< (std::ostream& aOs, PointOnProbingRay<Integer> const& aRay)
219{
220 aOs << "sigma=(" <<
221 aRay.sigma(0) << ", " <<
222 aRay.sigma(1) << ", " <<
223 aRay.sigma(2) << "); i=" << aRay.index();
224 return aOs;
225}