0

I am using a Polyhedron_3 as a surface. I distort the surface and to ensure quality I want to flip edges to avoid bad triangles. So far my code looks like :

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

The code is running fine but when I run P.is_valid(true) I have this error message:

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.

The documentation on flip_edgeis quite scarce. I don't know if I need to flip both halfedges, if it breaks something in the iterator (so that once I flipped one, all the others can't be flipped).

Cyril
  • 559
  • 5
  • 17
  • 1
    I'm not entirely sure what your code is doing, but I will say that flipping an edge changes a lot in the mesh connectivity; other half-edges can change which face they belong to, whether they are border edges, etc. Prebuilding a big list of half-edges to consider flipping is not going to work. – Sneftel May 07 '15 at 16:00
  • I don't see anything in particular that could break. Could you come up with a minimal compilable example showing the problem? – sloriot May 11 '15 at 06:22
  • I distort the surface, sometimes triangles can become flat. By flipping edges I could avoid that. I'll try to provide a compilable example. – Cyril May 11 '15 at 13:38

1 Answers1

1

We finally found why the edge flips caused the surface to break. Before you flip the facet e = P.flip_edge(e);, you have to make sure it doesn't create a singularity :

   // 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;
Cyril
  • 559
  • 5
  • 17