From ec7a6ac87642a00c7556567317a3ae35cc6710c0 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Fri, 10 Nov 2023 17:06:04 +0100 Subject: [PATCH] Added meshing parameter : initial_points --- Mesh_3/include/CGAL/make_mesh_3.h | 35 +++++++-- .../internal/mesh_option_classes.h | 73 +++++++++++++++---- .../internal/parameters_interface.h | 1 + 3 files changed, 89 insertions(+), 20 deletions(-) diff --git a/Mesh_3/include/CGAL/make_mesh_3.h b/Mesh_3/include/CGAL/make_mesh_3.h index 5a8b83b88e9..2c3d642cf74 100644 --- a/Mesh_3/include/CGAL/make_mesh_3.h +++ b/Mesh_3/include/CGAL/make_mesh_3.h @@ -407,7 +407,7 @@ struct C3t3_initializer < C3T3, MD, MC, true, CGAL::Tag_false > * } * \cgalParamDefault{`parameters::exude()`} * \cgalParamSectionEnd - * \cgalParamSectionBegin{Mesh initialization} + * \cgalParamSectionBegin{Mesh initialization with a functor} * \cgalParamDescription{an `InitialPointsGenerator` can optionally be provided to start the meshing process. * It must follow the `InitialPointsGenerator` concept. * The following named parameter controls this option: @@ -415,7 +415,24 @@ struct C3t3_initializer < C3T3, MD, MC, true, CGAL::Tag_false > *
  • `parameters::initial_points_generator()` * } * \cgalParamDefault{`CGAL::Null_Functor()`, the domain's `construct_initial_points_object()` - * will be called for the points initialization.} + * will be called for the points initialization.} + * \cgalParamSectionBegin{Mesh initialization with points} + * \cgalParamDescription{a `std::vector` of initial points, represented as + * `std::vector>` can optionally + * be provided to start the meshing process. + * `Weighted_point_3` is the point's position and weight, + * `int` is the dimension of the minimal dimension subcomplex on which + * the point lies, and + * `Index` is the underlying subcomplex index. + * The following named parameter controls this option: + *
      + *
    • `parameters::initial_points()` + *
    } + * \cgalParamDefault{`std::vector>()`} + * \cgalParamExtra{If this parameter is set, + * the domain's `construct_initial_points_object()` will not be called.} + * \cgalParamExtra{If the parameter `parameters::initial_points_generator()` is set, + * the points will be inserted before calling the functor.} * \cgalParamSectionEnd * \cgalNamedParamsEnd * @@ -444,6 +461,7 @@ C3T3 make_mesh_3(const MeshDomain& domain, const MeshCriteria& criteria, const C { using parameters::choose_parameter; using parameters::get_parameter; + using parameters::get_parameter_reference; C3T3 c3t3; parameters::internal::Exude_options exude_param = choose_parameter(get_parameter(np, internal_np::exude_options_param), parameters::exude().v); parameters::internal::Perturb_options perturb_param = choose_parameter(get_parameter(np, internal_np::perturb_options_param), parameters::perturb().v); @@ -453,9 +471,16 @@ C3T3 make_mesh_3(const MeshDomain& domain, const MeshCriteria& criteria, const C parameters::internal::Mesh_3_options mesh_options_param = choose_parameter(get_parameter(np, internal_np::mesh_param), parameters::internal::Mesh_3_options()); parameters::internal::Manifold_options manifold_options_param = choose_parameter(get_parameter(np, internal_np::manifold_param), parameters::internal::Manifold_options()); - parameters::internal::Initial_points_generator_options initial_points_generator_options_param = - parameters::internal::Initial_points_generator_generator() - (choose_parameter(get_parameter(np, internal_np::initial_points_generator_options_param), parameters::initial_points_generator().v)); + using Initial_points_generator_generator = parameters::internal::Initial_points_generator_generator; + using Initial_points = typename Initial_points_generator_generator::Initial_points; + Initial_points empty_vec; + const Initial_points& initial_points + = choose_parameter(get_parameter_reference(np, internal_np::initial_points_param), empty_vec); + parameters::internal::Initial_points_generator_options initial_points_generator_options_param = + Initial_points_generator_generator() + (choose_parameter(get_parameter(np, internal_np::initial_points_generator_options_param), + parameters::initial_points_generator().v), + initial_points); make_mesh_3_impl(c3t3, domain, criteria, exude_param, perturb_param, odt_param, lloyd_param, diff --git a/STL_Extension/include/CGAL/STL_Extension/internal/mesh_option_classes.h b/STL_Extension/include/CGAL/STL_Extension/internal/mesh_option_classes.h index c80235b10ab..57989a1f008 100644 --- a/STL_Extension/include/CGAL/STL_Extension/internal/mesh_option_classes.h +++ b/STL_Extension/include/CGAL/STL_Extension/internal/mesh_option_classes.h @@ -175,31 +175,54 @@ struct Initial_points_generator_options { typedef typename C3t3::Triangulation::Geom_traits::Weighted_point_3 Weighted_point_3; typedef typename MeshDomain::Index Index; - typedef typename std::back_insert_iterator>> OutputIterator; + typedef typename std::vector> Initial_points; + typedef typename std::back_insert_iterator OutputIterator; template - Initial_points_generator_options(const Initial_points_generator& generator, bool is_default = false) + Initial_points_generator_options(const Initial_points_generator& generator, const Initial_points& initial_points, bool is_default = false) : initial_points_generator_no_number_of_points_(generator) , initial_points_generator_(generator) - , is_default_(is_default) - { } + , is_default_(is_default && initial_points.size() == 0) + { + if (initial_points.size() == 0) + { + initial_points_ = nullptr; + } + else + { + initial_points_ = &initial_points; + } + } OutputIterator operator()(OutputIterator pts, const MeshDomain& domain, const C3t3& c3t3) const { + add_initial_points(pts); return initial_points_generator_no_number_of_points_(pts, domain, c3t3); } OutputIterator operator()(OutputIterator pts, const MeshDomain& domain, const C3t3& c3t3, int n) const { + add_initial_points(pts); return initial_points_generator_(pts, domain, c3t3, n); } + OutputIterator add_initial_points(OutputIterator pts) const + { + if (initial_points_ != nullptr) + { + for (const auto& point_tuple : *initial_points_) + *pts++ = point_tuple; + } + return pts; + } + bool is_default() const { return is_default_; } private: - const bool is_default_; const std::function initial_points_generator_no_number_of_points_; const std::function initial_points_generator_; + const Initial_points* initial_points_; + const bool is_default_; }; // ----------------------------------- @@ -249,11 +272,9 @@ struct Domain_features_generator< MeshDomain, true > template struct Initial_points_generator_generator { - typedef typename C3t3::Triangulation::Geom_traits::Weighted_point_3 Weighted_point_3; - typedef typename MeshDomain::Index Index; - typedef typename std::back_insert_iterator>> OutputIterator; - typedef typename CGAL::parameters::internal::Initial_points_generator_options Initial_points_generator_options; + typedef typename Initial_points_generator_options::Initial_points Initial_points; + typedef typename Initial_points_generator_options::OutputIterator OutputIterator; struct Initial_points_generator_domain_traductor { @@ -283,20 +304,42 @@ struct Initial_points_generator_generator } }; - template - Initial_points_generator_options operator()(const InitialPointsGenerator& initial_points_generator) + struct Initial_points_generator_empty { - return Initial_points_generator_options(initial_points_generator, false); + OutputIterator operator()(OutputIterator pts, const MeshDomain& domain, const C3t3& c3t3) + { return pts; } + OutputIterator operator()(OutputIterator pts, const MeshDomain& domain, const C3t3& c3t3, int n) + { return pts; } + }; + + // With a custom InitialPointsGenerator + template + Initial_points_generator_options operator()(const InitialPointsGenerator& initial_points_generator, const InitalPointsRange& input_features) + { + return Initial_points_generator_options(initial_points_generator, input_features, false); } - Initial_points_generator_options operator()(const Null_functor&) + // Without a custom InitialPointsGenerator + template + Initial_points_generator_options operator()(const InitalPointsRange& input_features) { - return operator()(); + // The domain's construct_initial_points_object is called only if input_features is empty + if (input_features.size() == 0) { + return Initial_points_generator_options(Initial_points_generator_domain_traductor(), input_features, true); + } + return Initial_points_generator_options(Initial_points_generator_empty(), input_features, true); + } + + template + Initial_points_generator_options operator()(const Null_functor&, const InitalPointsRange& input_features) + { + return operator()(input_features); } Initial_points_generator_options operator()() { - return Initial_points_generator_options(Initial_points_generator_domain_traductor(), true); + Initial_points empty_input_features; + return operator()(empty_input_features); } }; diff --git a/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h b/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h index 57715ff5a2a..8853e49bfd5 100644 --- a/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h +++ b/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h @@ -324,6 +324,7 @@ CGAL_add_named_parameter_with_compatibility(mesh_param_t, mesh_param, mesh_optio CGAL_add_named_parameter_with_compatibility(manifold_param_t, manifold_param, manifold_option) CGAL_add_named_parameter_with_compatibility(features_option_param_t,features_options_param,features_options) CGAL_add_named_parameter_with_compatibility(initial_points_generator_options_param_t,initial_points_generator_options_param,initial_points_generator_options) +CGAL_add_named_parameter_with_compatibility(initial_points_param_t,initial_points_param,initial_points) CGAL_add_named_parameter_with_compatibility_cref_only(image_3_param_t, image_3_param, image) CGAL_add_named_parameter_with_compatibility(iso_value_param_t, iso_value_param, iso_value)