add plugin that implements the function in PMP/repair.h

Remove degenerate faces
Remove isolated vertices //does not work yet because
                           Polyhedron item discards them
This commit is contained in:
Jane Tournois 2015-08-11 12:52:08 +02:00
parent a45368680f
commit 3f7021f20b
2 changed files with 117 additions and 1 deletions

View File

@ -400,8 +400,11 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
polyhedron_demo_plugin(corefinement_plugin Polyhedron_demo_corefinement_plugin)
target_link_libraries(corefinement_plugin scene_polyhedron_item scene_combinatorial_map_item scene_polylines_item)
polyhedron_demo_plugin(trivial_plugin Polyhedron_demo_trivial_plugin)
polyhedron_demo_plugin(repair_polyhedron_plugin Polyhedron_demo_repair_polyhedron_plugin)
target_link_libraries(repair_polyhedron_plugin scene_polyhedron_item)
polyhedron_demo_plugin(trivial_plugin Polyhedron_demo_trivial_plugin)
# Edit polyhedron scene item and plugin
if ( EIGEN3_FOUND AND "${EIGEN3_VERSION}" VERSION_GREATER "3.1.90" )
qt5_wrap_ui( editionUI_FILES Deform_mesh.ui )

View File

@ -0,0 +1,113 @@
#include <QtCore/qglobal.h>
#include "Scene_polyhedron_item.h"
#include "Scene_interface.h"
#include "Polyhedron_type.h"
#include "Polyhedron_demo_plugin_interface.h"
#include "Polyhedron_demo_plugin_helper.h"
#include "Messages_interface.h"
#include <CGAL/gl.h>
#include <QAction>
#include <QMainWindow>
#include <QObject>
#include <CGAL/Polygon_mesh_processing/repair.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
class Polyhedron_demo_repair_polyhedron_plugin :
public QObject,
public Polyhedron_demo_plugin_helper
{
Q_OBJECT
Q_INTERFACES(Polyhedron_demo_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0")
public:
// To silent a warning -Woverloaded-virtual
// See http://stackoverflow.com/questions/9995421/gcc-woverloaded-virtual-warnings
using Polyhedron_demo_plugin_helper::init;
void init(QMainWindow* mainWindow,
Scene_interface* scene_interface,
Messages_interface* m)
{
this->scene = scene_interface;
this->mw = mainWindow;
this->messages = m;
actionRemoveIsolatedVertices = new QAction(tr("Remove isolated vertices"), mw);
if (actionRemoveIsolatedVertices){
connect(actionRemoveIsolatedVertices, SIGNAL(triggered()),
this, SLOT(on_actionRemoveIsolatedVertices_triggered()));
}
actionRemoveDegenerateFaces = new QAction(tr("Remove degenerate faces"), mw);
if (actionRemoveDegenerateFaces){
connect(actionRemoveDegenerateFaces, SIGNAL(triggered()),
this, SLOT(on_actionRemoveDegenerateFaces_triggered()));
}
}
QList<QAction*> actions() const
{
return QList<QAction*>() << actionRemoveIsolatedVertices
<< actionRemoveDegenerateFaces;
}
bool applicable(QAction*) const
{
int item_id = scene->mainSelectionIndex();
return qobject_cast<Scene_polyhedron_item*>(
scene->item(item_id));
}
public Q_SLOTS:
void on_actionRemoveIsolatedVertices_triggered();
void on_actionRemoveDegenerateFaces_triggered();
private:
QAction* actionRemoveIsolatedVertices;
QAction* actionRemoveDegenerateFaces;
Messages_interface* messages;
}; // end Polyhedron_demo_repair_polyhedron_plugin
void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveIsolatedVertices_triggered()
{
const Scene_interface::Item_id index = scene->mainSelectionIndex();
Scene_polyhedron_item* poly_item =
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
if (poly_item)
{
std::size_t nbv =
CGAL::Polygon_mesh_processing::remove_isolated_vertices(
*poly_item->polyhedron());
messages->information(tr(" %1 isolated vertices have been removed.")
.arg(nbv));
poly_item->changed();
}
}
void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveDegenerateFaces_triggered()
{
const Scene_interface::Item_id index = scene->mainSelectionIndex();
Scene_polyhedron_item* poly_item =
qobject_cast<Scene_polyhedron_item*>(scene->item(index));
if (poly_item)
{
std::size_t nbv =
CGAL::Polygon_mesh_processing::remove_degenerate_faces(
*poly_item->polyhedron());
messages->information(tr(" %1 degenerate faces have been removed.")
.arg(nbv));
poly_item->changed();
}
}
#include "Polyhedron_demo_repair_polyhedron_plugin.moc"