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/>.
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
24 * Implementation of inline methods defined in PlaneProbingEstimatorHelper.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
32//////////////////////////////////////////////////////////////////////////////
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline functions.
36///////////////////////////////////////////////////////////////////////////////
38// ------------------------------------------------------------------------
39template < typename Point >
41typename Point::Coordinate
42DGtal::detail::squaredNorm (Point const& aPoint)
44 using Integer = typename Point::Coordinate;
45 Integer res = DGtal::NumberTraits<Integer>::ZERO;
47 for (typename Point::Dimension i = 0; i < aPoint.size(); ++i)
49 res += aPoint[i] * aPoint[i];
55// ------------------------------------------------------------------------
56template < int N, typename T >
59DGtal::detail::determinant (const T aMatrix[N][N])
61 DGtal::SimpleMatrix<T, N, N> m;
63 for (int i = 0; i < N; ++i)
65 for (int j = 0; j < N; ++j)
67 m.setComponent(i, j, aMatrix[i][j]);
71 return m.determinant();
74// ------------------------------------------------------------------------
75template < typename Point >
77typename Point::Coordinate
78DGtal::detail::distToSphere (std::array<Point, 5> const& aPoints)
80 using Integer = typename Point::Coordinate;
81 Integer one = DGtal::NumberTraits<Integer>::ONE,
82 zero = DGtal::NumberTraits<Integer>::ZERO;
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 } };
89 if ( DGtal::detail::determinant<4, Integer>(M0) == zero)
91 throw std::runtime_error("4 coplanar points in distToSphere");
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);
101// ------------------------------------------------------------------------
102template < typename Point >
105DGtal::detail::isBasisReduced (Point const& aU, Point const& aV)
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));
114///////////////////////////////////////////////////////////////////////////////
115// IMPLEMENTATION of inline methods.
116///////////////////////////////////////////////////////////////////////////////
118///////////////////////////////////////////////////////////////////////////////
119// ----------------------- Standard services ------------------------------
121// ------------------------------------------------------------------------
122template < typename Integer >
124DGtal::detail::PointOnProbingRay<Integer>::
125PointOnProbingRay (Permutation const& aSigma, Integer const& aIndex)
126 : mySigma(aSigma), myIndex(aIndex)
131// ------------------------------------------------------------------------
132template < typename Integer >
134DGtal::detail::PointOnProbingRay<Integer>
135DGtal::detail::PointOnProbingRay<Integer>::getBase () const
137 return PointOnProbingRay(mySigma, 0);
140// ------------------------------------------------------------------------
141template < typename Integer >
143typename DGtal::detail::PointOnProbingRay<Integer>::Permutation const&
144DGtal::detail::PointOnProbingRay<Integer>::sigma () const
149// ------------------------------------------------------------------------
150template < typename Integer >
153DGtal::detail::PointOnProbingRay<Integer>::sigma (int aIndex) const
155 assert(aIndex >= 0 && aIndex <= 2);
156 return mySigma[aIndex];
159// ------------------------------------------------------------------------
160template < typename Integer >
163DGtal::detail::PointOnProbingRay<Integer>::index () const
168// ------------------------------------------------------------------------
169template < typename Integer >
172DGtal::detail::PointOnProbingRay<Integer>::operator== (PointOnProbingRay const& aRay) const
174 return (mySigma == aRay.mySigma) && (myIndex == aRay.index());
178// ------------------------------------------------------------------------
179template < typename Integer >
182DGtal::detail::PointOnProbingRay<Integer>::operator!= (PointOnProbingRay const& aRay) const
184 return !(*this == aRay);
187// ------------------------------------------------------------------------
188template < typename Integer >
191DGtal::detail::PointOnProbingRay<Integer>::operator<= (PointOnProbingRay const& aRay) const
193 return (mySigma == aRay.mySigma) && (myIndex <= aRay.index());
196// ------------------------------------------------------------------------
197template < typename Integer >
199DGtal::detail::PointOnProbingRay<Integer>
200DGtal::detail::PointOnProbingRay<Integer>::next (Integer const& aInc) const
202 return PointOnProbingRay(mySigma, myIndex + aInc);
205// ------------------------------------------------------------------------
206template < typename Integer >
208DGtal::detail::PointOnProbingRay<Integer>
209DGtal::detail::PointOnProbingRay<Integer>::previous (Integer const& aDec) const
211 return PointOnProbingRay(mySigma, myIndex - aDec);
214// ------------------------------------------------------------------------
215template < typename Integer >
218DGtal::detail::operator<< (std::ostream& aOs, PointOnProbingRay<Integer> const& aRay)
221 aRay.sigma(0) << ", " <<
222 aRay.sigma(1) << ", " <<
223 aRay.sigma(2) << "); i=" << aRay.index();