计算点云凸包的关键代码:
hull, _ = pcl.compute_convex_hull() # pcl: PointCloud class; hull: TriangleMesh
import open3d as o3d
if __name__ == "__main__":
# 1. read triangle mesh
print("Displaying pointcloud with convex hull ...")
bunny = o3d.data.BunnyMesh()
mesh = o3d.io.read_triangle_mesh(bunny.path)
# 2. compute normal of mesh
mesh.compute_vertex_normals()
# 3. 采样10000个点,这10000个点代表了当前的mesh数据
pcl = mesh.sample_points_poisson_disk(number_of_points=10000) # PointCloud class
# 4. compute convex hull of PointCloud
hull, _ = pcl.compute_convex_hull() # TriangleMesh
# 5. view hull
hull_ls = o3d.geometry.LineSet.create_from_triangle_mesh(hull) # TriangleMesh to LineSet
hull_ls.paint_uniform_color((1, 0, 0))
o3d.visualization.draw([pcl, hull_ls])
兔子的凸包。