CGAL选取Surface_mesh中ROI生成新的mesh

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值