From 70c73237e79b5b04a30456288e1fba615ac377c8 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 11 Apr 2024 17:39:30 +0200 Subject: [PATCH] reimplement TDS_3::is_edge (speed-up by a factor 7) --- .../CGAL/Triangulation_data_structure_3.h | 69 +++++++++++++++---- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/TDS_3/include/CGAL/Triangulation_data_structure_3.h b/TDS_3/include/CGAL/Triangulation_data_structure_3.h index f2c87176315..ca34d9f92c5 100644 --- a/TDS_3/include/CGAL/Triangulation_data_structure_3.h +++ b/TDS_3/include/CGAL/Triangulation_data_structure_3.h @@ -2057,28 +2057,67 @@ is_edge(Vertex_handle u, Vertex_handle v, Cell_handle &c, int &i, int &j) const // returns false when dimension <1 or when indices wrong { - CGAL_expensive_precondition( is_vertex(u) && is_vertex(v) ); + CGAL_expensive_precondition(is_vertex(u) && is_vertex(v)); - if (u==v) - return false; + if(u == v) + return false; - bool result = false; + if(dimension() == 3) { + auto d = u->cell(); + boost::container::small_vector cells; + cells.emplace_back(d); + d->tds_data().mark_in_conflict(); - incident_cells(u, boost::make_function_output_iterator([&](Cell_handle ch) { - if(ch->has_vertex(v, j)) { - c = ch; - i = c->index(u); - result = true; - } - })); + auto cleanup_tds_data = make_scope_exit([&] { + for(auto c : cells) { + c->tds_data().clear(); + } + }); - return result; + int head = 0; + int tail = 1; + do { + Cell_handle ch = cells[head]; + + for(j = 0; j < 4; ++j) { // use parameter j on purpose + if(ch->vertex(j) == v) { + c = ch; + i = ch->index(u); + return true; + } + if(ch->vertex(j) == u) + continue; + Cell_handle next = ch->neighbor(j); + if(!next->tds_data().is_clear()) + continue; + cells.emplace_back(next); + ++tail; + next->tds_data().mark_in_conflict(); + } + ++head; + } while(head != tail); + return false; + } + + bool edge_found = false; + // try { + incident_cells_threadsafe(u, boost::make_function_output_iterator([&](Cell_handle ch) { + if(ch->has_vertex(v, j)) { + c = ch; + i = c->index(u); + // throw true; + edge_found = true; + } + })); + // } catch(bool b) { + // result = b; + // } + + return edge_found; } template -bool -Triangulation_data_structure_3:: -is_edge(Vertex_handle u, Vertex_handle v) const +bool Triangulation_data_structure_3::is_edge(Vertex_handle u, Vertex_handle v) const { Cell_handle c; int i, j;