Skip to content

Commit

Permalink
Add O3DVisualizer API to enable collapse control of verts in the side…
Browse files Browse the repository at this point in the history
… panel (#6865)

* Add GetText/SetText to CollapsableVert
---------
Co-authored-by: Ewing Kang <[email protected]>
  • Loading branch information
EwingKang authored Jul 25, 2024
1 parent 9f03592 commit 78e4bfd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- Fix segmentation fault (infinite recursion) of DetectPlanarPatches if multiple points have same coordinates (PR #6794)
- Fix build with fmt v10.2.0 (#6783)
- Fix segmentation fault (lambda reference capture) of VisualizerWithCustomAnimation::Play (PR #6804)
- Add O3DVisualizer API to enable collapse control of verts in the side panel (PR #6865)

## 0.13

Expand Down
14 changes: 10 additions & 4 deletions cpp/open3d/visualization/gui/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,7 @@ CollapsableVert::CollapsableVert(const char* text,
int spacing,
const Margins& margins /*= Margins()*/)
: Vert(spacing, margins), impl_(new CollapsableVert::Impl()) {
static int g_next_id = 1;

impl_->text_ = text;
impl_->id_ = impl_->text_ + "##collapsing_" + std::to_string(g_next_id++);
SetText(text);
}

CollapsableVert::~CollapsableVert() {}
Expand All @@ -398,6 +395,15 @@ void CollapsableVert::SetIsOpen(bool is_open) { impl_->is_open_ = is_open; }

bool CollapsableVert::GetIsOpen() { return impl_->is_open_; }

void CollapsableVert::SetText(const char* text) {
static int g_next_id = 1;

impl_->text_ = text;
impl_->id_ = impl_->text_ + "##collapsing_" + std::to_string(g_next_id++);
}

std::string CollapsableVert::GetText() const { return impl_->text_; };

FontId CollapsableVert::GetFontId() const { return impl_->font_id_; }

void CollapsableVert::SetFontId(FontId font_id) { impl_->font_id_ = font_id; }
Expand Down
5 changes: 5 additions & 0 deletions cpp/open3d/visualization/gui/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#include <string>

#include "open3d/visualization/gui/Widget.h"

namespace open3d {
Expand Down Expand Up @@ -148,6 +150,9 @@ class CollapsableVert : public Vert {
/// Returns true if open and false if collapsed.
bool GetIsOpen();

void SetText(const char* text);
std::string GetText() const;

FontId GetFontId() const;
void SetFontId(FontId font_id);

Expand Down
16 changes: 16 additions & 0 deletions cpp/open3d/visualization/visualizer/O3DVisualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,18 @@ Ctrl-alt-click to polygon select)";
}
}

void SetPanelOpen(const std::string &name, bool open) {
if (name == settings.mouse_panel->GetText()) {
settings.mouse_panel->SetIsOpen(open);
} else if (name == settings.scene_panel->GetText()) {
settings.scene_panel->SetIsOpen(open);
} else if (name == settings.light_panel->GetText()) {
settings.light_panel->SetIsOpen(open);
} else if (name == settings.geometries_panel->GetText()) {
settings.geometries_panel->SetIsOpen(open);
}
}

void SetPicking() {
if (selections_->GetNumberOfSets() == 0) {
NewSelectionSet();
Expand Down Expand Up @@ -2446,6 +2458,10 @@ void O3DVisualizer::SetMouseMode(SceneWidget::Controls mode) {
impl_->SetMouseMode(mode);
}

void O3DVisualizer::SetPanelOpen(const std::string &name, bool open) {
impl_->SetPanelOpen(name, open);
}

void O3DVisualizer::EnableGroup(const std::string &group, bool enable) {
impl_->EnableGroup(group, enable);
}
Expand Down
1 change: 1 addition & 0 deletions cpp/open3d/visualization/visualizer/O3DVisualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class O3DVisualizer : public gui::Window {
void SetLineWidth(int line_width);
void EnableGroup(const std::string& group, bool enable);
void SetMouseMode(gui::SceneWidget::Controls mode);
void SetPanelOpen(const std::string& name, bool open);

std::vector<O3DVisualizerSelections::SelectionSet> GetSelectionSets() const;

Expand Down
4 changes: 4 additions & 0 deletions cpp/pybind/visualization/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,10 @@ void pybind_gui_classes(py::module &m) {
"window is visible")
.def("get_is_open", &CollapsableVert::GetIsOpen,
"Check if widget is open.")
.def("set_text", &CollapsableVert::SetText, "text"_a,
"Sets the text for the CollapsableVert")
.def("get_text", &CollapsableVert::GetText,
"Gets the text for the CollapsableVert")
.def_property("font_id", &CollapsableVert::GetFontId,
&CollapsableVert::SetFontId,
"Set the font using the FontId returned from "
Expand Down
3 changes: 3 additions & 0 deletions cpp/pybind/visualization/o3dvisualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ void pybind_o3dvisualizer(py::module& m) {
"enable"_a)
.def("show_skybox", &O3DVisualizer::ShowSkybox,
"Show/Hide the skybox", "show"_a)
.def("set_panel_open", &O3DVisualizer::SetPanelOpen,
"Expand/Collapse verts(panels) within the settings panel",
"name"_a, "open"_a)
.def_property(
"show_settings",
[](const O3DVisualizer& dv) {
Expand Down

0 comments on commit 78e4bfd

Please sign in to comment.