Open3D解决SceneWidget加入布局中消失的问题

Open3D解决SceneWidget加入布局中消失的问题

  • Open3D解决SceneWidget加入布局中消失的问题
    • 1. 问题
    • 2. 问题代码
    • 3. 解决

Open3D解决SceneWidget加入布局中消失的问题

1. 问题

把SceneWidget加到布局管理其中图形可以展示出来,但是鼠标点击就消失了。

stackoverflow上已经有人提出这个问题了,还是2022年的时候,可是现在好像也没有解决。
https://stackoverflow.com/questions/71706506/why-does-open3d-visualization-disappear-when-i-left-click-the-window

2. 问题代码

在这里插入图片描述

# ----------------------------------------------------------------------------
# -                        Open3D: www.open3d.org                            -
# ----------------------------------------------------------------------------
# Copyright (c) 2018-2024 www.open3d.org
# SPDX-License-Identifier: MIT
# ----------------------------------------------------------------------------import open3d as o3d
import open3d.visualization.gui as gui
import open3d.visualization.rendering as rendering
import platform
import random
import threading
import timeisMacOS = (platform.system() == "Darwin")# This example shows two methods of adding geometry to an existing scene.
# 1) add via a UI callback (in this case a menu, but a button would be similar,
#    you would call `button.set_on_clicked(self.on_menu_sphere_)` when
#    configuring the button. See `on_menu_sphere()`.
# 2) add asynchronously by polling from another thread. GUI functions must be
#    called from the UI thread, so use Application.post_to_main_thread().
#    See `on_menu_random()`.
# Running the example will show a simple window with a Debug menu item with the
# two different options. The second method will add random spheres for
# 20 seconds, during which time you can be interacting with the scene, rotating,
# etc.
class SpheresApp:MENU_SPHERE = 1MENU_RANDOM = 2MENU_QUIT = 3def __init__(self):self._id = 0self.window = gui.Application.instance.create_window("Add Spheres Example", 800, 600)# The menu is global (because the macOS menu is global), so only create# it once, no matter how many windows are createdif gui.Application.instance.menubar is None:if isMacOS:app_menu = gui.Menu()app_menu.add_item("Quit", SpheresApp.MENU_QUIT)debug_menu = gui.Menu()debug_menu.add_item("Add Sphere", SpheresApp.MENU_SPHERE)debug_menu.add_item("Add Random Spheres", SpheresApp.MENU_RANDOM)if not isMacOS:debug_menu.add_separator()debug_menu.add_item("Quit", SpheresApp.MENU_QUIT)menu = gui.Menu()if isMacOS:# macOS will name the first menu item for the running application# (in our case, probably "Python"), regardless of what we call# it. This is the application menu, and it is where the# About..., Preferences..., and Quit menu items typically go.menu.add_menu("Example", app_menu)menu.add_menu("Debug", debug_menu)else:menu.add_menu("Debug", debug_menu)gui.Application.instance.menubar = menu# The menubar is global, but we need to connect the menu items to the# window, so that the window can call the appropriate function when the# menu item is activated.self.window.set_on_menu_item_activated(SpheresApp.MENU_SPHERE,self._on_menu_sphere)self.window.set_on_menu_item_activated(SpheresApp.MENU_RANDOM,self._on_menu_random)self.window.set_on_menu_item_activated(SpheresApp.MENU_QUIT,self._on_menu_quit)self.scene = gui.SceneWidget()self.scene.scene = rendering.Open3DScene(self.window.renderer)self.scene.scene.show_axes(True)mesh = o3d.geometry.TriangleMesh.create_sphere()mesh.compute_vertex_normals()material = rendering.MaterialRecord()material.shader = "defaultLit"self.scene.scene.add_geometry("sphere" + str(self._id), mesh, material)em = self.window.theme.font_sizeself.layout = gui.Horiz(0, gui.Margins(0.25*em,0.25*em,0.25*em,0.254*em))self.layout.add_child(gui.Label("Model file"))self.layout.add_fixed(0.25 * em)self.window.set_on_layout(self.on_window_layout)self.vlayout = gui.Vert(0, gui.Margins(0.25 * em, 0.25 * em, 0.25 * em, 0.254 * em))self.vlayout.add_child(self.scene)self.vlayout.add_fixed(0.25 * em)self.window.add_child(self.vlayout)self.window.add_child(self.layout)def on_window_layout(self, layout: gui.LayoutContext) -> None:"""This is called when layout is required for this widgets *immediate children*, like on resize. Only the immediatechildren are *manually* positioned here, by setting the x, y, width, and height of their frames. Thegrandchildren are *not* touched here; they're automatically handled after this."""# This is the area in this widget available to place child widgets in. The *units* here aren't window screen# pixels, like from the width/height here when setting up the window: gui.Application.instance.create_window("Test", width=500, height=600).rect = self.window.content_rectr = self.window.content_rectprint(r)print(layout.theme.default_layout_spacing)print(layout.theme.default_margin)print(layout.theme.font_size)# Put the layout (containing the controls) on the left 1/3 and the and scene on the right 2/3.x_division = rect.width // 3# Set the layout (gui.Vert) on left to 1/3 available width, full height.# gui.Rect(x, y, width, height)# Set the SceneWidget on on right, 2/3 available width, full heightself.vlayout.frame = gui.Rect(0, 0, r.width - x_division, r.height)self.layout.frame = gui.Rect(r.width - x_division, 0, x_division, r.height)def add_sphere(self):self._id += 1mat = rendering.MaterialRecord()mat.base_color = [random.random(),random.random(),random.random(), 1.0]mat.shader = "defaultLit"sphere = o3d.geometry.TriangleMesh.create_sphere(0.5)sphere.compute_vertex_normals()sphere.translate([10.0 * random.uniform(-1.0, 1.0), 10.0 * random.uniform(-1.0, 1.0),10.0 * random.uniform(-1.0, 1.0)])self.scene.scene.add_geometry("sphere" + str(self._id), sphere, mat)def _on_menu_sphere(self):# GUI callbacks happen on the main thread, so we can do everything# normally here.self.scene.scene.clear_geometry()self.add_sphere()def _on_menu_random(self):# This adds spheres asynchronously. This pattern is useful if you have# data coming in from another source than user interaction.def thread_main():for _ in range(0, 20):# We can only modify GUI objects on the main thread, so we# need to post the function to call to the main thread.gui.Application.instance.post_to_main_thread(self.window, self.add_sphere)time.sleep(0.5)threading.Thread(target=thread_main).start()def _on_menu_quit(self):gui.Application.instance.quit()def main():gui.Application.instance.initialize()SpheresApp()gui.Application.instance.run()if __name__ == "__main__":main()

3. 解决

不能放在布局中就直接手动布局吧,
不加到布局中去。。。

在这里插入图片描述

# ----------------------------------------------------------------------------
# -                        Open3D: www.open3d.org                            -
# ----------------------------------------------------------------------------
# Copyright (c) 2018-2024 www.open3d.org
# SPDX-License-Identifier: MIT
# ----------------------------------------------------------------------------import open3d as o3d
import open3d.visualization.gui as gui
import open3d.visualization.rendering as rendering
import platform
import random
import threading
import timeisMacOS = (platform.system() == "Darwin")# This example shows two methods of adding geometry to an existing scene.
# 1) add via a UI callback (in this case a menu, but a button would be similar,
#    you would call `button.set_on_clicked(self.on_menu_sphere_)` when
#    configuring the button. See `on_menu_sphere()`.
# 2) add asynchronously by polling from another thread. GUI functions must be
#    called from the UI thread, so use Application.post_to_main_thread().
#    See `on_menu_random()`.
# Running the example will show a simple window with a Debug menu item with the
# two different options. The second method will add random spheres for
# 20 seconds, during which time you can be interacting with the scene, rotating,
# etc.
class SpheresApp:MENU_SPHERE = 1MENU_RANDOM = 2MENU_QUIT = 3def __init__(self):self._id = 0self.window = gui.Application.instance.create_window("Add Spheres Example", 800, 600)# The menu is global (because the macOS menu is global), so only create# it once, no matter how many windows are createdif gui.Application.instance.menubar is None:if isMacOS:app_menu = gui.Menu()app_menu.add_item("Quit", SpheresApp.MENU_QUIT)debug_menu = gui.Menu()debug_menu.add_item("Add Sphere", SpheresApp.MENU_SPHERE)debug_menu.add_item("Add Random Spheres", SpheresApp.MENU_RANDOM)if not isMacOS:debug_menu.add_separator()debug_menu.add_item("Quit", SpheresApp.MENU_QUIT)menu = gui.Menu()if isMacOS:# macOS will name the first menu item for the running application# (in our case, probably "Python"), regardless of what we call# it. This is the application menu, and it is where the# About..., Preferences..., and Quit menu items typically go.menu.add_menu("Example", app_menu)menu.add_menu("Debug", debug_menu)else:menu.add_menu("Debug", debug_menu)gui.Application.instance.menubar = menu# The menubar is global, but we need to connect the menu items to the# window, so that the window can call the appropriate function when the# menu item is activated.self.window.set_on_menu_item_activated(SpheresApp.MENU_SPHERE,self._on_menu_sphere)self.window.set_on_menu_item_activated(SpheresApp.MENU_RANDOM,self._on_menu_random)self.window.set_on_menu_item_activated(SpheresApp.MENU_QUIT,self._on_menu_quit)self.scene = gui.SceneWidget()self.scene.scene = rendering.Open3DScene(self.window.renderer)self.scene.scene.show_axes(True)mesh = o3d.geometry.TriangleMesh.create_sphere()mesh.compute_vertex_normals()material = rendering.MaterialRecord()material.shader = "defaultLit"self.scene.scene.add_geometry("sphere" + str(self._id), mesh, material)em = self.window.theme.font_sizeself.layout = gui.Horiz(0, gui.Margins(0.25*em,0.25*em,0.25*em,0.254*em))self.layout.add_child(gui.Label("Model file"))self.layout.add_fixed(0.25 * em)self.window.set_on_layout(self.on_window_layout)self.window.add_child(self.scene)self.window.add_child(self.layout)def on_window_layout(self, layout: gui.LayoutContext) -> None:"""This is called when layout is required for this widgets *immediate children*, like on resize. Only the immediatechildren are *manually* positioned here, by setting the x, y, width, and height of their frames. Thegrandchildren are *not* touched here; they're automatically handled after this."""# This is the area in this widget available to place child widgets in. The *units* here aren't window screen# pixels, like from the width/height here when setting up the window: gui.Application.instance.create_window("Test", width=500, height=600).rect = self.window.content_rectr = self.window.content_rectprint(r)print(layout.theme.default_layout_spacing)print(layout.theme.default_margin)print(layout.theme.font_size)# Put the layout (containing the controls) on the left 1/3 and the and scene on the right 2/3.x_division = rect.width // 3# Set the layout (gui.Vert) on left to 1/3 available width, full height.# gui.Rect(x, y, width, height)# Set the SceneWidget on on right, 2/3 available width, full heightself.scene.frame = gui.Rect(0, 0, r.width - x_division, r.height)self.layout.frame = gui.Rect(r.width - x_division, 0, x_division, r.height)def add_sphere(self):self._id += 1mat = rendering.MaterialRecord()mat.base_color = [random.random(),random.random(),random.random(), 1.0]mat.shader = "defaultLit"sphere = o3d.geometry.TriangleMesh.create_sphere(0.5)sphere.compute_vertex_normals()sphere.translate([10.0 * random.uniform(-1.0, 1.0), 10.0 * random.uniform(-1.0, 1.0),10.0 * random.uniform(-1.0, 1.0)])self.scene.scene.add_geometry("sphere" + str(self._id), sphere, mat)def _on_menu_sphere(self):# GUI callbacks happen on the main thread, so we can do everything# normally here.self.scene.scene.clear_geometry()self.add_sphere()def _on_menu_random(self):# This adds spheres asynchronously. This pattern is useful if you have# data coming in from another source than user interaction.def thread_main():for _ in range(0, 20):# We can only modify GUI objects on the main thread, so we# need to post the function to call to the main thread.gui.Application.instance.post_to_main_thread(self.window, self.add_sphere)time.sleep(0.5)threading.Thread(target=thread_main).start()def _on_menu_quit(self):gui.Application.instance.quit()def main():gui.Application.instance.initialize()SpheresApp()gui.Application.instance.run()if __name__ == "__main__":main()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/26291.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

9 - QSPI Flash读写测试实验

文章目录 1 实验任务2 系统框图3 软件设计 1 实验任务 本实验任务是使用PS侧的QSPI Flash控制器,先后对QSPI Flash 进行写、 读操作。通过对比读出的数据是否等于写入的数据, 从而验证读写操作是否正确。 2 系统框图 3 软件设计 注意事项:…

简述一下anythingllm与vllm

政安晨的个人主页:政安晨 欢迎 👍点赞✍评论⭐收藏 希望政安晨的博客能够对您有所裨益,如有不足之处,欢迎在评论区提出指正! 关于 AnythingLLM 和 VLLM 的技术信息 AnythingLLM 特点与优势 对于主要需求在于文档问答…

JavaScript 数据类型和数据结构:从基础到实践

JavaScript 作为一门动态类型语言,以其灵活性和强大的功能在前端开发中占据了重要地位。理解 JavaScript 的数据类型和数据结构是掌握这门语言的关键。本文将带你深入探讨 JavaScript 中的数据类型、数据结构以及相关的类型检查和转换。 一、原始数据类型&#xff1…

深入解析XXL-JOB任务调度执行原理

引言 ​ 在分布式系统中,定时任务调度是业务场景中不可或缺的一环。面对海量任务、复杂依赖和高可用性要求,传统单机调度方案逐渐显得力不从心。XXL-JOB作为一款开源的分布式任务调度平台,凭借其轻量级、高扩展性和易用性成为众多企业的选择…

为AI聊天工具添加一个知识系统 之127 详细设计之68 编程 核心技术:Cognitive Protocol Language 之1

本文要点 要点 今天讨论的题目:本项目(为使用AI聊天工具的两天者加挂一个知识系统) 详细程序设计 之“编程的核心技术” 。 source的三个子类(Instrument, Agent, Effector) 分别表示--实际上actually ,…

word转换为pdf后图片失真解决办法、高质量PDF转换方法

1、安装Adobe Acrobat Pro DC 自行安装 2、配置Acrobat PDFMaker (1)点击word选项卡上的Acrobat插件,(2)点击“首选项”按钮,(3)点击“高级配置”按钮(4)点…

Kafka生产者相关

windows中kafka集群部署示例-CSDN博客 先启动集群或者单机也OK 引入依赖 <dependency><groupId>org.apache.kafka</groupId><artifactId>kafka-clients</artifactId><version>3.9.0</version></dependency>关于主题创建 理论…

《Effective Objective-C》阅读笔记(下)

目录 内存管理 理解引用计数 引用计数工作原理 自动释放池 保留环 以ARC简化引用计数 使用ARC时必须遵循的方法命名规则 变量的内存管理语义 ARC如何清理实例变量 在dealloc方法中只释放引用并解除监听 编写“异常安全代码”时留意内存管理问题 以弱引用避免保留环 …

一、对iic类模块分析与使用

bmp280驱动代码 说明&#xff1a; 1、该模块用于获取气压&#xff0c;温度&#xff0c;海拔等数据。 vcc&#xff0c;gnd接电源 sda &#xff0c;scl 接iic通信引脚 2、该模块使用iic通信&#xff0c;通过iic发送请求相关类的寄存器值&#xff0c;芯片获取对应寄存器返回的数据…

辛格迪客户案例 | 祐儿医药科技GMP培训管理(TMS)项目

01 项目背景&#xff1a;顺应行业趋势&#xff0c;弥补管理短板 随着医药科技行业的快速发展&#xff0c;相关法规和标准不断更新&#xff0c;对企业的质量管理和人员培训提出了更高要求。祐儿医药科技有限公司&#xff08;以下简称“祐儿医药”&#xff09;作为一家专注于创新…

汽车低频发射天线介绍

汽车低频PKE天线是基于RFID技术的深度研究及产品开发应用的一种天线&#xff0c;在汽车的智能系统中发挥着重要作用&#xff0c;以下是关于它的详细介绍&#xff1a; 移动管家PKE低频天线结构与原理 结构&#xff1a;产品一般由一个高Q值磁棒天线和一个高压电容组成&#xff…

Java 大视界 -- Java 大数据分布式文件系统的性能调优实战(101)

&#x1f496;亲爱的朋友们&#xff0c;热烈欢迎来到 青云交的博客&#xff01;能与诸位在此相逢&#xff0c;我倍感荣幸。在这飞速更迭的时代&#xff0c;我们都渴望一方心灵净土&#xff0c;而 我的博客 正是这样温暖的所在。这里为你呈上趣味与实用兼具的知识&#xff0c;也…

全国普通高等学校名单

全国普通高等学校名单 全国普通高等院校&#xff0c;简称“高校”&#xff0c;是指那些提供高等教育的学校&#xff0c;涵盖了大学、独立学院、高等专科学校以及高等职业学校等多种类型。这些机构通过国家普通高等教育招生考试&#xff0c;主要招收高中毕业生&#xff0c;并为…

Vue.js 学习笔记

文章目录 前言一、Vue.js 基础概念1.1 Vue.js 简介1.2 Vue.js 的特点1.3 Vue.js 基础示例 二、Vue.js 常用指令2.1 双向数据绑定&#xff08;v-model&#xff09;2.2 条件渲染&#xff08;v-if 和 v-show&#xff09;2.3 列表渲染&#xff08;v-for&#xff09;2.4 事件处理&am…

【Python】基础语法三

> 作者&#xff1a;დ旧言~ > 座右铭&#xff1a;松树千年终是朽&#xff0c;槿花一日自为荣。 > 目标&#xff1a;了解Python的函数、列表和数组。 > 毒鸡汤&#xff1a;有些事情&#xff0c;总是不明白&#xff0c;所以我不会坚持。早安! > 专栏选自&#xff…

传奇3光通版手游行会战攻略:团队协作与战术布局详解

戳一戳&#xff1b;了解更多 在《传奇3光通版》手游中&#xff0c;行会战是玩家们展现团队协作与战术布局的重要舞台。下面&#xff0c;我们就来详细解析一下行会战中的团队协作与战术布局攻略。 一、团队协作 ​职业搭配 在行会战中&#xff0c;合理的职业搭配至关重要。一般…

unity学习56:旧版legacy和新版TMP文本输入框 InputField学习

目录 1 旧版文本输入框 legacy InputField 1.1 新建一个文本输入框 1.2 InputField 的子物体构成 1.3 input field的的component 1.4 input Field的属性 2 过渡 transition 3 控件导航 navigation 4 占位文本 placeholder 5 文本 text 5.1 文本内容&#xff0c;用户…

99分巧克力

99分巧克力 ⭐️难度&#xff1a;中等 &#x1f31f;考点&#xff1a;二分 2017省赛真题 &#x1f4d6; &#x1f4da; import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc new Scanner(System.in);int n sc.nextInt();i…

Python 基础知识全面总结

Python 是一种广泛应用的编程语言&#xff0c;具有简洁、易读、功能强大等特点。本文将对 Python 的基础知识进行全面梳理&#xff0c;涵盖从入门必备知识到各类模块和编程概念等内容。 一、Python基础语法 &#xff08;一&#xff09;标识符 定义&#xff1a;用于给变量、函…

7.1.1 计算机网络的组成

文章目录 物理组成功能组成工作方式完整导图 物理组成 计算机网络是将分布在不同地域的计算机组织成系统&#xff0c;便于相互之间资源共享、传递信息。 计算机网络的物理组成包括硬件和软件。硬件中包含主机、前端处理器、连接设备、通信线路。软件中包含协议和应用软件。 功…