mirror of https://github.com/CGAL/cgal
compatibility old version of boost
This commit is contained in:
parent
30c93188c5
commit
b3514854de
|
|
@ -15,7 +15,7 @@ int main( )
|
||||||
{
|
{
|
||||||
int N=10000;
|
int N=10000;
|
||||||
std::vector<Point> v;
|
std::vector<Point> v;
|
||||||
boost::random::mt19937 gen;
|
boost::mt19937 gen;
|
||||||
gen.seed(time(0));
|
gen.seed(time(0));
|
||||||
|
|
||||||
random_convex_hull_in_disc_2(N,RADIUS,gen,std::back_inserter(v),K());
|
random_convex_hull_in_disc_2(N,RADIUS,gen,std::back_inserter(v),K());
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@
|
||||||
#ifndef CGAL_RANDOM_CONVEX_HULL_DISC_H
|
#ifndef CGAL_RANDOM_CONVEX_HULL_DISC_H
|
||||||
#define CGAL_RANDOM_CONVEX_HULL_DISC_H
|
#define CGAL_RANDOM_CONVEX_HULL_DISC_H
|
||||||
#include <boost/random.hpp>
|
#include <boost/random.hpp>
|
||||||
|
|
||||||
//#include <cmath>
|
//#include <cmath>
|
||||||
#include <CGAL/Polygon_2_algorithms.h>
|
#include <CGAL/Polygon_2_algorithms.h>
|
||||||
|
|
||||||
|
|
@ -36,8 +35,6 @@ struct compare_points_angle {
|
||||||
bool operator()(const P& p, const P& q) {
|
bool operator()(const P& p, const P& q) {
|
||||||
P zero(0,0);
|
P zero(0,0);
|
||||||
Traits traits;
|
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 Traits::Orientation_2 Orientation_2;
|
||||||
Orientation_2 orientation_2=traits.orientation_2_object();
|
Orientation_2 orientation_2=traits.orientation_2_object();
|
||||||
typedef typename Traits::Compare_y_2 Compare_y_2;
|
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(p, zero) == LARGER ){
|
||||||
if (compare_y_2(q, 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
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -53,7 +50,7 @@ struct compare_points_angle {
|
||||||
if (compare_y_2(q,zero)==LARGER)
|
if (compare_y_2(q,zero)==LARGER)
|
||||||
return true;
|
return true;
|
||||||
else
|
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<P>& l,
|
double big_radius, std::list<P>& l,
|
||||||
GEN& gen) { // generate n points between a and b
|
GEN& gen) { // generate n points between a and b
|
||||||
if (n > 1) {
|
if (n > 1) {
|
||||||
boost::random::binomial_distribution<long> bin_distribution(n, .5);
|
boost::binomial_distribution<long> bin_distribution(n, .5);
|
||||||
boost::random::variate_generator<GEN&, boost::binomial_distribution<long> >
|
boost::variate_generator<GEN&, boost::binomial_distribution<long> >
|
||||||
g(gen, bin_distribution);
|
g(gen, bin_distribution);
|
||||||
long nb = g();
|
long nb = g();
|
||||||
generate_points_annulus(nb, a, (a + b) / 2.0, small_radius, big_radius, l,
|
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 (n == 1) // generation of a point
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if BOOST_VERSION < 104700
|
||||||
|
|
||||||
|
boost::uniform_real<double> random_squared_radius_distribution(
|
||||||
|
small_radius * small_radius / (big_radius * big_radius), 1);
|
||||||
|
boost::uniform_real<double> random_angle_distribution(a, b);
|
||||||
|
boost::variate_generator<
|
||||||
|
GEN&, boost::uniform_real<double> > random_angle(gen, random_angle_distribution);
|
||||||
|
boost::variate_generator<
|
||||||
|
GEN&, boost::uniform_real<double> > random_squared_radius(gen, random_squared_radius_distribution);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
boost::random::uniform_real_distribution<double> random_squared_radius_distribution(
|
boost::random::uniform_real_distribution<double> random_squared_radius_distribution(
|
||||||
small_radius * small_radius / (big_radius * big_radius), 1);
|
small_radius * small_radius / (big_radius * big_radius), 1);
|
||||||
|
|
||||||
|
|
@ -83,6 +93,9 @@ void generate_points_annulus(long n, double a, double b, double small_radius,
|
||||||
GEN&, boost::random::uniform_real_distribution<double> > random_angle(gen, random_angle_distribution);
|
GEN&, boost::random::uniform_real_distribution<double> > random_angle(gen, random_angle_distribution);
|
||||||
boost::random::variate_generator<
|
boost::random::variate_generator<
|
||||||
GEN&, boost::random::uniform_real_distribution<double> > random_squared_radius(gen, random_squared_radius_distribution);
|
GEN&, boost::random::uniform_real_distribution<double> > random_squared_radius(gen, random_squared_radius_distribution);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
double alpha = random_angle();
|
double alpha = random_angle();
|
||||||
double r = big_radius * std::sqrt(random_squared_radius());
|
double r = big_radius * std::sqrt(random_squared_radius());
|
||||||
typedef Creator_uniform_2<double, P> Creator;
|
typedef Creator_uniform_2<double, P> Creator;
|
||||||
|
|
@ -107,29 +120,29 @@ void Graham_without_sort_2(std::list<P>& l, const Traits& traits) {
|
||||||
//typedef typename Traits::Left_turn_2 Left_turn;
|
//typedef typename Traits::Left_turn_2 Left_turn;
|
||||||
//Left_turn left_turn = traits.left_turn_2_object();
|
//Left_turn left_turn = traits.left_turn_2_object();
|
||||||
typedef typename Traits::Orientation_2 Orientation_2;
|
typedef typename Traits::Orientation_2 Orientation_2;
|
||||||
|
typedef typename std::list<P>::iterator Iterator;
|
||||||
Orientation_2 orientation_2=traits.orientation_2_object();
|
Orientation_2 orientation_2=traits.orientation_2_object();
|
||||||
|
|
||||||
typedef typename Traits::Compare_x_2 Compare_x_2;
|
typedef typename Traits::Compare_x_2 Compare_x_2;
|
||||||
Compare_x_2 compare_x_2=traits.compare_x_2_object();
|
Compare_x_2 compare_x_2=traits.compare_x_2_object();
|
||||||
|
|
||||||
typename std::list<P>::iterator pmin = l.begin();
|
Iterator pmin = l.begin();
|
||||||
for (typename std::list<P>::iterator it = l.begin(); it != l.end(); ++it) {
|
for (Iterator it = l.begin(); it != l.end(); ++it) {
|
||||||
//if ((*pmin).x() > (*it).x()) {
|
//if ((*pmin).x() > (*it).x()) {
|
||||||
|
|
||||||
if (compare_x_2(*pmin, *it) == LARGER){
|
if (compare_x_2(*pmin, *it) == LARGER){
|
||||||
pmin = it;
|
pmin = it;
|
||||||
}
|
}
|
||||||
} //*pmin is the extremal point on the left
|
} //*pmin is the extremal point on the left
|
||||||
typename std::list<P>::iterator u = pmin;
|
Iterator u = pmin;
|
||||||
typename std::list<P>::iterator u_next = u;
|
Iterator u_next = u;
|
||||||
Cyclic_increment(u_next, l);
|
Cyclic_increment(u_next, l);
|
||||||
|
|
||||||
typename std::list<P>::iterator u_next_next = u_next;
|
Iterator u_next_next = u_next;
|
||||||
Cyclic_increment(u_next_next, l);
|
Cyclic_increment(u_next_next, l);
|
||||||
|
|
||||||
while (u_next != pmin) {
|
while (u_next != pmin) {
|
||||||
|
|
||||||
//if (left_turn(*u, *u_next, *u_next_next)) {
|
|
||||||
if (orientation_2(*u,*u_next,*u_next_next)==LEFT_TURN){
|
if (orientation_2(*u,*u_next,*u_next_next)==LEFT_TURN){
|
||||||
Cyclic_increment(u, l);
|
Cyclic_increment(u, l);
|
||||||
Cyclic_increment(u_next, 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<typena
|
||||||
GEN& gen, const Traits& traits,
|
GEN& gen, const Traits& traits,
|
||||||
bool fast = true) {
|
bool fast = true) {
|
||||||
CGAL_precondition(n >= 3);
|
CGAL_precondition(n >= 3);
|
||||||
// typedef typename Kernel_traits<P>::Kernel K;
|
|
||||||
typedef typename Traits::Point_2 P;
|
typedef typename Traits::Point_2 P;
|
||||||
typedef typename Traits::FT FT;
|
typedef typename Traits::FT FT;
|
||||||
std::size_t simulated_points = 0;
|
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<typena
|
||||||
Graham_without_sort_2(l, traits);
|
Graham_without_sort_2(l, traits);
|
||||||
} while ((bounded_side_2(l.begin(), l.end(), zero, traits) !=
|
} while ((bounded_side_2(l.begin(), l.end(), zero, traits) !=
|
||||||
ON_BOUNDED_SIDE) &&
|
ON_BOUNDED_SIDE) &&
|
||||||
(simulated_points < n)); // initialisation such that 0 in P_n
|
(simulated_points < n)); // initialization such that 0 in P_n
|
||||||
|
|
||||||
std::size_t T = n;
|
std::size_t T = n;
|
||||||
if (!fast) T = static_cast<std::size_t>(std::floor(n / std::pow(std::log(n), 2)));
|
if (!fast) T = static_cast<std::size_t>(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<typena
|
||||||
{
|
{
|
||||||
typename std::list<P>::iterator it = l.begin();
|
typename std::list<P>::iterator it = l.begin();
|
||||||
while (compare_y_2(*it,zero) == LARGER){
|
while (compare_y_2(*it,zero) == LARGER){
|
||||||
//while (to_double((*it).y()) > 0) {
|
|
||||||
l.push_back(*it);
|
l.push_back(*it);
|
||||||
l.pop_front();
|
l.pop_front();
|
||||||
it = l.begin();
|
it = l.begin();
|
||||||
}
|
}
|
||||||
it = l.end();
|
it = l.end();
|
||||||
--it; // last element
|
--it; // last element
|
||||||
// while (to_double((*it).y()) < 0) {
|
|
||||||
while (compare_y_2(*it,zero) == SMALLER){
|
while (compare_y_2(*it,zero) == SMALLER){
|
||||||
l.push_front(*it);
|
l.push_front(*it);
|
||||||
l.pop_back();
|
l.pop_back();
|
||||||
|
|
@ -219,23 +229,21 @@ void random_convex_hull_in_disc_2(std::size_t n, double radius, std::list<typena
|
||||||
for (; it != l.end();
|
for (; it != l.end();
|
||||||
++it, Cyclic_increment(it2, l)) { // computation of annulus
|
++it, Cyclic_increment(it2, l)) { // computation of annulus
|
||||||
typename Traits::Segment_2 s(*it, *it2);
|
typename Traits::Segment_2 s(*it, *it2);
|
||||||
//double temp = to_double(squared_distance(s, zero));
|
|
||||||
FT temp=squared_distance(s,zero);
|
FT temp=squared_distance(s,zero);
|
||||||
if ( compare(squared_small_radius,temp) == LARGER ) squared_small_radius=temp;
|
if ( compare(squared_small_radius,temp) == LARGER ) squared_small_radius=temp;
|
||||||
//if (squared_small_radius > temp) squared_small_radius = temp;
|
|
||||||
}
|
}
|
||||||
} // squared_small_radius=squared small radius of the annulus
|
} // squared_small_radius=squared small radius of the annulus
|
||||||
|
|
||||||
FT p_disc = squared_small_radius / squared_radius;
|
FT p_disc = squared_small_radius / squared_radius;
|
||||||
std::size_t nb;
|
long nb;
|
||||||
if (simulated_points < T) {
|
if (simulated_points < T) {
|
||||||
nb = std::min(simulated_points, n - simulated_points);
|
nb = static_cast<long>(std::min(simulated_points, n - simulated_points));
|
||||||
} else {
|
} else {
|
||||||
nb = std::min(T, n - simulated_points);
|
nb = static_cast<long>(std::min(T, n - simulated_points));
|
||||||
}
|
}
|
||||||
boost::random::binomial_distribution<long> dbin(nb, to_double(p_disc));
|
boost::binomial_distribution<long> dbin(nb, to_double(p_disc));
|
||||||
boost::random::variate_generator<
|
boost::variate_generator<
|
||||||
GEN&, boost::random::binomial_distribution<long> > bin(gen, dbin);
|
GEN&, boost::binomial_distribution<long> > bin(gen, dbin);
|
||||||
|
|
||||||
// How many points are falling in the small disc and wont be generated:
|
// How many points are falling in the small disc and wont be generated:
|
||||||
long k_disc = bin();
|
long k_disc = bin();
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,26 @@ main( )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
Polygon_2 p;
|
Polygon_2 p,q;
|
||||||
int n( 1000);
|
int n( 1000);
|
||||||
boost::random::mt19937 gen;
|
boost::mt19937 gen(0);
|
||||||
|
|
||||||
// build random hull from n random points in a disc:
|
// 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:
|
// check convexity:
|
||||||
if ( ! p.is_convex()) {
|
if ( ! p.is_convex()) {
|
||||||
std::cerr << "ERROR: polygon is not convex." << std::endl;
|
std::cerr << "ERROR: polygon is not convex." << std::endl;
|
||||||
return 1;
|
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;
|
return 0;
|
||||||
} // int main( )
|
} // int main( )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,7 @@ void
|
||||||
MainWindow::on_actionGeneratePolytopeInDisc_triggered()
|
MainWindow::on_actionGeneratePolytopeInDisc_triggered()
|
||||||
{
|
{
|
||||||
typedef CGAL::Points_on_segment_2<Point_2> PG;
|
typedef CGAL::Points_on_segment_2<Point_2> PG;
|
||||||
boost::random::mt19937 gen;
|
boost::mt19937 gen;
|
||||||
gen.seed(time(0));
|
gen.seed(time(0));
|
||||||
std::vector<Point_2> points;
|
std::vector<Point_2> points;
|
||||||
QRectF rect = CGAL::Qt::viewportsBbox(&scene);
|
QRectF rect = CGAL::Qt::viewportsBbox(&scene);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue