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 // ------------------------------------------------------------------------
39 template < typename Point >
41 typename Point::Coordinate
42 DGtal::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 // ------------------------------------------------------------------------
56 template < int N, typename T >
59 DGtal::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 // ------------------------------------------------------------------------
75 template < typename Point >
77 typename Point::Coordinate
78 DGtal::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 // ------------------------------------------------------------------------
102 template < typename Point >
105 DGtal::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 // ------------------------------------------------------------------------
122 template < typename Integer, typename Index >
124 DGtal::detail::PointOnProbingRay<Integer,Index>::
125 PointOnProbingRay (Permutation const& aSigma, Integer const& aPosition)
126 : mySigma(aSigma), myPosition(aPosition)
131 // ------------------------------------------------------------------------
132 template < typename Integer, typename Index >
134 DGtal::detail::PointOnProbingRay<Integer,Index>
135 DGtal::detail::PointOnProbingRay<Integer,Index>::getBase () const
137 return PointOnProbingRay(mySigma, 0);
140 // ------------------------------------------------------------------------
141 template < typename Integer, typename Index >
143 typename DGtal::detail::PointOnProbingRay<Integer,Index>::Permutation const&
144 DGtal::detail::PointOnProbingRay<Integer,Index>::sigma () const
149 // ------------------------------------------------------------------------
150 template < typename Integer, typename Index >
153 DGtal::detail::PointOnProbingRay<Integer,Index>::sigma (Index const& aIndex) const
155 assert(aIndex >= 0 && aIndex <= 2);
156 return mySigma[aIndex];
159 // ------------------------------------------------------------------------
160 template < typename Integer, typename Index >
163 DGtal::detail::PointOnProbingRay<Integer,Index>::position () const
168 // ------------------------------------------------------------------------
169 template < typename Integer, typename Index >
170 template < typename Point >
173 DGtal::detail::PointOnProbingRay<Integer,Index>::relativePoint (std::array<Point, 3> const& aM) const {
174 return -aM[mySigma[0]] + aM[mySigma[1]] + aM[mySigma[2]] * myPosition;
177 // ------------------------------------------------------------------------
178 template < typename Integer, typename Index >
181 DGtal::detail::PointOnProbingRay<Integer,Index>::operator== (PointOnProbingRay const& aRay) const
183 return (mySigma == aRay.mySigma) && (myPosition == aRay.position());
186 // ------------------------------------------------------------------------
187 template < typename Integer, typename Index >
190 DGtal::detail::PointOnProbingRay<Integer,Index>::operator!= (PointOnProbingRay const& aRay) const
192 return !(*this == aRay);
195 // ------------------------------------------------------------------------
196 template < typename Integer, typename Index >
199 DGtal::detail::PointOnProbingRay<Integer,Index>::operator<= (PointOnProbingRay const& aRay) const
201 return (mySigma == aRay.mySigma) && (myPosition <= aRay.position());
204 // ------------------------------------------------------------------------
205 template < typename Integer, typename Index >
207 DGtal::detail::PointOnProbingRay<Integer,Index>
208 DGtal::detail::PointOnProbingRay<Integer,Index>::next (Integer const& aInc) const
210 return PointOnProbingRay(mySigma, myPosition + aInc);
213 // ------------------------------------------------------------------------
214 template < typename Integer, typename Index >
216 DGtal::detail::PointOnProbingRay<Integer,Index>
217 DGtal::detail::PointOnProbingRay<Integer,Index>::previous (Integer const& aDec) const
219 return PointOnProbingRay(mySigma, myPosition - aDec);
222 // ------------------------------------------------------------------------
223 template < typename Integer, typename Index >
226 DGtal::detail::operator<< (std::ostream& aOs, PointOnProbingRay<Integer,Index> const& aRay)
229 aRay.sigma(0) << ", " <<
230 aRay.sigma(1) << ", " <<
231 aRay.sigma(2) << "); i=" << aRay.position();