From 3baee3ce4cdb237bd2f58c0b68f16c604aa2180c Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 19 Nov 2009 14:18:33 +0000 Subject: [PATCH] - Insert a random sample of the polyhedron points, instead of the first points, to avoid having a triangulation of dimension < 3 - Set the error_behavior to ABORT, so that the try/catch of the Qt4 main loop does not intercept our CGAL assertions (that prevents efficient debugging). --- ...hedron_demo_remeshing_plugin_cgal_code.cpp | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp index cfc40b58727..c7e56ed1224 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp @@ -14,10 +14,15 @@ #include +#include + +#include + Polyhedron* cgal_code_remesh(const Polyhedron* pMesh, const double angle, const double sizing, const double approx) { + CGAL::set_error_behaviour(CGAL::ABORT); if(!pMesh) return 0; // remesh @@ -46,14 +51,29 @@ Polyhedron* cgal_code_remesh(const Polyhedron* pMesh, timer.reset(); std::cerr << "Insert initial point set..."; unsigned int nb_initial_points = 10; - Polyhedron::Point_const_iterator it; typedef CGAL::Cartesian_converter Converter; Converter convert; - unsigned int i = 0; - for(it = pMesh->points_begin(); - it != pMesh->points_end(), i < nb_initial_points; - it++, i++) - triangulation.insert(convert(*it)); + + { // new scope for the initialization, so that the vector + // polyhedron_points is destroyed as soon as the initialization is + // finished + std::vector polyhedron_points; + polyhedron_points.reserve(pMesh->size_of_vertices()); + std::copy(pMesh->points_begin(), pMesh->points_end(), + std::back_inserter(polyhedron_points)); + + for(int n = 0; + n < nb_initial_points || (n < 10 * nb_initial_points && + triangulation.dimension() < 3 ); + n = triangulation.number_of_vertices()) + { + const int pos = CGAL::default_random.get_int(0, polyhedron_points.size()); + triangulation.insert(convert(polyhedron_points[pos])); + } + } + if(triangulation.dimension() < 3) + return 0; + std::cerr << "done (" << timer.time() << " ms)" << std::endl; // remesh