diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h index a3d85e06bd1..415a6641d4e 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/self_intersections.h @@ -244,7 +244,10 @@ self_intersections( const FaceRange& face_range, * @tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" * * @param tmesh the triangulated surface mesh to be checked - * @param out output iterator to be filled with all pairs of non-adjacent faces that intersect + * @param out output iterator to be filled with all pairs of non-adjacent faces that intersect. + In case `tmesh` contains some degenerate faces, for each degenerate face `f` a pair `(f,f)` + will be put in `out` before any other self intersection between non-degenerate faces. + These are the only pairs where degenerate faces will be reported. * @param np optional sequence of \ref pmp_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin @@ -343,10 +346,15 @@ self_intersections( const FaceRange& face_range, BOOST_FOREACH(face_descriptor f, face_range) { - boxes.push_back(Box( get(vpmap, target(halfedge(f,tmesh),tmesh)).bbox() - + get(vpmap, target(next(halfedge(f, tmesh), tmesh), tmesh)).bbox() - + get(vpmap, target(next(next(halfedge(f, tmesh), tmesh), tmesh), tmesh)).bbox(), - f)); + typename boost::property_traits::reference + p = get(vpmap, target(halfedge(f,tmesh),tmesh)), + q = get(vpmap, target(next(halfedge(f, tmesh), tmesh), tmesh)), + r = get(vpmap, target(next(next(halfedge(f, tmesh), tmesh), tmesh), tmesh)); + + if ( collinear(p, q, r) ) + *out++= std::make_pair(f,f); + else + boxes.push_back(Box(p.bbox() + q.bbox() + r.bbox(), f)); } // generate box pointers std::vector box_ptr; diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/self_intersection_surface_mesh_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/self_intersection_surface_mesh_test.cpp index 9431c547a43..3addd6c9323 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/self_intersection_surface_mesh_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/self_intersection_surface_mesh_test.cpp @@ -115,5 +115,21 @@ int main(int argc, char** argv) std::cout << "Third test (Epec):" << std::endl; r += test_self_intersections(filename, expected); + // Fourth test ---------------------------------------------------------------- + expected = true; + filename = (argc > 7) ? argv[7] : "data_degeneracies/degtri_single.off"; + if(argc > 7) { + assert(argc > 8); + std::stringstream ss(argv[8]); + ss >> std::boolalpha >> expected; + assert(!ss.fail()); + } + + std::cout << "Fourth test (Epic):" << std::endl; + r += test_self_intersections(filename, expected); + + std::cout << "Fourth test (Epec):" << std::endl; + r += test_self_intersections(filename, expected); + return r; }