Index: voronoi_benchmark_segments.cpp =================================================================== --- voronoi_benchmark_segments.cpp (revision 84122) +++ voronoi_benchmark_segments.cpp (working copy) @@ -25,17 +25,19 @@ typedef boost::polygon::voronoi_diagram VD_BOOST; // Includes for the CGAL library. -#include -#include -#include +#include #include #include -typedef CGAL::Quotient ENT; -typedef CGAL::Simple_cartesian CK; -typedef CGAL::Simple_cartesian EK; -typedef CGAL::Segment_Delaunay_graph_filtered_traits_2< - CK, CGAL::Field_with_sqrt_tag, EK, CGAL::Field_tag> Gt; -typedef CGAL::Segment_Delaunay_graph_2 SDT_CGAL; +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Field_with_sqrt_tag MTag; +typedef CGAL::Integral_domain_without_division_tag EMTag; +typedef CGAL::Simple_cartesian EK; + +typedef CGAL::Segment_Delaunay_graph_filtered_traits_without_intersections_2 Gt; +typedef CGAL::Segment_Delaunay_graph_2 SDT_CGAL; typedef SDT_CGAL::Point_2 Point_CGAL; typedef SDT_CGAL::Site_2 Site_CGAL; @@ -140,8 +142,25 @@ bf << "\n"; } +struct Naive_dual + : public std::unary_function< + const SDT_CGAL::Face&, + Point_CGAL > +{ + Gt::Construct_svd_vertex_2 svd_vertex; + Point_CGAL + operator()(const SDT_CGAL::Face& face) const + { + return svd_vertex( + face.vertex(0)->site(), + face.vertex(1)->site(), + face.vertex(2)->site() ); + } +}; + void run_cgal_test(const std::vector &running_times) { boost::mt19937 gen(RANDOM_SEED); + Naive_dual compute_dual; bf << "CGAL Triangulation of Segments:\n"; for (int i = 0; i < NUM_TESTS; ++i) { timer.restart(); @@ -156,12 +175,61 @@ POINT_POLYGON(x1 + dx, y1 + dy))); } clean_segment_set(ssd); - SDT_CGAL dt; - for (SSD_POLYGON::iterator it = ssd.begin(); it != ssd.end(); ++it) { - dt.insert(Site_CGAL::construct_site_2( - Point_CGAL(it->low().x(), it->low().y()), - Point_CGAL(it->high().x(), it->high().y()))); + + typedef std::vector Points_container; + typedef std::vector::size_type Index_type; + typedef std::vector< std::pair > Constraints_container; + + typedef std::vector Indices; + typedef std::vector Vertices; + + Points_container points; + Constraints_container constraints; + points.reserve(ssd.size() * 2); + constraints.reserve(ssd.size()); + for(SSD_POLYGON::iterator it = ssd.begin(); it != ssd.end(); ++it) { + points.push_back(Point_CGAL(boost::polygon::x(it->low()), boost::polygon::y(it->low()))); + points.push_back(Point_CGAL(boost::polygon::x(it->high()), boost::polygon::y(it->high()))); + constraints.push_back(std::make_pair(points.size() -2, points.size() - 1)); } + + Indices indices; + indices.reserve(ssd.size()); + CGAL::Spatial_sort_traits_adapter_2 sort_traits(&(points[0])); + + + std::copy(boost::counting_iterator(0), + boost::counting_iterator(points.size()), + std::back_inserter(indices)); + + CGAL::spatial_sort(indices.begin(), indices.end(), sort_traits); + + SDT_CGAL sdg; + + Vertices vertices; + vertices.resize(points.size()); + SDT_CGAL::Vertex_handle hint; + for(Indices::const_iterator pt_ptr_it = indices.begin(), end = indices.end(); + pt_ptr_it != end; ++pt_ptr_it) { + SDT_CGAL::Vertex_handle vh = sdg.insert(points[*pt_ptr_it], hint); + hint = vh; + vertices[*pt_ptr_it] = vh; + } + + for(Constraints_container::const_iterator cit = constraints.begin(), end = constraints.end(); + cit != end; ++cit) { + const SDT_CGAL::Vertex_handle& v1 = vertices[cit->first]; + const SDT_CGAL::Vertex_handle& v2 = vertices[cit->second]; + if(v1 != v2) + sdg.insert(v1, v2); + } + std::size_t nb_faces = sdg.number_of_faces(); + std::vector voronoi_vertices; + voronoi_vertices.reserve( nb_faces ); + std::transform(sdg.finite_faces_begin(), sdg.finite_faces_end(), + std::back_inserter(voronoi_vertices),compute_dual); + if ( nb_faces>voronoi_vertices.size() ) std::cerr << "ERROR\n"; + } double time_per_test = (timer.elapsed() - running_times[i]) / NUM_RUNS[i]; format_line(NUM_SEGMENTS[i], NUM_RUNS[i], time_per_test); Index: voronoi_benchmark_points.cpp =================================================================== --- voronoi_benchmark_points.cpp (revision 84122) +++ voronoi_benchmark_points.cpp (working copy) @@ -26,19 +26,13 @@ typedef boost::polygon::voronoi_diagram VD_BOOST; // Includes for the CGAL library. -#include -#include -#include -#include -#include -typedef CGAL::Quotient ENT; -typedef CGAL::Simple_cartesian CK; -typedef CGAL::Simple_cartesian EK; -typedef CGAL::Segment_Delaunay_graph_filtered_traits_2< - CK, CGAL::Field_with_sqrt_tag, EK, CGAL::Field_tag> Gt; -typedef CGAL::Segment_Delaunay_graph_2 SDT_CGAL; -typedef SDT_CGAL::Point_2 Point_CGAL; +#include +#include +typedef CGAL::Exact_predicates_inexact_constructions_kernel Gt; +typedef CGAL::Delaunay_triangulation_2 DT2_CGAL; +typedef Gt::Point_2 Point_CGAL; + // Includes for the S-Hull library. #include @@ -75,17 +69,43 @@ bf << "\n"; } +struct Naive_dual + : public std::unary_function< + const DT2_CGAL::Face&, + Point_CGAL > +{ + Gt::Construct_circumcenter_2 circumcenter; + Point_CGAL + operator()(const DT2_CGAL::Face& face) const + { + return circumcenter( + face.vertex(0)->point(), + face.vertex(1)->point(), + face.vertex(2)->point() ); + } +}; + void run_cgal_test() { boost::mt19937 gen(RANDOM_SEED); bf << "CGAL Triangulation of Points:\n"; + Naive_dual compute_dual; for (int i = 0; i < NUM_TESTS; ++i) { timer.restart(); for (int j = 0; j < NUM_RUNS[i]; ++j) { - SDT_CGAL dt; + DT2_CGAL dt; + std::vector points; + points.reserve(NUM_POINTS[i]); for (int k = 0; k < NUM_POINTS[i]; ++k) { - dt.insert(Point_CGAL( + points.push_back(Point_CGAL( static_cast(gen()), static_cast(gen()))); } + dt.insert(points.begin(), points.end() ); + std::vector voronoi_vertices; + std::size_t nb_faces = dt.number_of_faces(); + voronoi_vertices.reserve( nb_faces ); + std::transform(dt.finite_faces_begin(), dt.finite_faces_end(), + std::back_inserter(voronoi_vertices),compute_dual); + if ( nb_faces!=voronoi_vertices.size() ) std::cerr << "ERROR\n"; } double time_per_test = timer.elapsed() / NUM_RUNS[i]; format_line(NUM_POINTS[i], NUM_RUNS[i], time_per_test);