From fef75785cb4c89f7c2993f2193e2421dde7c24eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 14 Apr 2021 17:38:49 +0200 Subject: [PATCH] handle polyline to protect in offset meshing --- .../Plugins/Surface_mesh/CMakeLists.txt | 3 +- .../Surface_mesh/Offset_meshing_plugin.cpp | 118 +++++++++-- .../Plugins/Surface_mesh/Remeshing_dialog.ui | 198 ++++++++++-------- 3 files changed, 204 insertions(+), 115 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/CMakeLists.txt index 0591da9f770..04002c3e067 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/CMakeLists.txt @@ -36,7 +36,8 @@ if(NOT CGAL_DISABLE_GMP) polyhedron_demo_plugin(offset_meshing_plugin Offset_meshing_plugin ${remeshingUI_FILES}) target_link_libraries(offset_meshing_plugin PUBLIC scene_surface_mesh_item - scene_polygon_soup_item) + scene_polygon_soup_item + scene_polylines_item) if(TARGET CGAL::Eigen3_support) target_link_libraries(offset_meshing_plugin PUBLIC CGAL::Eigen3_support) endif() diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Offset_meshing_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Offset_meshing_plugin.cpp index 428d3ad6114..a379cf36095 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Offset_meshing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Offset_meshing_plugin.cpp @@ -12,6 +12,7 @@ #include #include "Scene_surface_mesh_item.h" #include "Scene_polygon_soup_item.h" +#include "Scene_polylines_item.h" #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include #include @@ -250,15 +252,18 @@ public: // declare the CGAL function template SMesh* cgal_off_meshing(QWidget*, - Mesh* tm_ptr, - const double offset_value, - const double angle, - const double sizing, - const double approx, - int tag) + Mesh* tm_ptr, + Scene_polylines_item* polylines_item, + const double offset_value, + const double angle, + const double sizing, + const double approx, + const double edge_size, + int tag) { typedef EPICK GT; - typedef CGAL::Labeled_mesh_domain_3 Mesh_domain; + typedef CGAL::Labeled_mesh_domain_3 Mesh_domain_base; + typedef CGAL::Mesh_domain_with_polyline_features_3 Mesh_domain; typedef C3t3::Triangulation Tr; typedef CGAL::Mesh_criteria_3 Mesh_criteria; typedef GT::Sphere_3 Sphere_3; @@ -292,7 +297,20 @@ SMesh* cgal_off_meshing(QWidget*, Mesh_criteria criteria(p::facet_angle = angle, p::facet_size = sizing, p::facet_distance = approx, - p::facet_topology = topology); + p::facet_topology = topology, + p::edge_size = edge_size); + + if (polylines_item!=nullptr) + { + typedef std::vector Surface_patch_ids; + std::vector surface_patch_ids; + + domain.add_features_and_incidences(polylines_item->polylines.begin(), + polylines_item->polylines.end(), + CGAL::Identity_property_map(), + CGAL::Constant_property_map( + surface_patch_ids)); + } C3t3 c3t3 = CGAL::make_mesh_3(domain, criteria, p::no_perturb(), @@ -330,40 +348,48 @@ struct Mesher_thread:public QThread{ private: SMesh* sMesh; Scene_polygon_soup_item* soup_item; + Scene_polylines_item* polylines_item; const double offset_value; const double angle; const double sizing; const double approx; + const double edge_size; int tag_index; public: Mesher_thread( SMesh* tm_ptr, Scene_polygon_soup_item* soup_item, + Scene_polylines_item* polylines_item, const double offset_value, const double angle, const double sizing, const double approx, + const double edge_size, int tag) - :sMesh(tm_ptr), soup_item(soup_item), + :sMesh(tm_ptr), soup_item(soup_item), polylines_item(polylines_item), offset_value(offset_value), angle(angle), - sizing(sizing), approx(approx), tag_index(tag){ + sizing(sizing), approx(approx), edge_size(edge_size), tag_index(tag){ } void run() override { SMesh* new_mesh= nullptr; if(soup_item) new_mesh = cgal_off_meshing(CGAL::Three::Three::mainWindow(), soup_item, + polylines_item, offset_value, angle, sizing, approx, + edge_size, tag_index); else new_mesh = cgal_off_meshing(CGAL::Three::Three::mainWindow(), sMesh, + polylines_item, offset_value, angle, sizing, approx, + edge_size, tag_index); Q_EMIT resultReady(new_mesh); } @@ -399,12 +425,20 @@ public: } } - bool applicable(QAction* a) const { - Scene_item* item = scene->item(scene->mainSelectionIndex()); + bool applicable(QAction*) const { + if ( scene->selectionIndices().size() != 1 && + scene->selectionIndices().size() != 2 ) + { + return false; + } - return - qobject_cast(item) || - (a == actionOffsetMeshing && qobject_cast(item)); + Q_FOREACH(CGAL::Three::Scene_interface::Item_id index, scene->selectionIndices()) + { + if ( qobject_cast(scene->item(index)) || + qobject_cast(scene->item(index)) ) + return true; + } + return false; } QList actions() const { @@ -456,12 +490,37 @@ void Polyhedron_demo_offset_meshing_plugin::inflate_mesh() void Polyhedron_demo_offset_meshing_plugin::offset_meshing() { - const CGAL::Three::Scene_interface::Item_id index = scene->mainSelectionIndex(); - Scene_item* item = scene->item(index); - Scene_surface_mesh_item* sm_item = - qobject_cast(item); - Scene_polygon_soup_item* soup_item = - qobject_cast(item); + Scene_surface_mesh_item* sm_item = nullptr; + Scene_polygon_soup_item* soup_item = nullptr; + Scene_polylines_item* polylines_item = nullptr; + Scene_item* item = nullptr; + + bool mesh_or_soup_item_found = false; + + Q_FOREACH(CGAL::Three::Scene_interface::Item_id index, scene->selectionIndices()) + { + if (!mesh_or_soup_item_found) + { + sm_item = qobject_cast(scene->item(index)); + if (sm_item == nullptr) + { + soup_item = qobject_cast(item); + if (soup_item != nullptr) + { + item=scene->item(index); + mesh_or_soup_item_found = true; + continue; + } + } + else + { + item=scene->item(index); + mesh_or_soup_item_found = true; + continue; + } + } + polylines_item = qobject_cast(scene->item(index)); + } SMesh* sMesh = NULL; double diag = 0; @@ -507,6 +566,14 @@ void Polyhedron_demo_offset_meshing_plugin::offset_meshing() diag); // max ui.approx->setValue(diag * 0.005); + if (polylines_item!=nullptr) + { + ui.edge_sizing->setRange(diag * 10e-6, // min + diag); // max + ui.edge_sizing->setValue(diag * 0.05); // default value + } + else + ui.edge_sizing->setEnabled(false); int i = dialog.exec(); if(i == QDialog::Rejected) @@ -515,6 +582,7 @@ void Polyhedron_demo_offset_meshing_plugin::offset_meshing() const double angle = ui.angle->value(); const double approx = ui.approx->value(); const double sizing = ui.sizing->value(); + const double edge_size=polylines_item!=nullptr?ui.edge_sizing->value():0; const int tag_index = ui.tags->currentIndex(); if(tag_index < 0) return; @@ -532,22 +600,26 @@ void Polyhedron_demo_offset_meshing_plugin::offset_meshing() if(soup_item) worker = new Mesher_thread(nullptr, soup_item, + polylines_item, offset_value, angle, sizing, approx, + edge_size, tag_index); else worker = new Mesher_thread(sMesh, nullptr, + polylines_item, offset_value, angle, sizing, approx, + edge_size, tag_index); connect(worker, &QThread::finished, worker, &QObject::deleteLater); connect(worker, &Mesher_thread::resultReady, this, - [item, angle, sizing, approx, offset_value, index] + [item, angle, sizing, approx, offset_value/* , index */] (SMesh *new_mesh){ QApplication::restoreOverrideCursor(); if(!new_mesh){ @@ -563,7 +635,7 @@ void Polyhedron_demo_offset_meshing_plugin::offset_meshing() new_item->setColor(Qt::magenta); new_item->setWireframeMode(); CGAL::Three::Three::scene()->addItem(new_item); - CGAL::Three::Three::scene()->itemChanged(index); +// CGAL::Three::Three::scene()->itemChanged(index); QApplication::restoreOverrideCursor(); }); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Remeshing_dialog.ui b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Remeshing_dialog.ui index 8366a6dcab3..37b9073000f 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Remeshing_dialog.ui +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Remeshing_dialog.ui @@ -6,102 +6,78 @@ 0 0 - 344 - 169 + 376 + 216 Meshing criteria - - - - - - - 0.00 - - - - - - - - Non manifold - - - - - Manifold - - - - - Manifold with boundaries - - - - - - - - &Angle: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - &Size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Approximation &error: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - &Topological criterion: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - tags - - - - - - - 0.00 - - - - - - - 25.0 - - - - + + + + + 25.0 + + - + + + + 0.00 + + + + + + + Approximation &error: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0.00 + + + + + + + &Topological criterion: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + tags + + + + + + + + Non manifold + + + + + Manifold + + + + + Manifold with boundaries + + + + + Qt::Vertical @@ -114,7 +90,7 @@ - + Qt::Horizontal @@ -124,6 +100,46 @@ + + + + true + + + 0.00 + + + + + + + &Edge size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + &Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + &Angle: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + +