#include #include #include #include #include #include #include #include #include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef K::FT FT; typedef K::Point_3 Point_3; typedef CGAL::Bbox_3 Bbox_3; typedef CGAL::Surface_mesh Surface_mesh; typedef CGAL::Polyhedron_3 Polyhedron_3; typedef CGAL::Timer Timer; template void triangle_mesh(std::string fname) { typedef CGAL::AABB_face_graph_triangle_primitive Primitive; typedef CGAL::AABB_traits Traits; typedef CGAL::AABB_tree Tree; TriangleMesh tmesh; if(!CGAL::IO::read_polygon_mesh(fname, tmesh) || CGAL::is_triangle_mesh(tmesh)) { std::cerr << "Invalid input." << std::endl; return; } Timer t; t.start(); Tree tree(faces(tmesh).first, faces(tmesh).second, tmesh); tree.build(); std::cout << t.time() << " sec." << std::endl; std::cout << "Closest point to ORIGIN:" << tree.closest_point(CGAL::ORIGIN) << std::endl; } Bbox_3 bbox(boost::graph_traits::face_descriptor fd, const Surface_mesh& p) { boost::graph_traits::halfedge_descriptor hd = halfedge(fd,p); Bbox_3 res = p.point(source(hd,p)).bbox(); res += p.point(target(hd,p)).bbox(); res += p.point(target(next(hd,p),p)).bbox(); return res; } void surface_mesh_cache_bbox(std::string fname) { typedef boost::graph_traits::face_descriptor face_descriptor; typedef Surface_mesh::Property_map Bbox_pmap; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; typedef CGAL::AABB_traits Traits; typedef CGAL::AABB_tree Tree; Surface_mesh tmesh; std::ifstream in(fname); in >> tmesh; Timer t; t.start(); Bbox_pmap bb = tmesh.add_property_map("f:bbox",Bbox_3()).first; for(face_descriptor fd : faces(tmesh)) put(bb, fd, bbox(fd,tmesh)); Traits traits(bb); Tree tree(traits); tree.insert(faces(tmesh).first, faces(tmesh).second, tmesh); tree.build(); tmesh.remove_property_map(bb); std::cout << t.time() << " sec."<< std::endl; std::cout << "Closest point to ORIGIN:" << tree.closest_point(CGAL::ORIGIN) << std::endl; } int main(int argc, char* argv[]) { std::cout << "Polyhedron_3" << std::endl; triangle_mesh((argc>1)?argv[1]:CGAL::data_file_path("meshes/tetrahedron.off")); std::cout << "Surface_mesh" << std::endl; triangle_mesh((argc>1)?argv[1]:CGAL::data_file_path("meshes/tetrahedron.off")); std::cout << "Surface_mesh with cached Bbox_3" << std::endl; surface_mesh_cache_bbox((argc>1)?argv[1]:CGAL::data_file_path("meshes/tetrahedron.off")); return EXIT_SUCCESS; }