mirror of https://github.com/CGAL/cgal
Change rng; Remove random_shuffle
This commit is contained in:
parent
7a6f7f3e21
commit
be700acaba
|
|
@ -187,7 +187,6 @@ public:
|
||||||
int n = number_of_vertices();
|
int n = number_of_vertices();
|
||||||
|
|
||||||
std::vector<Point> points (first, last);
|
std::vector<Point> points (first, last);
|
||||||
std::random_shuffle (points.begin(), points.end());
|
|
||||||
spatial_sort (points.begin(), points.end(), geom_traits());
|
spatial_sort (points.begin(), points.end(), geom_traits());
|
||||||
Face_handle f;
|
Face_handle f;
|
||||||
for (typename std::vector<Point>::const_iterator p = points.begin(), end = points.end();
|
for (typename std::vector<Point>::const_iterator p = points.begin(), end = points.end();
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,6 @@ public:
|
||||||
int n = number_of_vertices();
|
int n = number_of_vertices();
|
||||||
|
|
||||||
std::vector<Point> points (first, last);
|
std::vector<Point> points (first, last);
|
||||||
std::random_shuffle (points.begin(), points.end());
|
|
||||||
CGAL::spatial_sort (points.begin(), points.end(), geom_traits());
|
CGAL::spatial_sort (points.begin(), points.end(), geom_traits());
|
||||||
|
|
||||||
Face_handle hint;
|
Face_handle hint;
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,6 @@ public:
|
||||||
|
|
||||||
std::vector<Point> points (first, last);
|
std::vector<Point> points (first, last);
|
||||||
|
|
||||||
std::random_shuffle (points.begin(), points.end());
|
|
||||||
spatial_sort (points.begin(), points.end(), geom_traits());
|
spatial_sort (points.begin(), points.end(), geom_traits());
|
||||||
|
|
||||||
Face_handle hint;
|
Face_handle hint;
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,6 @@ public:
|
||||||
int n = this->number_of_vertices();
|
int n = this->number_of_vertices();
|
||||||
|
|
||||||
std::vector<Point> points (first, last);
|
std::vector<Point> points (first, last);
|
||||||
std::random_shuffle (points.begin(), points.end());
|
|
||||||
spatial_sort (points.begin(), points.end(), geom_traits());
|
spatial_sort (points.begin(), points.end(), geom_traits());
|
||||||
Face_handle f;
|
Face_handle f;
|
||||||
for (typename std::vector<Point>::const_iterator p = points.begin(), end = points.end();
|
for (typename std::vector<Point>::const_iterator p = points.begin(), end = points.end();
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,6 @@ public:
|
||||||
int n = number_of_vertices();
|
int n = number_of_vertices();
|
||||||
|
|
||||||
std::vector<Weighted_point> points (first, last);
|
std::vector<Weighted_point> points (first, last);
|
||||||
std::random_shuffle (points.begin(), points.end());
|
|
||||||
spatial_sort (points.begin(), points.end(), geom_traits());
|
spatial_sort (points.begin(), points.end(), geom_traits());
|
||||||
|
|
||||||
Face_handle hint;
|
Face_handle hint;
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,12 @@
|
||||||
#include <CGAL/Triangulation_vertex_base_2.h>
|
#include <CGAL/Triangulation_vertex_base_2.h>
|
||||||
#include <CGAL/Triangulation_face_base_2.h>
|
#include <CGAL/Triangulation_face_base_2.h>
|
||||||
#include <CGAL/Triangulation_line_face_circulator_2.h>
|
#include <CGAL/Triangulation_line_face_circulator_2.h>
|
||||||
#include <CGAL/Random.h>
|
|
||||||
|
|
||||||
#include <CGAL/spatial_sort.h>
|
#include <CGAL/spatial_sort.h>
|
||||||
|
|
||||||
|
#include <boost/random/linear_congruential.hpp>
|
||||||
|
#include <boost/random/uniform_smallint.hpp>
|
||||||
|
#include <boost/random/variate_generator.hpp>
|
||||||
|
|
||||||
CGAL_BEGIN_NAMESPACE
|
CGAL_BEGIN_NAMESPACE
|
||||||
template < class Gt, class Tds > class Triangulation_2;
|
template < class Gt, class Tds > class Triangulation_2;
|
||||||
template < class Gt, class Tds > std::istream& operator>>
|
template < class Gt, class Tds > std::istream& operator>>
|
||||||
|
|
@ -179,7 +181,6 @@ protected:
|
||||||
Gt _gt;
|
Gt _gt;
|
||||||
Tds _tds;
|
Tds _tds;
|
||||||
Vertex_handle _infinite_vertex;
|
Vertex_handle _infinite_vertex;
|
||||||
mutable Random rng;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// CONSTRUCTORS
|
// CONSTRUCTORS
|
||||||
|
|
@ -1813,6 +1814,11 @@ march_locate_2D(Face_handle c,
|
||||||
{
|
{
|
||||||
CGAL_triangulation_assertion(! is_infinite(c));
|
CGAL_triangulation_assertion(! is_infinite(c));
|
||||||
|
|
||||||
|
boost::rand48 rng;
|
||||||
|
|
||||||
|
boost::uniform_smallint<> two(0, 1);
|
||||||
|
boost::variate_generator<boost::rand48&, boost::uniform_smallint<> > coin(rng, two);
|
||||||
|
|
||||||
Face_handle prev = Face_handle();
|
Face_handle prev = Face_handle();
|
||||||
bool first = true;
|
bool first = true;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
@ -1832,7 +1838,7 @@ march_locate_2D(Face_handle c,
|
||||||
// We do loop unrolling in order to find out if this is faster.
|
// We do loop unrolling in order to find out if this is faster.
|
||||||
// In the very beginning we do not have a prev, but for the first step
|
// In the very beginning we do not have a prev, but for the first step
|
||||||
// we do not need randomness
|
// we do not need randomness
|
||||||
int left_first = rng.template get_bits<1>();
|
int left_first = coin()%1;
|
||||||
|
|
||||||
const Point & p0 = c->vertex( 0 )->point();
|
const Point & p0 = c->vertex( 0 )->point();
|
||||||
const Point & p1 = c->vertex( 1 )->point();
|
const Point & p1 = c->vertex( 1 )->point();
|
||||||
|
|
@ -1986,6 +1992,9 @@ march_locate_2D(Face_handle c,
|
||||||
{
|
{
|
||||||
CGAL_triangulation_assertion(! is_infinite(c));
|
CGAL_triangulation_assertion(! is_infinite(c));
|
||||||
|
|
||||||
|
boost::uniform_smallint<> four(0, 3);
|
||||||
|
boost::variate_generator<boost::rand48&, boost::uniform_smallint<> > die4(rng, four);
|
||||||
|
|
||||||
Face_handle prev = Face_handle();
|
Face_handle prev = Face_handle();
|
||||||
while (1) {
|
while (1) {
|
||||||
if ( is_infinite(c) ) {
|
if ( is_infinite(c) ) {
|
||||||
|
|
@ -1999,7 +2008,7 @@ march_locate_2D(Face_handle c,
|
||||||
// we test its edges in a random order until we find a
|
// we test its edges in a random order until we find a
|
||||||
// neighbor to go further
|
// neighbor to go further
|
||||||
|
|
||||||
int i = rng.template get_bits<2>();
|
int i = die4();
|
||||||
int ccwi = ccw(i);
|
int ccwi = ccw(i);
|
||||||
int cwi = cw(i);
|
int cwi = cw(i);
|
||||||
const Point & p0 = c->vertex( i )->point();
|
const Point & p0 = c->vertex( i )->point();
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,13 @@
|
||||||
#define CGAL_TRIANGULATION_HIERARCHY_2_H
|
#define CGAL_TRIANGULATION_HIERARCHY_2_H
|
||||||
|
|
||||||
#include <CGAL/basic.h>
|
#include <CGAL/basic.h>
|
||||||
#include <CGAL/Random.h>
|
|
||||||
#include <CGAL/Triangulation_hierarchy_vertex_base_2.h>
|
#include <CGAL/Triangulation_hierarchy_vertex_base_2.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include <boost/random/linear_congruential.hpp>
|
||||||
|
#include <boost/random/geometric_distribution.hpp>
|
||||||
|
#include <boost/random/variate_generator.hpp>
|
||||||
|
|
||||||
CGAL_BEGIN_NAMESPACE
|
CGAL_BEGIN_NAMESPACE
|
||||||
|
|
||||||
// parameterization of the hierarchy
|
// parameterization of the hierarchy
|
||||||
|
|
@ -60,7 +63,7 @@ class Triangulation_hierarchy_2
|
||||||
private:
|
private:
|
||||||
// here is the stack of triangulations which form the hierarchy
|
// here is the stack of triangulations which form the hierarchy
|
||||||
Tr_Base* hierarchy[Triangulation_hierarchy_2__maxlevel];
|
Tr_Base* hierarchy[Triangulation_hierarchy_2__maxlevel];
|
||||||
Random random; // random generator
|
boost::rand48 random;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Triangulation_hierarchy_2(const Geom_traits& traits = Geom_traits());
|
Triangulation_hierarchy_2(const Geom_traits& traits = Geom_traits());
|
||||||
|
|
@ -69,7 +72,7 @@ public:
|
||||||
template<class InputIterator>
|
template<class InputIterator>
|
||||||
Triangulation_hierarchy_2(InputIterator first, InputIterator beyond,
|
Triangulation_hierarchy_2(InputIterator first, InputIterator beyond,
|
||||||
const Geom_traits& traits = Geom_traits())
|
const Geom_traits& traits = Geom_traits())
|
||||||
: Tr_Base(traits), random((long)0)
|
: Tr_Base(traits)
|
||||||
{
|
{
|
||||||
hierarchy[0] = this;
|
hierarchy[0] = this;
|
||||||
for(int i=1;i<Triangulation_hierarchy_2__maxlevel;++i)
|
for(int i=1;i<Triangulation_hierarchy_2__maxlevel;++i)
|
||||||
|
|
@ -102,7 +105,6 @@ public:
|
||||||
int n = this->number_of_vertices();
|
int n = this->number_of_vertices();
|
||||||
|
|
||||||
std::vector<Point> points (first, last);
|
std::vector<Point> points (first, last);
|
||||||
std::random_shuffle (points.begin(), points.end());
|
|
||||||
CGAL::spatial_sort (points.begin(), points.end(), geom_traits());
|
CGAL::spatial_sort (points.begin(), points.end(), geom_traits());
|
||||||
|
|
||||||
// hints[i] is the face of the previously inserted point in level i.
|
// hints[i] is the face of the previously inserted point in level i.
|
||||||
|
|
@ -205,7 +207,7 @@ private:
|
||||||
template <class Tr >
|
template <class Tr >
|
||||||
Triangulation_hierarchy_2<Tr>::
|
Triangulation_hierarchy_2<Tr>::
|
||||||
Triangulation_hierarchy_2(const Geom_traits& traits)
|
Triangulation_hierarchy_2(const Geom_traits& traits)
|
||||||
: Tr_Base(traits), random((long)0)
|
: Tr_Base(traits)
|
||||||
{
|
{
|
||||||
hierarchy[0] = this;
|
hierarchy[0] = this;
|
||||||
for(int i=1;i<Triangulation_hierarchy_2__maxlevel;++i)
|
for(int i=1;i<Triangulation_hierarchy_2__maxlevel;++i)
|
||||||
|
|
@ -217,7 +219,7 @@ Triangulation_hierarchy_2(const Geom_traits& traits)
|
||||||
template <class Tr>
|
template <class Tr>
|
||||||
Triangulation_hierarchy_2<Tr>::
|
Triangulation_hierarchy_2<Tr>::
|
||||||
Triangulation_hierarchy_2(const Triangulation_hierarchy_2<Tr> &tr)
|
Triangulation_hierarchy_2(const Triangulation_hierarchy_2<Tr> &tr)
|
||||||
: Tr_Base(), random((long)0)
|
: Tr_Base()
|
||||||
{
|
{
|
||||||
// create an empty triangulation to be able to delete it !
|
// create an empty triangulation to be able to delete it !
|
||||||
hierarchy[0] = this;
|
hierarchy[0] = this;
|
||||||
|
|
@ -564,16 +566,14 @@ int
|
||||||
Triangulation_hierarchy_2<Tr>::
|
Triangulation_hierarchy_2<Tr>::
|
||||||
random_level()
|
random_level()
|
||||||
{
|
{
|
||||||
int l = 0;
|
boost::geometric_distribution<> proba(1.0/Triangulation_hierarchy_2__ratio);
|
||||||
while (1) {
|
boost::variate_generator<boost::rand48&, boost::geometric_distribution<> > die(random, proba);
|
||||||
if ( random(Triangulation_hierarchy_2__ratio) ) break;
|
|
||||||
++l;
|
return (std::min)(die(), Triangulation_hierarchy_2__maxlevel)-1;
|
||||||
}
|
|
||||||
if (l >= Triangulation_hierarchy_2__maxlevel)
|
|
||||||
l = Triangulation_hierarchy_2__maxlevel -1;
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_END_NAMESPACE
|
CGAL_END_NAMESPACE
|
||||||
|
|
||||||
#endif // CGAL_TRIANGULATION_HIERARCHY_2_H
|
#endif // CGAL_TRIANGULATION_HIERARCHY_2_H
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue