14#include <lagrange/Mesh.h>
15#include <lagrange/MeshTrait.h>
16#include <lagrange/attributes/map_attributes.h>
17#include <lagrange/common.h>
18#include <lagrange/create_mesh.h>
19#include <lagrange/legacy/inline.h>
25template <
typename MeshType>
26std::unique_ptr<MeshType> remove_null_area_triangles(
const MeshType& mesh)
29 assert(mesh.get_vertex_per_facet() == 3);
31 using Index =
typename MeshType::FacetArray::Scalar;
32 const auto& vertices = mesh.get_vertices();
33 const auto& facets = mesh.get_facets();
35 auto has_non_null_area = [&vertices, &facets](Index fid) {
36 const auto& aa = vertices.row(facets(fid, 0));
37 const auto& bb = vertices.row(facets(fid, 1));
38 const auto& cc = vertices.row(facets(fid, 2));
39 const auto& area = (bb - aa).cross(cc - aa).norm();
43 const Index num_facets = mesh.get_num_facets();
44 std::vector<Index> good_triangle_indices;
45 for (Index i = 0; i < num_facets; i++) {
46 if (has_non_null_area(i)) {
47 good_triangle_indices.push_back(i);
51 Index num_non_degenerate_facets = lagrange::safe_cast<Index>(good_triangle_indices.size());
52 typename MeshType::FacetArray good_facets(num_non_degenerate_facets, 3);
53 for (Index i = 0; i < num_non_degenerate_facets; i++) {
54 good_facets.row(i) = facets.row(good_triangle_indices[i]);
59 lagrange::map_attributes(mesh, *mesh_, {}, good_triangle_indices);
Main namespace for Lagrange.
Definition: AABBIGL.h:30
auto create_mesh(const Eigen::MatrixBase< DerivedV > &vertices, const Eigen::MatrixBase< DerivedF > &facets)
This function create a new mesh given the vertex and facet arrays by copying data into the Mesh objec...
Definition: create_mesh.h:39
MeshTrait class provide compiler check for different mesh types.
Definition: MeshTrait.h:108