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

时间:2015-02-21 05:43:30

标签: cgal

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

我使用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看起来我只能为HalfedgeDSHalfedge拨打halfedge()

那时我很困惑如何遍历脸部的顶点。我是否只是将其视为循环链表并按照下一个指针直到我回到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

1 个答案:

答案 0 :(得分:0)

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

// 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);