当前位置: 首页 > news >正文

【Open3D】第二篇:GUI编程

文章目录

  • 基本控件创建
    • 创建文本框
    • 创建button
    • 创建布局
  • 绘制形状
    • 绘制线段
    • 绘制点云
  • 设置属性
    • 设置线宽
    • 设置点大小
  • 可用Shader汇总
  • GUI框架

基本控件创建

创建文本框

push_edit = gui.TextEdit()

创建button

push_button = gui.Button('...')
push_button.horizontal_padding_em = 0.5
push_button.vertical_padding_em = 0
push_button.set_on_clicked(self._on_push_button) # 设置回调函数

创建布局

# 文本框和按钮水平布局
push_button_layout = gui.Horiz()
push_button_layout.add_child(gui.Label('Push Button'))
push_button_layout.add_child(self._push_edit)
push_button_layout.add_fixed(0.25*em)
push_button_layout.add_child(push_button)# 总体垂直布局
self.pannel = gui.Vert()
self.pannel.add_fixed(0.5*em)
self.pannel.add_child(push_button_layout)
self.window.add_child(self.pannel)

绘制形状

绘制线段

import open3d.visualization.gui as gui
points = [[0,0,0],[1,0,0],[0,1,0],[1,1,0],[0,0,1],[1,0,1],[0,1,1],[1,1,1]]
lines = [[0,1],[0,2],[1,3],[2,3],[4,5],[4,6],[5,7],[6,7],[0,4],[1,5],[2,6],[3,7]]
object_lines = o3d.geometry.LineSet(points=o3d.utility.Vector3dVector(points),lines=o3d.utility.Vector2iVector(lines),
)
# define material
material = rendering.MaterialRecord()
material.shader = 'defaultLit'# insert into scene
my_scene = gui.SceneWidget()
my_scene.scene = rendering.Open3DScene(w.renderer)
my_scene.scene.add_geometry('lines',object_lines ,material)
bounds = object_lines.get_axis_aligned_bounding_box()
my_scene.setup_camera(60,bounds,bounds.get_center())
my_scene.force_redraw()

绘制点云

import numpy as np
import open3d as o3d
import open3d.visualization.rendering as renderingcloud=o3d.io.read_point_cloud("your_path_to_point_cloud")
cloud_xyz=np.asarray(cloud.points)# define material
material = rendering.MaterialRecord()
material.shader = 'defaultLit'# define colors
ctmp=np.zeros((len(cloud_xyz),3))
ctmp[:,0]=1# rendering
object_pts=o3d.geometry.PointCloud()
object_pts.points=o3d.utility.Vector3dVector(cloud_xyz)
object_pts.colors=o3d.utility.Vector3dVector(ctmp)

设置属性

设置线宽

material_default = rendering.MaterialRecord()
material_default.shader = 'unlitLine'
material_default.line_width = 3
self._scene.scene.add_geometry('lines', object_lines,  material_default)

设置点大小

material = o3d.visualization.rendering.Material()
material.shader = "defaultLit"
material.base_color = color
material.point_size = size
scene.add_geometry(name, cloud, material)

可用Shader汇总

参考网址

类型
适用shader
网格defaultLit/defaultLitTransparencynormals
点云defaultLit/defaultLitTransparencynormalsdefaultUnlit/defaultUnlitTransparency
线段最好unlitLine,只有这个可以控制线宽

GUI框架

main_window.py

import open3d.visualization.gui as guiclass App:count = 0def __init__(self):# 初始化gui.Application.instance.initialize()self.window = gui.Application.instance.create_window("Event and Widget", 300, 600)# 使用相对大小避免直接设置像素,因为不同显示器像素大小可能不同em = self.window.theme.font_size# 文本框和按钮self._push_edit = gui.TextEdit()push_button = gui.Button('...')push_button.horizontal_padding_em = 0.5push_button.vertical_padding_em = 0push_button.set_on_clicked(self._on_push_button)# 文本框和按钮水平布局push_button_layout = gui.Horiz()push_button_layout.add_child(gui.Label('Push Button'))push_button_layout.add_child(self._push_edit)push_button_layout.add_fixed(0.25*em)push_button_layout.add_child(push_button)# 总体垂直布局self.pannel = gui.Vert()self.pannel.add_fixed(0.5*em)self.pannel.add_child(push_button_layout)self.window.add_child(self.pannel)def _on_push_button(self):self.count += 1# 设置文本框文字self._push_edit.text_value = f'push count {self.count}'# 弹出消息框self.window.show_message_box('Push Info', 'Hello World!')def run(self):gui.Application.instance.run()if __name__ == "__main__":app = App()app.run()
http://www.lryc.cn/news/138868.html

相关文章:

  • 【Python】P0 本系列博文简介与大纲
  • FL Studio 21.1.0 Build 3713中文破解免费下载安装激活
  • 从0开始配置eslint
  • Activity 的启动流程(Android 13)
  • deepspeed学习资料
  • 数据分享|R语言PCA主成分、lasso、岭回归降维分析近年来各国土地面积变化影响...
  • Docker-Consul
  • Pygame编程(2)display模块
  • 第十五天|104.二叉树的最大深度、111.二叉树的最小深度、 222.完全二叉树的节点个数
  • 图像识别技术在医疗领域的革命:探索医学影像诊断的未来
  • 计网第四章(网络层)(二)
  • 原生微信小程序使用 wxs;微信小程序使用 vant-weapp组件
  • qml相关知识1
  • linux+c+qt杂记
  • shouldComponentUpdate有什么作用?
  • 华为OD-滑动窗口最大值
  • Linux:ansible自动化运维工具
  • 前端如何使用WebSocket发送消息
  • 纸贵科技连续三年蝉联IDC中国 FinTech 50榜单
  • 台积电美国厂施工现场混乱,真令人头痛 | 百能云芯
  • React绑定antd输入框,点击清空或者确定按钮实现清空输入框内容
  • Springboot整合liquIbase组件
  • Apache Paimon 实时数据湖 Streaming Lakehouse 的存储底座
  • 计算机网络(10) --- 高级IO
  • 学习中ChatGPT的17种用法
  • 融合CDN 如何有效的抵抗DDoS攻击
  • Git 原理与使用
  • 如何批量加密PDF文件并设置不同密码 - 批量PDF加密工具使用教程
  • 【Unity 工程化】unity一些资源路径用途
  • 使用Docker进行模型部署