I have 2 different pointclouds stored in 2 different numpy arrays and I can visualize them combined in open3d. But what I want to do is that one pointcloud stays constant and the other moves in the z direction (that is updating the coordinates of numpy array) without closing the window.
Below is the code in which I pass these two numpy arrays (npa and npa_test) to visualize in open3d. Please note that in the initial lines I store numpy arrays to a .pcd files (since they were extracted from different types of files .asc which open3d doesnot recognize) and then read them using open3d read function. I want to update the one pointcloud geomtry by moving it in z direction and then visualizing it on the same window without closing it. This can be done by updating the z cordinates by 1 in for loop as mentioned below. Please let me know if you have a solution regarding this. Thank you.
def draw(npa,npa_test):
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(npa)
o3d.io.write_point_cloud("C:/Users/Junaid/Desktop/test.ply", pcd)
pcd_load = o3d.io.read_point_cloud("C:/Users/Junaid/Desktop/test.ply")
pcd1 = o3d.geometry.PointCloud()
pcd1.points = o3d.utility.Vector3dVector(npa_test)
o3d.io.write_point_cloud("C:/Users/Junaid/Desktop/test1.ply", pcd1)
pcd_load1 = o3d.io.read_point_cloud("C:/Users/Junaid/Desktop/test1.ply")
o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug)
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd_load)
vis.add_geometry(pcd_load1)
npa.tolist()
for i in range(len(npa)):
npa[i][2] = npa[i][2] + 1
npa=np.asarray(npa, dtype=np.float32)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(npa)
o3d.io.write_point_cloud("C:/Users/Junaid/Desktop/test.ply", pcd)
pcd_load = o3d.io.read_point_cloud("C:/Users/Junaid/Desktop/test.ply")
vis.update_geometry(pcd_load)
vis.poll_events()
vis.update_renderer()
vis.destroy_window()
I see that you're using
npa[i][2] = npa[i][2] + 1
to modify the value which is overkill when you can just use Transformation Matrix to transform the geometry likepcd.transform(np.array([[1,0,0,0],[0,1,0,0],[0,0,1,z_val],[0,0,0,1]]))
.Here's easy solution of moving sphere from z=0.5 until 15.0 with increment of 0.005 using open3d.