From fbab5edb607f2f04c18ebe35166ead43dbf20dfd Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 18 Nov 2014 11:25:09 +0100 Subject: [PATCH] return Mesh_optimization_return_code as Mesh_3 optimizers do --- .../CGAL/Mesh_2/Mesh_global_optimizer_2.h | 19 ++++++++++++++++--- Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h | 12 ++++++++---- 2 files changed, 24 insertions(+), 7 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 e7a591a0803..5fb80e6aa29 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 @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -92,7 +93,7 @@ public: void set_time_limit(double time) { time_limit_ = time; } double time_limit() const { return time_limit_; } - void operator()(const int nb_iterations) + Mesh_optimization_return_code operator()(const int nb_iterations) { running_time_.reset(); running_time_.start(); @@ -172,10 +173,9 @@ public: } move_function_.after_all_moves(cdt_); + running_time_.stop(); #ifdef CGAL_MESH_2_OPTIMIZER_VERBOSE - running_time_.stop(); - std::cerr << std::endl; if(sq_freeze_ratio_ > 0. && moving_vertices.empty()) std::cerr << "All vertices frozen" << std::endl; else if(sq_freeze_ratio_ > 0. && convergence_stop) @@ -190,6 +190,19 @@ public: std::cerr << "Total optimization time: " << running_time_.time() << "s" << std::endl << std::endl; #endif + + if( sq_freeze_ratio_ > 0. && moving_vertices.empty() ) + return ALL_VERTICES_FROZEN; + else if( sq_freeze_ratio_ > 0. && convergence_stop ) + return CANT_IMPROVE_ANYMORE; + else if( is_time_limit_reached() ) + return TIME_LIMIT_REACHED; + else if( check_convergence() ) + return CONVERGENCE_REACHED; + else if( i >= nb_iterations ) + return MAX_ITERATION_NUMBER_REACHED; + else + return MESH_OPTIMIZATION_UNKNOWN_ERROR; } private: diff --git a/Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h b/Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h index 4d4dfaca5a1..a2a75794e17 100644 --- a/Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h +++ b/Mesh_2/include/CGAL/lloyd_optimize_mesh_2.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -18,7 +19,7 @@ BOOST_PARAMETER_NAME( (freeze_bound, tag) freeze_bound_) namespace CGAL { BOOST_PARAMETER_FUNCTION( - (void), + (Mesh_optimization_return_code), lloyd_optimize_mesh_2, tag, (required (in_out(cdt),*)) @@ -38,8 +39,9 @@ namespace CGAL } template - void lloyd_optimize_mesh_2_impl(CDT& cdt, - const unsigned int max_iterations, + Mesh_optimization_return_code + lloyd_optimize_mesh_2_impl(CDT& cdt, + const int max_iterations, const double convergence_ratio, const double freeze_bound, const double time_limit) @@ -65,13 +67,15 @@ namespace CGAL : max_iterations; //run optimization - lloyd(nb_iterations); + Mesh_optimization_return_code rc = lloyd(nb_iterations); #ifdef CGAL_MESH_2_OPTIMIZERS_DEBUG std::ofstream os2("after_lloyd.angles.txt"); lloyd.output_angles_histogram(os2); os2.close(); #endif + + return rc; } } //end namespace CGAL