Restrict shared vertices on the boundary (#8841)

function internally used not already exposed
This commit is contained in:
Sebastien Loriot 2025-04-16 18:46:16 +02:00 committed by GitHub
commit 2eba62408a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 30 additions and 13 deletions

View File

@ -1025,6 +1025,7 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes,
MeshMap mesh_map, MeshMap mesh_map,
const TagFunction& tag_function, const TagFunction& tag_function,
const std::vector<VertexPointMap>& vpms, const std::vector<VertexPointMap>& vpms,
bool shared_on_boundary_only,
bool do_not_triangulate_faces) bool do_not_triangulate_faces)
{ {
typedef typename boost::property_traits<MeshMap>::value_type Triangle_mesh; typedef typename boost::property_traits<MeshMap>::value_type Triangle_mesh;
@ -1092,23 +1093,37 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes,
//start by detecting and marking all shared vertices //start by detecting and marking all shared vertices
mesh_id = 0; mesh_id = 0;
auto register_point =
[&vertex_shared_maps, &point_to_vertex_maps, &vpms]
(vertex_descriptor v, std::size_t mesh_id)
{
std::multimap<std::size_t, vertex_descriptor>& mesh_id_to_vertex =
point_to_vertex_maps[get(vpms[mesh_id], v)];
if (!mesh_id_to_vertex.empty())
put(vertex_shared_maps[mesh_id], v, true);
if (mesh_id_to_vertex.size()==1)
{
std::pair<std::size_t, vertex_descriptor> other=*mesh_id_to_vertex.begin();
put(vertex_shared_maps[other.first], other.second, true);
}
mesh_id_to_vertex.insert( std::make_pair(mesh_id, v) );
};
for(Triangle_mesh* tm_ptr : mesh_ptrs) for(Triangle_mesh* tm_ptr : mesh_ptrs)
{ {
Triangle_mesh& tm = *tm_ptr; Triangle_mesh& tm = *tm_ptr;
for(vertex_descriptor v : vertices(tm)) if (shared_on_boundary_only)
{ for(halfedge_descriptor h : halfedges(tm))
std::multimap<std::size_t, vertex_descriptor>& mesh_id_to_vertex =
point_to_vertex_maps[get(vpms[mesh_id], v)];
if (!mesh_id_to_vertex.empty())
put(vertex_shared_maps[mesh_id], v, true);
if (mesh_id_to_vertex.size()==1)
{ {
std::pair<std::size_t, vertex_descriptor> other=*mesh_id_to_vertex.begin(); if (!is_border(h,tm)) continue;
put(vertex_shared_maps[other.first], other.second, true); vertex_descriptor v = target(h, tm);
register_point(v, mesh_id);
} }
mesh_id_to_vertex.insert( std::make_pair(mesh_id, v) ); else
} for(vertex_descriptor v : vertices(tm))
register_point(v, mesh_id);
++mesh_id; ++mesh_id;
} }
@ -1222,7 +1237,7 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes,
{ {
typedef std::pair<const std::size_t, vertex_descriptor> Map_pair_type; typedef std::pair<const std::size_t, vertex_descriptor> Map_pair_type;
auto find_res = point_to_vertex_maps.find(corners[cid]); auto find_res = point_to_vertex_maps.find(corners[cid]);
assert(find_res != point_to_vertex_maps.end()); if (find_res == point_to_vertex_maps.end()) continue; // the point is not shared
for(Map_pair_type& mp : find_res->second) for(Map_pair_type& mp : find_res->second)
{ {
std::size_t other_mesh_id = mp.first; std::size_t other_mesh_id = mp.first;
@ -1279,6 +1294,7 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes,
MeshMap mesh_map, MeshMap mesh_map,
double coplanar_cos_threshold, double coplanar_cos_threshold,
const std::vector<VertexPointMap>& vpms, const std::vector<VertexPointMap>& vpms,
bool shared_on_boundary_only,
bool do_not_triangulate_faces) bool do_not_triangulate_faces)
{ {
typedef typename boost::property_traits<MeshMap>::value_type Triangle_mesh; typedef typename boost::property_traits<MeshMap>::value_type Triangle_mesh;
@ -1300,6 +1316,7 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes,
mesh_map, mesh_map,
tag_function, tag_function,
vpms, vpms,
shared_on_boundary_only,
do_not_triangulate_faces); do_not_triangulate_faces);
} }
@ -1661,7 +1678,7 @@ bool decimate_meshes_with_common_interfaces(TriangleMeshRange& meshes, double co
for(Mesh_descriptor& md : meshes) for(Mesh_descriptor& md : meshes)
vpms.push_back( get(boost::vertex_point, mesh_map[md]) ); vpms.push_back( get(boost::vertex_point, mesh_map[md]) );
return Planar_segmentation::decimate_meshes_with_common_interfaces_impl<Kernel>(meshes, mesh_map, coplanar_cos_threshold, vpms, do_not_triangulate_faces); return Planar_segmentation::decimate_meshes_with_common_interfaces_impl<Kernel>(meshes, mesh_map, coplanar_cos_threshold, vpms, true, do_not_triangulate_faces);
} }
template <class TriangleMesh> template <class TriangleMesh>