CGAL 6.0 Surface Mesh enumerate edges vertices? - Stack Overflow

admin2025-04-21  1

Is a way to get table of edges with first and second vertices indexes?

This is a way to enumerate vertices of mesh:

Surface_mesh m;
// ... fill m points...

// enumerate points:
for (auto& vertex : m.points()) {
  verts.push_back(std::vector<float>{ (float)CGAL::to_double(vertex.x()), (float)CGAL::to_double(vertex.y()), (float)CGAL::to_double(vertex.z()) });
}

This is a way to enumerate face's vertex indices of mesh:

for (auto& fi : m.faces() ){
    auto& hf = m.halfedge(fi);
    std::vector<unsigned int> vect_vert_id;
    for (auto& hi : halfedges_around_face(hf, m)){
        vertex_descriptor& vi = target(hi, m);
        vect_vert_id.push_back(vi.idx()); // index of vertex in face
    }
    // vect_vert_id - list of vertices of face
}

But how to get list of edges vertices id as list of pairs? (id1, id2),(id2, id3), ...

I try to use faces to get all edges (use halfedges_around_face to get all indexes in one face then got list of second face, remove duplicate edges vertices and so on...)

Some info about CGAL Surface Mesh

Is a way to get table of edges with first and second vertices indexes?

This is a way to enumerate vertices of mesh:

Surface_mesh m;
// ... fill m points...

// enumerate points:
for (auto& vertex : m.points()) {
  verts.push_back(std::vector<float>{ (float)CGAL::to_double(vertex.x()), (float)CGAL::to_double(vertex.y()), (float)CGAL::to_double(vertex.z()) });
}

This is a way to enumerate face's vertex indices of mesh:

for (auto& fi : m.faces() ){
    auto& hf = m.halfedge(fi);
    std::vector<unsigned int> vect_vert_id;
    for (auto& hi : halfedges_around_face(hf, m)){
        vertex_descriptor& vi = target(hi, m);
        vect_vert_id.push_back(vi.idx()); // index of vertex in face
    }
    // vect_vert_id - list of vertices of face
}

But how to get list of edges vertices id as list of pairs? (id1, id2),(id2, id3), ...

I try to use faces to get all edges (use halfedges_around_face to get all indexes in one face then got list of second face, remove duplicate edges vertices and so on...)

Some info about CGAL Surface Mesh

Share Improve this question asked Jan 22 at 20:33 SatabolSatabol 982 silver badges7 bronze badges 6
  • There is no function returning a pair, but did you see the "source()" function? – Mael Commented Jan 22 at 23:04
  • there's this method Vertex_index vertex (Edge_index e, unsigned int i) const returns the i'th vertex of edge e, for i=0 or 1. It works off the edge index rather than the half edge index though, so you'll need e = edge(hi), then vertex(e, 0) and vertex(e, 1) – Neil Butcher Commented Jan 23 at 9:43
  • Or there's a edges() method to get the edges directly. – Neil Butcher Commented Jan 23 at 9:51
  • Hi @NeilButcher! It is work! thank you! github.com/user-attachments/assets/… – Satabol Commented Jan 23 at 13:15
  • @SatabolTen great, I'll post as an answer – Neil Butcher Commented Jan 23 at 13:22
 |  Show 1 more comment

1 Answer 1

Reset to default 1

There's a method edges() to get the Edge_range and iterate through all the edges of the Surface_mesh.

Then for each edge there is a method vertex (Edge_index e, unsigned int i) const

which can be called twice vertex(e,0) and vertex(e,1) to get the 2 vertices of the edge.

转载请注明原文地址:http://anycun.com/QandA/1745229150a90507.html