diff --git a/Triangulation/include/CGAL/Regular_triangulation.h b/Triangulation/include/CGAL/Regular_triangulation.h index 82c49704516..1f339c38d0a 100644 --- a/Triangulation/include/CGAL/Regular_triangulation.h +++ b/Triangulation/include/CGAL/Regular_triangulation.h @@ -265,6 +265,32 @@ public: Vertex_handle insert_outside_affine_hull(const Weighted_point &); Vertex_handle insert_in_conflicting_cell(const Weighted_point &, const Full_cell_handle); + + Vertex_handle insert_if_in_star(const Weighted_point &, + const Vertex_handle, + const Locate_type, + const Face &, + const Facet &, + const Full_cell_handle); + + Vertex_handle insert_if_in_star( + const Weighted_point & p, const Vertex_handle star_center, + const Full_cell_handle start = Full_cell_handle()) + { + Locate_type lt; + Face f(maximal_dimension()); + Facet ft; + Full_cell_handle s = locate(p, lt, f, ft, start); + return insert_if_in_star(p, star_center, lt, f, ft, s); + } + + Vertex_handle insert_if_in_star( + const Weighted_point & p, const Vertex_handle star_center, + const Vertex_handle hint) + { + CGAL_assertion( Vertex_handle() != hint ); + return insert_if_in_star(p, hint->full_cell()); + } // - - - - - - - - - - - - - - - - - - - - - - - - - GATHERING CONFLICTING SIMPLICES @@ -780,6 +806,48 @@ Regular_triangulation return insert_in_hole(p, cs.begin(), cs.end(), ft); } +template< typename RTTraits, typename TDS > +typename Regular_triangulation::Vertex_handle +Regular_triangulation +::insert_if_in_star(const Weighted_point & p, + const Vertex_handle star_center, + const Locate_type lt, const Face & f, const Facet & ft, + const Full_cell_handle s) +{ + switch( lt ) + { + case Base::OUTSIDE_AFFINE_HULL: + return insert_outside_affine_hull(p); + break; + case Base::ON_VERTEX: + { + Vertex_handle v = s->vertex(f.index(0)); + v->set_point(p); + return v; + break; + } + default: + if (s->has_vertex(star_center)) + { + if( 1 == current_dimension() ) + { + if( Base::OUTSIDE_CONVEX_HULL == lt ) + { + return insert_outside_convex_hull_1(p, s); + } + Vertex_handle v = tds().insert_in_full_cell(s); + v->set_point(p); + return v; + } + else + return insert_in_conflicting_cell(p, s); + } + break; + } + + return Vertex_handle(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GATHERING CONFLICTING SIMPLICES // NOT DOCUMENTED diff --git a/Triangulation/test/Triangulation/CMakeLists.txt b/Triangulation/test/Triangulation/CMakeLists.txt index 4b3674feed2..ff378f0b4b1 100644 --- a/Triangulation/test/Triangulation/CMakeLists.txt +++ b/Triangulation/test/Triangulation/CMakeLists.txt @@ -1,7 +1,6 @@ # Created by the script cgal_create_cmake_script # This is the CMake script for compiling a CGAL application. - project( Triangulation_test ) cmake_minimum_required(VERSION 2.6.2) @@ -27,19 +26,18 @@ if ( CGAL_FOUND ) include_directories (BEFORE "../../include") include_directories (BEFORE "include") + create_single_source_cgal_program( "test_triangulation.cpp" ) create_single_source_cgal_program( "test_delaunay.cpp" ) create_single_source_cgal_program( "test_regular.cpp" ) create_single_source_cgal_program( "test_tds.cpp" ) + create_single_source_cgal_program( "test_insert_if_in_star.cpp" ) create_single_source_cgal_program( "test_torture.cpp" ) - create_single_source_cgal_program( "test_triangulation.cpp" ) else() message(STATUS "NOTICE: Some of the executables in this directory need Eigen 3.1 (or greater) and will not be compiled.") endif() else() - message(STATUS "This program requires the CGAL library, and will not be compiled.") - endif() diff --git a/Triangulation/test/Triangulation/test_insert_if_in_star.cpp b/Triangulation/test/Triangulation/test_insert_if_in_star.cpp new file mode 100644 index 00000000000..7c392e72633 --- /dev/null +++ b/Triangulation/test/Triangulation/test_insert_if_in_star.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; + +template +void test(const int d, const string & type, const int N) +{ + typedef typename RTri::Vertex_handle Vertex_handle; + typedef typename RTri::Point Point; + typedef typename RTri::Bare_point Bare_point; + + typedef CGAL::Random_points_in_cube_d Random_points_iterator; + + RTri rt(d); + RTri rt_star_only(d); + cerr << "\nBuilding Regular triangulation of (" << type << d + << ") dimension with " << N << " points\n"; + assert(rt.empty()); + assert(rt_star_only.empty()); + + srand(10); + + // Insert first point (0, 0...) + vector coords(d); + for( int j = 0; j < d; ++j ) + coords[j] = 0; + + Point p = Point( + Bare_point(d, coords.begin(), coords.end()), + static_cast(rand() % 10000)/100000); + + rt.insert(p); + Vertex_handle first_vertex = rt_star_only.insert(p); + + // Insert the other points + for( int i = 1 ; i < N ; ++i ) + { + for( int j = 0; j < d; ++j ) + coords[j] = 10.*(rand() % RAND_MAX)/RAND_MAX - 5.; + + p = Point( + Bare_point(d, coords.begin(), coords.end()), + static_cast(rand() % 10000)/100000); + + rt.insert(p); + rt_star_only.insert_if_in_star(p, first_vertex); + } + + cerr << "\nChecking topology and geometry..." + << (rt.is_valid(true) ? "OK.\n" : "Error.\n"); + + cerr << "\nThe triangulation has current dimension " << rt.current_dimension() + << " and " << rt.number_of_full_cells() << " full cells\n"; + + // Export + std::ofstream off_stream_all("data/test_insert_all.off"); + CGAL::export_triangulation_to_off(off_stream_all, rt); + std::ofstream off_stream_star_only("data/test_insert_if_in_star.off"); + CGAL::export_triangulation_to_off(off_stream_star_only, rt_star_only); +} + +template< int D > +void go(const int N) +{ + //typedef CGAL::Epick_d FK; + typedef CGAL::Epick_d > FK; + typedef CGAL::Regular_triangulation_euclidean_traits Traits; + typedef CGAL::Regular_triangulation Triangulation; + //test(D, "dynamic", N); + test(D, "static", N); +} + +int main(int argc, char **argv) +{ + go<2>(100); + return 0; +}