From c6b9a282eea88d0f1be0afe2d98f769a69ebde4c Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 15 Feb 2018 15:15:06 +0100 Subject: [PATCH] Add an action to create a polyline from non manifold edges of a soup. --- .../Polyhedron/Plugins/PMP/CMakeLists.txt | 2 +- .../Plugins/PMP/Orient_soup_plugin.cpp | 37 +++++++++++++++++++ .../Polyhedron/Scene_polygon_soup_item.cpp | 6 +++ .../demo/Polyhedron/Scene_polygon_soup_item.h | 2 + 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt index bde2ed1888e..a485fbc1d35 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt @@ -39,7 +39,7 @@ endif() polyhedron_demo_plugin(orient_soup_plugin Orient_soup_plugin) -target_link_libraries(orient_soup_plugin PUBLIC scene_polygon_soup_item scene_polyhedron_item scene_surface_mesh_item) +target_link_libraries(orient_soup_plugin PUBLIC scene_polygon_soup_item scene_polyhedron_item scene_surface_mesh_item scene_polylines_item) polyhedron_demo_plugin(inside_out_plugin Inside_out_plugin) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Orient_soup_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Orient_soup_plugin.cpp index a41e9b55b26..08d969bdb84 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Orient_soup_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Orient_soup_plugin.cpp @@ -7,6 +7,7 @@ #include "Scene_polygon_soup_item.h" #include "Scene_polyhedron_item.h" +#include "Scene_polylines_item.h" #include "Scene_surface_mesh_item.h" #include @@ -45,6 +46,7 @@ public Q_SLOTS: void orientSM(); void shuffle(); void displayNonManifoldEdges(); + void createPolyline(); private: template @@ -56,6 +58,7 @@ private: QAction* actionOrientPoly; QAction* actionOrientSM; QAction* actionShuffle; + QAction* actionNMToPolyline; QAction* actionDisplayNonManifoldEdges; }; // end Polyhedron_demo_orient_soup_plugin @@ -88,6 +91,10 @@ void Polyhedron_demo_orient_soup_plugin::init(QMainWindow* mainWindow, actionDisplayNonManifoldEdges->setProperty("subMenuName", "View"); connect(actionDisplayNonManifoldEdges, SIGNAL(triggered()), this, SLOT(displayNonManifoldEdges())); + actionNMToPolyline = new QAction(tr("Non Manifold Edges to Polyline"), mainWindow); + actionNMToPolyline->setProperty("subMenuName", "Polygon Mesh Processing"); + connect(actionNMToPolyline, &QAction::triggered, + this, &Polyhedron_demo_orient_soup_plugin::createPolyline); } QList Polyhedron_demo_orient_soup_plugin::actions() const { @@ -95,6 +102,7 @@ QList Polyhedron_demo_orient_soup_plugin::actions() const { << actionOrientPoly << actionOrientSM << actionShuffle + << actionNMToPolyline << actionDisplayNonManifoldEdges; } @@ -271,5 +279,34 @@ void Polyhedron_demo_orient_soup_plugin::displayNonManifoldEdges() QApplication::restoreOverrideCursor(); } } +void Polyhedron_demo_orient_soup_plugin::createPolyline() +{ + const CGAL::Three::Scene_interface::Item_id index = scene->mainSelectionIndex(); + + Scene_polygon_soup_item* item = + qobject_cast(scene->item(index)); + + if(item) + { + QApplication::setOverrideCursor(Qt::WaitCursor); + Scene_polylines_item* poly = + new Scene_polylines_item(); + Polygon_soup::Edges nm_edges = item->non_manifold_edges(); + BOOST_FOREACH(Polygon_soup::Edge edge, nm_edges) + { + Point_3 a(item->points()[edge[0]]), b(item->points()[edge[1]]); + Scene_polylines_item::Polyline new_edge; + new_edge.push_back(a); + new_edge.push_back(b); + poly->polylines.push_back(new_edge); + } + poly->setName(QString("Non Manifold Edges of %1").arg(item->name())); + poly->setColor(QColor(Qt::red)); + + scene->addItem(poly); + QApplication::restoreOverrideCursor(); + } +} #include "Orient_soup_plugin.moc" + diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index fc648cfd220..456c6660080 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -920,3 +920,9 @@ void Scene_polygon_soup_item::itemAboutToBeDestroyed(Scene_item *item) } } } + +const Polygon_soup::Edges& +Scene_polygon_soup_item::non_manifold_edges() const +{ + return d->soup->non_manifold_edges; +} \ No newline at end of file diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h index 792c2a5ea5e..5a5a741b7eb 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h @@ -108,6 +108,7 @@ public: typedef Kernel::Point_3 Point_3; typedef Polygon_soup::Points Points; typedef Polygon_soup::Polygons Polygons; + typedef Polygon_soup::Edges Edges; Scene_polygon_soup_item(); ~Scene_polygon_soup_item(); @@ -151,6 +152,7 @@ public: const Points& points() const; const Polygons& polygons() const; + const Edges& non_manifold_edges() const; public Q_SLOTS: void shuffle_orientations();