From 8647878a6a4ca34fbc94de9da489d63c60a7f1f8 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Wed, 12 Nov 2014 17:13:18 +0100 Subject: [PATCH] use check_convergence() to stop optimization when vertices do not move enough the convergence ratio is set to 0.001 by default + fix the use of moving_vertices for iterations after the first one --- Mesh_2/include/CGAL/Mesh_2/Mesh_global_optimizer_2.h | 11 +++++------ Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h | 9 ++++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Mesh_2/include/CGAL/Mesh_2/Mesh_global_optimizer_2.h b/Mesh_2/include/CGAL/Mesh_2/Mesh_global_optimizer_2.h index 7931e9c60c5..78ef8028941 100644 --- a/Mesh_2/include/CGAL/Mesh_2/Mesh_global_optimizer_2.h +++ b/Mesh_2/include/CGAL/Mesh_2/Mesh_global_optimizer_2.h @@ -76,8 +76,8 @@ public: * Constructor */ Mesh_global_optimizer_2(CDT& cdt, - const FT& freeze_ratio = 0., //no criterion const FT& convergence_ratio = 0., //no criterion + const FT& freeze_ratio = 0., //no criterion const MoveFunction move_function = MoveFunction()) : cdt_(cdt) , sq_freeze_ratio_(freeze_ratio * freeze_ratio) @@ -137,6 +137,8 @@ public: // Update mesh with those moves update_mesh(moves, moving_vertices); + // ToDo : freeze vertices that do not move enough + move_function_.after_move(cdt_); #ifdef CGAL_MESH_2_OPTIMIZER_VERBOSE @@ -162,7 +164,8 @@ public: timer.stop(); std::cerr << std::endl; if ( check_convergence() ) - std::cerr << "Convergence reached" << std::endl; + std::cerr << "Convergence reached for ratio " + << convergence_ratio_ << std::endl; std::cerr << "Total optimization time: " << timer.time() << "s" << std::endl << std::endl; #endif @@ -316,14 +319,10 @@ private: //function not available, see Constrained_triangulation_2 cdt_.remove(v); cdt_.insert(new_position); - //todo : insert new faces to outdated_faces if( is_time_limit_reached() ) break; } - - // Update cdt - moving_vertices.clear(); } public: diff --git a/Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h b/Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h index 73c5ae9e779..b4eb38314c0 100644 --- a/Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h +++ b/Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h @@ -10,7 +10,8 @@ namespace CGAL template void lloyd_optimize_mesh_2(CDT& cdt, - const unsigned int nb_iterations) + const unsigned int nb_iterations = 1, + const double convergence_ratio = 0.001) { typedef typename CDT::Geom_traits Gt; typedef CGAL::Lipschitz_sizing_field_2 Lip_sizing; @@ -22,9 +23,11 @@ namespace CGAL ++vit) points.insert(vit->point()); Lip_sizing size(points.begin(), points.end()); - + + typedef CGAL::Mesh_2::Lloyd_move_2 Mf; - CGAL::Mesh_2::Mesh_global_optimizer_2 lloyd(cdt); + CGAL::Mesh_2::Mesh_global_optimizer_2 lloyd(cdt, + convergence_ratio); lloyd.set_sizing_field(size); lloyd(nb_iterations); }