mirror of https://github.com/CGAL/cgal
edits to tests and demo; using hyperbolic random point generator
This commit is contained in:
parent
f7799fa3e6
commit
800a14fffd
|
|
@ -5,6 +5,7 @@
|
|||
#include <CGAL/Periodic_4_hyperbolic_Delaunay_triangulation_traits_2.h>
|
||||
#include <CGAL/point_generators_2.h>
|
||||
#include <CGAL/Hyperbolic_octagon_translation_matrix.h>
|
||||
#include <CGAL/Hyperbolic_random_points_in_disc_2.h>
|
||||
|
||||
#include <CGAL/Qt/HyperbolicPainterOstream.h>
|
||||
// for viewportsBbox
|
||||
|
|
@ -249,7 +250,6 @@ void
|
|||
MainWindow::on_actionClear_triggered()
|
||||
{
|
||||
dt.clear();
|
||||
dt.insert_dummy_points();
|
||||
emit(changed());
|
||||
}
|
||||
|
||||
|
|
@ -276,21 +276,27 @@ MainWindow::on_actionInsertRandomPoints_triggered()
|
|||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
|
||||
typedef CGAL::Creator_uniform_2<double, Point> Creator;
|
||||
CGAL::Random_points_in_disc_2<Point, Creator> g( 1.0 );
|
||||
Side_of_fundamental_octagon pred;
|
||||
// typedef CGAL::Creator_uniform_2<double, Point> Creator;
|
||||
// CGAL::Random_points_in_disc_2<Point, Creator> g( 1.0 );
|
||||
typedef CGAL::Cartesian<double>::Point_2 Point_d;
|
||||
vector<Point_d> v;
|
||||
Hyperbolic_random_points_in_disc_2_double(v, 5*number_of_points, -1, 0.159);
|
||||
|
||||
Traits::Side_of_fundamental_octagon pred;
|
||||
|
||||
vector<Point> pts;
|
||||
int cnt = 0;
|
||||
do {
|
||||
Point pt = *g;
|
||||
++g;
|
||||
if (pred(pt) != CGAL::ON_UNBOUNDED_SIDE) {
|
||||
pts.push_back(pt);
|
||||
//processInput(make_object(pt));
|
||||
for (int i = 0; cnt < number_of_points && i < v.size(); i++) {
|
||||
if (pred(v[i]) != CGAL::ON_UNBOUNDED_SIDE) {
|
||||
pts.push_back(Point(v[i].x(), v[i].y()));
|
||||
cnt++;
|
||||
}
|
||||
} while (cnt < number_of_points);
|
||||
}
|
||||
|
||||
if (pts.size() < number_of_points) {
|
||||
cout << "Creation of random points failed! Please try again..." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
CGAL::Timer tt;
|
||||
tt.start();
|
||||
|
|
|
|||
|
|
@ -196,6 +196,12 @@ namespace CGAL {
|
|||
return (cnt == 0);
|
||||
}
|
||||
|
||||
|
||||
void clear() {
|
||||
Base::clear();
|
||||
insert_dummy_points(true);
|
||||
}
|
||||
|
||||
}; // class Periodic_4_hyperbolic_Delaunay_triangulation_2
|
||||
|
||||
|
||||
|
|
@ -346,9 +352,9 @@ insert(const Point &p, Face_handle start) {
|
|||
if (side != CGAL::ON_UNBOUNDED_SIDE) {
|
||||
Offset loff;
|
||||
if ( start == Face_handle() ) {
|
||||
Locate_type lt = Periodic_4_hyperbolic_Delaunay_triangulation_2<Gt, Tds>::FACE;
|
||||
//start = this->hyperbolic_locate(p, loff, lt, li, lj, start); //this->euclidean_visibility_locate(p, loff);
|
||||
start = this->euclidean_locate(p, loff);
|
||||
Locate_type lt;
|
||||
int li;
|
||||
start = this->euclidean_locate(p, lt, li, loff);
|
||||
if (lt == Periodic_4_hyperbolic_Delaunay_triangulation_2<Gt, Tds>::VERTEX) {
|
||||
return Vertex_handle();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,7 +187,6 @@ public:
|
|||
typedef typename R::Segment_2 Euclidean_segment_2; //only used internally here
|
||||
typedef boost::variant<Circular_arc_2, Euclidean_segment_2> Hyperbolic_segment_2;
|
||||
|
||||
|
||||
// Wrappers for the offset adapter
|
||||
typedef Hyperbolic_traits_with_offsets_2_adaptor<Self, typename R::Compare_x_2> Compare_x_2;
|
||||
typedef Hyperbolic_traits_with_offsets_2_adaptor<Self, typename R::Compare_y_2> Compare_y_2;
|
||||
|
|
@ -508,11 +507,14 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Side_of_fundamental_octagon {
|
||||
public:
|
||||
Side_of_fundamental_octagon() {}
|
||||
|
||||
CGAL::Bounded_side operator()(Point_2 p) {
|
||||
template <class Point_2_template>
|
||||
CGAL::Bounded_side operator()(Point_2_template p) {
|
||||
|
||||
// Rotation by pi/4
|
||||
CGAL::Aff_transformation_2<R> rotate(CGAL::ROTATION, std::sqrt(0.5), std::sqrt(0.5));
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ namespace CGAL {
|
|||
f_cnt = fcount;
|
||||
v_cnt = vcount;
|
||||
|
||||
dummy_points.clear();
|
||||
|
||||
if (rational) {
|
||||
|
||||
// Push back the origin
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ if ( CGAL_FOUND )
|
|||
create_single_source_cgal_program( "test_p4ht2_matrix.cpp" )
|
||||
create_single_source_cgal_program( "test_p4ht2_words.cpp" )
|
||||
create_single_source_cgal_program( "test_p4ht2_triangulation.cpp" )
|
||||
create_single_source_cgal_program( "test_p4ht2_hyperbolic_vs_euclidean.cpp" )
|
||||
# create_single_source_cgal_program( "test_p4ht2_simple_insertion.cpp" )
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,129 @@
|
|||
|
||||
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/random/linear_congruential.hpp>
|
||||
#include <boost/random/uniform_smallint.hpp>
|
||||
#include <boost/random/variate_generator.hpp>
|
||||
#include <CGAL/point_generators_2.h>
|
||||
#include <CGAL/Hyperbolic_random_points_in_disc_2.h>
|
||||
#include <CGAL/Periodic_4_hyperbolic_Delaunay_triangulation_2.h>
|
||||
#include <CGAL/Periodic_4_hyperbolic_Delaunay_triangulation_traits_2.h>
|
||||
#include <CGAL/CORE_Expr.h>
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/determinant.h>
|
||||
|
||||
#include <CGAL/Delaunay_triangulation_2.h>
|
||||
#include <CGAL/Periodic_2_Delaunay_triangulation_traits_2.h>
|
||||
#include <CGAL/Periodic_2_Delaunay_triangulation_2.h>
|
||||
|
||||
#include <CGAL/Timer.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef CORE::Expr NT;
|
||||
typedef CGAL::Cartesian<NT> Kernel;
|
||||
typedef CGAL::Periodic_4_hyperbolic_Delaunay_triangulation_traits_2<Kernel> Traits;
|
||||
typedef CGAL::Periodic_4_hyperbolic_Delaunay_triangulation_2<Traits> Triangulation;
|
||||
typedef Hyperbolic_octagon_translation_matrix<NT> Octagon_matrix;
|
||||
typedef Kernel::Point_2 Point;
|
||||
typedef Triangulation::Vertex_handle Vertex_handle;
|
||||
typedef Traits::Side_of_fundamental_octagon Side_of_fundamental_octagon;
|
||||
|
||||
typedef CGAL::Cartesian<double>::Point_2 Point_double;
|
||||
typedef CGAL::Creator_uniform_2<double, Point_double > Creator;
|
||||
|
||||
typedef CGAL::Delaunay_triangulation_2<Kernel> Euclidean_triangulation;
|
||||
typedef CGAL::Periodic_2_Delaunay_triangulation_traits_2<Kernel> Ptraits;
|
||||
typedef CGAL::Periodic_2_Delaunay_triangulation_2<Ptraits> PEuclidean_triangulation;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
if (argc < 2) {
|
||||
cout << "usage: " << argv[0] << " [number_of_points_to_insert] [optional: number_of_iterations]" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int N = atoi(argv[1]);
|
||||
int iters = 1;
|
||||
if (argc == 3) {
|
||||
iters = atoi(argv[2]);
|
||||
}
|
||||
|
||||
Side_of_fundamental_octagon pred;
|
||||
|
||||
|
||||
cout << "---- for best results, make sure that you have compiled me in Release mode ----" << endl;
|
||||
|
||||
double extime1 = 0.0;
|
||||
double extime3 = 0.0;
|
||||
|
||||
for (int exec = 1; exec <= iters; exec++) {
|
||||
|
||||
vector<Point_double> v;
|
||||
std::vector<Point> pts;
|
||||
|
||||
// We can consider points only in the circle circumscribing the fundamental domain
|
||||
Hyperbolic_random_points_in_disc_2_double(v, 5*N, -1, 0.159);
|
||||
|
||||
int cnt = 0;
|
||||
int idx = 0;
|
||||
do {
|
||||
Point pt = Point(v[idx].x(), v[idx].y());
|
||||
if (pred(pt) != CGAL::ON_UNBOUNDED_SIDE) {
|
||||
pts.push_back(pt);
|
||||
cnt++;
|
||||
}
|
||||
idx++;
|
||||
} while (cnt < N && idx < v.size());
|
||||
|
||||
if (cnt < N) {
|
||||
cout << "I failed to generate all the random points! Exiting..." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cout << "iteration " << exec << ": inserting into hyperbolic periodic triangulation... "; cout.flush();
|
||||
Triangulation tr;
|
||||
tr.insert_dummy_points(true);
|
||||
CGAL::Timer t1;
|
||||
t1.start();
|
||||
for (int j = 0; j < pts.size(); j++) {
|
||||
tr.insert(pts[j]);
|
||||
}
|
||||
t1.stop();
|
||||
extime1 += t1.time();
|
||||
cout << "DONE! (# of vertices = " << tr.number_of_vertices() << ", time = " << t1.time() << " secs)" << endl;
|
||||
|
||||
// cout << "inserting into Euclidean periodic triangulation... "; cout.flush();
|
||||
// PEuclidean_triangulation petr;
|
||||
// CGAL::Timer t2;
|
||||
// t2.start();
|
||||
// for (int j = 0; j < pts.size(); j++) {
|
||||
// petr.insert(pts[j]);
|
||||
// }
|
||||
// t2.stop();
|
||||
// cout << "DONE!" << endl;
|
||||
|
||||
cout << "iteration " << exec << ": inserting into Euclidean non-periodic triangulation... "; cout.flush();
|
||||
Euclidean_triangulation etr;
|
||||
CGAL::Timer t3;
|
||||
t3.start();
|
||||
for (int j = 0; j < pts.size(); j++) {
|
||||
etr.insert(pts[j]);
|
||||
}
|
||||
t3.stop();
|
||||
extime3 += t3.time();
|
||||
cout << "DONE! (# of vertices = " << etr.number_of_vertices() << ", time = " << t3.time() << " secs)" << endl;
|
||||
|
||||
}
|
||||
|
||||
extime1 /= (double)iters;
|
||||
extime3 /= (double)iters;
|
||||
|
||||
cout << "Hyperbolic periodic triangulation: average time = " << extime1 << endl;
|
||||
//cout << "Euclidean periodic triangulation: #vertices = " << petr.number_of_vertices() << ", insertion time = " << t2.time() << endl;
|
||||
cout << "Euclidean non-periodic triangulation: average time = " << extime3 << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/random/linear_congruential.hpp>
|
||||
#include <boost/random/uniform_smallint.hpp>
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
#include <CGAL/Periodic_4_hyperbolic_Delaunay_triangulation_2.h>
|
||||
#include <CGAL/Periodic_4_hyperbolic_Delaunay_triangulation_traits_2.h>
|
||||
#include <CGAL/CORE_Expr.h>
|
||||
//#include <CGAL/leda_real.h>
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/determinant.h>
|
||||
|
||||
|
|
@ -17,6 +18,7 @@
|
|||
|
||||
|
||||
typedef CORE::Expr NT;
|
||||
//typedef leda_real NT;
|
||||
typedef CGAL::Cartesian<NT> Kernel;
|
||||
typedef CGAL::Periodic_4_hyperbolic_Delaunay_triangulation_traits_2<Kernel> Traits;
|
||||
typedef CGAL::Periodic_4_hyperbolic_Delaunay_triangulation_2<Traits> Triangulation;
|
||||
|
|
@ -29,17 +31,30 @@ typedef CGAL::Cartesian<double>::Point_2
|
|||
typedef CGAL::Creator_uniform_2<double, Point_double > Creator;
|
||||
|
||||
|
||||
int main(void) {
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
if (argc < 2) {
|
||||
cout << "usage: " << argv[0] << " [number_of_points_to_insert] [optional: number_of_iterations]" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int N = atoi(argv[1]);
|
||||
int iters = 1;
|
||||
if (argc == 3) {
|
||||
iters = atoi(argv[2]);
|
||||
}
|
||||
|
||||
Side_of_fundamental_octagon pred;
|
||||
|
||||
int N = 10000;
|
||||
|
||||
std::vector<Point> pts;
|
||||
cout << "---- for best results, make sure that you have compiled me in Release mode ----" << endl;
|
||||
cout << "generating " << N << " random points in the octagon..." << endl;
|
||||
|
||||
double extime = 0.0;
|
||||
|
||||
for (int exec = 1; exec <= iters; exec++) {
|
||||
vector<Point_double> v;
|
||||
Hyperbolic_random_points_in_disc_2_double(v, 40*N, -1);
|
||||
std::vector<Point> pts;
|
||||
// We can consider points only in the circle circumscribing the fundamental domain
|
||||
Hyperbolic_random_points_in_disc_2_double(v, 5*N, -1, 0.159);
|
||||
|
||||
int cnt = 0;
|
||||
int idx = 0;
|
||||
|
|
@ -53,40 +68,27 @@ int main(void) {
|
|||
} while (cnt < N && idx < v.size());
|
||||
|
||||
if (cnt < N) {
|
||||
cout << "FAILED! Exiting..." << endl;
|
||||
cout << "I failed at the generation of random points! Exiting..." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cout << "DONE!" << endl;
|
||||
cout << "iteration " << exec << ": inserting into triangulation (rational dummy points)... "; cout.flush();
|
||||
Triangulation tr;
|
||||
tr.insert_dummy_points(true);
|
||||
|
||||
cout << "inserting into triangulation with rational dummy points..." << endl;
|
||||
Triangulation tr2;
|
||||
tr2.insert_dummy_points(true);
|
||||
|
||||
CGAL::Timer t2;
|
||||
t2.start();
|
||||
CGAL::Timer tt;
|
||||
tt.start();
|
||||
for (int j = 0; j < pts.size(); j++) {
|
||||
//cout << " now at " << j << endl;
|
||||
Vertex_handle vh = tr2.insert(pts[j]);
|
||||
tr.insert(pts[j]);
|
||||
}
|
||||
t2.stop();
|
||||
cout << " DONE!" << endl;
|
||||
|
||||
cout << "inserting into triangulation with exact dummy points..." << endl;
|
||||
Triangulation tr1;
|
||||
tr1.insert_dummy_points(false);
|
||||
|
||||
CGAL::Timer t1;
|
||||
t1.start();
|
||||
for (int j = 0; j < pts.size(); j++) {
|
||||
cout << " now at " << j << endl;
|
||||
Vertex_handle vh = tr1.insert(pts[j]);
|
||||
tt.stop();
|
||||
cout << "DONE! (# of vertices = " << tr.number_of_vertices() << ", time = " << tt.time() << " secs)" << endl;
|
||||
extime += tt.time();
|
||||
}
|
||||
t1.stop();
|
||||
cout << " DONE!" << endl;
|
||||
|
||||
cout << "Triangulation with exact dummy points: #vertices = " << tr1.number_of_vertices() << ", insertion time = " << t1.time() << endl;
|
||||
cout << "Triangulation with rational dummy points: #vertices = " << tr2.number_of_vertices() << ", insertion time = " << t2.time() << endl;
|
||||
double avgtime = extime / (double)iters;
|
||||
cout << "---------------------------------------" << endl;
|
||||
cout << "Average execution time over " << iters << " iterations: " << avgtime << " secs" << endl << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <boost/random/uniform_smallint.hpp>
|
||||
#include <boost/random/variate_generator.hpp>
|
||||
#include <CGAL/point_generators_2.h>
|
||||
#include <CGAL/Hyperbolic_random_points_in_disc_2.h>
|
||||
|
||||
#include <CGAL/Periodic_4_hyperbolic_Delaunay_triangulation_2.h>
|
||||
#include <CGAL/Periodic_4_hyperbolic_Delaunay_triangulation_traits_2.h>
|
||||
|
|
@ -21,7 +22,9 @@ typedef Triangulation::Face_iterator
|
|||
typedef Triangulation::Vertex_handle Vertex_handle;
|
||||
typedef Triangulation::Point Point;
|
||||
typedef Traits::Side_of_fundamental_octagon Side_of_fundamental_octagon;
|
||||
typedef CGAL::Creator_uniform_2<NT, Point > Creator;
|
||||
|
||||
typedef CGAL::Cartesian<double>::Point_2 Point_double;
|
||||
typedef CGAL::Creator_uniform_2<double, Point_double > Creator;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
|
|
@ -31,7 +34,6 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
|
||||
int iter = atoi(argv[1]);
|
||||
CGAL::Random_points_in_disc_2<Point, Creator> g( 1.0 );
|
||||
Side_of_fundamental_octagon pred;
|
||||
|
||||
int min = 1000;
|
||||
|
|
@ -40,16 +42,19 @@ int main(int argc, char** argv) {
|
|||
for (int j = 0; j < iter; j++) {
|
||||
cout << "Iteration " << (j+1) << "/" << iter << "..." << endl;
|
||||
|
||||
vector<Point_double> v;
|
||||
Hyperbolic_random_points_in_disc_2_double(v, 500, -1, 0.159);
|
||||
|
||||
Triangulation tr;
|
||||
tr.insert_dummy_points();
|
||||
tr.insert_dummy_points(true);
|
||||
assert(tr.is_valid(true));
|
||||
|
||||
int cnt = 0;
|
||||
int idx = 0;
|
||||
do {
|
||||
Point pt = *g;
|
||||
++g;
|
||||
Point_double pt = v[idx++];
|
||||
if (pred(pt) != CGAL::ON_UNBOUNDED_SIDE) {
|
||||
tr.insert(pt);
|
||||
tr.insert(Point(pt.x(), pt.y()));
|
||||
cnt++;
|
||||
}
|
||||
} while (tr.number_of_dummy_points() > 0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue