From f55e482d0f70c895148c4e494ced9ba92c3eeb13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 20 Oct 2021 09:24:13 +0200 Subject: [PATCH 1/3] add random generator np for sampling --- .../CGAL/boost/graph/parameters_interface.h | 1 + .../CGAL/Polygon_mesh_processing/distance.h | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/parameters_interface.h b/BGL/include/CGAL/boost/graph/parameters_interface.h index 780fc10cb0a..92d8d87f6e3 100644 --- a/BGL/include/CGAL/boost/graph/parameters_interface.h +++ b/BGL/include/CGAL/boost/graph/parameters_interface.h @@ -128,6 +128,7 @@ CGAL_add_named_parameter(match_faces_t, match_faces, match_faces) CGAL_add_named_parameter(face_epsilon_map_t, face_epsilon_map, face_epsilon_map) CGAL_add_named_parameter(maximum_number_t, maximum_number, maximum_number) CGAL_add_named_parameter(use_one_sided_hausdorff_t, use_one_sided_hausdorff, use_one_sided_hausdorff) +CGAL_add_named_parameter(random_generator_f, random_generator, random_generator) // List of named parameters that we use in the package 'Surface Mesh Simplification' CGAL_add_named_parameter(get_cost_policy_t, get_cost_policy, get_cost) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h index 4b5a96c9669..cb9df43f839 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h @@ -438,6 +438,7 @@ struct Triangle_structure_sampler_for_triangle_mesh Vpm pmap; double min_sq_edge_length; const Mesh& tm; + CGAL::Random rnd; Triangle_structure_sampler_for_triangle_mesh(const Mesh& m, PointOutputIterator& out, @@ -449,6 +450,8 @@ struct Triangle_structure_sampler_for_triangle_mesh pmap = choose_parameter(get_parameter(np, internal_np::vertex_point), get_const_property_map(vertex_point, tm)); + rnd = choose_parameter(get_parameter(np, internal_np::random_generator), + get_default_random()); min_sq_edge_length = (std::numeric_limits::max)(); } @@ -549,7 +552,7 @@ struct Triangle_structure_sampler_for_triangle_mesh Randomizer get_randomizer() { - return Randomizer(tm, pmap); + return Randomizer(tm, pmap, rnd); } void internal_sample_triangles(double grid_spacing_, bool smpl_fcs, bool smpl_dgs) @@ -609,6 +612,7 @@ struct Triangle_structure_sampler_for_triangle_soup double min_sq_edge_length; const PointRange& points; const TriangleRange& triangles; + Random rnd; Triangle_structure_sampler_for_triangle_soup(const PointRange& pts, const TriangleRange& trs, @@ -616,7 +620,12 @@ struct Triangle_structure_sampler_for_triangle_soup const NamedParameters& np) : Base(out, np), points(pts), triangles(trs) { + using parameters::choose_parameter; + using parameters::get_parameter; + min_sq_edge_length = (std::numeric_limits::max)(); + rnd = choose_parameter(get_parameter(np, internal_np::random_generator), + get_default_random()); } std::pair get_range() @@ -681,7 +690,7 @@ struct Triangle_structure_sampler_for_triangle_soup Randomizer get_randomizer() { - return Randomizer(triangles, points); + return Randomizer(triangles, points, rnd); } void internal_sample_triangles(double distance, bool, bool) @@ -737,6 +746,12 @@ struct Triangle_structure_sampler_for_triangle_soup * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} * \cgalParamNEnd * + * \cgalParamNBegin{random_generator} + * \cgalParamDescription{An instance of `CGAL::Random` used for generating random numbers.} + * \cgalParamType{`CGAL::Random`} + * \cgalParamType{`CGAL::get_default_random()`} + * \cgalParamNEnd + * * \cgalParamNBegin{use_random_uniform_sampling} * \cgalParamDescription{If `true` is passed, points are generated in a random and uniform way * on the surface of `tm`, and/or on edges of `tm`.} @@ -896,6 +911,12 @@ sample_triangle_mesh(const TriangleMesh& tm, * \cgalParamExtra{The geometric traits class must be compatible with the point range's point type.} * \cgalParamNEnd * + * \cgalParamNBegin{random_generator} + * \cgalParamDescription{An instance of `CGAL::Random` used for generating random numbers.} + * \cgalParamType{`CGAL::Random`} + * \cgalParamType{`CGAL::get_default_random()`} + * \cgalParamNEnd + * * \cgalParamNBegin{use_random_uniform_sampling} * \cgalParamDescription{If `true` is passed, points are generated in a random and uniform way * over the triangles of the soup.} From d34ff255715a46650418d8b3505c7aae36c3134f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 21 Oct 2021 09:11:18 +0200 Subject: [PATCH 2/3] test named parameters --- .../test/Polygon_mesh_processing/test_pmp_distance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp index c8d1040383d..b7f6076ab41 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp @@ -269,7 +269,7 @@ void general_tests(const TriangleMesh& m1, << "\n"; std::vector samples; - PMP::sample_triangle_mesh(m1, std::back_inserter(samples)); + PMP::sample_triangle_mesh(m1, std::back_inserter(samples), CGAL::parameters::random_generator(CGAL::get_default_random())); std::cout << samples.size()<<" points sampled on mesh."< Date: Mon, 3 Jan 2022 10:35:30 +0100 Subject: [PATCH 3/3] use random_seed --- .../CGAL/boost/graph/parameters_interface.h | 1 - .../CGAL/Polygon_mesh_processing/distance.h | 26 ++++++++++--------- .../test_pmp_distance.cpp | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/parameters_interface.h b/BGL/include/CGAL/boost/graph/parameters_interface.h index 92d8d87f6e3..780fc10cb0a 100644 --- a/BGL/include/CGAL/boost/graph/parameters_interface.h +++ b/BGL/include/CGAL/boost/graph/parameters_interface.h @@ -128,7 +128,6 @@ CGAL_add_named_parameter(match_faces_t, match_faces, match_faces) CGAL_add_named_parameter(face_epsilon_map_t, face_epsilon_map, face_epsilon_map) CGAL_add_named_parameter(maximum_number_t, maximum_number, maximum_number) CGAL_add_named_parameter(use_one_sided_hausdorff_t, use_one_sided_hausdorff, use_one_sided_hausdorff) -CGAL_add_named_parameter(random_generator_f, random_generator, random_generator) // List of named parameters that we use in the package 'Surface Mesh Simplification' CGAL_add_named_parameter(get_cost_policy_t, get_cost_policy, get_cost) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h index cb9df43f839..73ebe0fcae6 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h @@ -447,11 +447,12 @@ struct Triangle_structure_sampler_for_triangle_mesh { using parameters::choose_parameter; using parameters::get_parameter; + using parameters::is_default_parameter; pmap = choose_parameter(get_parameter(np, internal_np::vertex_point), get_const_property_map(vertex_point, tm)); - rnd = choose_parameter(get_parameter(np, internal_np::random_generator), - get_default_random()); + if (!(is_default_parameter(get_parameter(np, internal_np::random_seed)))) + rnd = CGAL::Random(choose_parameter(get_parameter(np, internal_np::random_seed),0)); min_sq_edge_length = (std::numeric_limits::max)(); } @@ -622,10 +623,11 @@ struct Triangle_structure_sampler_for_triangle_soup { using parameters::choose_parameter; using parameters::get_parameter; + using parameters::is_default_parameter; min_sq_edge_length = (std::numeric_limits::max)(); - rnd = choose_parameter(get_parameter(np, internal_np::random_generator), - get_default_random()); + if (!(is_default_parameter(get_parameter(np, internal_np::random_seed)))) + rnd = CGAL::Random(choose_parameter(get_parameter(np, internal_np::random_seed),0)); } std::pair get_range() @@ -746,10 +748,10 @@ struct Triangle_structure_sampler_for_triangle_soup * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} * \cgalParamNEnd * - * \cgalParamNBegin{random_generator} - * \cgalParamDescription{An instance of `CGAL::Random` used for generating random numbers.} - * \cgalParamType{`CGAL::Random`} - * \cgalParamType{`CGAL::get_default_random()`} + * \cgalParamNBegin{random_seed} + * \cgalParamDescription{a value to seed the random number generator} + * \cgalParamType{unsigned int} + * \cgalParamDefault{a value generated with `std::time()`} * \cgalParamNEnd * * \cgalParamNBegin{use_random_uniform_sampling} @@ -911,10 +913,10 @@ sample_triangle_mesh(const TriangleMesh& tm, * \cgalParamExtra{The geometric traits class must be compatible with the point range's point type.} * \cgalParamNEnd * - * \cgalParamNBegin{random_generator} - * \cgalParamDescription{An instance of `CGAL::Random` used for generating random numbers.} - * \cgalParamType{`CGAL::Random`} - * \cgalParamType{`CGAL::get_default_random()`} + * \cgalParamNBegin{random_seed} + * \cgalParamDescription{a value to seed the random number generator} + * \cgalParamType{unsigned int} + * \cgalParamDefault{a value generated with `std::time()`} * \cgalParamNEnd * * \cgalParamNBegin{use_random_uniform_sampling} diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp index b7f6076ab41..d3d9fb023f4 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp @@ -269,7 +269,7 @@ void general_tests(const TriangleMesh& m1, << "\n"; std::vector samples; - PMP::sample_triangle_mesh(m1, std::back_inserter(samples), CGAL::parameters::random_generator(CGAL::get_default_random())); + PMP::sample_triangle_mesh(m1, std::back_inserter(samples), CGAL::parameters::random_seed(0)); std::cout << samples.size()<<" points sampled on mesh."<