16#include <lagrange/Mesh.h>
17#include <lagrange/utils/range.h>
30template <
typename MeshType>
33 const typename MeshType::VertexType& center,
34 const typename MeshType::IndexList& active_facets =
typename MeshType::IndexList())
37 using Scalar =
typename MeshType::Scalar;
38 using Vector3 = Eigen::Matrix<Scalar, 1, 3>;
39 using Matrix3 = Eigen::Matrix<Scalar, 3, 3>;
41 const auto& vertices = mesh_ref.get_vertices();
42 const auto& facets = mesh_ref.get_facets();
44 la_runtime_assert(vertices.cols() == 3,
"Currently, only 3 dimensions are supported");
48 factors.row(0) << Scalar(1. / 2), Scalar(1. / 3), Scalar(1. / 6);
49 factors.row(1) << Scalar(1. / 3), Scalar(1. / 4), Scalar(1. / 8);
50 factors.row(2) << Scalar(1. / 6), Scalar(1. / 8), Scalar(1. / 12);
52 auto triangle_covariance = [&factors](
56 const Vector3& c) -> Matrix3 {
57 const Scalar a = (v2 - v1).cross(v3 - v1).norm();
63 const Matrix3 covariance = a * p.transpose() * factors * p;
68 Matrix3 covariance = Matrix3::Zero();
69 for (
auto facet_id :
range_sparse(mesh_ref.get_num_facets(), active_facets)) {
70 const Vector3 v0 = vertices.row(facets(facet_id, 0));
71 const Vector3 v1 = vertices.row(facets(facet_id, 1));
72 const Vector3 v2 = vertices.row(facets(facet_id, 2));
73 covariance += triangle_covariance(v0, v1, v2, center);
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
internal::SparseRange< Index > range_sparse(Index max, const std::vector< Index > &active)
Returns an iterable object representing a subset of the range [0, max).
Definition: range.h:217
Main namespace for Lagrange.
Definition: AABBIGL.h:30
std::array< std::array< Scalar, 3 >, 3 > compute_mesh_covariance(const SurfaceMesh< Scalar, Index > &mesh, const MeshCovarianceOptions &options={})
Compute the covariance matrix w.r.t.
Definition: compute_mesh_covariance.cpp:28