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>
37template <
typename MeshType>
38std::unique_ptr<MeshType> remove_topologically_degenerate_triangles(
const MeshType& mesh)
40 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
45 using Index =
typename MeshType::FacetArray::Scalar;
46 const auto& vertices = mesh.get_vertices();
47 const auto& facets = mesh.get_facets();
49 auto is_topologically_degenerate = [&facets](Index fid) {
50 return facets(fid, 0) == facets(fid, 1) || facets(fid, 1) == facets(fid, 2) ||
51 facets(fid, 2) == facets(fid, 0);
54 const Index num_facets = mesh.get_num_facets();
55 std::vector<Index> good_triangle_indices;
56 good_triangle_indices.reserve(num_facets);
57 for (Index i = 0; i < num_facets; i++) {
58 if (!is_topologically_degenerate(i)) {
59 good_triangle_indices.push_back(i);
63 Index num_non_degenerate_facets = safe_cast<Index>(good_triangle_indices.size());
64 typename MeshType::FacetArray good_facets(num_non_degenerate_facets, 3);
65 for (Index i = 0; i < num_non_degenerate_facets; i++) {
66 good_facets.row(i) = facets.row(good_triangle_indices[i]);
69 auto mesh2 =
create_mesh(vertices, std::move(good_facets));
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:40
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
void map_attributes(const SurfaceMesh< Scalar, Index > &source_mesh, SurfaceMesh< Scalar, Index > &target_mesh, span< const Index > mapping_data, span< const Index > mapping_offsets={}, const MapAttributesOptions &options={})
Map attributes from the source mesh to the target mesh.
Definition: map_attributes.cpp:26
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