72template<
typename DataPo
int>
74 using MatrixType =
typename DataPoint::MatrixType;
75 using Scalar =
typename DataPoint::Scalar;
76 using VectorType =
typename DataPoint::VectorType;
78 static constexpr Scalar
epsilon = Eigen::NumTraits<Scalar>::epsilon();
83 static bool isDegenerate(
const VectorType& a,
const VectorType& b,
const VectorType& c) {
84 Scalar d[3] = {(a - b).norm(), (a - c).norm(), (b - c).norm()};
90 if (d[1] > d[m]) m = 1;
91 if (d[2] > d[m]) m = 2;
92 return (fabs(d[m] - d[(m + 1) % 3] - d[(m + 2) % 3]) <
epsilon);
97 const VectorType& a,
const VectorType& b,
const VectorType& c,
98 VectorType& Ap , VectorType& Bp , VectorType& Cp
104 if (Ap.dot(a) < 0.0) Ap = -Ap;
105 if (Bp.dot(b) < 0.0) Bp = -Bp;
106 if (Cp.dot(c) < 0.0) Cp = -Cp;
114 const VectorType& a,
const VectorType& b,
const VectorType& c,
115 Scalar& alpha , Scalar& beta , Scalar& gamma
117 VectorType Ta, Tb, Tc;
122 if (Ta == VectorType::Zero() || Tb == VectorType::Zero() || Tc == VectorType::Zero())
123 alpha = beta = gamma = Scalar(0.0);
126 Scalar ca = std::max(Scalar(-1.0), std::min(Scalar(1.0), Tb.dot(Tc)));
127 Scalar cb = std::max(Scalar(-1.0), std::min(Scalar(1.0), Tc.dot(Ta)));
128 Scalar cc = std::max(Scalar(-1.0), std::min(Scalar(1.0), Ta.dot(Tb)));
136 static Scalar
area(
const VectorType& a,
const VectorType& b,
const VectorType& c) {
137 Scalar alpha, beta, gamma;
140 return ((fabs(alpha) <
epsilon)
144 : 2.0 * M_PI - alpha - beta - gamma;
148 static Scalar
algebraicArea(
const VectorType& a,
const VectorType& b,
const VectorType& c) {
149 Scalar S =
area(a, b, c);
150 VectorType M = a + b + c;
151 VectorType X = (b - a).cross(c - a);
152 if (M.template lpNorm<1>() <=
epsilon || X.template lpNorm<1>() <=
epsilon)
return 0.0;
153 return M.dot(X) < 0.0 ? -S : S;
179 const VectorType& ua,
180 const VectorType& ub,
181 const VectorType& uc,
186 VectorType uM = (ua + ub + uc) / 3.0;
188 auto uM_norm = uM.norm();
189 uM = uM_norm == 0.0 ? uM : uM / uM_norm;
191 return 0.5 * ((b - a).cross(c - a)).dot(uM);
211 const VectorType& ua,
212 const VectorType& ub,
213 const VectorType& uc,
217 VectorType uM = (ua + ub + uc) / 3.0;
218 if (unit_u) uM /= uM.norm();
219 return 0.25 * (uM.cross(uc - ub).dot(a)
220 + uM.cross(ua - uc).dot(b)
221 + uM.cross(ub - ua).dot(c));
241 const VectorType& ua,
242 const VectorType& ub,
243 const VectorType& uc,
252 return 0.5 * (ua.cross(ub).dot(uc));
269 const VectorType& ua,
270 const VectorType& ub,
271 const VectorType& uc,
274 MatrixType T = MatrixType::Zero();
275 VectorType uM = (ua + ub + uc) / 3.0;
276 if (unit_u) uM /= uM.norm();
277 const VectorType uac = uc - ua;
278 const VectorType uab = ub - ua;
279 const VectorType ab = b - a;
280 const VectorType ac = c - a;
281 for (
size_t i = 0; i < 3; ++i) {
282 VectorType X = VectorType::Zero();
284 for (
size_t j = 0; j < 3; ++j) {
288 0.5 * uM.dot(uac[j] * X.cross(ab)
289 - uab[j] * X.cross(ac));
309 const MatrixType& tensor,
313 auto Mt = tensor.transpose();
317 const Scalar coef_N = 1000.0 * area;
319 for (
int j = 0; j < 3; j++)
320 for (
int k = 0; k < 3; k++)
321 M(j, k) += coef_N * N[j] * N[k];
323 Eigen::SelfAdjointEigenSolver<MatrixType> eigensolver(M);
324 if (eigensolver.info() != Eigen::Success) abort();
328 assert(eigensolver.eigenvalues()(0) <= eigensolver.eigenvalues()(1));
329 assert(eigensolver.eigenvalues()(1) <= eigensolver.eigenvalues()(2));
330 VectorType v1 = eigensolver.eigenvectors().col(1);
331 VectorType v2 = eigensolver.eigenvectors().col(0);
332 return std::pair<VectorType, VectorType>(v1, v2);
341 const MatrixType& tensor,
345 auto Mt = tensor.transpose();
349 const Scalar coef_N = 1000.0 * area;
351 for (
int j = 0; j < 3; j++)
352 for (
int k = 0; k < 3; k++)
353 M(j, k) += coef_N * N[j] * N[k];
355 Eigen::SelfAdjointEigenSolver<MatrixType> eigensolver(M);
356 if (eigensolver.info() == Eigen::Success) {
359 assert(eigensolver.eigenvalues()(0) <= eigensolver.eigenvalues()(1));
360 assert(eigensolver.eigenvalues()(1) <= eigensolver.eigenvalues()(2));
361 VectorType v1 = eigensolver.eigenvectors().col(0);
362 VectorType v2 = eigensolver.eigenvectors().col(1);
363 return std::make_tuple(-eigensolver.eigenvalues()(0),
364 -eigensolver.eigenvalues()(1),
367 std::cerr <<
"Incorrect diagonalization for tensor " << M << std::endl;
369 return std::make_tuple(Scalar(0.0), Scalar(0.0), v1, v2);
Copyright (c) 2022 Jacques-Olivier Lachaud (jacques-olivier.lachaud@univ-savoie.fr) Laboratory of Mat...
Represents a triangle on a sphere of radius one.
static void polarTriangle(const VectorType &a, const VectorType &b, const VectorType &c, VectorType &Ap, VectorType &Bp, VectorType &Cp)
static Scalar area(const VectorType &a, const VectorType &b, const VectorType &c)
static Scalar algebraicArea(const VectorType &a, const VectorType &b, const VectorType &c)
static bool isDegenerate(const VectorType &a, const VectorType &b, const VectorType &c)
Spherical point data type.
static void interiorAngles(const VectorType &a, const VectorType &b, const VectorType &c, Scalar &alpha, Scalar &beta, Scalar &gamma)
Returns the interior angles of the spherical triangle ABC.
This class contains some stand-alone CorrectedNormalCurrent formulas for triangles,...
static Scalar mu2InterpolatedU(const VectorType &a, const VectorType &b, const VectorType &c, const VectorType &ua, const VectorType &ub, const VectorType &uc, bool unit_u=false)
Computes mu2 measure (Gaussian curvature) of triangle abc given an interpolated corrected normal vect...
static Scalar mu0InterpolatedU(const VectorType &a, const VectorType &b, const VectorType &c, const VectorType &ua, const VectorType &ub, const VectorType &uc, bool unit_u=false)
Computes mu0 measure (area) of triangle abc given an interpolated corrected normal vector ua,...
static MatrixType muXYInterpolatedU(const VectorType &a, const VectorType &b, const VectorType &c, const VectorType &ua, const VectorType &ub, const VectorType &uc, bool unit_u=false)
Computes muXY measure (anisotropic curvature) of triangle abc given an interpolated corrected normal ...
static std::tuple< Scalar, Scalar, VectorType, VectorType > curvaturesFromTensor(const MatrixType &tensor, const Scalar area, const VectorType &N)
Computing principal curvatures k1 and k2 from tensor.
static Scalar mu1InterpolatedU(const VectorType &a, const VectorType &b, const VectorType &c, const VectorType &ua, const VectorType &ub, const VectorType &uc, bool unit_u=false)
Computes mu1 measure (mean curvature) of triangle abc given an interpolated corrected normal vector u...
static constexpr Scalar epsilon
Small constant used to approximate zero.
static std::pair< VectorType, VectorType > curvDirFromTensor(const MatrixType &tensor, const Scalar area, const VectorType &N)
Computing principal curvatures k1 and k2 from tensor.