From 0f4661087bc6e97badbe0b42f28a56f73bf84a47 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 10 Oct 2016 17:34:37 +0200 Subject: [PATCH] Fix issue #1554 Fix a runtime error. The `Intersect_3` functor of `Robust_intersection_traits_3_new` was ignored cases in the intersection between a segment and a triangle. In `ts_intersection`, if one of the extremities of the segment was coplanar with the triangle, the empty object was always returned. This bug of mines was introduced in CGAL-4.3 by 56d733b2546ffa146598901f841567c554f80a65. (Fix #1554.) --- .../Mesh_3/Robust_intersection_traits_3.h | 67 +++- Mesh_3/test/Mesh_3/CMakeLists.txt | 1 + .../test/Mesh_3/data/thepart-simplified.off | 314 ++++++++++++++++++ Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cmd | 1 + Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cpp | 93 ++++++ 5 files changed, 473 insertions(+), 3 deletions(-) create mode 100644 Mesh_3/test/Mesh_3/data/thepart-simplified.off create mode 100644 Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cmd create mode 100644 Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cpp diff --git a/Mesh_3/include/CGAL/Mesh_3/Robust_intersection_traits_3.h b/Mesh_3/include/CGAL/Mesh_3/Robust_intersection_traits_3.h index 6aa5e679fbf..ad75c1ef72d 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Robust_intersection_traits_3.h +++ b/Mesh_3/include/CGAL/Mesh_3/Robust_intersection_traits_3.h @@ -326,7 +326,19 @@ ts_intersection(const typename K::Triangle_3 &t, return result_type(); default: // coplanar - return result_type(); + // q belongs to the triangle's supporting plane + // p sees the triangle in counterclockwise order + if(orientation(p,q,a,b) != POSITIVE + && orientation(p,q,b,c) != POSITIVE + && orientation(p,q,c,a) != POSITIVE) + { +#if CGAL_INTERSECTION_VERSION > 1 + return result_type(q); +#else + return make_object(q); +#endif + } + else return result_type(); } case NEGATIVE: switch ( abcq ) { @@ -352,10 +364,59 @@ ts_intersection(const typename K::Triangle_3 &t, return result_type(); default: // coplanar - return result_type(); + // q belongs to the triangle's supporting plane + // p sees the triangle in clockwise order + if(orientation(q,p,a,b) != POSITIVE + && orientation(q,p,b,c) != POSITIVE + && orientation(q,p,c,a) != POSITIVE) + { +#if CGAL_INTERSECTION_VERSION > 1 + return result_type(q); +#else + return make_object(q); +#endif + } + else return result_type(); } default: // coplanar - return result_type(); + switch ( abcq ) { + case POSITIVE: + // q sees the triangle in counterclockwise order + if(orientation(q,p,a,b) != POSITIVE + && orientation(q,p,b,c) != POSITIVE + && orientation(q,p,c,a) != POSITIVE) + { +#if CGAL_INTERSECTION_VERSION > 1 + return result_type(p); +#else + return make_object(p); +#endif + } + case NEGATIVE: + // q sees the triangle in clockwise order + if(orientation(p,q,a,b) != POSITIVE + && orientation(p,q,b,c) != POSITIVE + && orientation(p,q,c,a) != POSITIVE) + { +#if CGAL_INTERSECTION_VERSION > 1 + return result_type(p); +#else + return make_object(p); +#endif + } + case COPLANAR: + // the segment is coplanar with the triangle's supporting plane + // we test whether the segment intersects the triangle in the common + // supporting plane + // + // Laurent Rineau, 2016/10/10: this case is purposely ignored by + // Mesh_3, because if the intersection is not a point, it is + // ignored anyway. + return result_type(); + default: // should not happen. + CGAL_kernel_assertion(false); + return result_type(); + } } } diff --git a/Mesh_3/test/Mesh_3/CMakeLists.txt b/Mesh_3/test/Mesh_3/CMakeLists.txt index 3379e2d10f5..7bab5e4a7f7 100644 --- a/Mesh_3/test/Mesh_3/CMakeLists.txt +++ b/Mesh_3/test/Mesh_3/CMakeLists.txt @@ -53,6 +53,7 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "test_robust_weighted_circumcenter.cpp" ) create_single_source_cgal_program( "test_meshing_determinism.cpp" ) create_single_source_cgal_program( "test_c3t3_extract_subdomains_boundaries.cpp" ) + create_single_source_cgal_program( "test_mesh_3_issue_1554.cpp" ) else() diff --git a/Mesh_3/test/Mesh_3/data/thepart-simplified.off b/Mesh_3/test/Mesh_3/data/thepart-simplified.off new file mode 100644 index 00000000000..780ca14ab37 --- /dev/null +++ b/Mesh_3/test/Mesh_3/data/thepart-simplified.off @@ -0,0 +1,314 @@ +OFF +106 204 0 + +-0.33300000000000002 0.104 0.16700000000000001 +-0.33300000000000002 -0.036999999999999998 0.20799999999999999 +-0.33300000000000002 -0.036999999999999998 0.16700000000000001 +-0.28699999999999998 -0.16500000000000001 0.29199999999999998 +-0.27100000000000002 -0.16700000000000001 0.29199999999999998 +-0.27100000000000002 -0.16700000000000001 0.20799999999999999 +-0.28699999999999998 -0.16500000000000001 0.20799999999999999 +-0.30199999999999999 -0.158 0.29199999999999998 +-0.30199999999999999 -0.158 0.20799999999999999 +-0.315 -0.14799999999999999 0.29199999999999998 +-0.315 -0.14799999999999999 0.20799999999999999 +-0.32500000000000001 -0.13500000000000001 0.29199999999999998 +-0.32500000000000001 -0.13500000000000001 0.20799999999999999 +-0.33100000000000002 -0.12 0.29199999999999998 +-0.33300000000000002 -0.104 0.29199999999999998 +-0.33100000000000002 -0.12 0.20799999999999999 +-0.33300000000000002 -0.104 0.20799999999999999 +-0.33300000000000002 0.104 0.29199999999999998 +-0.33100000000000002 0.12 0.29199999999999998 +-0.33100000000000002 0.12 0.16700000000000001 +-0.32500000000000001 0.13500000000000001 0.29199999999999998 +-0.32500000000000001 0.13500000000000001 0.16700000000000001 +-0.315 0.14799999999999999 0.16700000000000001 +-0.315 0.14799999999999999 0.29199999999999998 +-0.30199999999999999 0.158 0.29199999999999998 +-0.30199999999999999 0.158 0.16700000000000001 +-0.28699999999999998 0.16500000000000001 0.16700000000000001 +-0.28699999999999998 0.16500000000000001 0.29199999999999998 +-0.27100000000000002 0.16700000000000001 0.29199999999999998 +0.12 0.16700000000000001 0.20799999999999999 +-0.27100000000000002 0.16700000000000001 0.16700000000000001 +0.12 0.16700000000000001 0.16700000000000001 +0.27100000000000002 0.16700000000000001 0.29199999999999998 +0.27100000000000002 0.16700000000000001 0.20799999999999999 +0.28699999999999998 0.16500000000000001 0.29199999999999998 +0.28699999999999998 0.16500000000000001 0.20799999999999999 +0.30199999999999999 0.158 0.29199999999999998 +0.30199999999999999 0.158 0.20799999999999999 +0.315 0.14799999999999999 0.29199999999999998 +0.315 0.14799999999999999 0.20799999999999999 +0.32500000000000001 0.13500000000000001 0.29199999999999998 +0.32500000000000001 0.13500000000000001 0.20799999999999999 +0.33100000000000002 0.12 0.29199999999999998 +0.33100000000000002 0.12 0.20799999999999999 +0.33300000000000002 0.104 0.29199999999999998 +0.33300000000000002 0.104 0.20799999999999999 +0.33300000000000002 -0.104 0.20799999999999999 +0.33300000000000002 -0.104 0.29199999999999998 +0.33100000000000002 -0.12 0.20799999999999999 +0.33100000000000002 -0.12 0.29199999999999998 +0.32500000000000001 -0.13500000000000001 0.20799999999999999 +0.32500000000000001 -0.13500000000000001 0.29199999999999998 +0.315 -0.14799999999999999 0.29199999999999998 +0.315 -0.14799999999999999 0.20799999999999999 +0.30199999999999999 -0.158 0.29199999999999998 +0.30199999999999999 -0.158 0.20799999999999999 +0.28699999999999998 -0.16500000000000001 0.29199999999999998 +0.28699999999999998 -0.16500000000000001 0.20799999999999999 +0.27100000000000002 -0.16700000000000001 0.29199999999999998 +0.27100000000000002 -0.16700000000000001 0.20799999999999999 +0.12 0.16500000000000001 0.20799999999999999 +0.13500000000000001 0.158 0.20799999999999999 +0.14799999999999999 0.14799999999999999 0.20799999999999999 +0.158 0.13500000000000001 0.20799999999999999 +0.16500000000000001 0.12 0.20799999999999999 +0.16700000000000001 0.104 0.20799999999999999 +0.16700000000000001 -0.021000000000000001 0.20799999999999999 +0.158 -0.051999999999999998 0.20799999999999999 +0.16500000000000001 -0.036999999999999998 0.20799999999999999 +0.14799999999999999 -0.065000000000000002 0.20799999999999999 +0.13500000000000001 -0.074999999999999997 0.20799999999999999 +0.12 -0.081000000000000003 0.20799999999999999 +0.104 -0.083000000000000004 0.20799999999999999 +-0.33100000000000002 -0.036999999999999998 0.20799999999999999 +-0.32500000000000001 -0.051999999999999998 0.20799999999999999 +-0.315 -0.065000000000000002 0.20799999999999999 +-0.30199999999999999 -0.074999999999999997 0.20799999999999999 +-0.28699999999999998 -0.081000000000000003 0.20799999999999999 +-0.27100000000000002 -0.083000000000000004 0.20799999999999999 +-0.33100000000000002 -0.036999999999999998 0.16700000000000001 +0.12 0.16500000000000001 0.16700000000000001 +-0.32500000000000001 -0.051999999999999998 0.16700000000000001 +-0.315 -0.065000000000000002 0.16700000000000001 +-0.30199999999999999 -0.074999999999999997 0.16700000000000001 +-0.28699999999999998 -0.081000000000000003 0.16700000000000001 +0.13500000000000001 0.158 0.16700000000000001 +0.14799999999999999 0.14799999999999999 0.16700000000000001 +0.158 0.13500000000000001 0.16700000000000001 +0.16500000000000001 0.12 0.16700000000000001 +0.16700000000000001 0.104 0.16700000000000001 +0.16700000000000001 -0.021000000000000001 0.16700000000000001 +0.16500000000000001 -0.036999999999999998 0.16700000000000001 +0.158 -0.051999999999999998 0.16700000000000001 +0.14799999999999999 -0.065000000000000002 0.16700000000000001 +0.13500000000000001 -0.074999999999999997 0.16700000000000001 +0.12 -0.081000000000000003 0.16700000000000001 +0.104 -0.083000000000000004 0.16700000000000001 +-0.27100000000000002 -0.083000000000000004 0.16700000000000001 +-0.46630000000000001 -0.2837 0.06075 +-0.46630000000000001 0.2837 0.06075 +0.46630000000000001 0.2837 0.06075 +0.46630000000000001 -0.2837 0.06075 +-0.46630000000000001 -0.2837 0.39824999999999996 +-0.46630000000000001 0.2837 0.39824999999999996 +0.46630000000000001 0.2837 0.39824999999999996 +0.46630000000000001 -0.2837 0.39824999999999996 +3 0 1 2 +3 3 4 5 +3 6 3 5 +3 7 3 6 +3 8 7 6 +3 9 7 8 +3 10 9 8 +3 11 9 10 +3 12 11 10 +3 13 11 12 +3 14 13 15 +3 16 14 15 +3 14 16 1 +3 17 14 1 +3 0 17 1 +3 18 17 0 +3 19 18 0 +3 20 18 19 +3 21 20 19 +3 22 23 21 +3 24 23 22 +3 25 24 22 +3 23 20 21 +3 26 27 25 +3 28 27 26 +3 29 30 31 +3 28 30 29 +3 32 28 29 +3 33 32 29 +3 34 32 33 +3 35 34 33 +3 36 34 35 +3 37 36 35 +3 38 36 37 +3 15 13 12 +3 39 38 37 +3 40 38 39 +3 41 40 39 +3 42 40 41 +3 43 42 41 +3 44 42 43 +3 45 44 43 +3 46 47 45 +3 48 49 46 +3 50 51 48 +3 52 51 50 +3 53 52 50 +3 54 52 53 +3 51 49 48 +3 55 54 53 +3 56 54 55 +3 57 56 55 +3 58 56 57 +3 59 58 57 +3 4 58 59 +3 5 4 59 +3 59 57 55 +3 53 59 55 +3 53 50 59 +3 48 59 50 +3 30 28 26 +3 48 46 59 +3 37 35 33 +3 43 41 33 +3 60 33 29 +3 60 61 33 +3 33 61 62 +3 63 33 62 +3 63 64 33 +3 33 64 65 +3 43 33 65 +3 43 65 45 +3 65 66 45 +3 45 66 46 +3 27 24 25 +3 67 46 68 +3 67 69 46 +3 46 69 59 +3 69 70 59 +3 59 70 71 +3 72 59 71 +3 1 16 73 +3 16 74 73 +3 47 44 45 +3 75 74 16 +3 75 16 76 +3 16 77 76 +3 16 15 77 +3 15 78 77 +3 12 78 15 +3 10 78 12 +3 6 78 8 +3 5 78 6 +3 72 5 59 +3 1 73 79 +3 2 1 79 +3 80 60 31 +3 60 29 31 +3 79 73 81 +3 73 74 81 +3 81 74 82 +3 74 75 82 +3 82 75 83 +3 75 76 83 +3 83 76 84 +3 76 77 84 +3 49 47 46 +3 61 60 80 +3 85 61 80 +3 62 61 85 +3 86 62 85 +3 63 62 86 +3 87 63 86 +3 64 63 87 +3 88 64 87 +3 65 64 88 +3 89 65 88 +3 66 65 89 +3 90 66 89 +3 68 66 90 +3 91 68 90 +3 67 68 91 +3 92 67 91 +3 69 67 92 +3 93 69 92 +3 70 69 93 +3 46 66 68 +3 94 70 93 +3 71 70 94 +3 95 71 94 +3 72 71 95 +3 96 72 95 +3 97 72 96 +3 78 72 97 +3 77 78 97 +3 84 77 97 +3 95 94 96 +3 96 94 93 +3 92 96 93 +3 92 91 96 +3 96 91 90 +3 33 41 39 +3 85 80 86 +3 80 87 86 +3 88 87 80 +3 88 80 89 +3 80 90 89 +3 96 90 80 +3 96 80 97 +3 31 30 80 +3 83 84 97 +3 83 97 82 +3 97 81 82 +3 37 33 39 +3 79 81 97 +3 2 79 0 +3 97 0 79 +3 26 25 30 +3 8 78 10 +3 30 25 22 +3 21 30 22 +3 21 19 30 +3 72 78 5 +3 30 19 0 +3 97 30 0 +3 80 30 97 +3 9 11 13 +3 9 13 14 +3 7 9 14 +3 18 20 23 +3 17 18 23 +3 17 23 24 +3 24 27 28 +3 17 24 28 +3 32 34 36 +3 38 40 42 +3 38 42 44 +3 36 38 44 +3 32 36 44 +3 32 44 47 +3 49 51 52 +3 47 49 52 +3 47 52 54 +3 54 56 58 +3 47 54 58 +3 32 47 58 +3 28 32 58 +3 28 58 4 +3 17 28 4 +3 14 17 4 +3 7 14 4 +3 4 3 7 +3 98 99 101 +3 101 99 100 +3 98 102 99 +3 99 102 103 +3 101 100 105 +3 105 100 104 +3 102 98 101 +3 105 102 101 +3 104 102 105 +3 104 103 102 +3 99 103 104 +3 100 99 104 + diff --git a/Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cmd b/Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cmd new file mode 100644 index 00000000000..05696b9f2b7 --- /dev/null +++ b/Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cmd @@ -0,0 +1 @@ +data/thepart-simplified.off diff --git a/Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cpp b/Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cpp new file mode 100644 index 00000000000..c9116d6a759 --- /dev/null +++ b/Mesh_3/test/Mesh_3/test_mesh_3_issue_1554.cpp @@ -0,0 +1,93 @@ +#include + +#include +#include +#include + +#include +#include + +// Domain +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Polyhedral_mesh_domain_with_features_3 Mesh_domain; + +#ifdef CGAL_CONCURRENT_MESH_3 +typedef CGAL::Parallel_tag Concurrency_tag; +#else +typedef CGAL::Sequential_tag Concurrency_tag; +#endif + +// Triangulation +typedef CGAL::Mesh_triangulation_3::type Tr; + +typedef CGAL::Mesh_complex_3_in_triangulation_3< + Tr,Mesh_domain::Corner_index,Mesh_domain::Curve_segment_index> C3t3; +typedef Tr::Geom_traits Gt; +// Criteria +typedef CGAL::Mesh_criteria_3 Mesh_criteria; + +// To avoid verbose function and named parameters call +using namespace CGAL::parameters; + +Gt::Construct_weighted_circumcenter_3 w_circumcenter = Gt().construct_weighted_circumcenter_3_object(); + +K::Point_3 wc_circumcenter(Tr::Cell_handle ch, bool force_exact = false) { + return w_circumcenter(ch->vertex(0)->point(), + ch->vertex(1)->point(), + ch->vertex(2)->point(), + ch->vertex(3)->point(), force_exact + ); +} + +int main(int argc, char*argv[]) +{ + const char* fname = (argc>1)?argv[1]:"data/fandisk.off"; + // Create domain + Mesh_domain domain(fname); + + // Get sharp features + domain.detect_features(); + + // Mesh criteria + Mesh_criteria criteria(edge_size = 0.037, + facet_angle = 25, + facet_size = 0.037, + facet_distance = 0.0037, + cell_radius_edge_ratio = 3); + + // Mesh generation + C3t3 c3t3 = CGAL::make_mesh_3(domain, criteria, no_perturb(), no_exude()); + + int return_code = 0; + for(C3t3::Cells_in_complex_iterator cit = c3t3.cells_in_complex_begin(); + cit != c3t3.cells_in_complex_end(); + ++cit) + { + for(int i = 0; i < 4; ++i) { + typedef Tr::Facet Facet; + typedef Tr::Cell_handle Cell_handle; + Cell_handle ch = cit; + Cell_handle nch = ch->neighbor(i); + if(c3t3.is_in_complex(nch)) continue; + if(!c3t3.is_in_complex(Facet(ch, i))) { + return_code = 1; + std::cout << "ERROR with facet: 3 \n"; + K::Point_3 p[3]; + for(int j = 0; j < 3; ++j) { + p[j] = ch->vertex(c3t3.triangulation().vertex_triple_index(i, j))->point().point(); + std::cout << " " << p[j] << "\n"; + } + int n_i = nch->index(ch); + K::Point_3 a = ch->vertex(i)->point().point(); + K::Point_3 b = nch->vertex(n_i)->point().point(); + std::cout << a << "\n"; + std::cout << b << "\n"; + std::cout << " " << wc_circumcenter(ch, true) << std::endl; + std::cout << " " << wc_circumcenter(nch, true) << std::endl; + } + } + } + std::cout << c3t3.triangulation().number_of_vertices() << std::endl; + // Output + return return_code; +}