18#include <lagrange/Mesh.h>
19#include <lagrange/MeshTrait.h>
20#include <lagrange/attributes/map_attributes.h>
21#include <lagrange/common.h>
22#include <lagrange/compute_edge_lengths.h>
23#include <lagrange/create_mesh.h>
24#include <lagrange/legacy/inline.h>
25#include <lagrange/mesh_cleanup/remove_isolated_vertices.h>
26#include <lagrange/mesh_cleanup/remove_topologically_degenerate_triangles.h>
27#include <lagrange/utils/DisjointSets.h>
28#include <lagrange/utils/safe_cast.h>
44template <
typename MeshType>
45std::unique_ptr<MeshType> remove_short_edges(
46 const MeshType& in_mesh,
47 typename MeshType::Scalar tol = 0.0)
49 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
50 using Index =
typename MeshType::Index;
56 auto meshPtr = remove_topologically_degenerate_triangles(in_mesh);
57 auto& mesh = *meshPtr;
63 DisjointSets<Index> clusters(num_vertices);
65 compute_edge_lengths(mesh);
67 const auto& edge_lengths = mesh.get_edge_attribute(
"length");
68 for (Index edge_idx = 0; edge_idx < num_edges; ++edge_idx) {
70 const auto& length = edge_lengths(edge_idx);
72 clusters.merge(edge[0], edge[1]);
76 auto facets = mesh.get_facets();
79 facets.data() + num_facets * vertex_per_facet,
81 [&](Index i) { return clusters.find(i); });
82 auto mesh2 =
create_mesh(mesh.get_vertices(), std::move(facets));
86 map_attributes(mesh, *mesh2);
88 mesh2 = remove_topologically_degenerate_triangles(*mesh2);
89 mesh2 = remove_isolated_vertices(*mesh2);
Index get_num_vertices() const
Retrieves the number of vertices.
Definition SurfaceMesh.h:671
std::array< Index, 2 > get_edge_vertices(Index e) const
Retrieve edge endpoints.
Definition SurfaceMesh.cpp:2469
Index get_num_edges() const
Retrieves the number of edges.
Definition SurfaceMesh.h:692
Index get_num_facets() const
Retrieves the number of facets.
Definition SurfaceMesh.h:678
Index get_vertex_per_facet() const
Retrieves the number of vertex per facet in a regular mesh.
Definition SurfaceMesh.cpp:2130
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:40
Main namespace for Lagrange.
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