From 62a64ae870dc2832dcfdc97d33cef64e1ecc4485 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 12 Dec 2023 09:28:01 +0000 Subject: [PATCH] Add check that it faces are triangles --- .../sample_example.cpp | 7 +++-- .../CGAL/Polygon_mesh_processing/distance.h | 4 +-- .../Point_set_from_sampling_plugin.cpp | 29 +++++++++++++++---- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/sample_example.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/sample_example.cpp index 474af00a16c5..113845a9cb6b 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/sample_example.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/sample_example.cpp @@ -34,7 +34,9 @@ int main(int argc, char* argv[]) std::vector points; - PMP::sample_triangle_mesh(mesh, std::back_inserter(points), CGAL::parameters::number_of_points_per_face(points_per_face)); + PMP::sample_triangle_mesh(mesh, + std::back_inserter(points), + CGAL::parameters::number_of_points_per_face(points_per_face)); std::cout.precision(17); for(const Point& p : points){ @@ -43,8 +45,7 @@ int main(int argc, char* argv[]) Point_set point_set; PMP::sample_triangle_mesh(mesh, - point_set.point_back_inserter(), - CGAL::parameters::point_map(point_set.point_push_map())); + point_set.point_back_inserter()); std::cout << point_set.number_of_points() << std::endl; return 0; 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 8b41ff2ecdb7..b3aaf70604f6 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h @@ -747,7 +747,7 @@ struct Triangle_structure_sampler_for_triangle_soup * @tparam TriangleMesh a model of the concepts `EdgeListGraph` and `FaceListGraph` * @tparam PointOutputIterator a model of `OutputIterator` * holding objects of the same point type as - * the value type of the point type associated to the mesh `tm`, i.e. the value type of the vertex + * the value type of the point type associated to the mesh `tm`, i.e., the value type of the vertex * point map property map, if provided, or the value type of the internal point property map otherwise * @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * @@ -1570,7 +1570,7 @@ bounded_error_squared_Hausdorff_distance_impl(const TriangleMesh1& tm1, candidate_triangles.pop(); // Only process the triangle if it can contribute to the Hausdorff distance, - // i.e. if its upper bound is higher than the currently known best lower bound + // i.e., if its upper bound is higher than the currently known best lower bound // and the difference between the bounds to be obtained is larger than the // user-given error. const auto& triangle_bounds = triangle_and_bounds.bounds; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Point_set_from_sampling_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Point_set_from_sampling_plugin.cpp index 8075bb003f13..33c07c12ec46 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Point_set_from_sampling_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Point_set_from_sampling_plugin.cpp @@ -1,3 +1,5 @@ + +#include #include #include #include @@ -14,6 +16,7 @@ #include "Messages_interface.h" #include +#include using namespace CGAL::Three; class Polyhedron_demo_point_set_from_sampling_plugin : @@ -52,7 +55,7 @@ void Polyhedron_demo_point_set_from_sampling_plugin::init(QMainWindow* mainWindo Messages_interface*) { scene = scene_interface; - actionPointSetFromSampling = new QAction(tr("&Create Point Set from Sampling"), mainWindow); + actionPointSetFromSampling = new QAction(tr("Create Point Set from Sampling"), mainWindow); actionPointSetFromSampling->setObjectName("actionPointSetFromSampling"); connect(actionPointSetFromSampling, SIGNAL(triggered()), this, SLOT(createPointSet())); @@ -75,18 +78,24 @@ void Polyhedron_demo_point_set_from_sampling_plugin::createPointSet() if (points){ points->setColor(Qt::blue); }else{ + QApplication::restoreOverrideCursor(); return; } Scene_surface_mesh_item* sm_item = qobject_cast(scene->item(index)); if (sm_item){ + if(! CGAL::is_triangle_mesh(*sm_item->polyhedron())){ + CGAL::Three::Three::error(QString("The mesh must have triangle faces")); + QApplication::restoreOverrideCursor(); + return; + } int nf = num_faces(*sm_item->polyhedron()); bool ok; int nb = 0; nb = QInputDialog::getInt(QApplication::activeWindow(), "Sampling", - "Enter number of sample points:", + "Number of sample points:", nf , 0, (std::numeric_limits::max)(), 1, &ok); points->setName(QString("%1 (sampled)").arg(sm_item->name())); @@ -95,9 +104,9 @@ void Polyhedron_demo_point_set_from_sampling_plugin::createPointSet() CGAL::Polygon_mesh_processing::sample_triangle_mesh(*sm_item->polyhedron(), points->point_set()->point_back_inserter(), CGAL::parameters::number_of_points_on_faces(nb) - .point_map(points->point_set()->point_push_map()) .do_sample_vertices(false) .do_sample_edges(false)); + scene->addItem(points); } } @@ -107,10 +116,18 @@ void Polyhedron_demo_point_set_from_sampling_plugin::createPointSet() if (soup_item){ int nf = soup_item->polygons().size(); + for(const auto& f : soup_item->polygons()){ + if(f.size() != 3){ + CGAL::Three::Three::error(QString("The polygons must be triangles")); + QApplication::restoreOverrideCursor(); + return; + } + } + bool ok; int nb = 0; nb = QInputDialog::getInt(QApplication::activeWindow(), "Sampling", - "Enter number of sample points:", + "Number of sample points:", nf , 0, (std::numeric_limits::max)(), 1, &ok); points->setName(QString("%1 (sampled)").arg(soup_item->name())); if( ok & (nb > 0)){ @@ -119,13 +136,13 @@ void Polyhedron_demo_point_set_from_sampling_plugin::createPointSet() soup_item->polygons(), points->point_set()->point_back_inserter(), CGAL::parameters::number_of_points_on_faces(nb) - .point_map(points->point_set()->point_push_map()) .do_sample_vertices(false) .do_sample_edges(false)); + scene->addItem(points); } } - scene->addItem(points); + QApplication::restoreOverrideCursor(); }