【Open3D】第二篇: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 rendering

cloud=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 gui

class App:
    count = 0
    def __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.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)

    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()
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
qt-opensource-windows5.4是指Qt开源框架的Windows版本5.4。 Qt是一款跨平台的应用程序开发框架,可以通过统一的代码编写方式,在不同的操作系统上运行程序。Qt提供了丰富的功能和工具,使开发者可以快速构建图形用户界面(GUI)应用程序。 Qt开源框架的Windows版本5.4是指适用于Windows操作系统的Qt开源框架的第五个主要版本,发布于2014年。这个版本为开发者提供了许多新功能和改进,以提高程序的性能和可靠性。 Qt-opensource-windows5.4版本具有以下特点: 1. 支持Windows平台:Qt-opensource-windows5.4版本是专门针对Windows操作系统开发的,可以在不同的Windows版本上运行。 2. 开源框架:Qt采用开源模式,使开发者可以自由地使用和修改框架,以满足不同的应用需求。 3. 丰富的GUI开发工具:Qt提供了各种用于开发图形用户界面的工具和组件,可以轻松创建出美观、交互性强的应用程序。 4. 跨平台:Qt的设计理念是“一次编写,到处运行”,使用Qt开发的应用程序可以在不同的操作系统上进行移植,包括Windows、macOS、Linux等。 5. 多种编程语言支持:Qt支持多种编程语言,包括C++、Python、Java等,开发者可以根据自己的习惯选择合适的语言进行开发。 总之,Qt-opensource-windows5.4是一个功能强大的开源框架,适用于Windows平台的应用程序开发。它提供了丰富的功能和工具,使开发者可以轻松创建出高性能、跨平台的图形用户界面应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

42方生科技

谢谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值