From db5738b3300a4b652db261ef2eb553eb8ded8b31 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 6 Mar 2017 17:11:47 +0100 Subject: [PATCH] PMP: Make triangulate faces work for Surface_mesh --- .../Polyhedron/Plugins/PMP/CMakeLists.txt | 2 +- .../Plugins/PMP/Triangulate_facets_plugin.cpp | 31 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt index e71da68a96d..1c573c0d911 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt @@ -76,7 +76,7 @@ polyhedron_demo_plugin(self_intersection_plugin Self_intersection_plugin) target_link_libraries(self_intersection_plugin scene_polyhedron_item scene_polyhedron_selection_item scene_surface_mesh_item) polyhedron_demo_plugin(triangulate_facets_plugin Triangulate_facets_plugin) -target_link_libraries(triangulate_facets_plugin scene_polyhedron_item) +target_link_libraries(triangulate_facets_plugin scene_polyhedron_item scene_surface_mesh_item) polyhedron_demo_plugin(corefinement_plugin Corefinement_plugin) target_link_libraries(corefinement_plugin scene_polyhedron_item) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Triangulate_facets_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Triangulate_facets_plugin.cpp index 74d9f62681c..b617f2fb714 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Triangulate_facets_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Triangulate_facets_plugin.cpp @@ -4,6 +4,7 @@ #include "Messages_interface.h" #include #include "Scene_polyhedron_item.h" +#include "Scene_surface_mesh_item.h" #include "Polyhedron_type.h" #include @@ -38,7 +39,8 @@ public: bool applicable(QAction*) const { Q_FOREACH(CGAL::Three::Scene_interface::Item_id index, scene->selectionIndices()){ - if ( qobject_cast(scene->item(index)) ) + if ( qobject_cast(scene->item(index)) || + qobject_cast(scene->item(index)) ) return true; } return false; @@ -46,6 +48,7 @@ public: public Q_SLOTS: void triangulate() { + QApplication::setOverrideCursor(Qt::WaitCursor); Q_FOREACH(CGAL::Three::Scene_interface::Item_id index, scene->selectionIndices()) { Scene_polyhedron_item* item = @@ -61,7 +64,6 @@ public Q_SLOTS: continue; } - QApplication::setOverrideCursor(Qt::WaitCursor); if(!CGAL::Polygon_mesh_processing::triangulate_faces(*pMesh)) messages->warning(tr("Some facets could not be triangulated.")); @@ -71,11 +73,28 @@ public Q_SLOTS: item->invalidateOpenGLBuffers(); scene->itemChanged(item); - // default cursor - QApplication::restoreOverrideCursor(); - } // end of if(item) + + } else { + Scene_surface_mesh_item* sm_item = + qobject_cast(scene->item(index)); + Scene_surface_mesh_item::SMesh* pMesh = sm_item->polyhedron(); + if(!pMesh) continue; + if(is_triangle_mesh(*pMesh)) { + messages->warning(tr("The polyhedron \"%1\" is already triangulated.") + .arg(sm_item->name()) ); + continue; + } + if(!CGAL::Polygon_mesh_processing::triangulate_faces(*pMesh)) + messages->warning(tr("Some facets could not be triangulated.")); - } // end of the loop on the selected items + std::cerr << *pMesh << std::endl; + sm_item->invalidateOpenGLBuffers(); + scene->itemChanged(sm_item); + } // end of if(item) + } // end of the loop on the selected items + + // default cursor + QApplication::restoreOverrideCursor(); } private: