diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt index adcd4f7f02b..9503348b9b7 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt @@ -100,7 +100,7 @@ add_custom_target(self_intersection_plugin) add_dependencies(self_intersection_plugin selection_plugin) polyhedron_demo_plugin(triangulate_facets_plugin Triangulate_facets_plugin KEYWORDS PMP) -target_link_libraries(triangulate_facets_plugin PUBLIC scene_surface_mesh_item scene_selection_item) +target_link_libraries(triangulate_facets_plugin PUBLIC scene_surface_mesh_item scene_selection_item scene_polygon_soup_item) polyhedron_demo_plugin(corefinement_plugin Corefinement_plugin KEYWORDS PMP) target_link_libraries(corefinement_plugin PUBLIC scene_surface_mesh_item) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Triangulate_facets_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Triangulate_facets_plugin.cpp index c342e536ff2..6b85c6fb45b 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Triangulate_facets_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Triangulate_facets_plugin.cpp @@ -4,10 +4,13 @@ #include "Messages_interface.h" #include #include + #include "Scene_surface_mesh_item.h" #include "Scene_polyhedron_selection_item.h" +#include "Scene_polygon_soup_item.h" #include + using namespace CGAL::Three; class Polyhedron_demo_triangulate_facets_plugin : public QObject, @@ -20,13 +23,13 @@ class Polyhedron_demo_triangulate_facets_plugin : typedef Scene_surface_mesh_item::Face_graph FaceGraph; typedef boost::graph_traits::face_descriptor face_descriptor; - struct Visitor + struct Selection_updater_visitor : public CGAL::Polygon_mesh_processing::Hole_filling::Default_visitor { typedef typename Scene_polyhedron_selection_item::Selection_set_facet Container; Container& faces; - Visitor(Container& container) + Selection_updater_visitor(Container& container) : faces(container) {} void before_subface_creations(face_descriptor fd) @@ -67,6 +70,8 @@ public: return true; if ( qobject_cast(scene->item(index))) return true; + if(qobject_cast(scene->item(index))) + return true; } return false; } @@ -83,39 +88,54 @@ public Q_SLOTS: Scene_polyhedron_selection_item* selection_item = qobject_cast(scene->item(index)); - SMesh* pMesh = (sm_item != nullptr) - ? sm_item->polyhedron() - : selection_item->polyhedron(); + Scene_polygon_soup_item* soup_item = + qobject_cast(scene->item(index)); - if(!pMesh) continue; - if(is_triangle_mesh(*pMesh)) { - CGAL::Three::Three::warning(tr("The polyhedron \"%1\" is already triangulated.") - .arg(sm_item->name()) ); - continue; - } - if (sm_item) + if (soup_item) { - if (!CGAL::Polygon_mesh_processing::triangulate_faces(*pMesh)) - CGAL::Three::Three::warning(tr("Some facets could not be triangulated.")); + soup_item->triangulate(); } - else if (selection_item) + else { - Visitor visitor(selection_item->selected_facets); - if (!CGAL::Polygon_mesh_processing::triangulate_faces( - selection_item->selected_facets, - *pMesh, - CGAL::parameters::visitor(visitor))) - CGAL::Three::Three::warning(tr("Some facets could not be triangulated.")); + SMesh* pMesh = (sm_item != nullptr) ? sm_item->polyhedron() + : selection_item->polyhedron(); - sm_item = selection_item->polyhedron_item(); - selection_item->set_num_faces(num_faces(*sm_item->face_graph())); + if(!pMesh) + continue; - selection_item->invalidateOpenGLBuffers(); - selection_item->itemChanged(); + if(is_triangle_mesh(*pMesh)) + { + CGAL::Three::Three::warning(tr("The polyhedron \"%1\" is already triangulated.") + .arg(sm_item->name()) ); + continue; + } + + if (sm_item) + { + if (!CGAL::Polygon_mesh_processing::triangulate_faces(*pMesh)) + CGAL::Three::Three::warning(tr("Some facets could not be triangulated.")); + + sm_item->invalidateOpenGLBuffers(); + } + else if (selection_item) + { + Selection_updater_visitor visitor(selection_item->selected_facets); + if (!CGAL::Polygon_mesh_processing::triangulate_faces( + selection_item->selected_facets, + *pMesh, + CGAL::parameters::visitor(visitor))) + CGAL::Three::Three::warning(tr("Some facets could not be triangulated.")); + + sm_item = selection_item->polyhedron_item(); + selection_item->set_num_faces(num_faces(*sm_item->face_graph())); + + selection_item->invalidateOpenGLBuffers(); + selection_item->itemChanged(); + } + + sm_item->resetColors(); // @todo should have a visitor to give the color of the parent face } - sm_item->resetColors(); - sm_item->invalidateOpenGLBuffers(); scene->itemChanged(sm_item); } // end of the loop on the selected items diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index b258e0c5714..8ba8813f349 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -419,6 +420,32 @@ void Scene_polygon_soup_item::inside_out() invalidateOpenGLBuffers(); } +void Scene_polygon_soup_item::repair(bool erase_dup, bool req_same_orientation) +{ + QApplication::setOverrideCursor(Qt::BusyCursor); + CGAL::Polygon_mesh_processing::repair_polygon_soup( + d->soup->points, + d->soup->polygons, + CGAL::parameters::erase_all_duplicates(erase_dup) + .require_same_orientation(req_same_orientation)); + QApplication::restoreOverrideCursor(); + invalidateOpenGLBuffers(); +} + +bool Scene_polygon_soup_item::triangulate() +{ + QApplication::setOverrideCursor(Qt::BusyCursor); + + bool success = true; + + CGAL::Polygon_mesh_processing::triangulate_polygons(d->soup->points, d->soup->polygons); + + QApplication::restoreOverrideCursor(); + invalidateOpenGLBuffers(); + + return success; +} + bool Scene_polygon_soup_item::orient(std::vector& non_manifold_vertices) { @@ -894,20 +921,6 @@ void Scene_polygon_soup_item::computeElements() const QApplication::restoreOverrideCursor(); } -void Scene_polygon_soup_item::repair(bool erase_dup, bool req_same_orientation) -{ - QApplication::setOverrideCursor(Qt::BusyCursor); - CGAL::Polygon_mesh_processing::repair_polygon_soup( - d->soup->points, - d->soup->polygons, - CGAL::parameters:: - erase_all_duplicates(erase_dup) - .require_same_orientation(req_same_orientation)); - QApplication::restoreOverrideCursor(); - - // CGAL::Three::Three::information( -} - CGAL::Three::Scene_item::Header_data Scene_polygon_soup_item::header() const { CGAL::Three::Scene_item::Header_data data; diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h index 5dea8c11f02..9fd1aed124f 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h @@ -187,6 +187,7 @@ public Q_SLOTS: bool exportAsSurfaceMesh(SMesh*); void inside_out(); void repair(bool erase_dup, bool req_same_orientation); + bool triangulate(); void setDisplayNonManifoldEdges(const bool); bool displayNonManifoldEdges() const;