max_cover_example.cpp
max_cover_example.cpp
—
C++ source code,
2Kb
File contents
#include <fstream> #include <sstream> #include <ostream> #include <boost/timer.hpp> #include <CGAL/Exact_predicates_exact_constructions_kernel.h> #include <CGAL/Arr_circle_segment_traits_2.h> #include <CGAL/Arrangement_2.h> typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; typedef Kernel::FT Number_type; typedef CGAL::Arr_circle_segment_traits_2<Kernel> Traits; typedef Traits::CoordNT CoordNT; typedef Traits::Point_2 Point; typedef Traits::Curve_2 Curve; typedef Traits::Rational_point_2 Rational_point; typedef Traits::Rational_segment_2 Segment; typedef Traits::Rational_circle_2 Circle; typedef CGAL::Arrangement_2<Traits> Arrangement; /*! Export a coordinate of type square-root extension to the standard output. */ std::ostream& operator<<(std::ostream& os, const CoordNT& c) { CGAL::Rational_traits<Number_type> rt; std::cout << "(" << rt.numerator(c.a0()) << "/" << rt.denominator(c.a0()) << "," << rt.numerator(c.a1()) << "/" << rt.denominator(c.a1()) << "," << rt.numerator(c.root()) << "/" << rt.denominator(c.root()) << ")"; return os; } /*! Export a point of two coordinates of type square-root extension to the * standard output. */ std::ostream& operator<<(std::ostream& os, const Point& p) { std::cout << "(" << p.x() << "," << p.y() << ")"; return os; } int main(int argc, char* argv[]) { Kernel::FT r_square; if (argc < 2) { std::cerr << "The radius is missing!" << std::endl; return 1; } std::istringstream r_square_stream(argv[1]); r_square_stream >> r_square; const char* filename = (argc > 2) ? argv[2] : "points.txt"; std::ifstream is; is.open(filename); if (!is.is_open()) { std::cerr << "Failed to open " << filename << "!" << std::endl; return 1; } size_t n; is >> n; std::vector<Curve> curves(n); for (auto i = 0; i < n; ++i) { Kernel::FT x, y; is >> x >> y; curves[i] = Curve(Circle(Rational_point(x, y), r_square)); } Arrangement arr; boost::timer timer; insert(arr, curves.begin(), curves.end()); double secs = timer.elapsed(); // Print the number of cells: std::cout << "Execution time: " << secs << std::endl; std::cout << "# vertices: " << arr.number_of_vertices() << std::endl << "# halfedges: " << arr.number_of_halfedges() << std::endl << "# faces: " << arr.number_of_faces() << std::endl; // Print one point: if (arr.number_of_vertices() > 0) std::cout << "1st point: " << arr.vertices_begin()->point() << std::endl; return 0; }