From e88d30d17793b650b3e8ff3639fa7c7b965f8aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 5 Nov 2010 09:22:49 +0000 Subject: [PATCH] add program to compare traits using or not Circular_kernel_2 --- .gitattributes | 1 + .../Benchmarks/arr_traits_comparison.cpp | 152 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 Circular_kernel_2/Benchmarks/arr_traits_comparison.cpp diff --git a/.gitattributes b/.gitattributes index 1dccc3bdd4a..6555b996e5a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1206,6 +1206,7 @@ CGAL_ipelets/include/CGAL/CGAL_Ipelet_base_v7.h -text CGAL_ipelets/include/CGAL/grabbers.h -text CGAL_ipelets/package_info/CGAL_ipelets/maintainer -text CGALimageIO/src/CGALimageIO/CMakeLists.txt -text +Circular_kernel_2/Benchmarks/arr_traits_comparison.cpp -text Circular_kernel_2/Benchmarks/parser/Report.pdf -text svneol=unset#application/pdf Circular_kernel_2/Benchmarks/readme.doc -text svneol=unset#application/msword Circular_kernel_2/Benchmarks/readme.pdf -text svneol=unset#application/pdf diff --git a/Circular_kernel_2/Benchmarks/arr_traits_comparison.cpp b/Circular_kernel_2/Benchmarks/arr_traits_comparison.cpp new file mode 100644 index 00000000000..ff9c8c5a812 --- /dev/null +++ b/Circular_kernel_2/Benchmarks/arr_traits_comparison.cpp @@ -0,0 +1,152 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef CGAL::Gmpq Number_type; +typedef CGAL::Cartesian Kernel; +typedef CGAL::Lazy_kernel< Kernel > Lazy_Kernel; +typedef CGAL::Arr_circle_segment_traits_2 Lazy_Traits; +typedef CGAL::Arr_circle_segment_traits_2 Traits; + +typedef CGAL::Cartesian K_exact; +typedef CGAL::Algebraic_kernel_for_circles_2_2 AK_exact; +typedef CGAL::Circular_kernel_2 CK_exact; + +typedef CGAL::Interval_nt_advanced ANT; +typedef CGAL::Cartesian ALK; +typedef CGAL::Algebraic_kernel_for_circles_2_2 AAK; +typedef CGAL::Circular_kernel_2 ACK; +typedef CGAL::Lazy_circular_kernel_2 CK; + +typedef CGAL::Arr_circular_line_arc_traits_2 Lazy_Traits_with_CK; +typedef CGAL::Arr_circular_line_arc_traits_2 Traits_with_CK; + +template +struct Get_exact{ + typename CK::EK::Root_of_2 operator()(const typename CK::Root_of_2& t) const { + return CGAL::exact(t); + } +}; + +template <> +struct Get_exact{ + const CK_exact::Root_of_2& operator()(const CK_exact::Root_of_2& t) const { + return t; + } +}; + + + +template +struct Benchmark +{ + + typedef CGAL::Arrangement_2 Arrangement_2; + typedef CGAL::Arrangement_2 Arrangement_2_with_CK; + typedef typename Traits_with_CK::Kernel::Circular_arc_2 C2; + typedef typename Traits_with_CK::Kernel::Line_arc_2 L2; + typedef typename Traits_with_CK::Curve_2 Curve_2_with_CK; + typedef std::vector Arccontainer; + typedef typename Traits_with_CK::Circular_arc_point_2 Circular_arc_point_2; + typedef typename Traits::CoordNT ORN; + + ORN convert (const typename Traits_with_CK::Kernel::Root_of_2& n) + { + Get_exact exact; + return CGAL::sign(exact(n).gamma())==CGAL::ZERO?ORN(exact(n).alpha()):ORN(exact(n).alpha(),exact(n).beta(),exact(n).gamma()); + } + + typename Traits::Point_2 convert(const Circular_arc_point_2& p) + { + ORN x=convert(p.x()); + ORN y=convert(p.y()); + return typename Traits::Point_2(x,y); + } + + + template + void read_from_dxf(const char* fname,Arccontainer& ac, Output_iterator out) + { + std::ifstream fin(fname); + CGAL::variant_load(fin,std::back_inserter(ac)); + fin.close(); + + for (typename Arccontainer::iterator it= ac.begin();it!=ac.end();++it) + { + L2* seg=boost::get(&(*it)); + if (seg!=NULL){ + typename Traits::Point_2 s=convert(seg->source()); + typename Traits::Point_2 t=convert(seg->target()); + typename Traits::Kernel::Line_2 line(seg->supporting_line().a(),seg->supporting_line().b(),seg->supporting_line().c()); + *out++ = typename Traits::Curve_2( line,s,t ); + } + else{ + C2* arc=boost::get(&(*it)); + assert(arc!=NULL); + Circular_arc_point_2 ck_s=arc->source(); + Circular_arc_point_2 ck_t=arc->target(); + typename Traits::Kernel::Point_2 center(typename Traits::Kernel::FT(arc->supporting_circle().center().x()), + typename Traits::Kernel::FT(arc->supporting_circle().center().y())); + typename Traits::Kernel::FT sqrad(arc->supporting_circle().squared_radius()); + *out++ = typename Traits::Curve_2(typename Traits::Kernel::Circle_2(center,sqrad,CGAL::COUNTERCLOCKWISE),convert(ck_s),convert(ck_t)); + } + } + } + + void run(const char* fname) + { + std::list curves; + Arccontainer ac; + + read_from_dxf(fname,ac,std::back_inserter(curves)); + + //using Arr_circle_segment_traits_2 + { + CGAL::Timer time; time.start(); + // Construct the arrangement of the curves. + Arrangement_2 arr; + insert (arr, curves.begin(), curves.end()); + // Print the size of the arrangement. + std::cout << "The arrangement size:" << std::endl + << " V = " << arr.number_of_vertices() + << ", E = " << arr.number_of_edges() + << ", F = " << arr.number_of_faces() << std::endl; + time.stop(); + std::cout << "Time for Arr_circle_segment_traits_2 " << time.time() << "\n"; + } + //using Arr_circular_line_arc_traits_2 + { + CGAL::Timer time; time.start(); + Arrangement_2_with_CK ck_arr; + insert (ck_arr, ac.begin(), ac.end(),boost::false_type()); + std::cout << "The arrangement size:" << std::endl + << " V = " << ck_arr.number_of_vertices() + << ", E = " << ck_arr.number_of_edges() + << ", F = " << ck_arr.number_of_faces() << std::endl; + time.stop(); + std::cout << "Time for Arr_circular_line_arc_traits_2 " << time.time() << "\n"; + } + } + +}; + +int main( int argc, char* argv[] ) +{ + std::cout << "Running with Lazy\n"; + Benchmark bench_lazy; + bench_lazy.run(argv[1]); + std::cout << "Running with Exact\n"; + Benchmark bench; + bench.run(argv[1]); + return 0; +} +