PMP: Make triangulate faces work for Surface_mesh

This commit is contained in:
Andreas Fabri 2017-03-06 17:11:47 +01:00 committed by Maxime Gimeno
parent 9b81b8969c
commit db5738b330
2 changed files with 26 additions and 7 deletions

View File

@ -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)

View File

@ -4,6 +4,7 @@
#include "Messages_interface.h"
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
#include "Scene_polyhedron_item.h"
#include "Scene_surface_mesh_item.h"
#include "Polyhedron_type.h"
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
@ -38,7 +39,8 @@ public:
bool applicable(QAction*) const {
Q_FOREACH(CGAL::Three::Scene_interface::Item_id index, scene->selectionIndices()){
if ( qobject_cast<Scene_polyhedron_item*>(scene->item(index)) )
if ( qobject_cast<Scene_polyhedron_item*>(scene->item(index)) ||
qobject_cast<Scene_surface_mesh_item*>(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_surface_mesh_item*>(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: