bool extract_ROI_mesh(const Mesh &original_mesh, Mesh &new_mesh, double *ref_point,
double radius_thresh)
{
std::map<Mesh::Vertex_index, Mesh::Vertex_index> vertex_map;
// Select vertices based on some condition
for (auto v : original_mesh.vertices())
{
auto pt = original_mesh.point(v);
double dist = sqrt(pow(pt.x() - ref_point[0], 2.0) + pow(pt.y() - ref_point[1],
2.0) + pow(pt.z() - ref_point[2], 2.0));
if (dist < radius_thresh) // 这里是按照点与参考点的距离来进行筛选的,可以换为其他判断条件
{
Mesh::Vertex_index new_v = new_mesh.add_vertex(original_mesh.point(v));
vertex_map[v] = new_v;
}
}
// Select faces based on some condition
for (auto f : original_mesh.faces())
{
std::vector<Mesh::Vertex_index> new_face_vertices;
for (auto v : CGAL::vertices_around_face(original_mesh.halfedge(f), original_mesh))
{
if (vertex_map.find(v) != vertex_map.end())
{
new_face_vertices.push_back(vertex_map[v]);
}
}
if (new_face_vertices.size() == 3)
{ // Assuming triangular faces
new_mesh.add_face(new_face_vertices);
}
}
return true;
}