From bbc5a345b8dcb01215c3474b3c723aa23e1e485d Mon Sep 17 00:00:00 2001 From: hoskillua <47090776+hoskillua@users.noreply.github.com> Date: Thu, 5 Oct 2023 13:08:42 +0300 Subject: [PATCH] adaptive clustering first version --- .../Polygon_mesh_processing/acvd_example.cpp | 26 ++++++++++++++- .../CGAL/Polygon_mesh_processing/acvd/acvd.h | 33 +++++++++++++++++-- .../internal/parameters_interface.h | 9 +++++ 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/acvd_example.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/acvd_example.cpp index 62f3f156df1..193362237cd 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/acvd_example.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/acvd_example.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -25,13 +26,36 @@ int main(int argc, char* argv[]) const int nb_clusters = (argc > 2) ? atoi(argv[2]) : 20; + const double gradation_factor = (argc > 3) ? atof(argv[3]) : 0; + + if (!CGAL::IO::read_polygon_mesh(filename, smesh)) { std::cerr << "Invalid input file." << std::endl; return EXIT_FAILURE; } - PMP::acvd_isotropic_simplification(smesh, nb_clusters); + bool created = false; + Surface_Mesh::Property_map> + principal_curvatures_and_directions_map; + + boost::tie(principal_curvatures_and_directions_map, created) = + smesh.add_property_map> + ("v:principal_curvatures_and_directions_map", { 0, 0, + Epic_kernel::Vector_3(0,0,0), + Epic_kernel::Vector_3(0,0,0) }); + assert(created); + + + PMP::interpolated_corrected_principal_curvatures_and_directions(smesh, principal_curvatures_and_directions_map); + + + PMP::acvd_isotropic_simplification( + smesh, + nb_clusters, + CGAL::parameters::vertex_principal_curvatures_and_directions_map(principal_curvatures_and_directions_map) + .gradation_factor(gradation_factor) + ); // std::cout << "kak3" << std::endl; return 0; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/acvd/acvd.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/acvd/acvd.h index cddc7c7644c..0d46ca802b4 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/acvd/acvd.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/acvd/acvd.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -120,6 +121,9 @@ void acvd_subdivide_if_needed( } +// provide a property map for principal curvatures as a named parameter for adaptive clustering +// provide a gradation factor as a named parameter for adaptive clustering + template PolygonMesh acvd_simplification( @@ -138,6 +142,10 @@ PolygonMesh acvd_simplification( typedef typename boost::property_map >::type VertexClusterMap; typedef typename boost::property_map >::type VertexWeightMap; typedef typename boost::property_map >::type HalfedgeVisitedMap; + typedef Constant_property_map> Default_principal_map; + typedef typename internal_np::Lookup_named_param_def::type Vertex_principal_curvatures_and_directions_map; using parameters::choose_parameter; using parameters::get_parameter; @@ -146,6 +154,17 @@ PolygonMesh acvd_simplification( Vertex_position_map vpm = choose_parameter(get_parameter(np, CGAL::vertex_point), get_property_map(CGAL::vertex_point, pmesh)); + // get curvature related parameters + const typename GT::FT gradation_factor = choose_parameter(get_parameter(np, internal_np::gradation_factor), 0); + const typename Vertex_principal_curvatures_and_directions_map vpcd_map = + choose_parameter(get_parameter(np, internal_np::vertex_principal_curvatures_and_directions_map), + Default_principal_map()); + + if (gradation_factor > 0 && + is_default_parameter::value) + interpolated_corrected_principal_curvatures_and_directions(pmesh, vpcd_map); + + // TODO: handle cases where the mesh is not a triangle mesh CGAL_precondition(CGAL::is_triangle_mesh(pmesh)); @@ -200,7 +219,15 @@ PolygonMesh acvd_simplification( for (Vertex_descriptor vd : vertices_around_face(halfedge(fd, pmesh), pmesh)) { typename GT::FT vertex_weight = get(vertex_weight_pmap, vd); - vertex_weight += weight; + if (gradation_factor == 0) // no adaptive clustering + vertex_weight += weight; + else // adaptive clustering + { + typename GT::FT k1 = get(vpcd_map, vd).min_curvature; + typename GT::FT k2 = get(vpcd_map, vd).max_curvature; + typename GT::FT k_sq = (k1 * k1 + k2 * k2); + vertex_weight += weight * pow(k_sq, gradation_factor / 2.0); // /2.0 because k_sq is squared + } put(vertex_weight_pmap, vd, vertex_weight); } } @@ -618,8 +645,8 @@ PolygonMesh acvd_simplification( orient_polygon_soup(points, polygons); polygon_soup_to_polygon_mesh(points, polygons, simplified_mesh); - // name = std::to_string(nb_clusters) + "_simped.off"; - // CGAL::IO::write_OFF(name, simplified_mesh); + name = std::to_string(nb_clusters) + "_simped.off"; + CGAL::IO::write_OFF(name, simplified_mesh); std::cout << "kak3" << std::endl; return simplified_mesh; 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 7792ad5cdb6..2734b8d3648 100644 --- a/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h +++ b/STL_Extension/include/CGAL/STL_Extension/internal/parameters_interface.h @@ -93,6 +93,14 @@ CGAL_add_named_parameter(number_of_points_per_edge_t, number_of_points_per_edge, CGAL_add_named_parameter(number_of_points_on_edges_t, number_of_points_on_edges, number_of_points_on_edges) CGAL_add_named_parameter(nb_points_per_area_unit_t, nb_points_per_area_unit, number_of_points_per_area_unit) CGAL_add_named_parameter(nb_points_per_distance_unit_t, nb_points_per_distance_unit, number_of_points_per_distance_unit) +CGAL_add_named_parameter(vertex_mean_curvature_map_t, vertex_mean_curvature_map, vertex_mean_curvature_map) +CGAL_add_named_parameter(vertex_Gaussian_curvature_map_t, vertex_Gaussian_curvature_map, vertex_Gaussian_curvature_map) +CGAL_add_named_parameter(vertex_principal_curvatures_and_directions_map_t, vertex_principal_curvatures_and_directions_map, vertex_principal_curvatures_and_directions_map) +CGAL_add_named_parameter(vertex_mean_curvature_t, vertex_mean_curvature, vertex_mean_curvature) +CGAL_add_named_parameter(vertex_Gaussian_curvature_t, vertex_Gaussian_curvature, vertex_Gaussian_curvature) +CGAL_add_named_parameter(vertex_principal_curvatures_and_directions_t, vertex_principal_curvatures_and_directions, vertex_principal_curvatures_and_directions) +CGAL_add_named_parameter(ball_radius_t, ball_radius, ball_radius) +CGAL_add_named_parameter(gradation_factor_t, gradation_factor, gradation_factor) CGAL_add_named_parameter(outward_orientation_t, outward_orientation, outward_orientation) CGAL_add_named_parameter(overlap_test_t, overlap_test, do_overlap_test_of_bounded_sides) CGAL_add_named_parameter(preserve_genus_t, preserve_genus, preserve_genus) @@ -155,6 +163,7 @@ CGAL_add_named_parameter(patch_normal_map_t, patch_normal_map, patch_normal_map) CGAL_add_named_parameter(region_primitive_map_t, region_primitive_map, region_primitive_map) CGAL_add_named_parameter(postprocess_regions_t, postprocess_regions, postprocess_regions) + // 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) CGAL_add_named_parameter(get_placement_policy_t, get_placement_policy, get_placement)