From 885741d4668bdc07dcacf43c8c2d5575804f485d Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 25 Mar 2014 11:51:23 +0100 Subject: [PATCH] Use Marc's new Kernel_d --- .../benchmark/Triangulation/delaunay.cpp | 30 ++++---- .../include/CGAL/Delaunay_triangulation.h | 60 ++++++++++------ Triangulation/include/CGAL/Triangulation.h | 72 +++++++++++++------ Triangulation/test/Triangulation/delaunay.cpp | 21 +++--- Triangulation/test/Triangulation/torture.cpp | 26 ++----- .../test/Triangulation/triangulation.cpp | 21 +++--- 6 files changed, 130 insertions(+), 100 deletions(-) diff --git a/Triangulation/benchmark/Triangulation/delaunay.cpp b/Triangulation/benchmark/Triangulation/delaunay.cpp index 55d1f3b3742..553d0a831b9 100644 --- a/Triangulation/benchmark/Triangulation/delaunay.cpp +++ b/Triangulation/benchmark/Triangulation/delaunay.cpp @@ -1,6 +1,4 @@ -#include -//#include -//#include +#include #include #include #include @@ -38,35 +36,33 @@ void test(const int d, const std::string & type, const int N) std::cout << " Delaunay triangulation of "< +template< int D > void go(const int N) { - //typedef CGAL::Simple_cartesian_d K; - typedef CGAL::Cartesian_d K; - //typedef CGAL::Filtered_kernel_d FK; + typedef CGAL::Epick_d > K; typedef CGAL::Delaunay_triangulation Triangulation; test(D, "static", N); } int main(int argc, char **argv) { - srand48(time(NULL)); + srand(static_cast(time(NULL))); int N = 100; if( argc > 1 ) N = atoi(argv[1]); - go<2, double>(N); - go<3, double>(N); - go<4, double>(N); - go<5, double>(N); - go<6, double>(N); - go<7, double>(N); - go<8, double>(N); + go<2>(N); + go<3>(N); + go<4>(N); + go<5>(N); + go<6>(N); + go<7>(N); + go<8>(N); return 0; diff --git a/Triangulation/include/CGAL/Delaunay_triangulation.h b/Triangulation/include/CGAL/Delaunay_triangulation.h index 7228ebfd9e2..e792a083f61 100644 --- a/Triangulation/include/CGAL/Delaunay_triangulation.h +++ b/Triangulation/include/CGAL/Delaunay_triangulation.h @@ -30,13 +30,12 @@ template< typename DCTraits, typename _TDS = Default > class Delaunay_triangulation : public Triangulation::type, + typename DCTraits::Dimension, Triangulation_vertex, Triangulation_full_cell > >::type > { - typedef typename Ambient_dimension::type - Maximal_dimension_; + typedef typename DCTraits::Dimension Maximal_dimension_; typedef typename Default::Get<_TDS, Triangulation_data_structure< Maximal_dimension_, Triangulation_vertex, @@ -45,14 +44,36 @@ class Delaunay_triangulation typedef Triangulation Base; typedef Delaunay_triangulation Self; - typedef typename DCTraits::Side_of_oriented_subsphere_d - Side_of_oriented_subsphere_d; typedef typename DCTraits::Side_of_oriented_sphere_d Side_of_oriented_sphere_d; - typedef typename DCTraits::Coaffine_orientation_d - Coaffine_orientation_d; typedef typename DCTraits::Orientation_d Orientation_d; + //*** Side_of_oriented_subsphere_d *** + using Base::Flat_orientation_d; + using Base::Construct_flat_orientation_d; + typedef typename DCTraits::In_flat_side_of_oriented_sphere_d In_flat_side_of_oriented_sphere_d; + // Wrapper + struct Side_of_oriented_subsphere_d + { + boost::optional* fop; + Construct_flat_orientation_d cfo; + In_flat_side_of_oriented_sphere_d ifsoos; + + Side_of_oriented_subsphere_d( + boost::optional& x, + Construct_flat_orientation_d const&y, + In_flat_side_of_oriented_sphere_d const&z) + : fop(&x), cfo(y), ifsoos(z) {} + + template + CGAL::Orientation operator()(Iter a, Iter b, const Point & p)const + { + if(!*fop) + *fop=cfo(a,b); + return ifsoos(fop->get(),a,b,p); + } + }; + public: // PUBLIC NESTED TYPES typedef DCTraits Geom_traits; @@ -84,13 +105,13 @@ public: // PUBLIC NESTED TYPES protected: // DATA MEMBERS - Side_of_oriented_subsphere_d side_of_oss_; public: using Base::maximal_dimension; using Base::are_incident_full_cells_valid; using Base::coaffine_orientation_predicate; + using Base::reset_flat_orientation; using Base::current_dimension; //using Base::star; //using Base::incident_full_cells; @@ -145,7 +166,7 @@ public: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CREATION Delaunay_triangulation(const int dim, const Geom_traits k = Geom_traits()) - : Base(dim, k), side_of_oss_() + : Base(dim, k) { } @@ -154,16 +175,15 @@ public: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ACCESS // Not Documented - Side_of_oriented_subsphere_d & side_of_oriented_subsphere_predicate() + Side_of_oriented_subsphere_d side_of_oriented_subsphere_predicate() const { - return side_of_oss_; + return Side_of_oriented_subsphere_d ( + flat_orientation_, + geom_traits().construct_flat_orientation_d_object(), + geom_traits().in_flat_side_of_oriented_sphere_d_object() + ); } - // Not Documented - const Side_of_oriented_subsphere_d & side_of_oriented_subsphere_predicate() const - { - return side_of_oss_; - } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - REMOVALS @@ -307,6 +327,8 @@ public: private: // Some internal types to shorten notation + using Base::Coaffine_orientation_d; + using Base::flat_orientation_; typedef Conflict_predicate Conflict_pred_in_subspace; typedef Conflict_predicate @@ -653,8 +675,7 @@ Delaunay_triangulation CGAL_precondition( current_dimension() >= 0 ); tds().remove_decrease_dimension(v, infinite_vertex()); // reset the predicates: - coaffine_orientation_predicate() = geom_traits().coaffine_orientation_d_object(); - side_of_oriented_subsphere_predicate() = geom_traits().side_of_oriented_subsphere_d_object(); + reset_flat_orientation(); if( 1 <= current_dimension() ) { // FIXME: infinite vertex is NOT at index 0 a priori. @@ -712,8 +733,7 @@ Delaunay_triangulation CGAL_precondition( current_dimension() < maximal_dimension() ); Vertex_handle v = tds().insert_increase_dimension(infinite_vertex()); // reset the predicates: - coaffine_orientation_predicate() = geom_traits().coaffine_orientation_d_object(); - side_of_oriented_subsphere_predicate() = geom_traits().side_of_oriented_subsphere_d_object(); + reset_flat_orientation(); v->set_point(p); if( current_dimension() >= 1 ) { diff --git a/Triangulation/include/CGAL/Triangulation.h b/Triangulation/include/CGAL/Triangulation.h index 22518f7f377..b9858cee6cd 100644 --- a/Triangulation/include/CGAL/Triangulation.h +++ b/Triangulation/include/CGAL/Triangulation.h @@ -37,17 +37,50 @@ namespace CGAL { template < class TriangulationTraits, class TDS_ = Default > class Triangulation { - typedef typename Ambient_dimension::type - Maximal_dimension_; + typedef typename TriangulationTraits::Dimension Maximal_dimension_; typedef typename Default::Get, Triangulation_full_cell > >::type TDS; typedef Triangulation Self; + +protected: + typedef typename TriangulationTraits::Flat_orientation_d Flat_orientation_d; + typedef typename TriangulationTraits::Construct_flat_orientation_d Construct_flat_orientation_d; + typedef typename TriangulationTraits::In_flat_orientation_d In_flat_orientation_d; + + // Wrapper + struct Coaffine_orientation_d + { + boost::optional* fop; + Construct_flat_orientation_d cfo; + In_flat_orientation_d ifo; + + Coaffine_orientation_d( + boost::optional& x, + Construct_flat_orientation_d const&y, + In_flat_orientation_d const&z) + : fop(&x), cfo(y), ifo(z) {} + + template + CGAL::Orientation operator()(Iter a, Iter b) const + { + // CJTODO: temporary code + if (!*fop) + *fop = cfo(a,b); + return ifo(fop->get(),a,b); + // CJTODO: replace with this code: + /*if (*fop) + return ifo(fop->get(),a,b); + *fop = cfo(a,b); + CGAL_assertion(ifo(fop->get(),a,b) == CGAL::POSITIVE); + return CGAL::POSITIVE;*/ + } + }; + + void reset_flat_orientation(){flat_orientation_=boost::none;} - typedef typename TriangulationTraits::Coaffine_orientation_d - Coaffine_orientation_d; typedef typename TriangulationTraits::Orientation_d Orientation_d; @@ -111,7 +144,7 @@ protected: // DATA MEMBERS const Geom_traits kernel_; Vertex_handle infinity_; mutable std::vector orientations_; - Coaffine_orientation_d coaffine_orientation_; + mutable boost::optional flat_orientation_; // for stochastic walk in the locate() function: mutable Random rng_; #ifdef CGAL_TRIANGULATION_STATISTICS @@ -185,7 +218,7 @@ public: // A full_cell has at most 1 + maximal_dimension() facets: orientations_.resize(1 + maximal_dimension()); // Our coaffine orientation predicates HAS state member variables - coaffine_orientation_predicate() = geom_traits().coaffine_orientation_d_object(); + reset_flat_orientation(); } ~Triangulation() {} @@ -215,14 +248,13 @@ public: tds().set_visited(s, b); } */ - Coaffine_orientation_d & coaffine_orientation_predicate() + Coaffine_orientation_d coaffine_orientation_predicate() const { - return coaffine_orientation_; - } - - const Coaffine_orientation_d & coaffine_orientation_predicate() const - { - return coaffine_orientation_; + return Coaffine_orientation_d ( + flat_orientation_, + geom_traits().construct_flat_orientation_d_object(), + geom_traits().in_flat_orientation_d_object() + ); } const Triangulation_ds & tds() const @@ -482,7 +514,7 @@ public: // A full_cell has at most 1 + maximal_dimension() facets: orientations_.resize(1 + maximal_dimension()); // Our coaffine orientation predicates HAS state member variables - coaffine_orientation_predicate() = geom_traits().coaffine_orientation_d_object(); + reset_flat_orientation(); #ifdef CGAL_TRIANGULATION_STATISTICS walk_size_ = 0; #endif @@ -519,7 +551,7 @@ protected: template< typename OrientationPredicate > Full_cell_handle do_locate( const Point &, Locate_type &, Face &, Facet &, Full_cell_handle start = Full_cell_handle(), - OrientationPredicate & o = geom_traits().orientation_d_object()) const; + const OrientationPredicate & o = geom_traits().orientation_d_object()) const; public: Full_cell_handle locate( const Point &, Locate_type &, Face &, Facet &, Full_cell_handle start = Full_cell_handle()) const; @@ -579,11 +611,11 @@ public: { Triangulation & t_; const Point & p_; - OrientationPredicate & ori_; + OrientationPredicate const& ori_; int cur_dim_; public: Outside_convex_hull_traversal_predicate(Triangulation & t, const Point & p, - OrientationPredicate & ori) + OrientationPredicate const& ori) : t_(t), p_(p), ori_(ori), cur_dim_(t.current_dimension()) {} // FUTURE change parameter to const reference bool operator()(Facet f) const @@ -798,7 +830,7 @@ Triangulation CGAL_precondition( current_dimension() < maximal_dimension() ); Vertex_handle v = tds().insert_increase_dimension(infinite_vertex()); // reset the orientation predicate: - coaffine_orientation_predicate() = geom_traits().coaffine_orientation_d_object(); + reset_flat_orientation(); v->set_point(p); if( current_dimension() >= 1 ) { @@ -824,7 +856,7 @@ Triangulation Face & face,// the face containing the query in its interior (when appropriate) Facet & facet,// the facet containing the query in its interior (when appropriate) const Full_cell_handle start// starting full_cell for the walk - , OrientationPredicate & orientation_pred + , OrientationPredicate const& orientation_pred ) const { const int cur_dim = current_dimension(); @@ -919,7 +951,7 @@ Triangulation points_begin(s) + cur_dim + 1); // restore the correct point for vertex |i| of the full_cell - s->vertex(i)->set_point(backup); /**/ + s->vertex(i)->set_point(backup); */ if( orientations_[i] != NEGATIVE ) { diff --git a/Triangulation/test/Triangulation/delaunay.cpp b/Triangulation/test/Triangulation/delaunay.cpp index 7cf6c542e0e..337eadcbba0 100644 --- a/Triangulation/test/Triangulation/delaunay.cpp +++ b/Triangulation/test/Triangulation/delaunay.cpp @@ -1,7 +1,5 @@ +#include #include -//#include -#include -#include #include #include #include @@ -43,11 +41,11 @@ void test(const int d, const string & type, const int N) Random_points_iterator rand_it(d, 2.0, rng); //CGAL::copy_n(rand_it, N, back_inserter(points)); - vector coords(d); + vector coords(d); for( int i = 0; i < N; ++i ) { for( int j = 0; j < d; ++j ) - coords[j] = lrand48() % 100000; + coords[j] = rand() % 100000; points.push_back(Point(d, coords.begin(), coords.end())); } pc.insert(points.begin(), points.end()); @@ -112,19 +110,20 @@ void test(const int d, const string & type, const int N) template< int D > void go(const int N) { - typedef double RT; + //typedef double RT; //typedef CGAL::Gmpq RT; - typedef CGAL::Cartesian_d K; + //typedef CGAL::Cartesian_d K; //typedef CGAL::Simple_cartesian_d K; - typedef CGAL::Filtered_kernel_d FK; + //typedef CGAL::Filtered_kernel_d FK; + typedef CGAL::Epick_d > FK; typedef CGAL::Delaunay_triangulation Triangulation; - test(D, "dynamic", N); - //test(D, "static", N); + //test(D, "dynamic", N); + test(D, "static", N); } int main(int argc, char **argv) { - srand48(time(NULL)); + srand(static_cast(time(NULL))); int N = 100; if( argc > 1 ) N = atoi(argv[1]); diff --git a/Triangulation/test/Triangulation/torture.cpp b/Triangulation/test/Triangulation/torture.cpp index dc5b88baedc..ad3e41888e5 100644 --- a/Triangulation/test/Triangulation/torture.cpp +++ b/Triangulation/test/Triangulation/torture.cpp @@ -1,12 +1,6 @@ +#include #include #include -//#define USE_NEW_KERNEL -#ifndef USE_NEW_KERNEL -#include // this is for Old_kernel_d -#else -#include // this is for New_kernel_d -#endif -#include #include #include #include @@ -50,7 +44,7 @@ void test(const int D, const int d, const int N, bool no_transform) CGAL::internal::Combination_enumerator combi(k, 0, D-1); if( no_transform ) { // choose a random set of axes: - int nb = lrand48() % 1000; + int nb = rand() % 1000; for( int i = 0; i < nb; ++i ) { ++combi; @@ -70,7 +64,7 @@ void test(const int D, const int d, const int N, bool no_transform) { int c(0); while( 0 == c ) - c = (lrand48() % 11) - 5; + c = (rand() % 11) - 5; aff[j].push_back(c); } } @@ -116,16 +110,8 @@ void test(const int D, const int d, const int N, bool no_transform) template< int D > void go(const int N, const int nb_trials) { - typedef double RT; - //typedef CGAL::Quotient RT; - //typedef CGAL::Gmpq RT; -#ifndef USE_NEW_KERNEL - typedef CGAL::Cartesian_d K; // this is for Old_kernel_d -#else - typedef CGAL::Simple_cartesian_d K; // this is for New_kernel_d -#endif - typedef CGAL::Filtered_kernel_d FK; - typedef CGAL::Delaunay_triangulation Triangulation; + typedef CGAL::Epick_d > K; + typedef CGAL::Delaunay_triangulation Triangulation; for( int d = 0; d <= D; ++d ) { cout << "\n\n** Delaunay of " << d @@ -150,7 +136,7 @@ int main(int argc, char **argv) if( argc > 3 ) rand_init = atoi(argv[3]); std::cout<(N, nb_trials); go<2>(N, nb_trials); go<3>(N, nb_trials); diff --git a/Triangulation/test/Triangulation/triangulation.cpp b/Triangulation/test/Triangulation/triangulation.cpp index 1ed8be1fed3..73b6e774fed 100644 --- a/Triangulation/test/Triangulation/triangulation.cpp +++ b/Triangulation/test/Triangulation/triangulation.cpp @@ -1,6 +1,5 @@ +#include #include -#include -#include #include #include #include @@ -34,10 +33,10 @@ void test(const int d, const string & type, int N) assert(tri.empty()); vector coords(d); - vector points; + vector points; CGAL::Random rng; - Random_points_iterator rand_it(d, 1.0, rng); - CGAL::copy_n(rand_it, N, std::back_inserter(points)); + Random_points_iterator rand_it(d, 1.0, rng); + CGAL::copy_n(rand_it, N, std::back_inserter(points)); cerr << '\n' << points.size() << " points in the grid."; @@ -107,17 +106,15 @@ void test(const int d, const string & type, int N) template< int D > void go(int N) { - typedef double RT; - typedef CGAL::Cartesian_d K; - typedef CGAL::Filtered_kernel_d FK; - typedef CGAL::Triangulation Triangulation; - //test(D, "static", N); - test(D, "dynamic", N); + typedef CGAL::Epick_d > K; + typedef CGAL::Triangulation Triangulation; + test(D, "static", N); + //test(D, "dynamic", N); } int main(int argc, char **argv) { - srand48(time(NULL)); + srand(static_cast(time(NULL))); int N = 1000; if( argc > 1 ) N = atoi(argv[1]);