diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/data/folded_star.off b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/folded_star.off new file mode 100644 index 00000000000..68c8a887da2 --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/folded_star.off @@ -0,0 +1,15 @@ +OFF +7 6 0 +0.50085999554530469 0.98935974982034269 0.054777016186685679 +0.51086414037695982 0.0074532224578913869 0.0098759303387234813 +0.23667027533904861 -0.19236191791372245 0.078118737677961653 +0.49890739640011506 0.47147692553082188 0.51901846156493603 +0.5 0.5 0 +0.8400145559724278 0.28990007922508693 -0.53104077094013602 +-0.011501240589425327 0.99837637926383715 0.011228717925938695 +3 4 5 0 +3 1 4 3 +3 3 4 6 +3 4 0 6 +3 1 2 4 +3 2 5 4 diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_compute_normals_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_compute_normals_test.cpp index 364df9d3cfa..4d222f79c3c 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_compute_normals_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/pmp_compute_normals_test.cpp @@ -1,62 +1,150 @@ #include #include -#include -#include -#include +#include +#include + +#include #include #include -typedef CGAL::Exact_predicates_inexact_constructions_kernel Epic; -typedef CGAL::Exact_predicates_exact_constructions_kernel Epec; +typedef CGAL::Exact_predicates_inexact_constructions_kernel EPICK; +typedef CGAL::Exact_predicates_exact_constructions_kernel EPECK; -template -void test_normals(const char* file_name) +typedef CGAL::Surface_mesh EPICK_SM; +typedef CGAL::Surface_mesh EPECK_SM; + +namespace PMP = CGAL::Polygon_mesh_processing; + +template +void test(const Mesh& mesh, + const VertexNormalPmap& vnormals, + const FaceNormalPmap& fnormals) { - typedef typename K::Point_3 Point; - typedef typename K::Vector_3 Vector; - typedef CGAL::Surface_mesh Surface_mesh; - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::face_descriptor face_descriptor; - - Surface_mesh mesh; + typedef typename K::Vector_3 Vector; + + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_descriptor face_descriptor; + + typedef typename PMP::GetVertexPointMap::const_type VPMap; + VPMap vpmap = get_const_property_map(CGAL::vertex_point, mesh); + + const vertex_descriptor first_vertex = *(vertices(mesh).begin()); + const face_descriptor first_face = *(faces(mesh).begin()); + + PMP::compute_face_normals(mesh, fnormals); + PMP::compute_face_normals(mesh, fnormals, PMP::parameters::vertex_point_map(vpmap)); + PMP::compute_face_normals(mesh, fnormals, CGAL::parameters::vertex_point_map(vpmap) + .geom_traits(K())); + + Vector f0n = PMP::compute_face_normal(first_face, mesh); + assert(f0n == get(fnormals, first_face)); + PMP::compute_face_normal(first_face, mesh, PMP::parameters::vertex_point_map(vpmap)); + + PMP::compute_vertex_normals(mesh, vnormals); + PMP::compute_vertex_normals(mesh, vnormals, PMP::parameters::vertex_point_map(vpmap)); + PMP::compute_vertex_normals(mesh, vnormals, CGAL::parameters::vertex_point_map(vpmap) + .geom_traits(K())); + + Vector v0n = PMP::compute_vertex_normal(first_vertex, mesh); + assert(v0n == get(vnormals, first_vertex)); + v0n = PMP::compute_vertex_normal(first_vertex, mesh, PMP::parameters::vertex_point_map(vpmap) + .face_normal_map(fnormals)); + assert(v0n == get(vnormals, first_vertex)); + + PMP::compute_normals(mesh, vnormals, fnormals); + PMP::compute_normals(mesh, vnormals, fnormals, PMP::parameters::vertex_point_map(vpmap)); + PMP::compute_normals(mesh, vnormals, fnormals, CGAL::parameters::vertex_point_map(vpmap) + .geom_traits(K())); + + for(vertex_descriptor v : vertices(mesh)) { + assert(get(vnormals, v) != CGAL::NULL_VECTOR); + } + + for(face_descriptor f : faces(mesh)) { + assert(get(fnormals, f) != CGAL::NULL_VECTOR); + } +} + +template +void test_SM(const char* file_name) +{ + typedef CGAL::Surface_mesh SM; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_descriptor face_descriptor; + + typedef typename K::Vector_3 Vector; + + SM mesh; std::ifstream input(file_name); - if (!(input >> mesh)){ - std::cerr << "Error: cannot read Surface_mesh : " << file_name << "\n"; + if(!(input >> mesh)) + { + std::cerr << "Error: cannot read " << file_name << " as a Surface_mesh\n"; assert(false); } - - typename Surface_mesh::template Property_map fnormals; - bool created; - boost::tie(fnormals, created) = mesh.template add_property_map("f:normals",Vector(0,0,0)); - CGAL::Polygon_mesh_processing::compute_face_normals(mesh, fnormals); - CGAL::Polygon_mesh_processing::compute_face_normals(mesh, fnormals, - CGAL::Polygon_mesh_processing::parameters::vertex_point_map(mesh.points())); - CGAL::Polygon_mesh_processing::compute_face_normals(mesh, fnormals, - CGAL::Polygon_mesh_processing::parameters::vertex_point_map(mesh.points()).geom_traits(K())); - typename Surface_mesh:: template Property_map vnormals; + typename SM::template Property_map vnormals; + vnormals = mesh.template add_property_map("v:normals", CGAL::NULL_VECTOR).first; + typename SM::template Property_map fnormals; + fnormals = mesh.template add_property_map("f:normals", CGAL::NULL_VECTOR).first; - boost::tie(vnormals, created) = mesh.template add_property_map("v:normals",Vector(0,0,0)); - CGAL::Polygon_mesh_processing::compute_vertex_normals(mesh, vnormals); - CGAL::Polygon_mesh_processing::compute_vertex_normals(mesh, vnormals, - CGAL::Polygon_mesh_processing::parameters::vertex_point_map(mesh.points())); - CGAL::Polygon_mesh_processing::compute_vertex_normals(mesh, vnormals, - CGAL::Polygon_mesh_processing::parameters::vertex_point_map(mesh.points()).geom_traits(K())); + test(mesh, vnormals, fnormals); +} - CGAL::Polygon_mesh_processing::compute_normals(mesh, vnormals, fnormals); - CGAL::Polygon_mesh_processing::compute_normals(mesh, vnormals, fnormals, - CGAL::Polygon_mesh_processing::parameters::vertex_point_map(mesh.points())); - CGAL::Polygon_mesh_processing::compute_normals(mesh, vnormals, fnormals, - CGAL::Polygon_mesh_processing::parameters::vertex_point_map(mesh.points()).geom_traits(K())); +template +void test_Polyhedron(const char* file_name) +{ + typedef CGAL::Polyhedron_3 Polyhedron; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_descriptor face_descriptor; + typedef typename K::Vector_3 Vector; + + Polyhedron mesh; + std::ifstream input(file_name); + if(!(input >> mesh)) + { + std::cerr << "Error: cannot read " << file_name << " as a Polyhedron\n"; + assert(false); + } + + typedef std::map VertexNormalMap; + typedef boost::associative_property_map VertexNormalPMap; + typedef std::map FaceNormalMap; + typedef boost::associative_property_map FaceNormalPMap; + + VertexNormalMap vn_map; + FaceNormalMap fn_map; + + for(vertex_descriptor v : vertices(mesh)) + vn_map[v] = CGAL::NULL_VECTOR; + for(face_descriptor f : faces(mesh)) + fn_map[f] = CGAL::NULL_VECTOR; + + VertexNormalPMap vnormals(vn_map); + FaceNormalPMap fnormals(fn_map); + + test(mesh, vnormals, fnormals); +} + +void test(const char* filename) +{ + std::cout << "test " << filename << "..." << std::endl; + + test_SM(filename); + test_SM(filename); + test_Polyhedron(filename); + test_Polyhedron(filename); } int main() { - test_normals("data/elephant.off"); - test_normals("data/elephant.off"); + test("../data/elephant.off"); + test("../data/folded_star.off"); + test("../data/joint_refined.off"); + test("../data/mannequin-devil.off"); + test("../data/U.off"); std::cerr << "All done." << std::endl; return EXIT_SUCCESS;