mirror of https://github.com/CGAL/cgal
Modifications to code (faster insertion via spatial sorting) + new test for Euclidean DT_2
This commit is contained in:
parent
fef53805d5
commit
cab6689327
|
|
@ -149,12 +149,21 @@ namespace CGAL {
|
||||||
|
|
||||||
std::vector<Vertex_handle> insert_dummy_points(bool rational = true);
|
std::vector<Vertex_handle> insert_dummy_points(bool rational = true);
|
||||||
|
|
||||||
Vertex_handle insert(const Point &p,
|
Vertex_handle insert(const Point &p, Face_handle start = Face_handle() );
|
||||||
Face_handle start = Face_handle() );
|
|
||||||
|
|
||||||
template < class InputIterator >
|
template < class InputIterator >
|
||||||
std::ptrdiff_t insert(InputIterator first,
|
std::ptrdiff_t
|
||||||
InputIterator last);
|
insert(InputIterator first, InputIterator last) {
|
||||||
|
size_type n = this->number_of_vertices();
|
||||||
|
|
||||||
|
std::vector<Point> points(first, last);
|
||||||
|
spatial_sort(points.begin(), points.end(), geom_traits());
|
||||||
|
Face_handle f;
|
||||||
|
for (typename std::vector<Point>::const_iterator p = points.begin(), end = points.end(); p != end; ++p)
|
||||||
|
f = insert(*p, f)->face();
|
||||||
|
|
||||||
|
return this->number_of_vertices() - n;
|
||||||
|
}
|
||||||
|
|
||||||
Face_handle locate(const Point& p, Locate_type& lt, int& li, const Face_handle fh = Face_handle()) const {
|
Face_handle locate(const Point& p, Locate_type& lt, int& li, const Face_handle fh = Face_handle()) const {
|
||||||
Offset lo;
|
Offset lo;
|
||||||
|
|
@ -340,7 +349,7 @@ template < class Gt, class Tds >
|
||||||
inline
|
inline
|
||||||
typename Periodic_4_hyperbolic_Delaunay_triangulation_2<Gt, Tds>::Vertex_handle
|
typename Periodic_4_hyperbolic_Delaunay_triangulation_2<Gt, Tds>::Vertex_handle
|
||||||
Periodic_4_hyperbolic_Delaunay_triangulation_2<Gt, Tds>::
|
Periodic_4_hyperbolic_Delaunay_triangulation_2<Gt, Tds>::
|
||||||
insert(const Point &p, Face_handle start) {
|
insert(const Point &p, Face_handle hint) {
|
||||||
|
|
||||||
Vertex_handle v;
|
Vertex_handle v;
|
||||||
|
|
||||||
|
|
@ -351,14 +360,12 @@ insert(const Point &p, Face_handle start) {
|
||||||
|
|
||||||
if (side != CGAL::ON_UNBOUNDED_SIDE) {
|
if (side != CGAL::ON_UNBOUNDED_SIDE) {
|
||||||
Offset loff;
|
Offset loff;
|
||||||
if ( start == Face_handle() ) {
|
|
||||||
Locate_type lt;
|
Locate_type lt;
|
||||||
int li;
|
int li;
|
||||||
start = this->euclidean_locate(p, lt, li, loff);
|
Face_handle start = this->euclidean_locate(p, lt, li, loff, hint);
|
||||||
if (lt == Periodic_4_hyperbolic_Delaunay_triangulation_2<Gt, Tds>::VERTEX) {
|
if (lt == Periodic_4_hyperbolic_Delaunay_triangulation_2<Gt, Tds>::VERTEX) {
|
||||||
return Vertex_handle();
|
return Vertex_handle();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Face_handle> faces;
|
std::vector<Face_handle> faces;
|
||||||
this->find_conflicts(start, p, loff, std::back_inserter(faces));
|
this->find_conflicts(start, p, loff, std::back_inserter(faces));
|
||||||
|
|
@ -387,7 +394,6 @@ insert(const Point &p, Face_handle start) {
|
||||||
std::map<Vertex_handle, Vertex_handle> vmap;
|
std::map<Vertex_handle, Vertex_handle> vmap;
|
||||||
|
|
||||||
if (is_removable(dummy_points[i].vertex(), dt, vmap)) {
|
if (is_removable(dummy_points[i].vertex(), dt, vmap)) {
|
||||||
//cout << "Removing dummy point " << i << endl;
|
|
||||||
remove(dummy_points[i].vertex());
|
remove(dummy_points[i].vertex());
|
||||||
dummy_points[i].set_inserted(false);
|
dummy_points[i].set_inserted(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -885,13 +885,13 @@ template <class GT, class TDS>
|
||||||
typename TDS::Face_handle Periodic_4_hyperbolic_triangulation_2<GT, TDS>::
|
typename TDS::Face_handle Periodic_4_hyperbolic_triangulation_2<GT, TDS>::
|
||||||
euclidean_locate(const Point& p, Locate_type& lt, int& li, Offset& loff, Face_handle f) const {
|
euclidean_locate(const Point& p, Locate_type& lt, int& li, Offset& loff, Face_handle f) const {
|
||||||
|
|
||||||
typedef typename GT::Side_of_fundamental_octagon Side_of_fundamental_octagon;
|
// typedef typename GT::Side_of_fundamental_octagon Side_of_fundamental_octagon;
|
||||||
|
|
||||||
Side_of_fundamental_octagon check = Side_of_fundamental_octagon();
|
// Side_of_fundamental_octagon check = Side_of_fundamental_octagon();
|
||||||
CGAL::Bounded_side side = check(p);
|
// CGAL::Bounded_side side = check(p);
|
||||||
if (side != ON_BOUNDED_SIDE) {
|
// if (side != ON_BOUNDED_SIDE) {
|
||||||
return Face_handle();
|
// return Face_handle();
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Handle the case where an initial Face_handle is not given
|
// Handle the case where an initial Face_handle is not given
|
||||||
if (f == Face_handle()) {
|
if (f == Face_handle()) {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ if ( CGAL_FOUND )
|
||||||
create_single_source_cgal_program( "test_p4ht2_dummy_points.cpp" )
|
create_single_source_cgal_program( "test_p4ht2_dummy_points.cpp" )
|
||||||
create_single_source_cgal_program( "test_p4ht2_locate.cpp" )
|
create_single_source_cgal_program( "test_p4ht2_locate.cpp" )
|
||||||
create_single_source_cgal_program( "test_p4ht2_insertion.cpp" )
|
create_single_source_cgal_program( "test_p4ht2_insertion.cpp" )
|
||||||
|
create_single_source_cgal_program( "test_p4ht2_insertion_euclidean.cpp" )
|
||||||
create_single_source_cgal_program( "test_p4ht2_removal.cpp" )
|
create_single_source_cgal_program( "test_p4ht2_removal.cpp" )
|
||||||
create_single_source_cgal_program( "test_p4ht2_remove_dummy_points.cpp" )
|
create_single_source_cgal_program( "test_p4ht2_remove_dummy_points.cpp" )
|
||||||
create_single_source_cgal_program( "test_p4ht2_complex.cpp" )
|
create_single_source_cgal_program( "test_p4ht2_complex.cpp" )
|
||||||
|
|
|
||||||
|
|
@ -88,9 +88,10 @@ int main(int argc, char** argv) {
|
||||||
tr.insert_dummy_points(true);
|
tr.insert_dummy_points(true);
|
||||||
CGAL::Timer t1;
|
CGAL::Timer t1;
|
||||||
t1.start();
|
t1.start();
|
||||||
for (int j = 0; j < pts.size(); j++) {
|
tr.insert(pts.begin(), pts.end());
|
||||||
tr.insert(pts[j]);
|
//for (int j = 0; j < pts.size(); j++) {
|
||||||
}
|
// tr.insert(pts[j]);
|
||||||
|
//}
|
||||||
t1.stop();
|
t1.stop();
|
||||||
extime1 += t1.time();
|
extime1 += t1.time();
|
||||||
cout << "DONE! (# of vertices = " << tr.number_of_vertices() << ", time = " << t1.time() << " secs)" << endl;
|
cout << "DONE! (# of vertices = " << tr.number_of_vertices() << ", time = " << t1.time() << " secs)" << endl;
|
||||||
|
|
@ -109,9 +110,10 @@ int main(int argc, char** argv) {
|
||||||
Euclidean_triangulation etr;
|
Euclidean_triangulation etr;
|
||||||
CGAL::Timer t3;
|
CGAL::Timer t3;
|
||||||
t3.start();
|
t3.start();
|
||||||
for (int j = 0; j < pts.size(); j++) {
|
etr.insert(pts.begin(), pts.end());
|
||||||
etr.insert(pts[j]);
|
//for (int j = 0; j < pts.size(); j++) {
|
||||||
}
|
// etr.insert(pts[j]);
|
||||||
|
//}
|
||||||
t3.stop();
|
t3.stop();
|
||||||
extime3 += t3.time();
|
extime3 += t3.time();
|
||||||
cout << "DONE! (# of vertices = " << etr.number_of_vertices() << ", time = " << t3.time() << " secs)" << endl;
|
cout << "DONE! (# of vertices = " << etr.number_of_vertices() << ", time = " << t3.time() << " secs)" << endl;
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,10 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
CGAL::Timer tt;
|
CGAL::Timer tt;
|
||||||
tt.start();
|
tt.start();
|
||||||
for (int j = 0; j < pts.size(); j++) {
|
tr.insert(pts.begin(), pts.end());
|
||||||
tr.insert(pts[j]);
|
//for (int j = 0; j < pts.size(); j++) {
|
||||||
}
|
// tr.insert(pts[j]);
|
||||||
|
//}
|
||||||
tt.stop();
|
tt.stop();
|
||||||
cout << "DONE! (# of vertices = " << tr.number_of_vertices() << ", time = " << tt.time() << " secs)" << endl;
|
cout << "DONE! (# of vertices = " << tr.number_of_vertices() << ", time = " << tt.time() << " secs)" << endl;
|
||||||
extime += tt.time();
|
extime += tt.time();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
|
||||||
|
#include <CGAL/basic.h>
|
||||||
|
#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/Delaunay_triangulation_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/leda_real.h>
|
||||||
|
#include <CGAL/Cartesian.h>
|
||||||
|
#include <CGAL/determinant.h>
|
||||||
|
|
||||||
|
#include <CGAL/Timer.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//typedef CORE::Expr NT;
|
||||||
|
//typedef leda_real NT;
|
||||||
|
typedef double NT;
|
||||||
|
typedef CGAL::Cartesian<NT> Kernel;
|
||||||
|
//typedef CGAL::Periodic_4_hyperbolic_Delaunay_triangulation_traits_2<Kernel> Traits;
|
||||||
|
typedef CGAL::Delaunay_triangulation_2<Kernel> 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::Creator_uniform_2<double, Point> Creator;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "---- for best results, make sure that you have compiled me in Release mode ----" << endl;
|
||||||
|
|
||||||
|
double extime = 0.0;
|
||||||
|
|
||||||
|
for (int exec = 1; exec <= iters; exec++) {
|
||||||
|
std::vector<Point> pts;
|
||||||
|
pts.reserve(N);
|
||||||
|
CGAL::Random_points_in_disc_2<Point, Creator> g(1.0);
|
||||||
|
CGAL::cpp11::copy_n( g, N, std::back_inserter(pts));
|
||||||
|
|
||||||
|
cout << "iteration " << exec << ": inserting into triangulation (rational dummy points)... "; cout.flush();
|
||||||
|
Triangulation tr;
|
||||||
|
//tr.insert_dummy_points(true);
|
||||||
|
|
||||||
|
CGAL::Timer tt;
|
||||||
|
tt.start();
|
||||||
|
tr.insert(pts.begin(), pts.end());
|
||||||
|
//for (int j = 0; j < pts.size(); j++) {
|
||||||
|
// tr.insert(pts[j]);
|
||||||
|
//}
|
||||||
|
tt.stop();
|
||||||
|
cout << "DONE! (# of vertices = " << tr.number_of_vertices() << ", time = " << tt.time() << " secs)" << endl;
|
||||||
|
extime += tt.time();
|
||||||
|
}
|
||||||
|
|
||||||
|
double avgtime = extime / (double)iters;
|
||||||
|
cout << "---------------------------------------" << endl;
|
||||||
|
cout << "Average execution time over " << iters << " iterations: " << avgtime << " secs" << endl << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue