CGAL:迭代所有面的所有顶点

时间:2018-01-04 22:44:15

标签: c++ mesh cgal

我在CGAL中有一个SurfaceMesh:

https://doc.cgal.org/latest/Surface_mesh/index.html

我理解如何遍历每个面,如示例中所示:

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3                    Point;
typedef CGAL::Surface_mesh<Point>          Surface_mesh;
BOOST_FOREACH(boost::graph_traits<Surface_mesh>::face_descriptor fit, faces(mesh)){
  //do something here
}

这里,mesh是一个Surface_mesh。对我来说根本不清楚的是face_descriptor是什么,以及如何使用它。当有一个face_descriptor时,如何访问一个面的半边和顶点?特别是,如何迭代半边的所有顶点,并得到它们的坐标?

2 个答案:

答案 0 :(得分:0)

Boost图库有一个概念Graph,用于定义vertex_descriptoredge_descriptor。它们是图表元素的标识符。在CGAL中,我们将其扩展到具有面和半边的图形。概念FaceGraph解释了您可以使用face_descriptor执行的操作。在这个页面中,您可以通过精炼:进入概念HalfedgeGraph,它可以告诉您如何使用其他描述符。

链接转到即将推出的CGAL版本的在线手册,我们改进了有关描述符的文档 - 所以你并不孤单。

答案 1 :(得分:0)

一种解决方案是,针对每个面孔迭代遍历该面孔周围的顶点。

以下代码的作用是什么

typedef CGAL::Surface_mesh<Point>    Mesh;
typedef CGAL_Mesh::Face_index        face_descriptor;

int i=0;
BOOST_FOREACH(face_descriptor f, faces(mesh)){
    int j=0;
    CGAL::Vertex_around_face_iterator<Mesh> vbegin, vend;
    for(boost::tie(vbegin, vend) = vertices_around_face(mesh.halfedge(f), mesh);
            vbegin != vend;
            ++vbegin){
        j++;
        std::cout << "jth index of ith face: "<< *vbegin << std::endl;
    }
    i++;
}