如何遍历 CGAL StraightSkeleton_2 / HalfedgeDS 中的所有面孔?

How do I iterate through all the faces in a CGAL StraightSkeleton_2 / HalfedgeDS?

我的目标是获取一个多边形,找到直骨架,然后将每个面都变成自己的多边形。

我使用 CGAL Create_straight_skeleton_2.cpp example 作为起点。我能够让它计算骨架并遍历面孔:

SsPtr iss = CGAL::create_interior_straight_skeleton_2(poly);
for( auto face = iss->faces_begin(); face != iss->faces_end(); ++face ) {
  // How do I iterate through the vertexes?
}

但是有一个HalfedgeDSFace it looks like I can only call halfedge() for a HalfedgeDSHalfedge

那时我很困惑如何遍历脸上的顶点。我是否只是将其视为循环链表并跟随下一个指针直到返回 face->halfedge()

这是我第一次尝试将其视为循环链表:

SsPtr iss = CGAL::create_interior_straight_skeleton_2(poly);
std::cout << "Faces:" << iss->size_of_faces() << std::endl;
for( auto face = iss->faces_begin(); face != iss->faces_end(); ++face ) {
  std::cout << "Faces:" << iss->size_of_faces() << std::endl;
  std::cout << "----" << std::endl;
  do {
    std::cout << edge->vertex()->point() << std::endl;
    edge = edge->next();
  } while (edge != face->halfedge());
}

但这似乎在每个面上都放置了一个空顶点:

Faces:4
----
197.401 420.778
0 0
166.95 178.812
----
511.699 374.635
0 0
197.401 420.778
----
428.06 122.923
0 0
511.699 374.635
----
166.95 178.812
0 0
428.06 122.923

所以迭代与我预期的一样多:

// Each face
for( auto face = iss->faces_begin(); face != iss->faces_end(); ++face ) {
    Ss::Halfedge_const_handle begin = face->halfedge();
    Ss::Halfedge_const_handle edge = begin;
    // Each vertex
    do {
        std::cout << edge->vertex()->point() << std::endl;
        edge = edge->next();
    } while (edge != begin);
}

它不起作用的原因是我使用的轮廓多边形是顺时针方向。一旦我颠倒了点的顺序,我就开始从面部获取有效数据。

作为参考,您将如何迭代轮廓中的顶点:

// Pick a face and use the opposite edge to get on the contour.
Ss::Halfedge_const_handle begin = iss->faces_begin()->halfedge()->opposite();
Ss::Halfedge_const_handle edge = begin;
do {
    std::cout << edge->vertex()->point() << std::endl;
    // Iterate in the opposite direction.
    edge = edge->prev();
} while (edge != begin);