From 0e62685f39ce88500b601fb4d46d7fe1981da259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 16 Sep 2022 14:36:06 +0200 Subject: [PATCH] force images to be taken by reference --- Mesh_3/include/CGAL/Labeled_mesh_domain_3.h | 12 ++++-- Mesh_3/include/CGAL/Mesh_3/parameters.h | 2 - .../include/CGAL/Named_function_parameters.h | 39 ++++++++++++++++++- .../internal/parameters_interface.h | 4 +- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Mesh_3/include/CGAL/Labeled_mesh_domain_3.h b/Mesh_3/include/CGAL/Labeled_mesh_domain_3.h index 8e9b13fb37f..2d430d2d5bc 100644 --- a/Mesh_3/include/CGAL/Labeled_mesh_domain_3.h +++ b/Mesh_3/include/CGAL/Labeled_mesh_domain_3.h @@ -506,8 +506,9 @@ From the example (\ref Mesh_3/mesh_implicit_domains_2.cpp): { static_assert(!parameters::is_default_parameter::value, "Value for required parameter not found"); using parameters::get_parameter; + using parameters::get_parameter_reference; using parameters::choose_parameter; - const CGAL::Image_3& image_ = get_parameter(np,internal_np::image_3_param); + const CGAL::Image_3& image_ = get_parameter_reference(np,internal_np::image_3_param); auto iso_value_ = choose_parameter(get_parameter(np, internal_np::iso_value_param), 0); auto value_outside_ = choose_parameter(get_parameter(np, internal_np::voxel_value), 0); FT relative_error_bound_ = choose_parameter(get_parameter(np, internal_np::error_bound), FT(1e-3)); @@ -597,6 +598,7 @@ where the labeled image is used with a precomputed 3D image of weights : static Labeled_mesh_domain_3 create_labeled_image_mesh_domain(const CGAL::Image_3& image_, const CGAL_NP_CLASS& np = parameters::default_values()) { using parameters::get_parameter; + using parameters::get_parameter_reference; using parameters::choose_parameter; auto iso_value_ = choose_parameter(get_parameter(np, internal_np::iso_value_param), FT(0)); auto value_outside_ = choose_parameter(get_parameter(np, internal_np::voxel_value), FT(0)); @@ -605,9 +607,10 @@ where the labeled image is used with a precomputed 3D image of weights : CGAL::Random* p_rng_ = choose_parameter(get_parameter(np, internal_np::rng), (CGAL::Random*)(0)); auto null_subdomain_index_ = choose_parameter(get_parameter(np, internal_np::null_subdomain_index_param), Null_functor()); auto construct_surface_patch_index_ = choose_parameter(get_parameter(np, internal_np::surface_patch_index), Null_functor()); - CGAL::Image_3 weights_ = choose_parameter(get_parameter(np, internal_np::weights_param), CGAL::Image_3()); + const CGAL::Image_3& weights_ = choose_parameter(get_parameter_reference(np, internal_np::weights_param), CGAL::Image_3()); CGAL_USE(iso_value_); namespace p = CGAL::parameters; + if (weights_.is_valid()) { return Labeled_mesh_domain_3 @@ -645,8 +648,9 @@ where the labeled image is used with a precomputed 3D image of weights : { static_assert(!parameters::is_default_parameter::value, "Value for required parameter not found"); using parameters::get_parameter; + using parameters::get_parameter_reference; using parameters::choose_parameter; - const CGAL::Image_3& image_ = get_parameter(np,internal_np::image_3_param); + const CGAL::Image_3& image_ = get_parameter_reference(np,internal_np::image_3_param); auto iso_value_ = choose_parameter(get_parameter(np, internal_np::iso_value_param), FT(0)); auto value_outside_ = choose_parameter(get_parameter(np, internal_np::voxel_value), FT(0)); FT relative_error_bound_ = choose_parameter(get_parameter(np, internal_np::error_bound), FT(1e-3)); @@ -654,7 +658,7 @@ where the labeled image is used with a precomputed 3D image of weights : CGAL::Random* p_rng_ = choose_parameter(get_parameter(np, internal_np::rng), (CGAL::Random*)(0)); auto null_subdomain_index_ = choose_parameter(get_parameter(np, internal_np::null_subdomain_index_param), Null_functor()); auto construct_surface_patch_index_ = choose_parameter(get_parameter(np, internal_np::surface_patch_index), Null_functor()); - CGAL::Image_3 weights_ = choose_parameter(get_parameter(np, internal_np::weights_param), CGAL::Image_3()); + const CGAL::Image_3& weights_ = choose_parameter(get_parameter_reference(np, internal_np::weights_param), CGAL::Image_3()); namespace p = CGAL::parameters; if (weights_.is_valid()) diff --git a/Mesh_3/include/CGAL/Mesh_3/parameters.h b/Mesh_3/include/CGAL/Mesh_3/parameters.h index ee512effc0c..5e6fd972523 100644 --- a/Mesh_3/include/CGAL/Mesh_3/parameters.h +++ b/Mesh_3/include/CGAL/Mesh_3/parameters.h @@ -12,9 +12,7 @@ #define CGAL_MESH_3_PARAMETERS_H #include -#include #include -#include namespace CGAL { diff --git a/STL_Extension/include/CGAL/Named_function_parameters.h b/STL_Extension/include/CGAL/Named_function_parameters.h index bb61f49afb3..2d5a83bc92c 100644 --- a/STL_Extension/include/CGAL/Named_function_parameters.h +++ b/STL_Extension/include/CGAL/Named_function_parameters.h @@ -48,10 +48,13 @@ enum all_default_t { all_default }; enum X { Y }; #define CGAL_add_named_parameter_with_compatibility(X, Y, Z) \ enum X { Y }; +#define CGAL_add_named_parameter_with_compatibility_ref_only(X, Y, Z) \ + enum X { Y }; #define CGAL_add_extra_named_parameter_with_compatibility(X, Y, Z) #include #undef CGAL_add_named_parameter #undef CGAL_add_named_parameter_with_compatibility +#undef CGAL_add_named_parameter_with_compatibility_ref_only #undef CGAL_add_extra_named_parameter_with_compatibility template @@ -271,6 +274,16 @@ struct Named_function_parameters typedef Named_function_parameters Params;\ return Params(k, *this); \ } +#define CGAL_add_named_parameter_with_compatibility_ref_only(X, Y, Z) \ + template \ + Named_function_parameters, \ + internal_np::X, self> \ + Z(const K& k) const \ + { \ + typedef Named_function_parameters,\ + internal_np::X, self> Params; \ + return Params(std::cref(k), *this); \ + } #define CGAL_add_extra_named_parameter_with_compatibility(X, Y, Z) \ template \ Named_function_parameters \ @@ -282,6 +295,7 @@ struct Named_function_parameters #include #undef CGAL_add_named_parameter #undef CGAL_add_named_parameter_with_compatibility +#undef CGAL_add_named_parameter_with_compatibility_ref_only #undef CGAL_add_extra_named_parameter_with_compatibility template @@ -325,7 +339,7 @@ inline no_parameters(Named_function_parameters) return Params(); } -template +template struct Boost_parameter_compatibility_wrapper { template @@ -345,6 +359,26 @@ struct Boost_parameter_compatibility_wrapper } }; +template +struct Boost_parameter_compatibility_wrapper +{ + template + Named_function_parameters, Tag> + operator()(const K& p) const + { + typedef Named_function_parameters, Tag> Params; + return Params(std::cref(p)); + } + + template + Named_function_parameters, Tag> + operator=(const K& p) const + { + typedef Named_function_parameters, Tag> Params; + return Params(std::cref(p)); + } +}; + // define free functions and Boost_parameter_compatibility_wrapper for named parameters #define CGAL_add_named_parameter(X, Y, Z) \ template \ @@ -357,12 +391,15 @@ struct Boost_parameter_compatibility_wrapper // TODO: need to make sure this works when using several compilation units #define CGAL_add_named_parameter_with_compatibility(X, Y, Z) \ const Boost_parameter_compatibility_wrapper Z; +#define CGAL_add_named_parameter_with_compatibility_ref_only(X, Y, Z) \ + const Boost_parameter_compatibility_wrapper Z; #define CGAL_add_extra_named_parameter_with_compatibility(X, Y, Z) \ const Boost_parameter_compatibility_wrapper Z; #include #undef CGAL_add_named_parameter #undef CGAL_add_extra_named_parameter_with_compatibility #undef CGAL_add_named_parameter_with_compatibility +#undef CGAL_add_named_parameter_with_compatibility_ref_only // function to extract a parameter template 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 cf9ef27c66c..01b9cae28ad 100644 --- a/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h +++ b/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h @@ -302,7 +302,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(image_3_param_t, image_3_param, image) +CGAL_add_named_parameter_with_compatibility_ref_only(image_3_param_t, image_3_param, image) CGAL_add_named_parameter_with_compatibility(iso_value_param_t, iso_value_param, iso_value) CGAL_add_named_parameter_with_compatibility(image_subdomain_index_t, image_subdomain_index, image_values_to_subdomain_indices) CGAL_add_named_parameter_with_compatibility(voxel_value_t, voxel_value, value_outside) @@ -310,7 +310,7 @@ CGAL_add_named_parameter_with_compatibility(error_bound_t, error_bound, relative CGAL_add_named_parameter_with_compatibility(rng_t, rng, p_rng) CGAL_add_named_parameter_with_compatibility(null_subdomain_index_param_t,null_subdomain_index_param, null_subdomain_index) CGAL_add_named_parameter_with_compatibility(surface_patch_index_t, surface_patch_index, construct_surface_patch_index) -CGAL_add_named_parameter_with_compatibility(weights_param_t, weights_param, weights) +CGAL_add_named_parameter_with_compatibility_ref_only(weights_param_t, weights_param, weights) CGAL_add_named_parameter_with_compatibility(edge_size_param_t, edge_size_param, edge_size) CGAL_add_named_parameter_with_compatibility(edge_sizing_field_param_t, edge_sizing_field_param, edge_sizing_field)