mirror of https://github.com/CGAL/cgal
add program to compare traits using or not Circular_kernel_2
This commit is contained in:
parent
8fdf99310f
commit
e88d30d177
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,152 @@
|
|||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Arr_circle_segment_traits_2.h>
|
||||
#include <CGAL/Arrangement_2.h>
|
||||
#include <CGAL/Gmpq.h>
|
||||
#include <CGAL/Lazy_kernel.h>
|
||||
#include <CGAL/IO/Dxf_variant_reader.h>
|
||||
#include <CGAL/Arr_circular_line_arc_traits_2.h>
|
||||
#include <CGAL/Circular_kernel_2.h>
|
||||
#include <CGAL/Lazy_circular_kernel_2.h>
|
||||
#include <CGAL/Algebraic_kernel_for_circles_2_2.h>
|
||||
#include <fstream>
|
||||
#include <CGAL/Timer.h>
|
||||
|
||||
typedef CGAL::Gmpq Number_type;
|
||||
typedef CGAL::Cartesian<Number_type> Kernel;
|
||||
typedef CGAL::Lazy_kernel< Kernel > Lazy_Kernel;
|
||||
typedef CGAL::Arr_circle_segment_traits_2<Lazy_Kernel> Lazy_Traits;
|
||||
typedef CGAL::Arr_circle_segment_traits_2<Kernel> Traits;
|
||||
|
||||
typedef CGAL::Cartesian<CGAL::Gmpq> K_exact;
|
||||
typedef CGAL::Algebraic_kernel_for_circles_2_2<CGAL::Gmpq> AK_exact;
|
||||
typedef CGAL::Circular_kernel_2<K_exact,AK_exact> CK_exact;
|
||||
|
||||
typedef CGAL::Interval_nt_advanced ANT;
|
||||
typedef CGAL::Cartesian<ANT> ALK;
|
||||
typedef CGAL::Algebraic_kernel_for_circles_2_2<ANT> AAK;
|
||||
typedef CGAL::Circular_kernel_2 <ALK,AAK> ACK;
|
||||
typedef CGAL::Lazy_circular_kernel_2<CK_exact,ACK> CK;
|
||||
|
||||
typedef CGAL::Arr_circular_line_arc_traits_2<CK> Lazy_Traits_with_CK;
|
||||
typedef CGAL::Arr_circular_line_arc_traits_2<CK_exact> Traits_with_CK;
|
||||
|
||||
template <class CK>
|
||||
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<CK_exact>{
|
||||
const CK_exact::Root_of_2& operator()(const CK_exact::Root_of_2& t) const {
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class Traits,class Traits_with_CK>
|
||||
struct Benchmark
|
||||
{
|
||||
|
||||
typedef CGAL::Arrangement_2<Traits> Arrangement_2;
|
||||
typedef CGAL::Arrangement_2<Traits_with_CK> 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<Curve_2_with_CK> 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<typename Traits_with_CK::Kernel> 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 <class Output_iterator>
|
||||
void read_from_dxf(const char* fname,Arccontainer& ac, Output_iterator out)
|
||||
{
|
||||
std::ifstream fin(fname);
|
||||
CGAL::variant_load<typename Traits_with_CK::Kernel, C2, L2>(fin,std::back_inserter(ac));
|
||||
fin.close();
|
||||
|
||||
for (typename Arccontainer::iterator it= ac.begin();it!=ac.end();++it)
|
||||
{
|
||||
L2* seg=boost::get<L2>(&(*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<C2>(&(*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<typename Traits::Curve_2> 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<Lazy_Traits,Lazy_Traits_with_CK> bench_lazy;
|
||||
bench_lazy.run(argv[1]);
|
||||
std::cout << "Running with Exact\n";
|
||||
Benchmark<Traits,Traits_with_CK> bench;
|
||||
bench.run(argv[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue