diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_polyhedral_envelope.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_polyhedral_envelope.cpp new file mode 100644 index 00000000000..5a06fecd980 --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_polyhedral_envelope.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include + +#include + +#include +#include + +namespace PMP = CGAL::Polygon_mesh_processing; + +typedef CGAL::Exact_predicates_inexact_constructions_kernel EPIC; +typedef CGAL::Exact_predicates_exact_constructions_kernel EPEC; + +void test_API() +{ + std::cout << "---- test_API() ----\n"; + std::vector points; + std::vector > triangles; + std::ifstream in("data/eight.off"); + CGAL::read_OFF(in, points, triangles); + CGAL::Surface_mesh sm; + CGAL::Polyhedron_3 poly; + PMP::polygon_soup_to_polygon_mesh(points, triangles, sm); + PMP::polygon_soup_to_polygon_mesh(points, triangles, poly); + + // build from the same kernel + { + CGAL::Polyhedral_envelope envelope; + assert(envelope.is_empty()); + envelope = CGAL::Polyhedral_envelope(sm,0.0001); + assert(!envelope.is_empty()); + assert(envelope(sm)); + assert(envelope(poly)); + assert(envelope(points, triangles)); + + envelope=CGAL::Polyhedral_envelope(points,triangles,0.0001); + assert(!envelope.is_empty()); + assert(envelope(sm)); + assert(envelope(poly)); + assert(envelope(points, triangles)); + + std::vector subfaces(faces(sm).begin(), std::next(faces(sm).begin(), 150)); + envelope=CGAL::Polyhedral_envelope(subfaces,sm,0.0001); + assert(!envelope.is_empty()); + assert(!envelope(sm)); + assert(!envelope(poly)); + assert(!envelope(points, triangles)); + } + + // build from different kernels + { + auto sm_np = CGAL::parameters::vertex_point_map( + CGAL::make_cartesian_converter_property_map( + get(boost::vertex_point, sm))); + auto poly_np = CGAL::parameters::vertex_point_map( + CGAL::make_cartesian_converter_property_map( + get(boost::vertex_point, poly))); + auto soup_np = CGAL::parameters::point_map( + CGAL::make_cartesian_converter_property_map( + CGAL::Identity_property_map())); + + CGAL::Polyhedral_envelope envelope(poly,0.0001,poly_np); + assert(envelope(sm, sm_np)); + assert(envelope(poly, poly_np)); + assert(envelope(points, triangles, soup_np)); + + envelope = CGAL::Polyhedral_envelope(points,triangles,0.0001, soup_np); + assert(envelope(sm, sm_np)); + assert(envelope(poly, poly_np)); + assert(envelope(points, triangles, soup_np)); + + std::vector subfaces(faces(sm).begin(), std::next(faces(sm).begin(), 150)); + envelope=CGAL::Polyhedral_envelope(subfaces,sm,0.0001,sm_np); + assert(!envelope.is_empty()); + assert(!envelope(sm, sm_np)); + assert(!envelope(poly, poly_np)); + assert(!envelope(points, triangles, soup_np)); + } +} + +void test_remove_si() +{ + std::cout << "---- test_remove_si() ----\n"; + CGAL::Surface_mesh tm; + std::ifstream in("data/pig.off"); + in >> tm; + assert(tm.vertices().size()!=0); + + // try with a small bound --> reject fix + PMP::experimental::remove_self_intersections(tm, CGAL::parameters::polyhedral_envelope_epsilon(0.0001)); + assert(PMP::does_self_intersect(tm)); + // try with a larger bound --> accept fix + PMP::experimental::remove_self_intersections(tm, CGAL::parameters::polyhedral_envelope_epsilon(0.001)); + assert(!PMP::does_self_intersect(tm)); +} + +int main() +{ + test_remove_si(); + test_API(); +} \ No newline at end of file