Search code examples
graphicsgeometrycgal

How to obtain border edges (CGAL) after deleting some faces?


I have a Cdt from constrained delaunay triangulation. I need to obtain border edges which should be trivial: edges which have one face only but I don't know how to obtain these in CGAL:

for(Cdt::Finite_edges_iterator eit = cdt.finite_edges_begin(); eit != cdt.finite_edges_end(); ++eit) 
{
    CD_Cdt::Edge ed = *eit;

    ???
} 

enter image description here

  • red lines are the borders

Also one thing, using is_constrained() is useless because I already delete some faces before.

======== EDIT ========

user3146587's answer actually works but since I have deleted some faces I cannot detect the borders anymore:

std::vector<CDT::Face_handle> invalid_fhs;

// ... add faces to invalid_fhs

// I delete all face handles in invalid_fhs

for(int a = invalid_fhs.size() - 1; a >= 0; a--)
{ cdt.delete_face(invalid_fhs[a]); }

Solution

  • OK I get it,

    I found my mistake: Deleting face is a very very bad thing. Since it makes the cdt invalid and mess up everything.

    So What I do:

    (1) Instead of delete faces I just mark them to be outside the domain :

    fit->set_marked(false);
    

    (2) A border edge has one face is in the domain, another isn't :

    for (Cdt::Finite_edges_iterator eit = cdt.finite_edges_begin(); eit != cdt.finite_edges_end(); ++eit) 
    {
        const Cdt::Face_handle& fh = eit->first;
    
        int ctr = 0;
        if(fh->is_in_domain())
        {
            ctr++;
        }
        if(fh->neighbor(eit->second)->is_in_domain())
        {
            ctr++;
        }
    
        if(ctr == 1)
        {
            Cdt::Segment s = cd_cdt.segment(eit);
            // yeah, I get my border !!
        }
    }