diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt index 448ac468466..c9ee41b3ab1 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt @@ -58,7 +58,7 @@ target_link_libraries(point_inside_polyhedron_plugin scene_polyhedron_item scene qt5_wrap_ui( polyhedron_slicerUI_FILES Polyhedron_slicer_widget.ui) polyhedron_demo_plugin(polyhedron_slicer_plugin Polyhedron_slicer_plugin ${polyhedron_slicerUI_FILES}) -target_link_libraries(polyhedron_slicer_plugin scene_polyhedron_item scene_basic_objects scene_polylines_item) +target_link_libraries(polyhedron_slicer_plugin scene_polyhedron_item scene_surface_mesh_item scene_basic_objects scene_polylines_item) polyhedron_demo_plugin(polyhedron_stitching_plugin Polyhedron_stitching_plugin) target_link_libraries(polyhedron_stitching_plugin scene_polyhedron_item scene_polylines_item) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Polyhedron_slicer_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Polyhedron_slicer_plugin.cpp index 53b059bed4a..251f84e49bd 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Polyhedron_slicer_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Polyhedron_slicer_plugin.cpp @@ -4,6 +4,7 @@ #include "Messages_interface.h" #include "Scene_plane_item.h" #include "Scene_polyhedron_item.h" +#include "Scene_surface_mesh_item.h" #include "Scene_polylines_item.h" #include "Scene.h" @@ -36,7 +37,12 @@ class Polyhedron_demo_polyhedron_slicer_plugin : Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: - bool applicable(QAction*) const { return qobject_cast(scene->item(scene->mainSelectionIndex())); } + bool applicable(QAction*) const + { + return qobject_cast(scene->item(scene->mainSelectionIndex())) || + qobject_cast(scene->item(scene->mainSelectionIndex())); + } + void print_message(QString message) { messages->information(message);} void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface* m); @@ -83,7 +89,8 @@ private: QDockWidget* dock_widget; Ui::Polyhedron_slicer ui_widget; - void intersection_of_plane_Polyhedra_3_using_AABB_wrapper(Polyhedron& mesh, + template + void intersection_of_plane_Polyhedra_3_using_AABB_wrapper(TriangleMesh& mesh, const std::vector& planes, const std::vector& plane_positions, std::list >& polylines); @@ -213,10 +220,12 @@ bool Polyhedron_demo_polyhedron_slicer_plugin::on_Update_plane_button_clicked() void Polyhedron_demo_polyhedron_slicer_plugin::on_Generate_button_clicked() { Scene_polyhedron_item* item = getSelectedItem(); - if(!item) { + Scene_surface_mesh_item* sm_item = getSelectedItem(); + if(!item && ! sm_item) { print_message("Error: There is no selected Scene_polyhedron_item!"); return; } + QString item_name = (item)?item->name() : sm_item->name(); if(!on_Update_plane_button_clicked()) { return; } const qglviewer::Vec offset = static_cast(QGLViewer::QGLViewerPool().first())->offset(); @@ -246,10 +255,11 @@ void Polyhedron_demo_polyhedron_slicer_plugin::on_Generate_button_clicked() } // construct a bbox for selected polyhedron - const CGAL::Three::Scene_interface::Bbox& bbox = item->bbox(); + const CGAL::Three::Scene_interface::Bbox& bbox = (item)?item->bbox(): sm_item->bbox(); CGAL::Bbox_3 cgal_bbox(bbox.xmin(), bbox.ymin(), bbox.zmin(), bbox.xmax(), bbox.ymax(), bbox.zmax()); - Polyhedron* poly = item->polyhedron(); + Polyhedron* poly = (item)?item->polyhedron():NULL; + Scene_surface_mesh_item::SMesh* smesh = (sm_item)?sm_item->polyhedron():NULL; // continue generating planes while inside bbox std::vector planes; @@ -283,13 +293,17 @@ void Polyhedron_demo_polyhedron_slicer_plugin::on_Generate_button_clicked() Scene_polylines_item* new_polylines_item = new Scene_polylines_item(); QTime time; time.start(); // call algorithm and fill polylines in polylines_item - intersection_of_plane_Polyhedra_3_using_AABB_wrapper(*poly, planes, plane_positions, new_polylines_item->polylines); + if(item){ + intersection_of_plane_Polyhedra_3_using_AABB_wrapper(*poly, planes, plane_positions, new_polylines_item->polylines); + }else{ + intersection_of_plane_Polyhedra_3_using_AABB_wrapper(*smesh, planes, plane_positions, new_polylines_item->polylines); + } // set names etc and print timing print_message( QString("Done: processed %1 cuts - generated %2 polylines in %3 ms!"). arg(planes.size()).arg(new_polylines_item->polylines.size()).arg(time.elapsed()) ); new_polylines_item->setName(QString("%1 with %2 cuts"). - arg(item->name()).arg(planes.size()) ); + arg(item_name).arg(planes.size()) ); new_polylines_item->setColor(Qt::green); new_polylines_item->setRenderingMode(Wireframe); scene->addItem(new_polylines_item); @@ -308,7 +322,7 @@ void Polyhedron_demo_polyhedron_slicer_plugin::on_Generate_button_clicked() Scene_polylines_item* new_polylines_item = new Scene_polylines_item(); new_polylines_item->polylines.push_back(*it); new_polylines_item->setName(QString("%1 with %2 cuts %3"). - arg(item->name()).arg(planes.size()).arg(counter) ); + arg(item_name).arg(planes.size()).arg(counter) ); new_polylines_item->setColor(Qt::green); new_polylines_item->setRenderingMode(Wireframe); scene->addItem(new_polylines_item); @@ -334,13 +348,14 @@ void Polyhedron_demo_polyhedron_slicer_plugin::dock_widget_closed() { scene->erase(id); } // this function assumes 'planes' are parallel +template void Polyhedron_demo_polyhedron_slicer_plugin::intersection_of_plane_Polyhedra_3_using_AABB_wrapper( - Polyhedron& poly, + TriangleMesh& poly, const std::vector& planes, const std::vector& plane_positions, std::list >& polylines) { - CGAL::Polygon_mesh_slicer slicer(poly); + CGAL::Polygon_mesh_slicer slicer(poly); std::vector::const_iterator plane_position_it = plane_positions.begin(); for(std::vector::const_iterator plane_it = planes.begin(); plane_it != planes.end(); ++plane_it, ++plane_position_it) slicer(*plane_it, std::front_inserter(polylines));