make it work with Polyhedron

This commit is contained in:
Sébastien Loriot 2025-03-19 19:47:08 +01:00
parent 2e070b304a
commit 8abe5b0c23
3 changed files with 51 additions and 22 deletions

View File

@ -399,7 +399,7 @@ acvd_impl(TriangleMesh& tmesh,
using Matrix4x4 = typename Eigen::Matrix<FT, 4, 4>;
using Vertex_position_map = typename GetVertexPointMap<TriangleMesh, NamedParameters>::const_type;
using Vertex_position_map = typename GetVertexPointMap<TriangleMesh, NamedParameters>::type;
using halfedge_descriptor = typename boost::graph_traits<TriangleMesh>::halfedge_descriptor;
using edge_descriptor = typename boost::graph_traits<TriangleMesh>::edge_descriptor;
@ -635,17 +635,48 @@ acvd_impl(TriangleMesh& tmesh,
// randomly initialize clusters
//TODO: (possible optimization) use std::lower_bound with vertex_weight_pmap for better sampling
// moreover with non-random access iterators, the complexity will be bad
static constexpr bool is_rand_access =
std::is_same_v<typename std::iterator_traits<decltype(vertices(tmesh).begin())>::iterator_category,
std::random_access_iterator_tag>;
std::vector<vertex_descriptor> cluster_vertices;
cluster_vertices.reserve(nb_clusters);
if constexpr (is_rand_access)
{
for (int ci = 0; ci < nb_clusters; ++ci)
{
int vi;
vertex_descriptor vd;
do {
vi = rnd.get_int(0, nb_vertices);
vd = *std::next(vertices(tmesh).begin(), vi);
} while (get(vertex_cluster_pmap, vd) != -1);
cluster_vertices.push_back(vd);
put(vertex_cluster_pmap, vd, ci);
}
}
else
{
std::vector<vertex_descriptor> verts;
verts.reserve(num_vertices(tmesh));
verts.assign(vertices(tmesh).begin(), vertices(tmesh).end());
for (int ci = 0; ci < nb_clusters; ++ci)
{
vertex_descriptor vd;
do {
vd = verts[rnd.get_int(0, nb_vertices)];
} while (get(vertex_cluster_pmap, vd) != -1);
cluster_vertices.push_back(vd);
put(vertex_cluster_pmap, vd, ci);
}
}
for (int ci = 0; ci < nb_clusters; ++ci)
{
int vi;
vertex_descriptor vd;
do {
vi = rnd.get_int(0, nb_vertices);
vd = *(vertices(tmesh).begin() + vi);
} while (get(vertex_cluster_pmap, vd) != -1);
put(vertex_cluster_pmap, vd, ci);
vertex_descriptor vd=cluster_vertices[ci];
Point_3 vp = get(vpm, vd);
Vector_3 vpv = vp - ORIGIN;
clusters[ci].add_vertex(vpv, get(vertex_weight_pmap, vd), get(vertex_quadric_pmap, vd));
@ -1273,7 +1304,7 @@ acvd_impl(TriangleMesh& tmesh,
*
* performs Approximated Centroidal Voronoi Diagram (ACVD) remeshing on a triangle mesh. The remeshing is either uniform or adaptative.
* Note that there is no guarantee that the output mesh will have the same topology as the input.
* See \ref acvdrem for more details on the algorithm. This function required the \eigen library.
* See \ref acvdrem for more details on the algorithm. This function requires the \eigen library.
*
* @tparam TriangleMesh a model of `FaceListGraph` and `MutableFaceGraph`
* @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters".

View File

@ -622,7 +622,7 @@ void interpolated_corrected_curvatures_one_vertex(
using parameters::get_parameter;
using parameters::is_default_parameter;
Vertex_position_map vpm = choose_parameter(get_parameter(np, CGAL::vertex_point),
Vertex_position_map vpm = choose_parameter(get_parameter(np, internal_np::vertex_point),
get_const_property_map(CGAL::vertex_point, pmesh));
Vertex_normal_map vnm = choose_parameter(get_parameter(np, internal_np::vertex_normal_map),
@ -773,7 +773,7 @@ private:
using parameters::get_parameter;
using parameters::is_default_parameter;
vpm = choose_parameter(get_parameter(np, CGAL::vertex_point),
vpm = choose_parameter(get_parameter(np, internal_np::vertex_point),
get_const_property_map(CGAL::vertex_point, pmesh));
vnm = choose_parameter(get_parameter(np, internal_np::vertex_normal_map),

View File

@ -2,6 +2,7 @@
#include <CGAL/Polygon_mesh_processing/approximated_centroidal_Voronoi_diagram_remeshing.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Polygon_mesh_processing/bbox.h>
@ -13,11 +14,12 @@
namespace PMP = CGAL::Polygon_mesh_processing;
using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Mesh = CGAL::Surface_mesh<K::Point_3>;
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
using Surface_mesh = CGAL::Surface_mesh<K::Point_3>;
using Polyhedron = CGAL::Polyhedron_3<K>;
namespace params = CGAL::parameters;
template <class Mesh>
void run_test(std::string fname, std::size_t genus)
{
Mesh mesh;
@ -44,19 +46,15 @@ void run_test(std::string fname, std::size_t genus)
assert(std::abs(bb.ymax()-bb_ref.ymax()) < 0.01 * dy);
assert(std::abs(bb.zmax()-bb_ref.zmax()) < 0.01 * dz);
std::ofstream("/tmp/out_"+std::to_string(genus)+".off") << mesh;
PMP::approximated_centroidal_Voronoi_diagram_remeshing(mesh, 4);
assert(-(vertices(mesh).size()-edges(mesh).size()+faces(mesh).size()-2)/2==genus);
std::ofstream("/tmp/min_out_"+std::to_string(genus)+".off") << mesh;
}
int main()
{
run_test(CGAL::data_file_path("meshes/tetrahedron.off"), 0);
run_test(CGAL::data_file_path("meshes/torus_quad.off"), 1);
run_test(CGAL::data_file_path("meshes/double-torus-example.off"), 2);
run_test<Surface_mesh>(CGAL::data_file_path("meshes/tetrahedron.off"), 0);
run_test<Polyhedron>(CGAL::data_file_path("meshes/torus_quad.off"), 1);
run_test<Surface_mesh>(CGAL::data_file_path("meshes/double-torus-example.off"), 2);
return 0;
}