// To deactivate statics filters in the 2D/3D case //#define CGAL_NO_STATIC_FILTERS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "console_color.h" template struct Stats_getter; // T2 specialization template struct Stats_getter > { typedef CGAL::Delaunay_triangulation_2 DT; Stats_getter(DT const& dt) : m_dt(dt) {} std::size_t number_of_vertices() { return m_dt.number_of_vertices(); } std::size_t number_of_finite_cells() { return m_dt.number_of_faces(); } DT m_dt; }; // RT2 specialization template struct Stats_getter > { typedef CGAL::Regular_triangulation_2 DT; Stats_getter(DT const& dt) : m_dt(dt) {} std::size_t number_of_vertices() { return m_dt.number_of_vertices(); } std::size_t number_of_finite_cells() { return m_dt.number_of_faces(); } DT m_dt; }; // T3 specialization template struct Stats_getter > { typedef CGAL::Delaunay_triangulation_3 DT; Stats_getter(DT const& dt) : m_dt(dt) {} std::size_t number_of_vertices() { return m_dt.number_of_vertices(); } std::size_t number_of_finite_cells() { return m_dt.number_of_finite_cells(); } DT m_dt; }; // RT3 specialization template struct Stats_getter > { typedef CGAL::Regular_triangulation_3 DT; Stats_getter(DT const& dt) : m_dt(dt) {} std::size_t number_of_vertices() { return m_dt.number_of_vertices(); } std::size_t number_of_finite_cells() { return m_dt.number_of_finite_cells(); } DT m_dt; }; template void test( int d, int N, Pt_d_range const& points_d, Pt_23_range const& points_23, std::string const& DTd_static_or_dyn) { // Td { DT_d dt(d); CGAL::Timer timer; timer.start(); dt.insert(points_d.begin(), points_d.end()); std::cerr << " * Td: " << yellow << timer.time() << " s" << white << std::endl; std::cerr << " " << dt.number_of_vertices() << " vertices, " << dt.number_of_finite_full_cells() << " finite cells." << std::endl; } // T2 or T3 { CGAL::Timer timer; timer.start(); DT_23 dt; dt.insert(points_23.begin(), points_23.end()); std::cerr << " * T" << d << ": " << yellow << timer.time() << " s" << white << std::endl; Stats_getter sg(dt); std::cerr << " " << sg.number_of_vertices() << " vertices, " << sg.number_of_finite_cells() << " finite cells." << std::endl; } } template< int D, typename Dim_tag > void go(const int N) { CGAL_assertion(D == 2 || D == 3); // Generate points (in a common "array" format) std::vector > coords; coords.reserve(N); for (int i = 0; i < N; ++i) { std::array pt; for (int j = 0; j < D; ++j) pt[j] = CGAL::get_default_random().get_double(-1., 1.); coords.push_back(pt); } // Generate weights std::vector weights; weights.reserve(N); for (int i = 0; i < N; ++i) weights.push_back(CGAL::get_default_random().get_double(-10., 10.)); // DTd typedef CGAL::Epick_d Kd; typedef CGAL::Delaunay_triangulation DT_d; typedef typename DT_d::Point Point_d; std::vector points_d; points_d.reserve(N); for (int i = 0; i < N; ++i) points_d.push_back(Point_d(D, coords[i].begin(), coords[i].end())); // RTd typedef CGAL::Regular_triangulation RT_d; //typedef typename RT_d::Point Bare_point_d; // because of Regular_traits_adapter Point is actually a Weighted_point typedef typename RT_d::Weighted_point WPoint_d; std::vector wpoints_d; wpoints_d.reserve(N); for (int i = 0; i < N; ++i) { wpoints_d.push_back(WPoint_d( Point_d(D, coords[i].begin(), coords[i].end()), weights[i])); } // T2 or T3 typedef CGAL::Exact_predicates_inexact_constructions_kernel K23; if (D == 2) { // Delaunay typedef CGAL::Delaunay_triangulation_2 DT_2; typedef typename DT_2::Point Point; std::vector points; points.reserve(N); for (int i = 0; i < N; ++i) points.push_back(Point(coords[i][0], coords[i][1])); std::cerr << std::endl << "DELAUNAY - dim " << D << " - " << N << " points." << std::endl; test(D, N, points_d, points, "static"); // Regular typedef CGAL::Regular_triangulation_2 RT_2; typedef typename RT_2::Bare_point Bare_point; typedef typename RT_2::Point WPoint; std::vector wpoints; wpoints.reserve(N); for (int i = 0; i < N; ++i) { wpoints.push_back(WPoint( Bare_point(coords[i][0], coords[i][1]), weights[i])); } std::cerr << std::endl << "REGULAR - dim " << D << " - " << N << " points." << std::endl; test(D, N, wpoints_d, wpoints, "static"); } else if (D == 3) { typedef CGAL::Delaunay_triangulation_3 DT_3; typedef typename DT_3::Point Point; std::vector points; points.reserve(N); for (int i = 0; i < N; ++i) points.push_back(Point(coords[i][0], coords[i][1], coords[i][2])); std::cerr << std::endl << "DELAUNAY - dim " << D << " - " << N << " points." << std::endl; test(D, N, points_d, points, "static"); // Regular typedef CGAL::Regular_triangulation_3 RT_3; typedef typename RT_3::Bare_point Bare_point; typedef typename RT_3::Point WPoint; std::vector wpoints; wpoints.reserve(N); for (int i = 0; i < N; ++i) { wpoints.push_back(WPoint( Bare_point(coords[i][0], coords[i][1], coords[i][2]), weights[i])); } std::cerr << std::endl << "REGULAR - dim " << D << " - " << N << " points." << std::endl; test(D, N, wpoints_d, wpoints, "static"); } } int main(int argc, char **argv) { srand(static_cast(time(NULL))); #ifdef _DEBUG int N = 100; #else int N = 100000; #endif if (argc > 1) N = atoi(argv[1]); std::cerr << "-----------------------------------------" << std::endl; std::cerr << "-- STATIC --" << std::endl; std::cerr << "-----------------------------------------" << std::endl; go<2, CGAL::Dimension_tag<2> >(N); go<3, CGAL::Dimension_tag<3> >(N); std::cerr << std::endl; std::cerr << "-----------------------------------------" << std::endl; std::cerr << "-- DYNAMIC --" << std::endl; std::cerr << "-----------------------------------------" << std::endl; go<2, CGAL::Dynamic_dimension_tag>(N); go<3, CGAL::Dynamic_dimension_tag>(N); std::cerr << std::endl; return 0; }