From b3514854debcf45bedd4d81f8c57f9076593d2b8 Mon Sep 17 00:00:00 2001 From: Remy Thomasse Date: Thu, 7 Aug 2014 15:38:49 +0200 Subject: [PATCH] compatibility old version of boost --- .../Generator/random_convex_hull_2.cpp | 2 +- .../CGAL/random_convex_hull_in_disc_2.h | 62 +++++++++++-------- Generator/test/Generator/random_hull_test.cpp | 14 ++++- GraphicsView/demo/Generator/Generator_2.cpp | 2 +- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/Generator/examples/Generator/random_convex_hull_2.cpp b/Generator/examples/Generator/random_convex_hull_2.cpp index 693a7cf407f..f066a1521dd 100644 --- a/Generator/examples/Generator/random_convex_hull_2.cpp +++ b/Generator/examples/Generator/random_convex_hull_2.cpp @@ -15,7 +15,7 @@ int main( ) { int N=10000; std::vector v; - boost::random::mt19937 gen; + boost::mt19937 gen; gen.seed(time(0)); random_convex_hull_in_disc_2(N,RADIUS,gen,std::back_inserter(v),K()); diff --git a/Generator/include/CGAL/random_convex_hull_in_disc_2.h b/Generator/include/CGAL/random_convex_hull_in_disc_2.h index cdea40c8057..ee1819d3e57 100644 --- a/Generator/include/CGAL/random_convex_hull_in_disc_2.h +++ b/Generator/include/CGAL/random_convex_hull_in_disc_2.h @@ -25,7 +25,6 @@ #ifndef CGAL_RANDOM_CONVEX_HULL_DISC_H #define CGAL_RANDOM_CONVEX_HULL_DISC_H #include - //#include #include @@ -36,8 +35,6 @@ struct compare_points_angle { bool operator()(const P& p, const P& q) { P zero(0,0); Traits traits; - //typedef typename Traits::Left_turn_2 Left_turn; - //Left_turn left_turn = traits.left_turn_2_object(); typedef typename Traits::Orientation_2 Orientation_2; Orientation_2 orientation_2=traits.orientation_2_object(); typedef typename Traits::Compare_y_2 Compare_y_2; @@ -45,7 +42,7 @@ struct compare_points_angle { if (compare_y_2(p, zero) == LARGER ){ if (compare_y_2(q, zero)==LARGER) - return (orientation_2(zero,p,q)==LEFT_TURN);//left_turn(zero, p, q); + return (orientation_2(zero,p,q)==LEFT_TURN); else return false; @@ -53,7 +50,7 @@ struct compare_points_angle { if (compare_y_2(q,zero)==LARGER) return true; else - return (orientation_2(zero,p,q)==LEFT_TURN);//left_turn(zero, p, q); + return (orientation_2(zero,p,q)==LEFT_TURN); } } }; @@ -64,8 +61,8 @@ void generate_points_annulus(long n, double a, double b, double small_radius, double big_radius, std::list

& l, GEN& gen) { // generate n points between a and b if (n > 1) { - boost::random::binomial_distribution bin_distribution(n, .5); - boost::random::variate_generator > + boost::binomial_distribution bin_distribution(n, .5); + boost::variate_generator > g(gen, bin_distribution); long nb = g(); generate_points_annulus(nb, a, (a + b) / 2.0, small_radius, big_radius, l, @@ -75,6 +72,19 @@ void generate_points_annulus(long n, double a, double b, double small_radius, } if (n == 1) // generation of a point { + + #if BOOST_VERSION < 104700 + + boost::uniform_real random_squared_radius_distribution( + small_radius * small_radius / (big_radius * big_radius), 1); + boost::uniform_real random_angle_distribution(a, b); + boost::variate_generator< + GEN&, boost::uniform_real > random_angle(gen, random_angle_distribution); + boost::variate_generator< + GEN&, boost::uniform_real > random_squared_radius(gen, random_squared_radius_distribution); + + #else + boost::random::uniform_real_distribution random_squared_radius_distribution( small_radius * small_radius / (big_radius * big_radius), 1); @@ -83,9 +93,12 @@ void generate_points_annulus(long n, double a, double b, double small_radius, GEN&, boost::random::uniform_real_distribution > random_angle(gen, random_angle_distribution); boost::random::variate_generator< GEN&, boost::random::uniform_real_distribution > random_squared_radius(gen, random_squared_radius_distribution); + + #endif + double alpha = random_angle(); double r = big_radius * std::sqrt(random_squared_radius()); - typedef Creator_uniform_2 Creator; + typedef Creator_uniform_2 Creator; Creator creator; typedef typename Creator::argument_type T; l.push_back(creator(T(r * cos(alpha)), T(r * std::sin(alpha)))); @@ -107,29 +120,29 @@ void Graham_without_sort_2(std::list

& l, const Traits& traits) { //typedef typename Traits::Left_turn_2 Left_turn; //Left_turn left_turn = traits.left_turn_2_object(); typedef typename Traits::Orientation_2 Orientation_2; + typedef typename std::list

::iterator Iterator; Orientation_2 orientation_2=traits.orientation_2_object(); typedef typename Traits::Compare_x_2 Compare_x_2; Compare_x_2 compare_x_2=traits.compare_x_2_object(); - typename std::list

::iterator pmin = l.begin(); - for (typename std::list

::iterator it = l.begin(); it != l.end(); ++it) { + Iterator pmin = l.begin(); + for (Iterator it = l.begin(); it != l.end(); ++it) { //if ((*pmin).x() > (*it).x()) { if (compare_x_2(*pmin, *it) == LARGER){ pmin = it; } } //*pmin is the extremal point on the left - typename std::list

::iterator u = pmin; - typename std::list

::iterator u_next = u; + Iterator u = pmin; + Iterator u_next = u; Cyclic_increment(u_next, l); - typename std::list

::iterator u_next_next = u_next; + Iterator u_next_next = u_next; Cyclic_increment(u_next_next, l); while (u_next != pmin) { - //if (left_turn(*u, *u_next, *u_next_next)) { if (orientation_2(*u,*u_next,*u_next_next)==LEFT_TURN){ Cyclic_increment(u, l); Cyclic_increment(u_next, l); @@ -159,7 +172,6 @@ void random_convex_hull_in_disc_2(std::size_t n, double radius, std::list= 3); - // typedef typename Kernel_traits

::Kernel K; typedef typename Traits::Point_2 P; typedef typename Traits::FT FT; std::size_t simulated_points = 0; @@ -184,7 +196,7 @@ void random_convex_hull_in_disc_2(std::size_t n, double radius, std::list(std::floor(n / std::pow(std::log(n), 2))); @@ -195,14 +207,12 @@ void random_convex_hull_in_disc_2(std::size_t n, double radius, std::list::iterator it = l.begin(); while (compare_y_2(*it,zero) == LARGER){ - //while (to_double((*it).y()) > 0) { l.push_back(*it); l.pop_front(); it = l.begin(); } it = l.end(); --it; // last element - // while (to_double((*it).y()) < 0) { while (compare_y_2(*it,zero) == SMALLER){ l.push_front(*it); l.pop_back(); @@ -219,23 +229,21 @@ void random_convex_hull_in_disc_2(std::size_t n, double radius, std::list temp) squared_small_radius = temp; } } // squared_small_radius=squared small radius of the annulus FT p_disc = squared_small_radius / squared_radius; - std::size_t nb; + long nb; if (simulated_points < T) { - nb = std::min(simulated_points, n - simulated_points); + nb = static_cast(std::min(simulated_points, n - simulated_points)); } else { - nb = std::min(T, n - simulated_points); + nb = static_cast(std::min(T, n - simulated_points)); } - boost::random::binomial_distribution dbin(nb, to_double(p_disc)); - boost::random::variate_generator< - GEN&, boost::random::binomial_distribution > bin(gen, dbin); + boost::binomial_distribution dbin(nb, to_double(p_disc)); + boost::variate_generator< + GEN&, boost::binomial_distribution > bin(gen, dbin); // How many points are falling in the small disc and wont be generated: long k_disc = bin(); @@ -268,4 +276,4 @@ void random_convex_hull_in_disc_2(std::size_t n, double radius, Generator& gen, } } // namespace CGAL -#endif \ No newline at end of file +#endif diff --git a/Generator/test/Generator/random_hull_test.cpp b/Generator/test/Generator/random_hull_test.cpp index 0645d336bb4..37dde93d73d 100644 --- a/Generator/test/Generator/random_hull_test.cpp +++ b/Generator/test/Generator/random_hull_test.cpp @@ -14,18 +14,26 @@ main( ) { - Polygon_2 p; + Polygon_2 p,q; int n( 1000); - boost::random::mt19937 gen; + boost::mt19937 gen(0); // build random hull from n random points in a disc: - random_convex_hull_in_disc_2(n,1.0,gen,std::back_inserter(p),K()); + random_convex_hull_in_disc_2(n,1.0,gen,std::back_inserter(p),K(), true); // check convexity: if ( ! p.is_convex()) { std::cerr << "ERROR: polygon is not convex." << std::endl; return 1; } + + // build random hull from n random points in a disc: + random_convex_hull_in_disc_2(n,1.0,gen,std::back_inserter(q),K(), false); + // check convexity: + if ( ! q.is_convex()) { + std::cerr << "ERROR: polygon is not convex." << std::endl; + return 1; + } return 0; } // int main( ) diff --git a/GraphicsView/demo/Generator/Generator_2.cpp b/GraphicsView/demo/Generator/Generator_2.cpp index 413e3229e9a..a004fc721f2 100644 --- a/GraphicsView/demo/Generator/Generator_2.cpp +++ b/GraphicsView/demo/Generator/Generator_2.cpp @@ -269,7 +269,7 @@ void MainWindow::on_actionGeneratePolytopeInDisc_triggered() { typedef CGAL::Points_on_segment_2 PG; - boost::random::mt19937 gen; + boost::mt19937 gen; gen.seed(time(0)); std::vector points; QRectF rect = CGAL::Qt::viewportsBbox(&scene);