Fix Face_filtered_graph::is_selection_valid() (master)

This commit is contained in:
Mael Rouxel-Labbé 2019-04-26 09:20:36 +02:00
parent c8a3fdaff6
commit ccf98605ab
1 changed files with 42 additions and 49 deletions

View File

@ -463,64 +463,57 @@ struct Face_filtered_graph
/// returns `true` if around any vertex of a selected face,
/// there is at most one connected set of selected faces.
bool is_selection_valid()
bool is_selection_valid() const
{
for(vertex_descriptor vd : vertices(*this) )
{
face_descriptor first_selected = boost::graph_traits<Graph>::null_face();
bool first_unselected_found(false),
second_unselected_found(false);
typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
typedef typename boost::graph_traits<Graph>::halfedge_descriptor halfedge_descriptor;
//find an unselected face, then find the first selected face.
//Find another unselected face, the next selected face must be the first;
//else this is not valid.
halfedge_descriptor hd = halfedge(vd, _graph);
face_descriptor first_tested = boost::graph_traits<Graph>::null_face();
while(1) //will break if valid, return false if not valid
{
face_descriptor fd = face(hd, _graph);
// Non-manifoldness can appear either:
// - if 'pm' is pinched at a vertex. While traversing the incoming halfedges at this vertex,
// we will meet strictly more than one border halfedge.
// - if there are multiple umbrellas around a vertex. In that case, we will find a non-visited
// halfedge that has for target a vertex that is already visited.
if(first_tested == boost::graph_traits<Graph>::null_face())
first_tested = fd;
else if(fd == first_tested )
boost::unordered_set<vertex_descriptor> vertices_visited;
boost::unordered_set<halfedge_descriptor> halfedges_handled;
for(halfedge_descriptor hd : halfedges(*this))
{
//if there is no unselected face, break
if(selected_faces[get(fimap, fd)] && !first_unselected_found)
break;
//if there is no selected face, break
else if(!selected_faces[get(fimap, fd)] &&
first_selected == boost::graph_traits<Graph>::null_face())
break;
CGAL_assertion(is_in_cc(hd));
if(!halfedges_handled.insert(hd).second) // already treated this halfedge
continue;
vertex_descriptor vd = target(hd, *this);
CGAL_assertion(is_in_cc(vd));
// Check if we have already met this vertex before (necessarily in a different umbrella
// since we have never treated the halfedge 'hd')
if(!vertices_visited.insert(vd).second)
return false;
std::size_t border_halfedge_counter = 0;
// Can't simply call halfedges_around_target(vd, *this) because 'halfedge(vd)' is not necessarily 'hd'
halfedge_descriptor ihd = hd;
do
{
halfedges_handled.insert(ihd);
if(is_border(ihd, *this))
++border_halfedge_counter;
do
{
ihd = prev(opposite(ihd, _graph), _graph);
}
if(fd != boost::graph_traits<Graph>::null_face())
{
if(selected_faces[get(fimap, fd)])
{
if(first_unselected_found &&
first_selected == boost::graph_traits<Graph>::null_face())
{
first_selected = fd;
while(!is_in_cc(ihd) && ihd != hd);
}
else if(second_unselected_found)
{
if(fd == first_selected)
break;
else
while(ihd != hd);
if(border_halfedge_counter > 1)
return false;
}
}
else
{
if(first_selected == boost::graph_traits<Graph>::null_face())
first_unselected_found = true;
else
second_unselected_found = true;
}
}
hd = next(opposite(hd, _graph), _graph);
}
}
return true;
}