void Scene::generate_edge_points(const unsigned int nb_points) { if(m_pPolyhedron == NULL) { std::cout << "Load polyhedron first." << std::endl; return; } typedef CGAL::AABB_halfedge_graph_segment_primitive<Polyhedron> Primitive; typedef CGAL::AABB_traits<Kernel, Primitive> Traits; typedef CGAL::AABB_tree<Traits> Tree; typedef Tree::Object_and_primitive_id Object_and_primitive_id; std::cout << "Construct AABB tree..."; Tree tree( CGAL::edges(*m_pPolyhedron).first, CGAL::edges(*m_pPolyhedron).second, *m_pPolyhedron); std::cout << "done." << std::endl; CGAL::Timer timer; timer.start(); std::cout << "Generate edge points: "; unsigned int nb = 0; unsigned int nb_planes = 0; while(nb < nb_points) { Plane plane = random_plane(tree.bbox()); std::list<Object_and_primitive_id> intersections; tree.all_intersections(plane,std::back_inserter(intersections)); nb_planes++; std::list<Object_and_primitive_id>::iterator it; for(it = intersections.begin(); it != intersections.end(); it++) { Object_and_primitive_id op = *it; CGAL::Object object = op.first; Point point; if(CGAL::assign(point,object)) { m_points.push_back(point); nb++; } } } std::cout << nb_planes << " plane queries, " << timer.time() << " s." << std::endl; changed(); }
void Scene::benchmark_intersections(const double duration) { if(m_pPolyhedron == NULL) { std::cout << "Load polyhedron first." << std::endl; return; } // constructs tree std::cout << "Construct AABB tree..."; CGAL::Timer timer; timer.start(); Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); std::cout << "done (" << timer.time() << " s)" << std::endl; // generates random queries const int nb_queries = 1000000; std::cout << "Generates random queries..."; std::vector<Ray> rays; std::vector<Line> lines; std::vector<Plane> planes; std::vector<Segment> segments; timer.start(); srand(0); int i = 0; for(i=0; i<nb_queries; i++) { rays.push_back(random_ray(tree.bbox())); lines.push_back(random_line(tree.bbox())); planes.push_back(random_plane(tree.bbox())); segments.push_back(random_segment(tree.bbox())); } std::cout << "done (" << timer.time() << " s)" << std::endl; // bench for all functions and query types bench_intersections(tree,duration,DO_INTERSECT,"do_intersect()",rays,lines,planes,segments,nb_queries); bench_intersections(tree,duration,ANY_INTERSECTED_PRIMITIVE,"any_intersected_primitive()",rays,lines,planes,segments,nb_queries); bench_intersections(tree,duration,ANY_INTERSECTION,"any_intersection()",rays,lines,planes,segments,nb_queries); bench_intersections(tree,duration,NB_INTERSECTIONS,"number_of_intersected_primitives()",rays,lines,planes,segments,nb_queries); bench_intersections(tree,duration,ALL_INTERSECTED_PRIMITIVES,"all_intersected_primitives()",rays,lines,planes,segments,nb_queries); bench_intersections(tree,duration,ALL_INTERSECTIONS,"all_intersections()",rays,lines,planes,segments,nb_queries); }