2015-05-07 33 views
0

我正在使用Polyhedron_3作为曲面。我扭曲表面,并确保质量我想翻转边缘,以避免不好的三角形。 到目前为止,我的代码如下所示:CGAL Polyhedron_3 flip_edge函数中断表面

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文档是相当稀少。我不知道是否需要翻转这两个halfedges,如果它在迭代器中破坏了某些东西(所以一旦我翻转了一个,所有其他的都不能翻转)。

+1

我并不完全相信你的代码做什么,但我会说,翻转的边缘变化很大网状连接;其他的半边可以改变它们属于哪个面,不管它们是边界边等等。预先建立一个半边的大列表来考虑翻转是行不通的。 – Sneftel

+0

我没有看到任何特别的东西可以打破。你能想出一个最小的可编辑的例子来显示问题吗? – sloriot

+0

我扭曲了曲面,有时三角形可能会变平。通过翻转边缘我可以避免这一点。我会尽力提供一个可编辑的例子。 – Cyril

回答

1

我们终于找到了边缘翻转导致表面破裂的原因。之前翻转面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;