Ponca  292d8d7132745e0d4242ff9a01e93697fc96b204
Point Cloud Analysis library
Loading...
Searching...
No Matches
weingarten.hpp
1#include <Eigen/Eigenvalues>
2#include <Eigen/Core>
3
4namespace Ponca
5{
7 template <class DataPoint, class _NFilter, typename T>
8 requires FUNDAMENTAL_FORM_WEINGARTEN_ESTIMATOR_REQUIREMENTS
9 typename FundamentalFormWeingartenEstimator<DataPoint, _NFilter, T>::Matrix2 FundamentalFormWeingartenEstimator<
10 DataPoint, _NFilter, T>::firstFundamentalForm() const
11 {
12 Matrix2 first;
14 return first;
15 }
16
17 template <class DataPoint, class _NFilter, typename T>
18 requires FUNDAMENTAL_FORM_WEINGARTEN_ESTIMATOR_REQUIREMENTS
19 template <typename Matrix2Derived>
21 {
22 Base::firstFundamentalFormComponents(first(0, 0), first(1, 0), first(1, 1));
23 first(0, 1) = first(1, 0); // diagonal
24 }
25
26 template <class DataPoint, class _NFilter, typename T>
27 requires FUNDAMENTAL_FORM_WEINGARTEN_ESTIMATOR_REQUIREMENTS
28 typename FundamentalFormWeingartenEstimator<DataPoint, _NFilter, T>::Matrix2 FundamentalFormWeingartenEstimator<
29 DataPoint, _NFilter, T>::secondFundamentalForm() const
30 {
31 Matrix2 second;
33 return second;
34 }
35
36 template <class DataPoint, class _NFilter, typename T>
37 requires FUNDAMENTAL_FORM_WEINGARTEN_ESTIMATOR_REQUIREMENTS
38 template <typename Matrix2Derived>
40 {
41 Base::secondFundamentalFormComponents(second(0, 0), second(1, 0), second(1, 1));
42 second(0, 1) = second(1, 0); // diagonal
43 }
44
45 template <class DataPoint, class _NFilter, typename T>
46 requires FUNDAMENTAL_FORM_WEINGARTEN_ESTIMATOR_REQUIREMENTS
47 typename FundamentalFormWeingartenEstimator<DataPoint, _NFilter, T>::Matrix2 FundamentalFormWeingartenEstimator<
48 DataPoint, _NFilter, T>::weingartenMap() const
49 {
50 Matrix2 w;
52 return w;
53 }
54
55 template <class DataPoint, class _NFilter, typename T>
56 requires FUNDAMENTAL_FORM_WEINGARTEN_ESTIMATOR_REQUIREMENTS
57 template <typename Matrix2Derived>
62
63 template <class DataPoint, class _NFilter, typename T>
64 requires FUNDAMENTAL_FORM_WEINGARTEN_ESTIMATOR_REQUIREMENTS
66 DataPoint, _NFilter, T>::kMean() const
67 {
68 Scalar E, F, G, L, M, N;
69 Base::firstFundamentalFormComponents(E, F, G);
70 Base::secondFundamentalFormComponents(L, M, N);
71 return (G * L - Scalar(2) * F * M + E * N) / (Scalar(2) * (E * G - F * F));
72 }
73
74 template <class DataPoint, class _NFilter, typename T>
75 requires FUNDAMENTAL_FORM_WEINGARTEN_ESTIMATOR_REQUIREMENTS
77 DataPoint, _NFilter, T>::GaussianCurvature() const
78 {
79 Scalar E, F, G, L, M, N;
80 Base::firstFundamentalFormComponents(E, F, G);
81 Base::secondFundamentalFormComponents(L, M, N);
82 return (L * N - M * M) / (E * G - F * F);
83 }
84
86 template <class DataPoint, class _NFilter, int DiffType, typename T>
87 requires NORMAL_DERIVATIVE_WEINGARTEN_ESTIMATOR_REQUIREMENTS
88 typename NormalDerivativeWeingartenEstimator<DataPoint, _NFilter, DiffType, T>::Matrix2
95
96 template <class DataPoint, class _NFilter, int DiffType, typename T>
97 requires NORMAL_DERIVATIVE_WEINGARTEN_ESTIMATOR_REQUIREMENTS
98 FIT_RESULT NormalDerivativeWeingartenEstimator<DataPoint, _NFilter, DiffType, T>::finalize()
99 {
100
101 PONCA_MULTIARCH_STD_MATH(abs);
102 PONCA_MULTIARCH_STD_MATH(sqrt);
103
104 using Index = typename VectorType::Index;
105
106 // Checked below
107 (void)Base::finalize();
108
109 // Test if base finalize end on a viable case (stable / unstable)
110 if (this->isReady())
111 {
112 Index i0 = Index(-1), i1 = Index(-1), i2 = Index(-1);
113
114 MatrixType dN = Base::dNormal().template middleCols<DataPoint::Dim>(Base::isScaleDer() ? 1 : 0);
115
116 // Make sure m_tangentBasis is orthonormal
117 VectorType n = Base::primitiveGradient(Base::getNeighborFilter().center()).normalized();
118 n.array().abs().minCoeff(&i0); // i0: dimension where n extends the least
119 i1 = (i0 + 1) % 3;
120 i2 = (i0 + 2) % 3;
121
122 m_tangentBasis.col(0) = n;
123
124 m_tangentBasis.col(1)[i0] = 0;
125 m_tangentBasis.col(1)[i1] = n[i2];
126 m_tangentBasis.col(1)[i2] = -n[i1];
127
128 m_tangentBasis.col(1).normalize();
129 m_tangentBasis.col(2) = m_tangentBasis.col(1).cross(n);
130 }
131 return Base::m_eCurrentState;
132 }
133
134 template <class DataPoint, class _NFilter, int DiffType, typename T>
135 requires NORMAL_DERIVATIVE_WEINGARTEN_ESTIMATOR_REQUIREMENTS
136 template <typename Matrix2Derived>
138 {
139 PONCA_MULTIARCH_STD_MATH(abs);
140 PONCA_MULTIARCH_STD_MATH(sqrt);
141
142 using Index = typename VectorType::Index;
143 using Matrix32 = Eigen::Matrix<Scalar, 3, 2>;
144
145 // Get the object space Weingarten map dN
146 MatrixType dN = Base::dNormal().template middleCols<DataPoint::Dim>(Base::isScaleDer() ? 1 : 0);
147
148 // Compute tangent-space change of basis function
149 auto B = m_tangentBasis.template rightCols<2>();
150
151 // Compute the 2x2 matrix representing the shape operator by transforming dN to the basis B.
152 // Recall that dN is a bilinear form, it thus transforms as follows:
153 W = B.transpose() * dN * B;
154
155 // Recall that at this stage, the shape operator represented by W describes the normal curvature K_n(u) in the
156 // direction u \in R^2 as follows:
157 // K_n(u) = u^T W u
158 // The principal curvatures are fully defined by the values and the directions of the extrema of K_n.
159 //
160 // If the normal field N(x) comes from the gradient of a scalar field, then N(x) is curl-free, and dN and W are
161 // symmetric matrices. In this case, the extrema of the previous quadratic form are directly obtained by the
162 // eigenvalue decomposition of W. However, if N(x) is only an approximation of the normal field of a surface,
163 // then N(x) is not necessarily curl-free, and in this case W is not symmetric. In this case, we first have to
164 // find an equivalent symmetric matrix W' such that:
165 // K_n(u) = u^T W' u,
166 // for any u \in R^2.
167 // It is easy to see that such a W' is simply obtained as:
168 // W' = (W + W^T)/2
169 W(0, 1) = W(1, 0) = (W(0, 1) + W(1, 0)) / Scalar(2);
170 }
171
172 template <class DataPoint, class _NFilter, int DiffType, typename T>
173 requires NORMAL_DERIVATIVE_WEINGARTEN_ESTIMATOR_REQUIREMENTS
176 const VectorType& _q, bool _isPositionVector) const
177 {
178 return m_tangentBasis.transpose() * Base::getNeighborFrame().convertToLocalBasis(_q, _isPositionVector);
179 }
180
181 template <class DataPoint, class _NFilter, int DiffType, typename T>
182 requires NORMAL_DERIVATIVE_WEINGARTEN_ESTIMATOR_REQUIREMENTS
185 const VectorType& _lq, bool _isPositionVector) const
186 {
187 return Base::getNeighborFrame().convertToGlobalBasis(m_tangentBasis * _lq, _isPositionVector);
188 }
189
190 namespace internal
191 {
193 template <class DataPoint, class _NFilter, typename T>
194 requires WIENGARTEN_CURVATURE_ESTIMATOR_REQUIREMENTS
195 FIT_RESULT WeingartenCurvatureEstimatorBase<DataPoint, _NFilter, T>::finalize()
196 {
197 if (Base::finalize() != STABLE)
198 return Base::m_eCurrentState;
199
200 Matrix2 w;
201 Base::weingartenMap(w);
202 m_solver.computeDirect(w);
203
204 return Base::m_eCurrentState;
205 }
206 } // namespace internal
207} // namespace Ponca
208
Compute a Weingarten map from fundamental forms.
Definition weingarten.h:44
Scalar GaussianCurvature() const
Returns an estimate of the Gaussian curvature directly from the fundamental forms.
Scalar kMean() const
Returns an estimate of the mean curvature directly from the fundamental forms.
Matrix2 weingartenMap() const
Returns the Weingarten Map.
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition weingarten.h:45
Matrix2 secondFundamentalForm() const
Assembles and returns the second fundamental form from the base class.
Matrix2 firstFundamentalForm() const
Assembles and returns the first fundamental form from the base class.
typename Base::VectorType VectorType
Alias to vector type.
Definition weingarten.h:114
VectorType tangentPlaneToWorld(const VectorType &_q, bool _isPositionVector=true) const
Transform a point from the tangent plane [h, u, v]^T to ambient space.
VectorType worldToTangentPlane(const VectorType &_q, bool _isPositionVector=true) const
Express a point in ambient space relatively to the tangent plane.
typename DataPoint::MatrixType MatrixType
Alias to matrix type.
Definition weingarten.h:115
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition weingarten.h:114
Matrix2 weingartenMap() const
Returns the Weingarten Map.
Copyright (c) 2022 Jacques-Olivier Lachaud (jacques-olivier.lachaud@univ-savoie.fr) Laboratory of Mat...
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
FIT_RESULT
Enum corresponding to the state of a fitting method (and what the finalize function returns).
Definition enums.h:15
@ STABLE
The fitting is stable and ready to use.
Definition enums.h:17