diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt index 2cf56fecfdf..b5b28bcc402 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/CMakeLists.txt @@ -61,7 +61,7 @@ polyhedron_demo_plugin(polyhedron_slicer_plugin Polyhedron_slicer_plugin ${polyh 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) +target_link_libraries(polyhedron_stitching_plugin scene_polyhedron_item scene_surface_mesh_item scene_polylines_item) qt5_wrap_ui( selectionUI_FILES Selection_widget.ui) polyhedron_demo_plugin(selection_plugin Selection_plugin ${selectionUI_FILES}) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Polyhedron_stitching_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Polyhedron_stitching_plugin.cpp index 0975d502f98..f9b205d32d3 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Polyhedron_stitching_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Polyhedron_stitching_plugin.cpp @@ -4,6 +4,7 @@ #include "Kernel_type.h" #include "Polyhedron_type.h" #include "Scene_polyhedron_item.h" +#include "Scene_surface_mesh_item.h" #include "Scene_polylines_item.h" #include @@ -62,12 +63,19 @@ public: bool applicable(QAction*) const { Q_FOREACH(int index, scene->selectionIndices()) { - if ( qobject_cast(scene->item(index)) ) + if ( qobject_cast(scene->item(index)) || + qobject_cast(scene->item(index)) ) return true; } return false; } + template + void on_actionDetectBorders_triggered(Scene_interface::Item_id index); + + template + void on_actionStitchBorders_triggered(Scene_interface::Item_id index); + public Q_SLOTS: void on_actionDetectBorders_triggered(); void on_actionStitchBorders_triggered(); @@ -75,13 +83,14 @@ public Q_SLOTS: }; // end Polyhedron_demo_polyhedron_stitching_plugin - +template struct Polyline_visitor { Scene_polylines_item* new_item; + typename boost::property_map::const_type vpm; - Polyline_visitor(Scene_polylines_item* new_item) - : new_item(new_item) + Polyline_visitor(const Poly& poly, Scene_polylines_item* new_item) + : new_item(new_item), vpm(get(CGAL::vertex_point,poly)) {} void start_new_polyline() @@ -89,79 +98,82 @@ struct Polyline_visitor new_item->polylines.push_back( Scene_polylines_item::Polyline() ); } - void add_node(boost::graph_traits::vertex_descriptor vd) + void add_node(typename boost::graph_traits::vertex_descriptor vd) { - new_item->polylines.back().push_back(vd->point()); + + new_item->polylines.back().push_back(get(vpm,vd)); } + void end_polyline(){} }; -void Polyhedron_demo_polyhedron_stitching_plugin::on_actionDetectBorders_triggered() -{ - Q_FOREACH(int index, scene->selectionIndices()) - { - Scene_polyhedron_item* item = - qobject_cast(scene->item(index)); - if(item) +template +void Polyhedron_demo_polyhedron_stitching_plugin::on_actionDetectBorders_triggered(Scene_interface::Item_id index) +{ + typedef typename Item::FaceGraph FaceGraph; + Item* item = qobject_cast(scene->item(index)); + + if(item) { Scene_polylines_item* new_item = new Scene_polylines_item(); - Polyhedron* pMesh = item->polyhedron(); - pMesh->normalize_border(); + FaceGraph* pMesh = item->polyhedron(); + normalize_border(*pMesh); -#if 0 - for (Polyhedron::Halfedge_iterator - it=pMesh->border_halfedges_begin(), it_end=pMesh->halfedges_end(); - it!=it_end; ++it) - { - if (!it->is_border()) continue; - /// \todo build cycles and graph with nodes of valence 2. - new_item->polylines.push_back( Scene_polylines_item::Polyline() ); - new_item->polylines.back().push_back( it->opposite()->vertex()->point() ); - new_item->polylines.back().push_back( it->vertex()->point() ); - } -#else - typedef boost::filtered_graph, Is_border > BorderGraph; + + typedef boost::filtered_graph, Is_border > BorderGraph; - Is_border ib(*pMesh); + Is_border ib(*pMesh); BorderGraph bg(*pMesh,ib,ib); - Polyline_visitor polyline_visitor(new_item); + Polyline_visitor polyline_visitor(*pMesh, new_item); CGAL::split_graph_into_polylines( bg, polyline_visitor, CGAL::internal::IsTerminalDefault() ); -#endif + if (new_item->polylines.empty()) - { - delete new_item; - } + { + delete new_item; + } else - { - new_item->setName(tr("Boundary of %1").arg(item->name())); - new_item->setColor(Qt::red); - scene->addItem(new_item); - new_item->invalidateOpenGLBuffers(); - } + { + new_item->setName(tr("Boundary of %1").arg(item->name())); + new_item->setColor(Qt::red); + scene->addItem(new_item); + new_item->invalidateOpenGLBuffers(); + } } +} + +void Polyhedron_demo_polyhedron_stitching_plugin::on_actionDetectBorders_triggered() +{ + Q_FOREACH(int index, scene->selectionIndices()){ + on_actionDetectBorders_triggered(index); + on_actionDetectBorders_triggered(index); } } +template +void Polyhedron_demo_polyhedron_stitching_plugin::on_actionStitchBorders_triggered(Scene_interface::Item_id index) +{ + Item* item = + qobject_cast(scene->item(index)); + + if(item){ + typename Item::FaceGraph* pMesh = item->polyhedron(); + CGAL::Polygon_mesh_processing::stitch_borders(*pMesh); + item->invalidateOpenGLBuffers(); + scene->itemChanged(item); + } +} + + void Polyhedron_demo_polyhedron_stitching_plugin::on_actionStitchBorders_triggered() { - Q_FOREACH(int index, scene->selectionIndices()) - { - Scene_polyhedron_item* item = - qobject_cast(scene->item(index)); - - if(item) - { - Polyhedron* pMesh = item->polyhedron(); - CGAL::Polygon_mesh_processing::stitch_borders(*pMesh); - item->invalidateOpenGLBuffers(); - scene->itemChanged(item); - } + Q_FOREACH(int index, scene->selectionIndices()){ + on_actionStitchBorders_triggered(index); + on_actionStitchBorders_triggered(index); } } - #include "Polyhedron_stitching_plugin.moc" diff --git a/Polyhedron/include/CGAL/boost/graph/graph_traits_Polyhedron_3.h b/Polyhedron/include/CGAL/boost/graph/graph_traits_Polyhedron_3.h index 661ceada703..69cdfdc1f67 100644 --- a/Polyhedron/include/CGAL/boost/graph/graph_traits_Polyhedron_3.h +++ b/Polyhedron/include/CGAL/boost/graph/graph_traits_Polyhedron_3.h @@ -462,6 +462,13 @@ bool is_valid(const CGAL::Polyhedron_3& p, bool verbose = false) { return p.is_valid(verbose); } + +template +void normalize_border(CGAL::Polyhedron_3& p) +{ + p.normalize_border(); +} + } // namespace CGAL diff --git a/Surface_mesh/include/CGAL/boost/graph/graph_traits_Surface_mesh.h b/Surface_mesh/include/CGAL/boost/graph/graph_traits_Surface_mesh.h index df181424ec7..b9ebdec62e6 100644 --- a/Surface_mesh/include/CGAL/boost/graph/graph_traits_Surface_mesh.h +++ b/Surface_mesh/include/CGAL/boost/graph/graph_traits_Surface_mesh.h @@ -517,6 +517,10 @@ bool is_valid(const CGAL::Surface_mesh

& sm, bool verbose = false) return sm.is_valid(verbose); } +template +void normalize_border(const CGAL::Surface_mesh

& sm) +{} + } // namespace CGAL #endif // CGAL_BOOST_GRAPH_TRAITS_SURFACE_MESH_H