c++ - CGAL Polyhedron_3 flip_edge 函数打破表面

标签 c++ cgal

我使用 Polyhedron_3 作为表面。我扭曲了表面并确保质量我想翻转边缘以避免坏三角形。 到目前为止,我的代码看起来像:

std::vector<std::pair<PlaneMeshAPI::Polyhedron::Halfedge_handle, double> > vEdgeToFlip;
for (PlaneMeshAPI::Polyhedron::Edge_iterator e = P.edges_begin(); e != P.edges_end(); ++e)
{
    // Edge_iterator so that we consider only one of the 2 possible halfedges
    bool bFlippable = true;
    if (e->is_border_edge()) bFlippable = false;
    if (bFlippable && e->facet()->marked() == -1) bFlippable = false;
    if (bFlippable && e->facet()->marked() != e->opposite()->facet()->marked()) bFlippable = false;
    // Marked() returns an int, I want to flip edges between two triangles of the same component

    if (bFlippable)
    {
        PlaneMeshAPI::Polyhedron::Facet_iterator f1, f2;
        PlaneMeshAPI::Polyhedron::Halfedge_handle heh = e;
        double lowestBef = lowestAngle(e->facet(), e->opposite()->facet()); // returns the lowest angle of the two adjacent triangles
        vEdgeToFlip.push_back(std::make_pair(e, lowestBef));
    }
}

for (int i = 0; i < vEdgeToFlip.size(); ++i)
{
    PlaneMeshAPI::Polyhedron::Halfedge_handle e = vEdgeToFlip[i].first;
    e = P.flip_edge(e);
    double lowestNow = lowestAngle(e->facet(), e->opposite()->facet());
    if (lowestNow < vEdgeToFlip[i].second)
        P.flip_edge(e);
}

代码运行良好,但当我运行 P.is_valid(true) 时我收到此错误消息:

halfedge 7504 previous pointer integrity corrupted. summe border halfedges (2*nb) = 0 end of CGAL::HalfedgeDS_const_decorator<HDS>::is_valid(): structure is NOT VALID . counting halfedges failed. end of CGAL::Polyhedron_3<...>::is_valid(): structure is NOT VALID.

关于 flip_edge 的文档相当稀缺。我不知道我是否需要翻转两个半边,如果它破坏了迭代器中的某些东西(这样一旦我翻转了一个,所有其他的都不能翻转)。

最佳答案

我们终于找到了边缘翻转导致表面破裂的原因。在翻转面 e = P.flip_edge(e); 之前,您必须确保它不会产生奇点:

   // Do not flip if this would create two triangle with the same vertices
    if (e->next()->opposite()->next()->opposite() == e->opposite()->next()->next()) continue;
    if (e->opposite()->next()->opposite()->next()->opposite() == e->next()->next()) continue;

    // Do not flip if it would create an edge linking a vertex with itself
    if (e->next()->vertex() == e->opposite()->next()->vertex()) continue;

关于c++ - CGAL Polyhedron_3 flip_edge 函数打破表面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30105882/

相关文章:

C++ 静态变量声明奇怪的链接器错误

c++ - 模板数据成员

centos - 如何在 CentOS 7(或 CentOS 6)上安装 cgal?

linux - 如何将 CGAL 代码编译成共享库?

c++ - 是否有适用于 Linux 且具有这些功能的免费 C++ IDE?

C++0x : Slice template fails to compile with range-based for()

c++ - Visual C++ 中的 std::vector::erase() 中的段错误

graphics - 最近距离+两个网格的顶点

c++ - 如何用CGAL获取多边形网格的顶点和面?

c++ - 来自一组源节点的 BGL dfs