diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_of_coplanar_triangles_3.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_of_coplanar_triangles_3.h index 3cfcf3326fd..489bbd963aa 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_of_coplanar_triangles_3.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_of_coplanar_triangles_3.h @@ -79,7 +79,7 @@ struct Intersect_coplanar_faces_3{ //constructor for intersection of edges. prev and curr are two points on an edge of the first facet (preserving the //orientation of the facet). This edge is intersected by h2 from the second facet. // - //The rational is the following: we first check whether curr and prev are on the same edge. I so we create + //The rational is the following: we first check whether curr and prev are on the same edge. If so we create //an intersection point between two edges. Otherwise, the point is a vertex of the second facet included into //the first facet. // @@ -102,9 +102,25 @@ struct Intersect_coplanar_faces_3{ res.info_2=h2; if (ipt_prev.type_1==ON_VERTEX && next(ipt_prev.info_1, tm1) == ipt_curr.info_1){ - CGAL_assertion(ipt_curr.type_1!=ON_FACE); - res.type_1=ON_EDGE; - res.info_1=ipt_curr.info_1; + if(ipt_curr.type_1!=ON_FACE) + { + res.type_1=ON_EDGE; + res.info_1=ipt_curr.info_1; + } + else + { + CGAL_assertion( ipt_curr.type_2==ON_VERTEX); + res.type_1=ON_FACE; + res.info_1=h1; + res.type_2=ON_VERTEX; + typename Exact_kernel::Collinear_3 is_collinear = Exact_kernel().collinear_3_object(); + if ( !is_collinear(ipt_prev.point,ipt_curr.point,to_exact(get(vpm2,target(res.info_2,tm2)) ) ) ){ + res.info_2=prev(res.info_2,tm2); + CGAL_assertion( is_collinear(ipt_prev.point,ipt_curr.point,to_exact(get(vpm2,target(res.info_2,tm2))) ) ); + } + res.point = to_exact( get(vpm2, target(res.info_2,tm2)) ); + return res; + } } else{ if(ipt_curr.type_1==ON_VERTEX && ipt_prev.info_1 == ipt_curr.info_1){ diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/data-coref/coplanar_triangles/all_cases/bugreport/tr2-1.off b/Polygon_mesh_processing/test/Polygon_mesh_processing/data-coref/coplanar_triangles/all_cases/bugreport/tr2-1.off new file mode 100644 index 00000000000..692c64e5c3d --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/data-coref/coplanar_triangles/all_cases/bugreport/tr2-1.off @@ -0,0 +1,6 @@ +OFF +3 1 0 +0 5310 100 +0 5400 100 +0 5310 150 +3 0 2 1 diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/data-coref/coplanar_triangles/all_cases/bugreport/tr2-2.off b/Polygon_mesh_processing/test/Polygon_mesh_processing/data-coref/coplanar_triangles/all_cases/bugreport/tr2-2.off new file mode 100644 index 00000000000..21bb089ace4 --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/data-coref/coplanar_triangles/all_cases/bugreport/tr2-2.off @@ -0,0 +1,6 @@ +OFF +3 1 0 +0 5375 105 +0 5350 110 +0 5375 110 +3 1 2 0 diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_corefine.cmd b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_corefine.cmd index a173eef4b20..e7e5fb3547b 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_corefine.cmd +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_corefine.cmd @@ -64,6 +64,7 @@ data-coref/coplanar_triangles/all_cases/deg/tr15-1.off data-coref/coplanar_trian data-coref/coplanar_triangles/all_cases/deg/tr16-1.off data-coref/coplanar_triangles/all_cases/deg/tr16-2.off data-coref/coplanar_triangles/all_cases/deg/tr17-1.off data-coref/coplanar_triangles/all_cases/deg/tr17-2.off data-coref/coplanar_triangles/all_cases/bugreport/tr1-1.off data-coref/coplanar_triangles/all_cases/bugreport/tr1-2.off +data-coref/coplanar_triangles/all_cases/bugreport/tr2-1.off data-coref/coplanar_triangles/all_cases/bugreport/tr2-2.off data-coref/coplanar_triangles/all_cases/tr1-1.off data-coref/coplanar_triangles/all_cases/tr1-2.off data-coref/coplanar_triangles/all_cases/tr2-1.off data-coref/coplanar_triangles/all_cases/tr2-2.off data-coref/coplanar_triangles/all_cases/tr3-1.off data-coref/coplanar_triangles/all_cases/tr3-2.off diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_corefine.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_corefine.cpp index 6f51922d838..4aee863f3a6 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_corefine.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_corefine.cpp @@ -10,42 +10,48 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Surface_mesh Surface_mesh; typedef CGAL::Polyhedron_3 Polyhedron_3; + +void test(const char* f1, const char* f2) +{ + std::cout << "Corefining " << f1 + << " and " << f2 << "\n"; + + std::cout << " with Surface_mesh\n"; + Surface_mesh sm1, sm2; + std::ifstream input(f1); + assert(input); + input >> sm1; + input.close(); + input.open(f2); + assert(input); + input >> sm2; + input.close(); + + CGAL::Polygon_mesh_processing::corefine(sm1, sm2); + + assert(sm1.is_valid()); + assert(sm2.is_valid()); + + std::cout << " with Polyhedron_3\n"; + Polyhedron_3 P, Q; + input.open(f1); + assert(input); + input >> P; + input.close(); + input.open(f2); + assert(input); + input >> Q; + + CGAL::Polygon_mesh_processing::corefine(P, Q); + + assert(P.is_valid()); + assert(Q.is_valid()); +} int main(int argc, char** argv) { for(int i=0; i< (argc-1)/2;++i) { - std::cout << "Corefining " << argv[2*i+1] - << " and " << argv[2*(i+1)] << "\n"; - - std::cout << " with Surface_mesh\n"; - Surface_mesh sm1, sm2; - std::ifstream input(argv[2*i+1]); - assert(input); - input >> sm1; - input.close(); - input.open(argv[2*(i+1)]); - assert(input); - input >> sm2; - input.close(); - - CGAL::Polygon_mesh_processing::corefine(sm1, sm2); - - assert(sm1.is_valid()); - assert(sm2.is_valid()); - - std::cout << " with Polyhedron_3\n"; - Polyhedron_3 P, Q; - input.open(argv[2*i+1]); - assert(input); - input >> P; - input.close(); - input.open(argv[2*(i+1)]); - assert(input); - input >> Q; - - CGAL::Polygon_mesh_processing::corefine(P, Q); - - assert(P.is_valid()); - assert(Q.is_valid()); + test(argv[2*i+1], argv[2*(i+1)]); + test(argv[2*(i+1)], argv[2*i+1]); } }