Skip to content

Instantly share code, notes, and snippets.

@okanyenigun
Last active September 22, 2022 13:33
Show Gist options
  • Save okanyenigun/27eb5c66e94c454c6e8e658dc86b718d to your computer and use it in GitHub Desktop.
Save okanyenigun/27eb5c66e94c454c6e8e658dc86b718d to your computer and use it in GitHub Desktop.
import numpy as np
import open3d as o3d
#get point cloud data
armadillo = o3d.data.ArmadilloMesh()
mesh = o3d.io.read_triangle_mesh(armadillo.path)
N = 2000 #point
pcd = mesh.sample_points_poisson_disk(N)
# fit to unit cube
pcd.scale(1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()),
center=pcd.get_center())
pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0, 1, size=(N, 3)))
o3d.visualization.draw_geometries([pcd])
#convert to voxel
voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd,
voxel_size=0.05)
o3d.visualization.draw_geometries([voxel_grid])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment