diff --git a/Mesh_3/examples/Mesh_3/mesh_perturbation_example.cpp b/Mesh_3/examples/Mesh_3/mesh_perturbation_example.cpp index c6af2736aeb..2a6bcde777a 100644 --- a/Mesh_3/examples/Mesh_3/mesh_perturbation_example.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_perturbation_example.cpp @@ -1,3 +1,6 @@ +#define CGAL_MESH_3_VERBOSE +#define CGAL_MESH_3_PERTURBER_VERBOSE + #include #include @@ -45,7 +48,7 @@ int main() C3t3 c3t3 = CGAL::make_mesh_3(domain, criteria, no_perturb(), no_exude()); // Mesh perturbation - CGAL::perturb_mesh_3(c3t3, domain, time_limit=15); + CGAL::perturb_mesh_3(c3t3, domain, time_limit=15, sliver_bound=10); // Output std::ofstream medit_file("out.mesh"); diff --git a/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h b/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h index 88002c5e247..acaf6c08a06 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h +++ b/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h @@ -45,6 +45,7 @@ #include #include #include +#include #include #ifdef CGAL_MESH_3_USE_RELAXED_HEAP @@ -64,7 +65,8 @@ namespace Mesh_3 { template < typename C3T3, typename MeshDomain, - typename SliverCriterion, + typename SliverCriterion = Mesh_3::Min_dihedral_angle_criterion + , typename Visitor_ = Null_perturber_visitor > class Sliver_perturber { @@ -233,8 +235,7 @@ public: * The perturber runs step by step, using delta as step size. */ Mesh_optimization_return_code - operator()(const FT& sliver_bound = SliverCriterion::max_value, - const FT& delta = FT(1.), + operator()(const FT& delta = FT(1.), Visitor visitor = Visitor()); /** @@ -245,6 +246,10 @@ public: /// Time accessors void set_time_limit(double time) { time_limit_ = time; } double time_limit() const { return time_limit_; } + + /// Sliver bound + void set_sliver_bound(double bound) { sliver_bound_ = bound; } + double sliver_bound() const { return sliver_bound_; } private: @@ -342,8 +347,8 @@ private: Tr& tr_; const MeshDomain& domain_; double sliver_bound_; - Perturbation_vector perturbation_vector_; SliverCriterion sliver_criterion_; + Perturbation_vector perturbation_vector_; C3T3_helpers helper_; // Internal perturbation ordering @@ -368,6 +373,7 @@ Sliver_perturber(C3T3& c3t3, : c3t3_(c3t3) , tr_(c3t3_.triangulation()) , domain_(domain) + , sliver_bound_(Sc::max_value) , sliver_criterion_(criterion) , helper_(c3t3_,domain_) , next_perturbation_order_(0) @@ -380,7 +386,7 @@ Sliver_perturber(C3T3& c3t3, template Mesh_optimization_return_code Sliver_perturber:: -operator()(const FT& sliver_bound, const FT& delta, Visitor visitor) +operator()(const FT& delta, Visitor visitor) { // Reset sliver value cache helper_.reset_cache(); @@ -407,7 +413,7 @@ operator()(const FT& sliver_bound, const FT& delta, Visitor visitor) FT current_bound = delta; bool perturbation_ok = true; - while ( current_bound <= sliver_bound && perturbation_ok) + while ( current_bound <= sliver_bound() && perturbation_ok) { #ifdef CGAL_MESH_3_PERTURBER_HIGH_VERBOSITY // reset_perturbation_counters is not const @@ -418,10 +424,10 @@ operator()(const FT& sliver_bound, const FT& delta, Visitor visitor) visitor.bound_reached(current_bound); current_bound += delta; - if ( (current_bound >= sliver_bound) - && (current_bound < sliver_bound + delta) ) + if ( (current_bound >= sliver_bound()) + && (current_bound < sliver_bound() + delta) ) { - current_bound = sliver_bound; + current_bound = sliver_bound(); } } diff --git a/Mesh_3/include/CGAL/Mesh_3/global_parameters.h b/Mesh_3/include/CGAL/Mesh_3/global_parameters.h index b024ab5d9e6..1652a3ff311 100644 --- a/Mesh_3/include/CGAL/Mesh_3/global_parameters.h +++ b/Mesh_3/include/CGAL/Mesh_3/global_parameters.h @@ -61,6 +61,7 @@ BOOST_PARAMETER_NAME( criteria ) BOOST_PARAMETER_NAME( (time_limit, tag) time_limit_ ) BOOST_PARAMETER_NAME( (sliver_bound, tag) sliver_bound_) +BOOST_PARAMETER_NAME( (sliver_criterion, tag) sliver_criterion_) BOOST_PARAMETER_NAME( (freeze_bound, tag) freeze_bound_) BOOST_PARAMETER_NAME( (do_freeze, tag) do_freeze_) BOOST_PARAMETER_NAME( (max_iteration_number, tag) max_iteration_number_ ) diff --git a/Mesh_3/include/CGAL/Mesh_3/parameters_defaults.h b/Mesh_3/include/CGAL/Mesh_3/parameters_defaults.h index c651d1fea44..f63fc6f1808 100644 --- a/Mesh_3/include/CGAL/Mesh_3/parameters_defaults.h +++ b/Mesh_3/include/CGAL/Mesh_3/parameters_defaults.h @@ -26,6 +26,8 @@ #ifndef CGAL_MESH_3_PARAMETERS_DEFAULTS_H #define CGAL_MESH_3_PARAMETERS_DEFAULTS_H +#include + namespace CGAL { namespace parameters { namespace default_values { @@ -34,6 +36,14 @@ const double exude_sliver_bound = 0.; // perturb_mesh_3 const double perturb_sliver_bound = 0.; +template +CGAL::Mesh_3::Min_dihedral_angle_criterion + + default_sliver_criterion(const C3T3&) +{ + typedef typename C3T3::Triangulation::Geom_traits Gt; + return CGAL::Mesh_3::Min_dihedral_angle_criterion(); +} // global optimizers const bool do_freeze = true; diff --git a/Mesh_3/include/CGAL/Mesh_3/sliver_criteria.h b/Mesh_3/include/CGAL/Mesh_3/sliver_criteria.h index 73101bce55f..1c971190856 100644 --- a/Mesh_3/include/CGAL/Mesh_3/sliver_criteria.h +++ b/Mesh_3/include/CGAL/Mesh_3/sliver_criteria.h @@ -32,9 +32,17 @@ namespace CGAL { namespace Mesh_3 { +template +class Sliver_criterion +{ + typedef typename K::Tetrahedron_3 Tetrahedron_3; + +public: + virtual double operator()(const Tetrahedron_3& t) const = 0; +}; template -class Min_dihedral_angle_criterion +class Min_dihedral_angle_criterion : public Sliver_criterion { typedef typename K::Tetrahedron_3 Tetrahedron_3; @@ -55,7 +63,7 @@ template double Min_dihedral_angle_criterion::max_value = 90.; template double Min_dihedral_angle_criterion::min_value = 0.; template -class Radius_radio_criterion +class Radius_radio_criterion : public Sliver_criterion { typedef typename K::Tetrahedron_3 Tetrahedron_3; diff --git a/Mesh_3/include/CGAL/perturb_mesh_3.h b/Mesh_3/include/CGAL/perturb_mesh_3.h index 5f2b000b9b1..9cf14643fb2 100644 --- a/Mesh_3/include/CGAL/perturb_mesh_3.h +++ b/Mesh_3/include/CGAL/perturb_mesh_3.h @@ -42,25 +42,29 @@ BOOST_PARAMETER_FUNCTION( (optional (time_limit_, *, 0 ) (sliver_bound_, *, parameters::default_values::perturb_sliver_bound ) + (sliver_criterion_, *, + parameters::default_values::default_sliver_criterion(c3t3)) ) ) { - return perturb_mesh_3_impl(c3t3, domain, time_limit_, sliver_bound_); + return perturb_mesh_3_impl(c3t3, domain, time_limit_, sliver_criterion_, sliver_bound_); } -template +template Mesh_optimization_return_code perturb_mesh_3_impl(C3T3& c3t3, const MeshDomain& domain, const double time_limit, + const SliverCriterion& sliver_criterion, const double sliver_bound) { typedef MeshDomain Md; typedef typename C3T3::Triangulation::Geom_traits Gt; - typedef Mesh_3::Min_dihedral_angle_criterion Sc; - //typedef Mesh_3::Radius_radio_criterion Sc; + typedef SliverCriterion Sc; typedef Mesh_3::Sliver_perturber Perturber; typedef Mesh_3::Sq_radius_perturbation Sq_radius; @@ -78,12 +82,12 @@ perturb_mesh_3_impl(C3T3& c3t3, // Set max time perturber.set_time_limit(time_limit); + + // Set sliver bound + perturber.set_sliver_bound(sliver_bound); // Launch perturber - if ( sliver_bound != 0 ) - return perturber(sliver_bound); - else - return perturber(); + return perturber(); }