mirror of https://github.com/CGAL/cgal
adaptive clustering first version
This commit is contained in:
parent
4f99fddb39
commit
bbc5a345b8
|
|
@ -3,6 +3,7 @@
|
|||
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
#include <CGAL/property_map.h>
|
||||
#include <CGAL/Polygon_mesh_processing/interpolated_corrected_curvatures.h>
|
||||
|
||||
#include <boost/graph/graph_traits.hpp>
|
||||
|
||||
|
|
@ -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<vertex_descriptor, PMP::Principal_curvatures_and_directions<Epic_kernel>>
|
||||
principal_curvatures_and_directions_map;
|
||||
|
||||
boost::tie(principal_curvatures_and_directions_map, created) =
|
||||
smesh.add_property_map<vertex_descriptor, PMP::Principal_curvatures_and_directions<Epic_kernel>>
|
||||
("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;
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
|
||||
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
|
||||
#include <CGAL/Polygon_mesh_processing/border.h>
|
||||
#include <CGAL/Polygon_mesh_processing/interpolated_corrected_curvatures.h>
|
||||
#include <CGAL/subdivision_method_3.h>
|
||||
|
||||
#include <CGAL/Point_set_3/IO.h>
|
||||
|
|
@ -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 <typename PolygonMesh, /*ClusteringMetric,*/
|
||||
typename NamedParameters = parameters::Default_named_parameters>
|
||||
PolygonMesh acvd_simplification(
|
||||
|
|
@ -138,6 +142,10 @@ PolygonMesh acvd_simplification(
|
|||
typedef typename boost::property_map<PolygonMesh, CGAL::dynamic_vertex_property_t<int> >::type VertexClusterMap;
|
||||
typedef typename boost::property_map<PolygonMesh, CGAL::dynamic_vertex_property_t<typename GT::FT> >::type VertexWeightMap;
|
||||
typedef typename boost::property_map<PolygonMesh, CGAL::dynamic_halfedge_property_t<bool> >::type HalfedgeVisitedMap;
|
||||
typedef Constant_property_map<Vertex_descriptor, Principal_curvatures_and_directions<GT>> Default_principal_map;
|
||||
typedef typename internal_np::Lookup_named_param_def<internal_np::vertex_principal_curvatures_and_directions_map_t,
|
||||
NamedParameters,
|
||||
Default_principal_map>::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<NamedParameters, internal_np::vertex_principal_curvatures_and_directions_map_t>::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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue