64#include "../../Common/Assert.h"
74 template <
typename DataPo
int>
77 using MatrixType =
typename DataPoint::MatrixType;
78 using Scalar =
typename DataPoint::Scalar;
79 using VectorType =
typename DataPoint::VectorType;
81 static constexpr Scalar
epsilon = Eigen::NumTraits<Scalar>::epsilon();
87 static bool isDegenerate(
const VectorType& a,
const VectorType& b,
const VectorType& c)
89 Scalar d[3] = {(a - b).norm(), (a - c).norm(), (b - c).norm()};
99 return (fabs(d[m] - d[(m + 1) % 3] - d[(m + 2) % 3]) <
epsilon);
103 static void polarTriangle(
const VectorType& a,
const VectorType& b,
const VectorType& c, VectorType& Ap,
104 VectorType& Bp, VectorType& Cp)
122 static void interiorAngles(
const VectorType& a,
const VectorType& b,
const VectorType& c, Scalar& alpha,
123 Scalar& beta, Scalar& gamma)
125 VectorType Ta, Tb, Tc;
130 if (Ta == VectorType::Zero() || Tb == VectorType::Zero() || Tc == VectorType::Zero())
131 alpha = beta = gamma = Scalar(0.0);
134 Scalar ca = std::max(Scalar(-1.0), std::min(Scalar(1.0), Tb.dot(Tc)));
135 Scalar cb = std::max(Scalar(-1.0), std::min(Scalar(1.0), Tc.dot(Ta)));
136 Scalar cc = std::max(Scalar(-1.0), std::min(Scalar(1.0), Ta.dot(Tb)));
144 static Scalar
area(
const VectorType& a,
const VectorType& b,
const VectorType& c)
146 Scalar alpha, beta, gamma;
152 : Scalar(2.0 * M_PI) - alpha - beta - gamma;
156 static Scalar
algebraicArea(
const VectorType& a,
const VectorType& b,
const VectorType& c)
158 Scalar S =
area(a, b, c);
159 VectorType M = a + b + c;
160 VectorType X = (b - a).cross(c - a);
161 if (M.template lpNorm<1>() <=
epsilon || X.template lpNorm<1>() <=
epsilon)
163 return M.dot(X) < 0.0 ? -S : S;
184 static Scalar
mu0InterpolatedU(
const VectorType& a,
const VectorType& b,
const VectorType& c,
185 const VectorType& ua,
const VectorType& ub,
const VectorType& uc,
190 VectorType uM = (ua + ub + uc) / 3.0;
193 auto uM_norm = uM.norm();
194 uM = uM_norm == Scalar(0.0) ? uM : uM / uM_norm;
196 return Scalar(0.5) * ((b - a).cross(c - a)).dot(uM);
211 static Scalar
mu1InterpolatedU(
const VectorType& a,
const VectorType& b,
const VectorType& c,
212 const VectorType& ua,
const VectorType& ub,
const VectorType& uc,
216 VectorType uM = (ua + ub + uc) / Scalar(3.0);
219 return Scalar(0.25) * (uM.cross(uc - ub).dot(a) + uM.cross(ua - uc).dot(b) + uM.cross(ub - ua).dot(c));
234 static Scalar
mu2InterpolatedU(
const VectorType& a,
const VectorType& b,
const VectorType& c,
235 const VectorType& ua,
const VectorType& ub,
const VectorType& uc,
244 return Scalar(0.5) * (ua.cross(ub).dot(uc));
256 static MatrixType
muXYInterpolatedU(
const VectorType& a,
const VectorType& b,
const VectorType& c,
257 const VectorType& ua,
const VectorType& ub,
const VectorType& uc,
260 MatrixType T = MatrixType::Zero();
261 VectorType uM = (ua + ub + uc) / 3.0;
264 const VectorType uac = uc - ua;
265 const VectorType uab = ub - ua;
266 const VectorType ab = b - a;
267 const VectorType ac = c - a;
268 for (
size_t i = 0; i < 3; ++i)
270 VectorType X = VectorType::Zero();
272 for (
size_t j = 0; j < 3; ++j)
276 const Scalar tij = Scalar(0.5) * uM.dot(uac[j] * X.cross(ab) - uab[j] * X.cross(ac));
295 static std::pair<VectorType, VectorType>
curvDirFromTensor(
const MatrixType& tensor,
const Scalar area,
298 auto Mt = tensor.transpose();
302 const Scalar coef_N = Scalar(1000.0) * area;
304 for (
int j = 0; j < 3; j++)
305 for (
int k = 0; k < 3; k++)
306 M(j, k) += coef_N * N[j] * N[k];
308 Eigen::SelfAdjointEigenSolver<MatrixType> eigensolver(M);
309 if (eigensolver.info() != Eigen::Success)
314 PONCA_ASSERT(eigensolver.eigenvalues()(0) <= eigensolver.eigenvalues()(1));
315 PONCA_ASSERT(eigensolver.eigenvalues()(1) <= eigensolver.eigenvalues()(2));
316 VectorType v1 = eigensolver.eigenvectors().col(1);
317 VectorType v2 = eigensolver.eigenvectors().col(0);
318 return std::pair<VectorType, VectorType>(v1, v2);
330 auto Mt = tensor.transpose();
334 const Scalar coef_N = Scalar(1000.0) * area;
336 for (
int j = 0; j < 3; j++)
337 for (
int k = 0; k < 3; k++)
338 M(j, k) += coef_N * N[j] * N[k];
340 Eigen::SelfAdjointEigenSolver<MatrixType> eigensolver(M);
341 if (eigensolver.info() == Eigen::Success)
345 PONCA_ASSERT(eigensolver.eigenvalues()(0) <= eigensolver.eigenvalues()(1));
346 PONCA_ASSERT(eigensolver.eigenvalues()(1) <= eigensolver.eigenvalues()(2));
347 VectorType v1 = eigensolver.eigenvectors().col(0);
348 VectorType v2 = eigensolver.eigenvectors().col(1);
349 return std::make_tuple(-eigensolver.eigenvalues()(0), -eigensolver.eigenvalues()(1), v1, v2);
354 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.