本代码修改自open3d官方GitHub的示例代码:
# examples/python/visualization/non_blocking_visualization.py
# examples/python/visualization/non_blocking_visualization.py
import open3d as o3d
import numpy as np
import copy
if __name__ == "__main__":
# o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug)
point_cloud = o3d.io.read_point_cloud(r"D:\workspace\realsense\test\open3d\point_cloud.ply")
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(point_cloud)
# vis.add_geometry(target)
threshold = 0.05
icp_iteration = 100
save_image = False
ctr = vis.get_view_control()
ctr.set_lookat(np.array([0.0, 0.0, 55.0]))
ctr.set_up((0, -1, 0)) # set the positive direction of the x-axis as the up direction
ctr.set_front((-1, 0, 0)) # set the positive direction of the x-axis toward you
for i in range(icp_iteration):
R = point_cloud.get_rotation_matrix_from_xyz((np.pi / 180 * 1, 0, 0 * np.pi / 2))
point_cloud.rotate(R, center=(0.0,0,55.0))
vis.update_geometry(point_cloud)
vis.poll_events()
vis.update_renderer()
if save_image:
vis.capture_screen_image("temp_%04d.jpg" % i)
vis.destroy_window()
set_lookat设置的是:拖动模型旋转时,围绕哪个点进行旋转。
set_front设置的是:垂直指向屏幕外的向量,三维空间中有无数向量,垂直指向屏幕外的只有一个。
set_up设置的是:是设置指向屏幕上方的向量,当设置了垂直指向屏幕外的向量后,模型三维空间中的哪个面和屏幕平行就确定了(垂直屏幕的向量相当于法向量),还剩下一个旋转自由度,设置指向屏幕上方的向量后,模型的显示方式就确定了。
注:set_front和set_up设置的向量应该要满足一定的约束关系,否则可能得不到想要的效果。
参考文献:
1.set_lookat(), set_front(), set_up() usage of VisualControl #2139
2.Open3d学习计划——高级篇 10(自定义可视化)
3.open3d.visualization.ViewControl
4.Open3d之自定义可视化
5.open3d.visualization.draw_geometries
6.官网Visualization Function draw_geometries
7.官网Transformation