From d905a36e837a31255d3da88e4bf401a314d4d7c6 Mon Sep 17 00:00:00 2001 From: Daniel Rauch Date: Fri, 29 Mar 2024 11:22:46 +0100 Subject: [PATCH 1/4] Fix #6725: O3DVisualizer: make points removable and fix point size calc Correctly forward keymodifier to enable point removing and fix bounding box calculation for picked point size selection. --- .../gui/PickPointsInteractor.cpp | 60 ++++++++++--------- .../visualizer/O3DVisualizer.cpp | 21 +++---- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/cpp/open3d/visualization/gui/PickPointsInteractor.cpp b/cpp/open3d/visualization/gui/PickPointsInteractor.cpp index 45ca7c44c1e..9f7c7d7be0f 100644 --- a/cpp/open3d/visualization/gui/PickPointsInteractor.cpp +++ b/cpp/open3d/visualization/gui/PickPointsInteractor.cpp @@ -268,37 +268,41 @@ void PickPointsInteractor::SetOnStartedPolygonPicking( } void PickPointsInteractor::Mouse(const MouseEvent &e) { - if (e.type == MouseEvent::BUTTON_UP) { - if (e.modifiers & int(KeyModifier::ALT)) { - if (pending_.empty() || pending_.back().keymods == 0) { - pending_.push({{gui::Point(e.x, e.y)}, int(KeyModifier::ALT)}); - if (on_ui_changed_) { - on_ui_changed_({}); - } - } else { - pending_.back().polygon.push_back(gui::Point(e.x, e.y)); - if (on_started_poly_pick_) { - on_started_poly_pick_(); - } - if (on_ui_changed_) { - std::vector lines; - auto &polygon = pending_.back().polygon; - for (size_t i = 1; i < polygon.size(); ++i) { - auto &p0 = polygon[i - 1]; - auto &p1 = polygon[i]; - lines.push_back({p0.x, p0.y}); - lines.push_back({p1.x, p1.y}); - } - lines.push_back({polygon.back().x, polygon.back().y}); - lines.push_back({polygon[0].x, polygon[0].y}); - on_ui_changed_(lines); - } + if (e.type != MouseEvent::BUTTON_UP) + return; + + bool polygon_picking_requested = e.modifiers & int(KeyModifier::ALT); + if (!polygon_picking_requested) { + // standard point picking + pending_.push({{gui::Point(e.x, e.y)}, e.modifiers}); + DoPick(); + } else { + // special polygon picking mode + if (pending_.empty() || pending_.back().keymods == 0) { + pending_.push({{gui::Point(e.x, e.y)}, e.modifiers}); + if (on_ui_changed_) { + on_ui_changed_({}); } } else { - pending_.push({{gui::Point(e.x, e.y)}, 0}); - DoPick(); + pending_.back().polygon.push_back(gui::Point(e.x, e.y)); + if (on_started_poly_pick_) { + on_started_poly_pick_(); + } + if (on_ui_changed_) { + std::vector lines; + auto &polygon = pending_.back().polygon; + for (size_t i = 1; i < polygon.size(); ++i) { + auto &p0 = polygon[i - 1]; + auto &p1 = polygon[i]; + lines.push_back({p0.x, p0.y}); + lines.push_back({p1.x, p1.y}); + } + lines.push_back({polygon.back().x, polygon.back().y}); + lines.push_back({polygon[0].x, polygon[0].y}); + on_ui_changed_(lines); + } } - } + } } void PickPointsInteractor::Key(const KeyEvent &e) { diff --git a/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp b/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp index 3ab06cec1b9..652386d4dd4 100644 --- a/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp +++ b/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp @@ -384,8 +384,8 @@ struct O3DVisualizer::Impl { std::vector>> &indices, int keymods) { - if ((keymods & int(KeyModifier::SHIFT)) || - polygon_selection_unselects_) { + bool unselect_mode_requested = keymods & int(KeyModifier::SHIFT); + if (unselect_mode_requested || polygon_selection_unselects_) { selections_->UnselectIndices(indices); } else { selections_->SelectIndices(indices); @@ -489,10 +489,13 @@ struct O3DVisualizer::Impl { #if __APPLE__ const char *selection_help = - "Cmd-click to select a point\nCmd-ctrl-click to polygon select"; + const char *selection_help = R"(Cmd-click to select a point +Cmd-shift-click to deselect a point +Cmd-alt-click to polygon select)"; #else - const char *selection_help = - "Ctrl-click to select a point\nCmd-alt-click to polygon select"; + const char *selection_help = R"(Ctrl-click to select a point +Ctrl-shift-click to deselect a point +Ctrl-alt-click to polygon select)"; #endif // __APPLE__ h = new Horiz(); h->AddStretch(); @@ -1545,12 +1548,10 @@ struct O3DVisualizer::Impl { OverrideMaterial(o.name, o.material, ui_state_.scene_shader); } - auto bbox = scene_->GetScene()->GetBoundingBox(); - auto xdim = bbox.max_bound_.x() - bbox.min_bound_.x(); - auto ydim = bbox.max_bound_.y() - bbox.min_bound_.z(); - auto zdim = bbox.max_bound_.z() - bbox.min_bound_.y(); + auto bbox_extend = scene_->GetScene()->GetBoundingBox().GetExtent(); auto psize = double(std::max(5, px)) * 0.000666 * - std::max(xdim, std::max(ydim, zdim)); + std::max(bbox_extend.x(), + std::max(bbox_extend.y(), bbox_extend.z())); selections_->SetPointSize(psize); scene_->SetPickablePointSize(px); From 0c9f41dc50c5cff81790d1d4c5d0c9350b83b0ec Mon Sep 17 00:00:00 2001 From: Daniel Rauch Date: Fri, 29 Mar 2024 20:50:28 +0000 Subject: [PATCH 2/4] Apply style --- .../visualization/gui/PickPointsInteractor.cpp | 5 ++--- .../visualization/visualizer/O3DVisualizer.cpp | 14 ++++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cpp/open3d/visualization/gui/PickPointsInteractor.cpp b/cpp/open3d/visualization/gui/PickPointsInteractor.cpp index 9f7c7d7be0f..4052b09e91b 100644 --- a/cpp/open3d/visualization/gui/PickPointsInteractor.cpp +++ b/cpp/open3d/visualization/gui/PickPointsInteractor.cpp @@ -268,8 +268,7 @@ void PickPointsInteractor::SetOnStartedPolygonPicking( } void PickPointsInteractor::Mouse(const MouseEvent &e) { - if (e.type != MouseEvent::BUTTON_UP) - return; + if (e.type != MouseEvent::BUTTON_UP) return; bool polygon_picking_requested = e.modifiers & int(KeyModifier::ALT); if (!polygon_picking_requested) { @@ -302,7 +301,7 @@ void PickPointsInteractor::Mouse(const MouseEvent &e) { on_ui_changed_(lines); } } - } + } } void PickPointsInteractor::Key(const KeyEvent &e) { diff --git a/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp b/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp index 652386d4dd4..4be43494763 100644 --- a/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp +++ b/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp @@ -384,8 +384,10 @@ struct O3DVisualizer::Impl { std::vector>> &indices, int keymods) { - bool unselect_mode_requested = keymods & int(KeyModifier::SHIFT); - if (unselect_mode_requested || polygon_selection_unselects_) { + bool unselect_mode_requested = + keymods & int(KeyModifier::SHIFT); + if (unselect_mode_requested || + polygon_selection_unselects_) { selections_->UnselectIndices(indices); } else { selections_->SelectIndices(indices); @@ -488,8 +490,8 @@ struct O3DVisualizer::Impl { }); #if __APPLE__ - const char *selection_help = - const char *selection_help = R"(Cmd-click to select a point + const char *selection_help = const char *selection_help = + R"(Cmd-click to select a point Cmd-shift-click to deselect a point Cmd-alt-click to polygon select)"; #else @@ -1550,8 +1552,8 @@ Ctrl-alt-click to polygon select)"; auto bbox_extend = scene_->GetScene()->GetBoundingBox().GetExtent(); auto psize = double(std::max(5, px)) * 0.000666 * - std::max(bbox_extend.x(), - std::max(bbox_extend.y(), bbox_extend.z())); + std::max(bbox_extend.x(), + std::max(bbox_extend.y(), bbox_extend.z())); selections_->SetPointSize(psize); scene_->SetPickablePointSize(px); From 3137df695e5892e9c8185ee4ae290d1a49c3cd3c Mon Sep 17 00:00:00 2001 From: Daniel Rauch Date: Fri, 29 Mar 2024 21:35:14 +0000 Subject: [PATCH 3/4] Fix crash occuring when trying to make selection and non-pickable geometries where in scene Error example: [Open3D Error] (void open3d::visualization::gui::SelectionIndexLookup::Add(const string&, size_t)) start_index 3248 must be larger than all previously added objects 3248. --- cpp/open3d/visualization/gui/PickPointsInteractor.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cpp/open3d/visualization/gui/PickPointsInteractor.cpp b/cpp/open3d/visualization/gui/PickPointsInteractor.cpp index 4052b09e91b..63ecfba7955 100644 --- a/cpp/open3d/visualization/gui/PickPointsInteractor.cpp +++ b/cpp/open3d/visualization/gui/PickPointsInteractor.cpp @@ -155,8 +155,6 @@ void PickPointsInteractor::SetPickableGeometry( // TriangleMesh so that occluded points are not selected. points_.clear(); for (auto &pg : geometry) { - lookup_->Add(pg.name, points_.size()); - auto cloud = dynamic_cast(pg.geometry); auto tcloud = dynamic_cast(pg.tgeometry); @@ -166,6 +164,12 @@ void PickPointsInteractor::SetPickableGeometry( auto lineset = dynamic_cast(pg.geometry); auto tlineset = dynamic_cast(pg.tgeometry); + + // only add geometry with pickable points + if (cloud || tcloud || mesh || tmesh || lineset || tlineset) { + lookup_->Add(pg.name, points_.size()); + } + if (cloud) { points_.insert(points_.end(), cloud->points_.begin(), cloud->points_.end()); From c4d26f0fade4512a6434b43620516178639bcdae Mon Sep 17 00:00:00 2001 From: Daniel Rauch Date: Wed, 17 Apr 2024 13:10:27 +0200 Subject: [PATCH 4/4] Fix copy&paste error in help text for MACOS --- cpp/open3d/visualization/visualizer/O3DVisualizer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp b/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp index 4be43494763..554d38b2466 100644 --- a/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp +++ b/cpp/open3d/visualization/visualizer/O3DVisualizer.cpp @@ -490,8 +490,7 @@ struct O3DVisualizer::Impl { }); #if __APPLE__ - const char *selection_help = const char *selection_help = - R"(Cmd-click to select a point + const char *selection_help = R"(Cmd-click to select a point Cmd-shift-click to deselect a point Cmd-alt-click to polygon select)"; #else