2015-05-07 70 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;