From 5384ba50e174978ab9a2def87a4e04a592e83f5b Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 29 Oct 2018 09:57:56 +0100 Subject: [PATCH 01/21] Fix 1s bug after recenter scene. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index c7bffa69bd3..5fde118d693 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -2055,7 +2055,7 @@ void MainWindow::setAddKeyFrameKeyboardModifiers(::Qt::KeyboardModifiers m) void MainWindow::on_actionRecenterScene_triggered() { updateViewerBBox(); - viewer->camera()->interpolateToFitScene(); + viewer->camera()->showEntireScene(); } void MainWindow::on_actionLoadPlugin_triggered() From 315c01a0f175f03b2ebc7f6df0ffc69d04d272ee Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 29 Oct 2018 10:44:04 +0100 Subject: [PATCH 02/21] Fix set different colors for base color black and white --- Polyhedron/demo/Polyhedron/Color_map.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Color_map.h b/Polyhedron/demo/Polyhedron/Color_map.h index ce4cb684e1e..096f2e20720 100644 --- a/Polyhedron/demo/Polyhedron/Color_map.h +++ b/Polyhedron/demo/Polyhedron/Color_map.h @@ -12,14 +12,22 @@ compute_color_map(QColor base_color, qreal hue = base_color.hueF(); const qreal step = ((qreal)1) / nb_of_colors; - qreal h = hue; + int s = base_color.saturation(), + v = base_color.value(); + s = s<90 ? s+90 : s; + v = v<90 ? v+90 : v; + float sf=s/256.0f, + vf=v/256.0f; + + qreal h = hue==-1 ? 0 + :hue; for(unsigned i = 0; i < nb_of_colors; ++i) { if (h!=-1) h += step; if ( h > 1 ) { h -= 1; } - +//avoid S and V near 0 to avoid having all the same colors *out++ = QColor::fromHsvF(h, - base_color.saturationF(), - base_color.valueF()); + sf, + vf); } return out; } From f14a335e105ff5c9395c5874904bcf575b582700 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 29 Oct 2018 11:12:28 +0100 Subject: [PATCH 03/21] Fix is_degenerate_triangle bug and NaN failures in highlighting Euler. --- GraphicsView/include/CGAL/Buffer_for_vao.h | 19 ++++++++++++++++++- .../Polyhedron/Scene_surface_mesh_item.cpp | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/GraphicsView/include/CGAL/Buffer_for_vao.h b/GraphicsView/include/CGAL/Buffer_for_vao.h index b8ca1f752bb..b7658d45021 100644 --- a/GraphicsView/include/CGAL/Buffer_for_vao.h +++ b/GraphicsView/include/CGAL/Buffer_for_vao.h @@ -426,8 +426,25 @@ public: const Local_point& S=facet[id]; const Local_point& T=facet[(id+1==facet.size())?0:id+1]; Local_vector V1=Local_vector((T-S).x(), (T-S).y(), (T-S).z()); - + if(std::isnan(S.x()) || + std::isnan(S.y()) || + std::isnan(S.z())) + { + return false; + } + if(std::isnan(T.x()) || + std::isnan(T.y()) || + std::isnan(T.z())) + { + return false; + } const Local_point& U=facet[(id+2==facet.size())?0:id+2]; + if(std::isnan(U.x()) || + std::isnan(U.y()) || + std::isnan(U.z())) + { + return false; + } Local_vector V2=Local_vector((U-T).x(), (U-T).y(), (U-T).z()); orientation = Local_kernel::Orientation_3()(V1, V2, normal); diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp index 825e855497b..9dc67234bbf 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp @@ -1072,7 +1072,7 @@ void* Scene_surface_mesh_item_priv::get_aabb_tree() BOOST_FOREACH( face_descriptor f, faces(*sm)) { //if face is degenerate, skip it - if (CGAL::Polygon_mesh_processing::is_degenerate_triangle_face(f, *sm)) + if (CGAL::is_triangle(halfedge(f, *sm), *sm) && CGAL::Polygon_mesh_processing::is_degenerate_triangle_face(f, *sm)) continue; //if face not triangle, triangulate corresponding primitive before adding it to the tree if(!CGAL::is_triangle(halfedge(f, *sm), *sm)) From 0da822a295a5d8f8cdd0305d384a23b0fa9e2e31 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 29 Oct 2018 11:37:28 +0100 Subject: [PATCH 04/21] Add normals size and points size to the list of groupable actions. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 80 ++++++++++++++++++- .../Scene_points_with_normal_item.cpp | 4 +- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 5fde118d693..2d34e9b95de 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1347,6 +1347,14 @@ void MainWindow::showSceneContextMenu(const QPoint& p) { { menu_actions["alpha slider"] = action->menu()->actions().last(); } + else if(action->text() == QString("Points Size")) + { + menu_actions["points slider"] = action->menu()->actions().last(); + } + else if(action->text() == QString("Normals Length")) + { + menu_actions["normals slider"] = action->menu()->actions().last(); + } } } @@ -1364,7 +1372,9 @@ void MainWindow::showSceneContextMenu(const QPoint& p) { QMenu menu; Q_FOREACH(QString name, menu_actions.keys()) { - if(name == QString("alpha slider")) + if(name == QString("alpha slider") + || name == QString("points slider") + || name == QString("normals slider")) continue; if(name == QString("Alpha value")) { @@ -1401,6 +1411,74 @@ void MainWindow::showSceneContextMenu(const QPoint& p) { new_menu->addAction(sliderAction); menu.addMenu(new_menu); } + else if(name == QString("Points Size")) + { + QWidgetAction* sliderAction = new QWidgetAction(&menu); + QSlider* slider = new QSlider(&menu); + slider->setMinimum(1); + slider->setMaximum(25); + slider->setValue( + qobject_cast( + qobject_cast + (menu_actions["points slider"])->defaultWidget() + )->value()); + slider->setOrientation(Qt::Horizontal); + sliderAction->setDefaultWidget(slider); + + connect(slider, &QSlider::valueChanged, [this, slider]() + { + Q_FOREACH(Scene::Item_id id, scene->selectionIndices()) + { + Scene_item* item = scene->item(id); + Q_FOREACH(QAction* action, item->contextMenu()->actions()) + { + if(action->text() == "Points Size") + { + QWidgetAction* sliderAction = qobject_cast(action->menu()->actions().last()); + QSlider* ac_slider = qobject_cast(sliderAction->defaultWidget()); + ac_slider->setValue(slider->value()); + break; + } + } + } + }); + QMenu* new_menu = new QMenu("Points Size", &menu); + new_menu->addAction(sliderAction); + menu.addMenu(new_menu); + } + else if(name == QString("Normals Length")) + { + QWidgetAction* sliderAction = new QWidgetAction(&menu); + QSlider* slider = new QSlider(&menu); + slider->setValue( + qobject_cast( + qobject_cast + (menu_actions["normals slider"])->defaultWidget() + )->value()); + slider->setOrientation(Qt::Horizontal); + sliderAction->setDefaultWidget(slider); + + connect(slider, &QSlider::valueChanged, [this, slider]() + { + Q_FOREACH(Scene::Item_id id, scene->selectionIndices()) + { + Scene_item* item = scene->item(id); + Q_FOREACH(QAction* action, item->contextMenu()->actions()) + { + if(action->text() == "Normals Length") + { + QWidgetAction* sliderAction = qobject_cast(action->menu()->actions().last()); + QSlider* ac_slider = qobject_cast(sliderAction->defaultWidget()); + ac_slider->setValue(slider->value()); + break; + } + } + } + }); + QMenu* new_menu = new QMenu("Normals Length", &menu); + new_menu->addAction(sliderAction); + menu.addMenu(new_menu); + } else { QAction* action = menu.addAction(name); diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index fd6fae2feb2..4d46a4adf5e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp @@ -931,7 +931,7 @@ QMenu* Scene_points_with_normal_item::contextMenu() connect(d->normal_Slider, &QSlider::sliderReleased, this, &Scene_points_with_normal_item::itemChanged); } sliderAction->setDefaultWidget(d->normal_Slider); - + container->menuAction()->setProperty("is_groupable", true); container->addAction(sliderAction); menu->addMenu(container); } @@ -942,7 +942,7 @@ QMenu* Scene_points_with_normal_item::contextMenu() connect(d->point_Slider, &QSlider::valueChanged, this, &Scene_points_with_normal_item::itemChanged); sliderAction->setDefaultWidget(d->point_Slider); - + container->menuAction()->setProperty("is_groupable", true); container->addAction(sliderAction); menu->addMenu(container); From 7317db2c91f75fe68fe42cf872b18157d2298bd4 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 30 Oct 2018 12:38:18 +0100 Subject: [PATCH 05/21] Save alpha state --- Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp | 2 ++ Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp | 9 +++++++++ Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h | 3 +++ 3 files changed, 14 insertions(+) diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index c2842b84760..8abcf815820 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -1881,6 +1881,8 @@ void Scene_c3t3_item::copyProperties(Scene_item *item) show_cnc(c3t3_item->has_cnc()); show_grid(c3t3_item->has_grid()); + int value = c3t3_item->alphaSlider()->value(); + alphaSlider()->setValue(value); } bool Scene_c3t3_item::is_valid() const diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp index 9dc67234bbf..d72484c22da 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp @@ -2207,3 +2207,12 @@ void Scene_surface_mesh_item::computeElements()const d->compute_elements(ALL); setBuffersFilled(true); } + +void Scene_surface_mesh_item::copyProperties(Scene_item *item) +{ + Scene_surface_mesh_item* sm_item = qobject_cast(item); + if(!sm_item) + return; + int value = sm_item->alphaSlider()->value(); + alphaSlider()->setValue(value); +} diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h index 9daecd0e565..edd108368c1 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h @@ -8,6 +8,7 @@ #include "Scene_surface_mesh_item_config.h" #include #include +#include #ifndef Q_MOC_RUN #include "SMesh_type.h" @@ -32,6 +33,7 @@ class QSlider; struct Scene_surface_mesh_item_priv; class SCENE_SURFACE_MESH_ITEM_EXPORT Scene_surface_mesh_item : public CGAL::Three::Scene_item_rendering_helper, + public CGAL::Three::Scene_item_with_properties, public CGAL::Three::Scene_zoomable_item_interface, public CGAL::Three::Scene_print_item_interface{ Q_INTERFACES(CGAL::Three::Scene_print_item_interface) @@ -62,6 +64,7 @@ public: bool isEmpty() const Q_DECL_OVERRIDE; Bbox bbox() const Q_DECL_OVERRIDE; QString toolTip() const Q_DECL_OVERRIDE; + void copyProperties(Scene_item *) Q_DECL_OVERRIDE; QMenu* contextMenu() Q_DECL_OVERRIDE; From 3fdcf9c047e264b747345a5590644e16c6cb93e7 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 30 Oct 2018 12:57:38 +0100 Subject: [PATCH 06/21] sliders are put after the renderingmode options in the menu. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 2d34e9b95de..73db7ec75cf 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1337,6 +1337,7 @@ void MainWindow::showSceneContextMenu(const QPoint& p) { else if(scene->selectionIndices().size() > 1 ) { QMap menu_actions; + QVector slider_menus; bool has_stats = false; Q_FOREACH(QAction* action, scene->item(main_index)->contextMenu()->actions()) { @@ -1409,7 +1410,7 @@ void MainWindow::showSceneContextMenu(const QPoint& p) { }); QMenu* new_menu = new QMenu("Alpha value", &menu); new_menu->addAction(sliderAction); - menu.addMenu(new_menu); + slider_menus.push_back(new_menu); } else if(name == QString("Points Size")) { @@ -1444,7 +1445,7 @@ void MainWindow::showSceneContextMenu(const QPoint& p) { }); QMenu* new_menu = new QMenu("Points Size", &menu); new_menu->addAction(sliderAction); - menu.addMenu(new_menu); + slider_menus.push_back(new_menu); } else if(name == QString("Normals Length")) { @@ -1477,7 +1478,7 @@ void MainWindow::showSceneContextMenu(const QPoint& p) { }); QMenu* new_menu = new QMenu("Normals Length", &menu); new_menu->addAction(sliderAction); - menu.addMenu(new_menu); + slider_menus.push_back(new_menu); } else { @@ -1485,6 +1486,13 @@ void MainWindow::showSceneContextMenu(const QPoint& p) { connect(action, &QAction::triggered, this, &MainWindow::propagate_action); } } + if(!slider_menus.empty()) + { + Q_FOREACH(QMenu* m, slider_menus){ + menu.addMenu(m); + } + menu.insertSeparator(0); + } if(has_stats) { QAction* actionStatistics = From efc55de9ab11bc150dba40c9b8aca76ad8cd04bf Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 30 Oct 2018 13:03:30 +0100 Subject: [PATCH 07/21] Cancelling Save as... stops the pocess instead of passing to the next item. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 73db7ec75cf..5e6fdb4409d 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1796,7 +1796,7 @@ void MainWindow::on_actionSaveAs_triggered() &sf); if(filename.isEmpty()) - continue; + return; last_saved_dir = QFileInfo(filename).absoluteDir().path(); extensions.indexIn(sf.split(";;").first()); QString filter_ext, filename_ext; From a8e2de77aa9e372209ae791954d3fa97e92be316 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 31 Oct 2018 11:12:52 +0100 Subject: [PATCH 08/21] Don't show menus if search filter is not empty. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 40 ++++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 5e6fdb4409d..8f779072f81 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -350,7 +350,7 @@ MainWindow::MainWindow(bool verbose, QWidget* parent) readSettings(); // Among other things, the column widths are stored. // Load plugins, and re-enable actions that need it. - operationSearchBar.setPlaceholderText("Research..."); + operationSearchBar.setPlaceholderText("Filter..."); searchAction->setDefaultWidget(&operationSearchBar); connect(&operationSearchBar, &QLineEdit::textChanged, this, &MainWindow::filterOperations); @@ -397,29 +397,45 @@ MainWindow::MainWindow(bool verbose, QWidget* parent) } //Recursive function that do a pass over a menu and its sub-menus(etc.) and hide them when they are empty -void filterMenuOperations(QMenu* menu) +void filterMenuOperations(QMenu* menu, bool showFullMenu) { - Q_FOREACH(QAction* action, menu->actions()) { - if(QMenu* menu = action->menu()) - { - filterMenuOperations(menu); - action->setVisible(!(menu->isEmpty())); - } + Q_FOREACH(QAction* action, menu->actions()) { + if(QMenu* menu = action->menu()) + { + filterMenuOperations(menu, showFullMenu); + action->setVisible(showFullMenu && !(menu->isEmpty())); } + } } void MainWindow::filterOperations() { + static QVector to_remove; + Q_FOREACH(QAction* action, to_remove) + ui->menuOperations->removeAction(action); QString filter=operationSearchBar.text(); - Q_FOREACH(const PluginNamePair& p, plugins) { - Q_FOREACH(QAction* action, p.first->actions()) { + if(!filter.isEmpty()) + Q_FOREACH(const PluginNamePair& p, plugins) { + Q_FOREACH(QAction* action, p.first->actions()) { action->setVisible( p.first->applicable(action) && action->text().contains(filter, Qt::CaseInsensitive)); + if(action->menu() != ui->menuOperations){ + ui->menuOperations->addAction(action); + to_remove.push_back(action); + } + } } + else{ + Q_FOREACH(const PluginNamePair& p, plugins) { + Q_FOREACH(QAction* action, p.first->actions()) { + action->setVisible( p.first->applicable(action) + && action->text().contains(filter, Qt::CaseInsensitive)); + } + } + // do a pass over all menus in Operations and their sub-menus(etc.) and hide them when they are empty } - // do a pass over all menus in Operations and their sub-menus(etc.) and hide them when they are empty - filterMenuOperations(ui->menuOperations); + filterMenuOperations(ui->menuOperations, filter.isEmpty()); } #include From 3fb15424bf7ca5b8cc4e5c8b8cf35a9c14e7123c Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 31 Oct 2018 11:43:55 +0100 Subject: [PATCH 09/21] Add option to disable recenter on visibility changed --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 8 ++++++++ Polyhedron/demo/Polyhedron/Preferences.ui | 7 +++++++ Polyhedron/demo/Polyhedron/Scene.cpp | 8 +++++++- Polyhedron/demo/Polyhedron/Scene.h | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 8f779072f81..12b4cf28d43 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1575,6 +1575,7 @@ void MainWindow::readSettings() QSettings settings; viewer->setAntiAliasing(settings.value("antialiasing", false).toBool()); viewer->setFastDrawing(settings.value("quick_camera_mode", true).toBool()); + scene->enableVisibilityRecentering(settings.value("offset_update", true).toBool()); viewer->textRenderer()->setMax(settings.value("max_text_items", 10000).toInt()); viewer->setTotalPass(settings.value("transparency_pass_number", 4).toInt()); CGAL::Three::Three::s_defaultSMRM = CGAL::Three::Three::modeFromName( @@ -1947,6 +1948,11 @@ void MainWindow::on_actionPreferences_triggered() QSettings settings; prefdiag.setupUi(&dialog); + prefdiag.offset_updateCheckBox->setChecked( + settings.value("offset_update", true).toBool()); + connect(prefdiag.offset_updateCheckBox, SIGNAL(toggled(bool)), + scene, SLOT(enableVisibilityRecentering(bool))); + prefdiag.antialiasingCheckBox->setChecked(settings.value("antialiasing", false).toBool()); connect(prefdiag.antialiasingCheckBox, SIGNAL(toggled(bool)), viewer, SLOT(setAntiAliasing(bool))); @@ -2042,6 +2048,8 @@ void MainWindow::on_actionPreferences_triggered() //write settings settings.setValue("antialiasing", prefdiag.antialiasingCheckBox->isChecked()); + settings.setValue("offset_update", + prefdiag.offset_updateCheckBox->isChecked()); settings.setValue("quick_camera_mode", prefdiag.quick_cameraCheckBox->isChecked()); settings.setValue("transparency_pass_number", diff --git a/Polyhedron/demo/Polyhedron/Preferences.ui b/Polyhedron/demo/Polyhedron/Preferences.ui index 0435444e306..474bdf0aff1 100644 --- a/Polyhedron/demo/Polyhedron/Preferences.ui +++ b/Polyhedron/demo/Polyhedron/Preferences.ui @@ -78,6 +78,13 @@ + + + + Visibility Changes Recenter + + + diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index 7e4e0fcf240..7de9e1ab986 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -1201,7 +1201,8 @@ void Scene::itemVisibilityChanged(CGAL::Three::Scene_item* item) && !item->isEmpty()) { //does not recenter - Q_EMIT updated_bbox(false); + if(visibility_recentering_enabled) + Q_EMIT updated_bbox(false); } } @@ -1662,3 +1663,8 @@ void Scene::adjustIds(Item_id removed_id) m_entries[i]->setId(i-1);//the signal is emitted before m_entries is amputed from the item, so new id is current id -1. } } + +void Scene::enableVisibilityRecentering(bool b) +{ + visibility_recentering_enabled = b; +} diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index aa778970fb7..9f33be6ee5f 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -208,6 +208,7 @@ public Q_SLOTS: void setItemA(int i); //!Sets the item_B as the item at index i . void setItemB(int i); + void enableVisibilityRecentering(bool); Q_SIGNALS: //generated automatically by moc @@ -280,6 +281,7 @@ private: QOpenGLShaderProgram program; QOpenGLVertexArrayObject* vao; mutable QOpenGLBuffer vbo[2]; + bool visibility_recentering_enabled; }; // end class Scene From d7751c0fbd1db4db49cdd614a889a62df2603d32 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 31 Oct 2018 12:26:36 +0100 Subject: [PATCH 10/21] Add default points/lines/normals size in preferences. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 36 +++++++++- Polyhedron/demo/Polyhedron/Preferences.ui | 69 +++++++++++++++++++ .../Scene_points_with_normal_item.cpp | 28 ++------ .../demo/Polyhedron/Scene_polylines_item.cpp | 5 +- Polyhedron/demo/Polyhedron/Three.cpp | 17 +++++ Three/include/CGAL/Three/Three.h | 6 ++ 6 files changed, 135 insertions(+), 26 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 12b4cf28d43..c8f821ca412 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1586,6 +1586,9 @@ void MainWindow::readSettings() QStringList blacklist=settings.value("plugin_blacklist",QStringList()).toStringList(); Q_FOREACH(QString name,blacklist){ plugin_blacklist.insert(name); } def_save_dir = settings.value("default_saveas_dir", QDir::homePath()).toString(); + this->default_point_size = settings.value("points_size").toInt(); + this->default_normal_length = settings.value("normals_length").toInt(); + this->default_lines_width = settings.value("lines_width").toInt(); } void MainWindow::writeSettings() @@ -1948,6 +1951,17 @@ void MainWindow::on_actionPreferences_triggered() QSettings settings; prefdiag.setupUi(&dialog); + float lineWidth[2]; + if(!viewer->isOpenGL_4_3()) + viewer->glGetFloatv(GL_LINE_WIDTH_RANGE, lineWidth); + else + { + lineWidth[0] = 0; + lineWidth[1] = 10; + } + prefdiag.linesHorizontalSlider->setMinimum(lineWidth[0]); + prefdiag.linesHorizontalSlider->setMaximum(lineWidth[1]); + prefdiag.offset_updateCheckBox->setChecked( settings.value("offset_update", true).toBool()); connect(prefdiag.offset_updateCheckBox, SIGNAL(toggled(bool)), @@ -1973,6 +1987,24 @@ void MainWindow::on_actionPreferences_triggered() { setTransparencyPasses(i); }); + prefdiag.pointsHorizontalSlider->setValue(this->default_point_size); + connect(prefdiag.pointsHorizontalSlider, &QSlider::valueChanged, + this, [this](int i) + { + this->default_point_size = i; + }); + prefdiag.normalsHorizontalSlider->setValue(this->default_normal_length); + connect(prefdiag.normalsHorizontalSlider, &QSlider::valueChanged, + this, [this](int i) + { + this->default_normal_length = i; + }); + prefdiag.linesHorizontalSlider->setValue(this->default_lines_width); + connect(prefdiag.linesHorizontalSlider, &QSlider::valueChanged, + this, [this](int i) + { + this->default_lines_width = i; + }); connect(prefdiag.background_colorPushButton, &QPushButton::clicked, this, &MainWindow::setBackgroundColor); @@ -2061,7 +2093,9 @@ void MainWindow::on_actionPreferences_triggered() CGAL::Three::Three::defaultSurfaceMeshRenderingMode())); settings.setValue("default_ps_rm", CGAL::Three::Three::modeName( CGAL::Three::Three::defaultPointSetRenderingMode())); - + settings.setValue("points_size", this->default_point_size); + settings.setValue("normals_length", this->default_normal_length); + settings.setValue("lines_width", this->default_lines_width); } } diff --git a/Polyhedron/demo/Polyhedron/Preferences.ui b/Polyhedron/demo/Polyhedron/Preferences.ui index 474bdf0aff1..ee852a82298 100644 --- a/Polyhedron/demo/Polyhedron/Preferences.ui +++ b/Polyhedron/demo/Polyhedron/Preferences.ui @@ -192,6 +192,75 @@ + + + + Default Sizes + + + + + + Points: + + + + + + + 1 + + + 25 + + + 2 + + + Qt::Horizontal + + + + + + + 20 + + + Qt::Horizontal + + + + + + + 2 + + + false + + + Qt::Horizontal + + + + + + + Normals: + + + + + + + Lines: + + + + + + diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index 4d46a4adf5e..1bdc1b7058e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp @@ -47,10 +47,10 @@ struct Scene_points_with_normal_item_priv nb_lines = 0; is_point_slider_moving = false; normal_Slider = new QSlider(Qt::Horizontal); - normal_Slider->setValue(20); + normal_Slider->setValue(CGAL::Three::Three::getDefaultNormalLength()); point_Slider = new QSlider(Qt::Horizontal); point_Slider->setMinimum(1); - point_Slider->setValue(2); + point_Slider->setValue(CGAL::Three::Three::getDefaultPointSize()); point_Slider->setMaximum(25); } Scene_points_with_normal_item_priv(Scene_points_with_normal_item* parent) @@ -223,11 +223,6 @@ Scene_points_with_normal_item::Scene_points_with_normal_item(const Scene_points_ setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode()); is_selected = true; } - - if(d->m_points->number_of_points() < 30 ) - d->point_Slider->setValue(5); - else - d->point_Slider->setValue(2); invalidateOpenGLBuffers(); } @@ -241,10 +236,6 @@ Scene_points_with_normal_item::Scene_points_with_normal_item(const SMesh& input_ d = new Scene_points_with_normal_item_priv(input_mesh, this); setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode()); is_selected = true; - if(d->m_points->number_of_points() < 30 ) - d->point_Slider->setValue(5); - else - d->point_Slider->setValue(2); invalidateOpenGLBuffers(); } @@ -622,10 +613,7 @@ bool Scene_points_with_normal_item::read_ply_point_set(std::istream& stream) bool ok = stream && CGAL::read_ply_point_set (stream, *(d->m_points), &(d->m_comments)) && !isEmpty(); - if(d->m_points->number_of_points() < 30 ) - d->point_Slider->setValue(5); - else - d->point_Slider->setValue(2); + d->point_Slider->setValue(CGAL::Three::Three::getDefaultPointSize()); std::cerr << d->m_points->info(); if (!d->m_points->has_normal_map()) @@ -673,10 +661,7 @@ bool Scene_points_with_normal_item::read_off_point_set(std::istream& stream) bool ok = stream && CGAL::read_off_point_set(stream, *(d->m_points)) && !isEmpty(); - if(d->m_points->number_of_points() < 30 ) - d->point_Slider->setValue(5); - else - d->point_Slider->setValue(2); + d->point_Slider->setValue(CGAL::Three::Three::getDefaultPointSize()); invalidateOpenGLBuffers(); return ok; } @@ -702,10 +687,7 @@ bool Scene_points_with_normal_item::read_xyz_point_set(std::istream& stream) bool ok = stream && CGAL::read_xyz_point_set (stream, *(d->m_points)) && !isEmpty(); - if(d->m_points->number_of_points() < 30 ) - d->point_Slider->setValue(5); - else - d->point_Slider->setValue(2); + d->point_Slider->setValue(CGAL::Three::Three::getDefaultPointSize()); invalidateOpenGLBuffers(); return ok; } diff --git a/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp index 2055f3f75d6..801205d5653 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp @@ -2,6 +2,7 @@ #include "Scene_spheres_item.h" #include +#include #include #include #include @@ -18,9 +19,9 @@ struct Scene_polylines_item_private { spheres_drawn_square_radius(0) { line_Slider = new QSlider(Qt::Horizontal); - line_Slider->setMaximum(2); + line_Slider->setValue(CGAL::Three::Three::getDefaultLinesWidth()); + line_Slider->setMaximum(2000); line_Slider->setMinimum(1); - line_Slider->setValue(2); item = parent; invalidate_stats(); } diff --git a/Polyhedron/demo/Polyhedron/Three.cpp b/Polyhedron/demo/Polyhedron/Three.cpp index 5bedb74a671..b29abaa2e6e 100644 --- a/Polyhedron/demo/Polyhedron/Three.cpp +++ b/Polyhedron/demo/Polyhedron/Three.cpp @@ -11,6 +11,9 @@ QObject* Three::s_connectable_scene = NULL; Three* Three::s_three = NULL; RenderingMode Three::s_defaultSMRM; RenderingMode Three::s_defaultPSRM; +int Three::default_point_size; +int Three::default_normal_length; +int Three::default_lines_width; QMainWindow* Three::mainWindow() { @@ -184,3 +187,17 @@ RenderingMode Three::modeFromName(QString name) { return Points; } +int Three::getDefaultPointSize() +{ + return default_point_size; +} + +int Three::getDefaultNormalLength() +{ + return default_normal_length; +} + +int Three::getDefaultLinesWidth() +{ + return default_lines_width; +} diff --git a/Three/include/CGAL/Three/Three.h b/Three/include/CGAL/Three/Three.h index 9887ed55727..17197383a41 100644 --- a/Three/include/CGAL/Three/Three.h +++ b/Three/include/CGAL/Three/Three.h @@ -52,6 +52,9 @@ public: static RenderingMode defaultPointSetRenderingMode(); static QString modeName(RenderingMode mode); static RenderingMode modeFromName(QString name); + static int getDefaultPointSize(); + static int getDefaultNormalLength(); + static int getDefaultLinesWidth(); /*! \brief Adds a dock widget to the interface * * Adds a dock widget in the left section of the MainWindow. If the slot is already @@ -81,6 +84,9 @@ protected: static Three* s_three; static RenderingMode s_defaultSMRM; static RenderingMode s_defaultPSRM; + static int default_point_size; + static int default_normal_length; + static int default_lines_width; }; } From 3b63dce6b91e3d3160cdd966b1b7697cd5eaf756 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 31 Oct 2018 12:33:36 +0100 Subject: [PATCH 11/21] Invert the blacklist tick system. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index c8f821ca412..ddb3e860cb5 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -2046,10 +2046,10 @@ void MainWindow::on_actionPreferences_triggered() QTreeWidgetItem *item = new QTreeWidgetItem(pluginItem); item->setText(1, name); if(plugin_blacklist.contains(name)){ - item->setCheckState(0, Qt::Checked); + item->setCheckState(0, Qt::Unchecked); } else{ - item->setCheckState(0, Qt::Unchecked); + item->setCheckState(0, Qt::Checked); } if(pluginsStatus_map[name] == QString("success")) item->setBackground(1, successBrush); @@ -2073,7 +2073,7 @@ void MainWindow::on_actionPreferences_triggered() for (std::size_t k=0; kcheckState(0)==Qt::Checked) + if (item->checkState(0)==Qt::Unchecked) plugin_blacklist.insert(item->text(1)); } From 89ac95747bbadb4afa1c94540698a7988d5003f1 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 31 Oct 2018 13:10:53 +0100 Subject: [PATCH 12/21] Don't scroll topp after deletion. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index ddb3e860cb5..594df761c94 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1175,6 +1175,7 @@ void MainWindow::selectSceneItem(int i) sceneView->selectionModel()->select(s, QItemSelectionModel::ClearAndSelect); + sceneView->scrollTo(s.indexes().first()); } } From b2ada55672b5e152256df6088026273b53f0e429 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 31 Oct 2018 15:15:44 +0100 Subject: [PATCH 13/21] WIP moving several items up or down at the same time --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 19 ++++ Polyhedron/demo/Polyhedron/MainWindow.h | 5 + Polyhedron/demo/Polyhedron/Scene.cpp | 106 ++++++++++++++-------- Polyhedron/demo/Polyhedron/Scene.h | 4 + 4 files changed, 95 insertions(+), 39 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 594df761c94..9991b1c4eb6 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -211,6 +211,8 @@ MainWindow::MainWindow(bool verbose, QWidget* parent) connect(scene, SIGNAL(selectionChanged(int)), this, SLOT(selectSceneItem(int))); + connect(scene, SIGNAL(selectionChanged(QList)), + this, SLOT(selectSceneItems(QList))); connect(scene, SIGNAL(itemPicked(const QModelIndex &)), this, SLOT(recenterSceneView(const QModelIndex &))); @@ -1179,6 +1181,23 @@ void MainWindow::selectSceneItem(int i) } } +void MainWindow::selectSceneItems(QList is) +{ + if(is.first() < 0 || is.last() >= scene->numberOfEntries()) { + sceneView->selectionModel()->clearSelection(); + updateInfo(); + updateDisplayInfo(); + } + else { + QItemSelection s = + proxyModel->mapSelectionFromSource(scene->createSelection(is)); + + sceneView->selectionModel()->select(s, + QItemSelectionModel::ClearAndSelect); + sceneView->scrollTo(s.indexes().first()); + } +} + void MainWindow::showSelectedPoint(double x, double y, double z) { diff --git a/Polyhedron/demo/Polyhedron/MainWindow.h b/Polyhedron/demo/Polyhedron/MainWindow.h index cc543525563..845a28c1ae8 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.h +++ b/Polyhedron/demo/Polyhedron/MainWindow.h @@ -142,6 +142,11 @@ public Q_SLOTS: * the index i in the Geometric Objects view. */ void selectSceneItem(int i); + /*! + * Clears the current selection and selects the scene_items with + * indices in is in the Geometric Objects view. + */ + void selectSceneItems(QList i); /*! * Prints coordinates of a point and its distance to the last * position printed by this function. diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index 7de9e1ab986..8485a4d2138 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -1076,62 +1076,81 @@ bool Scene::dropMimeData(const QMimeData * /*data*/, void Scene::moveRowUp() { - - int selected_id = selectionIndices().first(); - Scene_item* selected_item = item(selected_id); - if(!selected_item) + QList to_select; + QList sorted_list = selectionIndices(); + std::sort(sorted_list.begin(), sorted_list.end()); + if( children.indexOf(sorted_list.first()) == 0) return; - if(index_map.key(selected_id).row() > 0) + for(int i=0; ihas_group >0) + Item_id selected_id = sorted_list[i]; + Scene_item* selected_item = item(selected_id); + if(!selected_item) + return; + if(index_map.key(selected_id).row() > 0) { - Scene_group_item* group = selected_item->parentGroup(); - if(group) + if(item(selected_id)->has_group >0) { - int id = group->getChildren().indexOf(item_id(selected_item)); - group->moveUp(id); + Scene_group_item* group = selected_item->parentGroup(); + if(group) + { + int id = group->getChildren().indexOf(item_id(selected_item)); + group->moveUp(id); + } } + else + { + //if not in group + QModelIndex baseId = index_map.key(selected_id); + int newId = children.indexOf( + index_map.value(index(baseId.row()-1, baseId.column(),baseId.parent()))) ; + children.move(children.indexOf(selected_id), newId); + } + redraw_model(); + to_select.append(m_entries.indexOf(selected_item)); } - else - { - //if not in group - QModelIndex baseId = index_map.key(selected_id); - int newId = children.indexOf( - index_map.value(index(baseId.row()-1, baseId.column(),baseId.parent()))) ; - children.move(children.indexOf(selected_id), newId); - } - redraw_model(); - setSelectedItem(m_entries.indexOf(selected_item)); } + setSelectedItemsList(to_select); + selectionChanged(to_select); } void Scene::moveRowDown() { - int selected_id = selectionIndices().first(); - Scene_item* selected_item = item(selected_id); - if(!selected_item) + QList to_select; + QList sorted_list = selectionIndices(); + std::sort(sorted_list.begin(), sorted_list.end()); + if( children.indexOf(sorted_list.last()) == children.size() -1) return; - if(index_map.key(selected_id).row() < rowCount(index_map.key(selected_id).parent())-1) + for(int i=sorted_list.size()-1; i>=0; --i) { - if(item(selected_id)->has_group >0) + Item_id selected_id = sorted_list[i]; + Scene_item* selected_item = item(selected_id); + if(!selected_item) + return; + if(index_map.key(selected_id).row() < rowCount(index_map.key(selected_id).parent())-1) { - Scene_group_item* group = selected_item->parentGroup(); - if(group) + if(item(selected_id)->has_group >0) { - int id = group->getChildren().indexOf(item_id(selected_item)); - group->moveDown(id); + Scene_group_item* group = selected_item->parentGroup(); + if(group) + { + int id = group->getChildren().indexOf(item_id(selected_item)); + group->moveDown(id); + } } + else + { + //if not in group + QModelIndex baseId = index_map.key(selected_id); + int newId = children.indexOf( + index_map.value(index(baseId.row()+1, baseId.column(),baseId.parent()))) ; + children.move(children.indexOf(selected_id), newId); + } + redraw_model(); + to_select.prepend(m_entries.indexOf(selected_item)); } - else - { - //if not in group - QModelIndex baseId = index_map.key(selected_id); - int newId = children.indexOf( - index_map.value(index(baseId.row()+1, baseId.column(),baseId.parent()))) ; - children.move(children.indexOf(selected_id), newId); - } - redraw_model(); - setSelectedItem(m_entries.indexOf(selected_item)); } + setSelectedItemsList(to_select); + selectionChanged(to_select); } Scene::Item_id Scene::mainSelectionIndex() const { return (selectionIndices().size() == 1) ? selected_item : -1; @@ -1155,6 +1174,15 @@ QItemSelection Scene::createSelection(int i) index_map.keys(i).at(4)); } +QItemSelection Scene::createSelection(QList is) +{ + QItemSelection sel; + Q_FOREACH(int i, is) + sel.select(index_map.keys(i).at(0), + index_map.keys(i).at(4)); + return sel; +} + QItemSelection Scene::createSelectionAll() { //it is not possible to directly create a selection with items that have different parents, so diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index 9f33be6ee5f..8ba07e17898 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -128,6 +128,8 @@ public: // auxiliary public function for QMainWindow //Selects the row at index i in the sceneView. QItemSelection createSelection(int i); + //same fo lists + QItemSelection createSelection(QList is); //Selects all the rows in the sceneView. QItemSelection createSelectionAll(); //Connects specific signals to a group when it is added and @@ -229,6 +231,8 @@ Q_SIGNALS: void selectionRay(double, double, double, double, double, double); //! Used to update the selected item in the Geometric Objects view. void selectionChanged(int i); + //! Used to update the selected items in the Geometric Objects view. + void selectionChanged(QList is); //! Used when you don't want to update the selectedItem in the Geometric Objects view. void itemIndexSelected(int i); //! Emit this to reset the collapsed state of all groups after the Geometric Objects view has been redrawn. From 836f14533fa7e97bf0d4faf182ed50669f9b1d11 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 31 Oct 2018 16:07:10 +0100 Subject: [PATCH 14/21] fix sorting of selectionIndices --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 15 ++++++++------- Polyhedron/demo/Polyhedron/Scene.cpp | 14 ++++++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 9991b1c4eb6..1f012d30843 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1565,14 +1565,15 @@ void MainWindow::updateInfo() { if(item) { QString item_text = item->toolTip(); QString item_filename = item->property("source filename").toString(); - if(item->bbox()!=CGAL::Bbox_3()) + CGAL::Bbox_3 bbox = item->bbox(); + if(bbox !=CGAL::Bbox_3()) item_text += QString("
Bounding box: min (%1,%2,%3), max (%4,%5,%6)
") - .arg(item->bbox().xmin()) - .arg(item->bbox().ymin()) - .arg(item->bbox().zmin()) - .arg(item->bbox().xmax()) - .arg(item->bbox().ymax()) - .arg(item->bbox().zmax()); + .arg(bbox.xmin()) + .arg(bbox.ymin()) + .arg(bbox.zmin()) + .arg(bbox.xmax()) + .arg(bbox.ymax()) + .arg(bbox.zmax()); if(!item_filename.isEmpty()) { item_text += QString("
File: %1
").arg(item_filename); } diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index 8485a4d2138..ef833414f61 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -1078,7 +1078,10 @@ void Scene::moveRowUp() { QList to_select; QList sorted_list = selectionIndices(); - std::sort(sorted_list.begin(), sorted_list.end()); + std::sort(sorted_list.begin(), sorted_list.end(), + [this](int a, int b) { + return children.indexOf(a) < children.indexOf(b); +}); if( children.indexOf(sorted_list.first()) == 0) return; for(int i=0; i to_select; QList sorted_list = selectionIndices(); - std::sort(sorted_list.begin(), sorted_list.end()); + std::sort(sorted_list.begin(), sorted_list.end(), + [this](int a, int b) { + return children.indexOf(a) < children.indexOf(b); +}); if( children.indexOf(sorted_list.last()) == children.size() -1) return; for(int i=sorted_list.size()-1; i>=0; --i) @@ -1125,6 +1130,7 @@ void Scene::moveRowDown() Item_id selected_id = sorted_list[i]; Scene_item* selected_item = item(selected_id); if(!selected_item) + return; if(index_map.key(selected_id).row() < rowCount(index_map.key(selected_id).parent())-1) { @@ -1149,7 +1155,7 @@ void Scene::moveRowDown() to_select.prepend(m_entries.indexOf(selected_item)); } } - setSelectedItemsList(to_select); + selectionChanged(to_select); } Scene::Item_id Scene::mainSelectionIndex() const { From 00178a0f066e41ecef48e04cc7ba32f285837ebb Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 31 Oct 2018 17:26:09 +0100 Subject: [PATCH 15/21] WIP move up and down : - groups are blocked. Need a way to treat differently full selected groups . --- Polyhedron/demo/Polyhedron/Scene.cpp | 160 ++++++++++++++++++++------- Polyhedron/demo/Polyhedron/Scene.h | 3 +- 2 files changed, 119 insertions(+), 44 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index ef833414f61..aa135a7a301 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -1074,88 +1074,162 @@ bool Scene::dropMimeData(const QMimeData * /*data*/, return true; } -void Scene::moveRowUp() -{ - QList to_select; - QList sorted_list = selectionIndices(); - std::sort(sorted_list.begin(), sorted_list.end(), + +bool Scene::sort_lists(QVector >&sorted_lists, bool up) +{ + QVector group_found; + Q_FOREACH(int i, selectionIndices()) + { + Scene_item* item = this->item(i); + if(item->has_group == 0) + { + sorted_lists.first().push_back(i); + } + else + { + int group_id = item_id(item->parentGroup()); + if(group_found.contains(group_id)) + sorted_lists[group_id].push_back(i); + else + { + group_found.push_back(group_id); + if(sorted_lists.size() < group_id+1) + sorted_lists.resize(group_id+1); + sorted_lists[group_id].push_back(i); + } + } + } + std::sort(sorted_lists.first().begin(), sorted_lists.first().end(), [this](int a, int b) { return children.indexOf(a) < children.indexOf(b); }); - if( children.indexOf(sorted_list.first()) == 0) - return; - for(int i=0; i& list = sorted_lists[i]; + if(list.isEmpty()) + continue; + Scene_group_item* group = qobject_cast(this->item(i)); + if(!group) + continue; + std::sort(list.begin(), list.end(), + [this, group](int a, int b) { + return group->getChildren().indexOf(a) < group->getChildren().indexOf(b); + }); + if(up && group->getChildren().indexOf(list.first()) == 0) + return false; + else if(!up && group->getChildren().indexOf(list.last()) == group->getChildren().size()-1) + return false; + } + return true; +} +void Scene::moveRowUp() +{ + QVector >sorted_lists(1); + QList to_select; + //sort lists according to the indices of each item in its container (scene or group) + //if moving one up would put it out of range, then we stop and do nothing. + if(!sort_lists(sorted_lists, true)) + return; + + for(int i=0; i 0) { - if(item(selected_id)->has_group >0) + //if not in group + QModelIndex baseId = index_map.key(selected_id); + int newId = children.indexOf( + index_map.value(index(baseId.row()-1, baseId.column(),baseId.parent()))) ; + children.move(children.indexOf(selected_id), newId); + redraw_model(); + to_select.append(m_entries.indexOf(selected_item)); + } + } + for(int i=1; i 0) { Scene_group_item* group = selected_item->parentGroup(); if(group) { int id = group->getChildren().indexOf(item_id(selected_item)); group->moveUp(id); + redraw_model(); + to_select.append(m_entries.indexOf(selected_item)); } } - else - { - //if not in group - QModelIndex baseId = index_map.key(selected_id); - int newId = children.indexOf( - index_map.value(index(baseId.row()-1, baseId.column(),baseId.parent()))) ; - children.move(children.indexOf(selected_id), newId); - } - redraw_model(); - to_select.append(m_entries.indexOf(selected_item)); } } - selectionChanged(to_select); + if(!to_select.isEmpty()) + selectionChanged(to_select); } void Scene::moveRowDown() { + QVector >sorted_lists(1); QList to_select; - QList sorted_list = selectionIndices(); - std::sort(sorted_list.begin(), sorted_list.end(), - [this](int a, int b) { - return children.indexOf(a) < children.indexOf(b); -}); - if( children.indexOf(sorted_list.last()) == children.size() -1) + //sort lists according to the indices of each item in its container (scene or group) + //if moving one up would put it out of range, then we stop and do nothing. + if(!sort_lists(sorted_lists, false)) return; - for(int i=sorted_list.size()-1; i>=0; --i) + for(int i=sorted_lists.first().size()-1; i>=0; --i) { - Item_id selected_id = sorted_list[i]; + Item_id selected_id = sorted_lists.first()[i]; Scene_item* selected_item = item(selected_id); if(!selected_item) - return; if(index_map.key(selected_id).row() < rowCount(index_map.key(selected_id).parent())-1) { - if(item(selected_id)->has_group >0) - { - Scene_group_item* group = selected_item->parentGroup(); - if(group) - { - int id = group->getChildren().indexOf(item_id(selected_item)); - group->moveDown(id); - } - } - else - { //if not in group QModelIndex baseId = index_map.key(selected_id); int newId = children.indexOf( index_map.value(index(baseId.row()+1, baseId.column(),baseId.parent()))) ; children.move(children.indexOf(selected_id), newId); - } + redraw_model(); to_select.prepend(m_entries.indexOf(selected_item)); } } - + for(int i=1; i=0; --j) + { + Item_id selected_id = sorted_lists[i][j]; + Scene_item* selected_item = item(selected_id); + if(!selected_item) + return; + if(index_map.key(selected_id).row() < rowCount(index_map.key(selected_id).parent())-1) + { + if(item(selected_id)->has_group >0) + { + Scene_group_item* group = selected_item->parentGroup(); + if(group) + { + int id = group->getChildren().indexOf(item_id(selected_item)); + group->moveDown(id); + } + } + redraw_model(); + to_select.prepend(m_entries.indexOf(selected_item)); + } + } + } selectionChanged(to_select); } Scene::Item_id Scene::mainSelectionIndex() const { diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index 8ba07e17898..753bfc9e13f 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -286,7 +287,7 @@ private: QOpenGLVertexArrayObject* vao; mutable QOpenGLBuffer vbo[2]; bool visibility_recentering_enabled; - + bool sort_lists(QVector >&sorted_lists, bool up); }; // end class Scene class QAbstractProxyModel; From c06b3b1d729fe8cccb765852fd931da302881b83 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 31 Oct 2018 17:38:29 +0100 Subject: [PATCH 16/21] WIP group managment --- Polyhedron/demo/Polyhedron/Scene.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index aa135a7a301..4f00531a77c 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -1074,7 +1074,7 @@ bool Scene::dropMimeData(const QMimeData * /*data*/, return true; } - +//todo : if a group is selected, don't treat it's children. bool Scene::sort_lists(QVector >&sorted_lists, bool up) { QVector group_found; @@ -1099,6 +1099,17 @@ bool Scene::sort_lists(QVector >&sorted_lists, bool up) } } } + //iterate the first list to find the groups that are selected and remove the corresponding + //sub lists. + //todo: do that for each group. (treat subgroups) + for(int i = 0; i< sorted_lists.first().size(); ++i) + { + Scene_group_item* group = qobject_cast(this->item(sorted_lists.first()[i])); + if(group && ! group->getChildren().isEmpty()) + { + sorted_lists[sorted_lists.first()[i]].clear(); + } + } std::sort(sorted_lists.first().begin(), sorted_lists.first().end(), [this](int a, int b) { return children.indexOf(a) < children.indexOf(b); From d200f2ca71766dd2e3d6ee0aa5296753c91ba59a Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 7 Nov 2018 14:40:52 +0100 Subject: [PATCH 17/21] Modify selection IO so it tries all the surface_mesh_items in the scene before deciding it shouldn't load. --- .../Plugins/IO/Selection_io_plugin.cpp | 15 +++++--- .../Polyhedron/Plugins/IO/VTK_io_plugin.cpp | 2 +- .../Plugins/PMP/Selection_plugin.cpp | 35 +++++++++++++------ 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/Selection_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/Selection_io_plugin.cpp index bbbfe24bf58..67440917a89 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/Selection_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/Selection_io_plugin.cpp @@ -16,11 +16,16 @@ public: QString nameFilters() const { return "Selection files(*.selection.txt)"; } bool canLoad() const { - Scene_facegraph_item* sel_item = qobject_cast(CGAL::Three::Three::scene()->item( - CGAL::Three::Three::scene()->mainSelectionIndex())); - if(sel_item) - return true; - return false; + Scene_item * item = CGAL::Three::Three::scene()->item( + CGAL::Three::Three::scene()->mainSelectionIndex()); + Scene_facegraph_item* fg_item = qobject_cast(item); + if(fg_item) + return true; + Scene_polyhedron_selection_item* sel_item = + qobject_cast(item); + if (sel_item) + return true; + return false; } CGAL::Three::Scene_item* load(QFileInfo fileinfo) { if(fileinfo.suffix().toLower() != "txt") return 0; diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index 29d0217948b..badf88cc4e3 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -280,7 +280,7 @@ public: QString nameFilters() const { return "VTK PolyData files (*.vtk);; VTK XML PolyData (*.vtp);; VTK XML UnstructuredGrid (*.vtu)"; } - QString name() const { return "vtk_sm_plugin"; } + QString name() const { return "vtk_plugin"; } bool canSave(const CGAL::Three::Scene_item* item) { return (qobject_cast(item) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Selection_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Selection_plugin.cpp index 95e2fbd401f..338a0f979ce 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Selection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Selection_plugin.cpp @@ -855,23 +855,36 @@ public Q_SLOTS: qobject_cast(scene->item(item_id)); if(!selection_item) { return; } - Scene_face_graph_item* poly_item = getSelectedItem(); + Scene_face_graph_item* poly_item = NULL; + if(selection_item->polyhedron_item() == NULL) { //coming from selection_io loader + bool found = false; + for(int i = 0; inumberOfEntries(); ++i){ + poly_item = qobject_cast(scene->item(i)); + if(!poly_item) + continue; + if(!selection_item->actual_load(poly_item, mw)) { + continue; + } + found = true; + selection_item->invalidateOpenGLBuffers(); + scene->itemChanged(selection_item); + break; + } + if(!found) + { + print_message("Error: loading selection item is not successful!"); + scene->erase(item_id); + return; + } + } else { + poly_item = getSelectedItem(); + } if(!poly_item) { - CGAL_assertion(selection_item->polyhedron_item() == NULL); // which means it is coming from selection_io loader print_message("Error: please select corresponding polyhedron item from Geometric Objects list."); scene->erase(item_id); return; } - if(selection_item->polyhedron_item() == NULL) { //coming from selection_io loader - if(!selection_item->actual_load(poly_item, mw)) { - print_message("Error: loading selection item is not successful!"); - scene->erase(item_id); - return; - } - selection_item->invalidateOpenGLBuffers(); - scene->itemChanged(selection_item); - } // now set default params both for selection items coming from selection_io, or on_Create_selection_item_button_clicked Active_handle::Type aht = static_cast(ui_widget.Selection_type_combo_box->currentIndex()); bool is_insert = ui_widget.Insertion_radio_button->isChecked(); From 31966f5b4ba8094e82d04cfa820e2a51d1b6f098 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 8 Nov 2018 10:04:06 +0100 Subject: [PATCH 18/21] Remove key_C for clipping entire scene. --- Polyhedron/demo/Polyhedron/Viewer.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index 9c47fef8fac..05343dde80a 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -611,12 +611,6 @@ void Viewer::keyPressEvent(QKeyEvent* e) update(); return; } - else if(e->key() == Qt::Key_C) { - QVector4D box[6]; - for(int i=0; i<6; ++i) - box[i] = QVector4D(1,0,0,0); - enableClippingBox(box); - } } else if(e->key() == Qt::Key_I && e->modifiers() & Qt::ControlModifier){ d->scene->printAllIds(this); From 16a8ef22aaa071a7377e0146b9a13e3c6dd79099 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 12 Nov 2018 09:08:18 +0100 Subject: [PATCH 19/21] Fix warning in lambda --- Polyhedron/demo/Polyhedron/Scene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index 4f00531a77c..19304b2f735 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -1130,7 +1130,7 @@ bool Scene::sort_lists(QVector >&sorted_lists, bool up) if(!group) continue; std::sort(list.begin(), list.end(), - [this, group](int a, int b) { + [group](int a, int b) { return group->getChildren().indexOf(a) < group->getChildren().indexOf(b); }); if(up && group->getChildren().indexOf(list.first()) == 0) From 5139da74c5908315c5b209f8c8328b456ae2a710 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 12 Nov 2018 12:12:49 +0100 Subject: [PATCH 20/21] Fix problems with patch ids in surface_mesh_item --- .../PMP/Join_and_split_polyhedra_plugin.cpp | 12 +++++------- .../Surface_mesh/Mesh_segmentation_plugin.cpp | 2 +- .../demo/Polyhedron/Scene_surface_mesh_item.cpp | 15 +++++++++------ .../demo/Polyhedron/Scene_surface_mesh_item.h | 6 +++++- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Join_and_split_polyhedra_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Join_and_split_polyhedra_plugin.cpp index 7c91e1593f4..fa58b268279 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Join_and_split_polyhedra_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Join_and_split_polyhedra_plugin.cpp @@ -81,7 +81,6 @@ public Q_SLOTS: private : CGAL::Three::Scene_interface* scene; - std::vector colors_; }; // end Polyhedron_demo_polyhedron_stitching_plugin void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionJoinPolyhedra_triggered() @@ -140,7 +139,6 @@ bool operator()(FaceGraph* mesh1, FaceGraph* mesh2) void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionSplitPolyhedra_triggered() { Q_FOREACH(int index, scene->selectionIndices()) { - colors_.clear(); Scene_facegraph_item* item = qobject_cast(scene->item(index)); if(item) @@ -176,17 +174,17 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionSplitPolyhedra_tr } int cc=0; - - compute_color_map(item->color(), item->isItemMulticolor() ? static_cast(new_polyhedra.size()) : 1, - std::back_inserter(colors_)); - + Scene_group_item *group = new Scene_group_item("CC"); scene->addItem(group); BOOST_FOREACH(FaceGraph* polyhedron_ptr, new_polyhedra) { Scene_facegraph_item* new_item=new Scene_facegraph_item(polyhedron_ptr); new_item->setName(tr("%1 - CC %2").arg(item->name()).arg(cc)); - new_item->setColor(colors_[item->isItemMulticolor()? cc : 0]); + if(item->isItemMulticolor() || item->hasPatchIds()) + new_item->setColor(item->color_vector()[cc]); + else + new_item->setColor(item->color()); ++cc; scene->addItem(new_item); scene->changeGroup(new_item, group); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_segmentation_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_segmentation_plugin.cpp index 000dbb05def..a4f5d553b81 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_segmentation_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_segmentation_plugin.cpp @@ -377,7 +377,7 @@ void Polyhedron_demo_mesh_segmentation_plugin::colorize_sdf( } put(pidmap, *facet_it, static_cast(patch_id)); } - item->setItemIsMulticolor(true); + item->setItemIsMulticolor(true, false); } diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp index d72484c22da..1f8fb0058f5 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp @@ -287,9 +287,9 @@ void Scene_surface_mesh_item::standard_constructor(SMesh* sm) d->textVItems = new TextListItem(this); d->textEItems = new TextListItem(this); d->textFItems = new TextListItem(this); - are_buffers_filled = false; invalidate(ALL); + } Scene_surface_mesh_item::Scene_surface_mesh_item(SMesh* sm) { @@ -674,10 +674,12 @@ void Scene_surface_mesh_item_priv::initialize_colors() const max = (std::max)(max, fpatch_id_map[fd]); min_patch_id = (std::min)(min_patch_id, fpatch_id_map[fd]); } - - colors_.clear(); - compute_color_map(item->color(), (std::max)(1, max + 1 - min_patch_id), - std::back_inserter(colors_)); + if(item->property("recompute_colors").toBool()) + { + colors_.clear(); + compute_color_map(item->color(), (std::max)(1, max + 1 - min_patch_id), + std::back_inserter(colors_)); + } } void Scene_surface_mesh_item_priv::initializeBuffers(CGAL::Three::Viewer_interface* viewer)const @@ -1379,8 +1381,9 @@ bool Scene_surface_mesh_item::intersect_face(double orig_x, return false; } -void Scene_surface_mesh_item::setItemIsMulticolor(bool b) +void Scene_surface_mesh_item::setItemIsMulticolor(bool b, bool recompute_colors) { + this->setProperty("recompute_colors",recompute_colors); if(b) { d->fpatch_id_map = d->smesh_->add_property_map("f:patch_id", 1).first; diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h index edd108368c1..b38db8a218f 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h @@ -68,7 +68,11 @@ public: QMenu* contextMenu() Q_DECL_OVERRIDE; - void setItemIsMulticolor(bool); + //first bool to set property, second to disable the recomputation of the colors_ vector + //to scale on min_patch value. For example, the Mesh_segmentation_plugin computes the colors_ + // vector itself, so it must set recompute_colors to false to avoid having it ovewritten + // in the code of this item. + void setItemIsMulticolor(bool, bool recompute_colors = true); bool isItemMulticolor(); bool hasPatchIds(); Vertex_selection_map vertex_selection_map(); From 9dc71d3a61bca184b1324b57b8dbe2db85fe7b81 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 13 Nov 2018 15:14:59 +0100 Subject: [PATCH 21/21] Change API --- .../Plugins/Mesh_3/Optimization_plugin_cgal_code.cpp | 1 + .../Partition_graph_plugin.cpp | 5 ++++- .../Plugins/PMP/Detect_sharp_edges_plugin.cpp | 1 + .../Plugins/PMP/Isotropic_remeshing_plugin.cpp | 11 ++++++++++- .../Plugins/PMP/Join_and_split_polyhedra_plugin.cpp | 1 + .../PMP/Mean_curvature_flow_skeleton_plugin.cpp | 1 + .../Surface_mesh/Mesh_plane_detection_plugin.cpp | 1 + .../Plugins/Surface_mesh/Mesh_segmentation_plugin.cpp | 4 +++- .../demo/Polyhedron/Scene_polyhedron_selection_item.h | 1 + .../demo/Polyhedron/Scene_surface_mesh_item.cpp | 8 ++++++-- Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h | 11 +++++++---- 11 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Optimization_plugin_cgal_code.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Optimization_plugin_cgal_code.cpp index ea98ff61bfd..3475f12e163 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Optimization_plugin_cgal_code.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Optimization_plugin_cgal_code.cpp @@ -133,6 +133,7 @@ Optimizer_thread* cgal_code_optimization(Scene_c3t3_item& c3t3_item, if ( NULL != sm_item ) { const_cast(sm_item)->setItemIsMulticolor(true); + const_cast(sm_item)->computeItemColorVectorAutomatically(true); // Build domain const SMesh* smesh = sm_item->face_graph(); if ( NULL == smesh ) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Partition_graph_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Partition_graph_plugin.cpp index 8a252edf612..c2b390a14bd 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Partition_graph_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Operations_on_polyhedra/Partition_graph_plugin.cpp @@ -97,8 +97,11 @@ private: QApplication::setOverrideCursor(Qt::WaitCursor); item->face_graph()->collect_garbage(); item->color_vector().clear(); - if(!item->hasPatchIds()) + if(!item->hasPatchIds()){ item->setItemIsMulticolor(true); + item->computeItemColorVectorAutomatically(true); + } + typedef boost::property_map >::type PatchIDMap; FaceGraph* fg =item->face_graph(); boost::property_map::type diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Detect_sharp_edges_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Detect_sharp_edges_plugin.cpp index f7f559c373c..357f34c8eca 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Detect_sharp_edges_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Detect_sharp_edges_plugin.cpp @@ -133,6 +133,7 @@ void Polyhedron_demo_detect_sharp_edges_plugin::detectSharpEdges(bool input_dial .vertex_incident_patches_map(vip)); //update item item->setItemIsMulticolor(true); + item->computeItemColorVectorAutomatically(true); item->invalidateOpenGLBuffers(); // update scene diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Isotropic_remeshing_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Isotropic_remeshing_plugin.cpp index 3fa8fcca4fe..60a0209510c 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Isotropic_remeshing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Isotropic_remeshing_plugin.cpp @@ -473,7 +473,16 @@ public Q_SLOTS: } selection_item->polyhedron_item()->setColor( selection_item->polyhedron_item()->color()); - selection_item->polyhedron_item()->setItemIsMulticolor(fpmap_valid); + if(fpmap_valid) + { + selection_item->polyhedron_item()->setItemIsMulticolor(true); + selection_item->polyhedron_item()->computeItemColorVectorAutomatically(true); + } + else + { + selection_item->polyhedron_item()->setItemIsMulticolor(false); + } + selection_item->polyhedron_item()->polyhedron()->collect_garbage(); //fix constrained_edges_map for(int i=0; i< nE; ++i) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Join_and_split_polyhedra_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Join_and_split_polyhedra_plugin.cpp index fa58b268279..a04801e613c 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Join_and_split_polyhedra_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Join_and_split_polyhedra_plugin.cpp @@ -244,6 +244,7 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionColorConnectedCom typedef boost::graph_traits::face_descriptor face_descriptor; selection_item->polyhedron_item()->setItemIsMulticolor(true); + selection_item->polyhedron_item()->computeItemColorVectorAutomatically(true); FaceGraph& pmesh = *(selection_item->polyhedron()); boost::property_map::type fim diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Mean_curvature_flow_skeleton_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Mean_curvature_flow_skeleton_plugin.cpp index fb4ccf514bf..cd7f6c5fbab 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Mean_curvature_flow_skeleton_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Mean_curvature_flow_skeleton_plugin.cpp @@ -429,6 +429,7 @@ void Polyhedron_demo_mean_curvature_flow_skeleton_plugin::on_actionSegment() } item_segmentation->setItemIsMulticolor(true); + item_segmentation->computeItemColorVectorAutomatically(true); item_segmentation->setProperty("NbPatchIds", nb_segment); //for join_and_split plugin item_segmentation->invalidateOpenGLBuffers(); scene->addItem(item_segmentation); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_plane_detection_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_plane_detection_plugin.cpp index 4fb812dae88..28de24b4acc 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_plane_detection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_plane_detection_plugin.cpp @@ -229,6 +229,7 @@ void Polyhedron_demo_mesh_plane_detection_plugin::colorize_segmentation( std::vector& color_vector) { item->setItemIsMulticolor(true); + item->computeItemColorVectorAutomatically(true); SMesh* sm = item->face_graph(); color_vector.clear(); std::size_t max_segment = 0; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_segmentation_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_segmentation_plugin.cpp index a4f5d553b81..02b3740984f 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_segmentation_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Mesh_segmentation_plugin.cpp @@ -377,7 +377,8 @@ void Polyhedron_demo_mesh_segmentation_plugin::colorize_sdf( } put(pidmap, *facet_it, static_cast(patch_id)); } - item->setItemIsMulticolor(true, false); + item->setItemIsMulticolor(true); + item->computeItemColorVectorAutomatically(false); } @@ -407,6 +408,7 @@ void Polyhedron_demo_mesh_segmentation_plugin::colorize_segmentation( color_vector.push_back(aColor); } item->setItemIsMulticolor(true); + item->computeItemColorVectorAutomatically(true); item->setProperty("NbPatchIds", static_cast(max_segment + 1)); //for join_and_split plugin } diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h index 8791f416e93..ba3617816b1 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h @@ -793,6 +793,7 @@ public: void setItemIsMulticolor(bool b) { poly_item->setItemIsMulticolor(b); + poly_item->computeItemColorVectorAutomatically(b); } void selection_changed(bool b); diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp index 1f8fb0058f5..0013b1e4313 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.cpp @@ -1381,9 +1381,8 @@ bool Scene_surface_mesh_item::intersect_face(double orig_x, return false; } -void Scene_surface_mesh_item::setItemIsMulticolor(bool b, bool recompute_colors) +void Scene_surface_mesh_item::setItemIsMulticolor(bool b) { - this->setProperty("recompute_colors",recompute_colors); if(b) { d->fpatch_id_map = d->smesh_->add_property_map("f:patch_id", 1).first; @@ -2219,3 +2218,8 @@ void Scene_surface_mesh_item::copyProperties(Scene_item *item) int value = sm_item->alphaSlider()->value(); alphaSlider()->setValue(value); } + +void Scene_surface_mesh_item::computeItemColorVectorAutomatically(bool b) +{ + this->setProperty("recompute_colors",b); +} diff --git a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h index b38db8a218f..6f2bc777a61 100644 --- a/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_surface_mesh_item.h @@ -68,11 +68,14 @@ public: QMenu* contextMenu() Q_DECL_OVERRIDE; - //first bool to set property, second to disable the recomputation of the colors_ vector - //to scale on min_patch value. For example, the Mesh_segmentation_plugin computes the colors_ - // vector itself, so it must set recompute_colors to false to avoid having it ovewritten + void setItemIsMulticolor(bool); + //to be called before invalidate() to enable or disable the recomputation + //of the colors_ vector to scale on min_patch value. + // For example, the Mesh_segmentation_plugin computes the colors_ + // vector itself, so it must set recompute_colors to false to avoid + // having it ovewritten // in the code of this item. - void setItemIsMulticolor(bool, bool recompute_colors = true); + void computeItemColorVectorAutomatically(bool); bool isItemMulticolor(); bool hasPatchIds(); Vertex_selection_map vertex_selection_map();