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
This commit is contained in:
Jane Tournois 2014-11-12 17:13:18 +01:00
parent 5e2fab9a51
commit 8647878a6a
2 changed files with 11 additions and 9 deletions

View File

@ -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:

View File

@ -10,7 +10,8 @@ namespace CGAL
template<typename CDT>
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<Gt> 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<CDT, Lip_sizing> Mf;
CGAL::Mesh_2::Mesh_global_optimizer_2<CDT, Mf> lloyd(cdt);
CGAL::Mesh_2::Mesh_global_optimizer_2<CDT, Mf> lloyd(cdt,
convergence_ratio);
lloyd.set_sizing_field(size);
lloyd(nb_iterations);
}