Python API

I/O

# read and write
cloud1 = o3d.io.read_point_cloud("cloud1.pcd")
cloud2 = o3d.io.read_point_cloud("cloud2.ply")
o3d.io.write_point_cloud("cloud3.pcd", cloud3)

Geometry

# use np.asarray() to access data
cloud_ndarray = np.asarray(cloud.points)

# use o3d.utility.Vector3dVector to convert to o3d format
cloud.points = o3d.utility.Vector3dVector(cloud_ndarray)

# can also change data using np.asarray
np.asarray(cloud.colors)[idx[1:], :] = [0, 1, 0] # color nbr points to green

# paint color
cloud.paint_uniform_color([1.0, 0.0, 0.0])

# K-D Tree and NN search
cloud_tree = o3d.geometry.KDTreeFlann(cloud)
[k, idx, _] = cloud_tree.search_knn_vector_3d(cloud.points[1500], 200)
[k, idx, dist] = cloud_tree.search_radius_vector_3d(query_point, radius)

Visualization

# basic viewers at high level
o3d.visualization.draw_geometries([pcd])
o3d.visualization.draw_geometries_with_editing([pcd])

# custom visualization
def custom_draw_geometry(pcd):
    # The following code achieves the same effect as:
    # o3d.visualization.draw_geometries([pcd])
    vis = o3d.visualization.Visualizer()
    vis.create_window()
    vis.add_geometry(pcd)
    vis.run()
    vis.destroy_window()

# non-blocking visualization
vis = o3d.visualization.Visualizer()
vis.create_window()
for i in range(icp_iteration):
    # do ICP single iteration
    # transform geometry using ICP
    vis.update_geometry(geometry)
    vis.poll_events()
    vis.update_renderer()

Last updated