From ef75dbb26dcc6c49a59355fd4e0a800be4f76df5 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 8 Oct 2020 13:01:28 +0100 Subject: [PATCH] Deal with degenerate queries --- .../CGAL/Polygon_mesh_processing/Envelope.h | 26 ++++++++++++++----- .../test_edge_collapse_Envelope.cpp | 2 +- .../test_edge_collapse_FastEnvelope.cpp | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Envelope.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Envelope.h index 6a3b67663cb..1bd707e20ca 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Envelope.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Envelope.h @@ -1720,6 +1720,9 @@ struct Envelope { bool operator()(const Point_3& source, const Point_3& target) const { + if(source == target){ + return (*this)(source); + } std::vector prismindex; Segment_3 query(source,target); tree.all_intersected_primitives(query, std::back_inserter(prismindex)); @@ -1735,16 +1738,25 @@ struct Envelope { bool operator()(const Point_3& t0, const Point_3& t1, const Point_3& t2) const { + if (collinear(t0,t1,t2)){ + Point_3 p0(t0), p1(t1), p2(t2); + if(lexicographically_xyz_smaller(p1,p0)){ + std::swap(p1,p0); + } + if(lexicographically_xyz_smaller(p2,p1)){ + std::swap(p2,p1); + } + if(lexicographically_xyz_smaller(p1,p0)){ + std::swap(p1,p0); + } + return (*this)(p0,p2); + } std::vector prismindex; Triangle_3 query(t0, t1, t2); tree.all_intersected_primitives(query, std::back_inserter(prismindex)); - std::sort(prismindex.begin(), prismindex.end()); -#ifdef CGAL_ENVELOPE_DEBUG - for(int i=0; i < prismindex.size(); i++){ - std::cout << prismindex[i] << " "; - } - std::cout << std::endl; -#endif + + // only needed when we want to compare runs with FastEnvelope + // std::sort(prismindex.begin(), prismindex.end()); #ifdef CGAL_ENVELOPE_DEBUG for(int i = 0; i < prismindex.size(); i++){ diff --git a/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_Envelope.cpp b/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_Envelope.cpp index 63009fd7af7..939a443b17e 100644 --- a/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_Envelope.cpp +++ b/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_Envelope.cpp @@ -96,7 +96,7 @@ int main(int argc, char** argv) std::ifstream is(argc > 1 ? argv[1] : "data/helmet.off"); is >> ref_mesh; - SMS::Count_stop_predicate stop(num_halfedges(ref_mesh)/10); + SMS::Count_stop_predicate stop(num_halfedges(ref_mesh)/100); Stats stats; My_visitor vis(&stats); diff --git a/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_FastEnvelope.cpp b/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_FastEnvelope.cpp index 79b3173ea97..2ceeb83352e 100644 --- a/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_FastEnvelope.cpp +++ b/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_FastEnvelope.cpp @@ -96,7 +96,7 @@ int main(int argc, char** argv) std::ifstream is(argc > 1 ? argv[1] : "data/helmet.off"); is >> ref_mesh; - SMS::Count_stop_predicate stop(num_halfedges(ref_mesh)/10); + SMS::Count_stop_predicate stop(num_halfedges(ref_mesh)/100); Stats stats; My_visitor vis(&stats);