MCPcopy
hub / github.com/zju3dv/4K4D / voxel_reconstruction

Function voxel_reconstruction

easyvolcap/utils/fusion_utils.py:19–40  ·  view source on GitHub ↗
(pcd: torch.Tensor, voxel_size: float = 0.01)

Source from the content-addressed store, hash-verified

17
18
19def voxel_reconstruction(pcd: torch.Tensor, voxel_size: float = 0.01):
20 if isinstance(pcd, np.ndarray): pcd = torch.from_numpy(pcd) # for a consistent api
21
22 # Convert torch tensor to Open3D PointCloud
23 o3d_pcd = o3d.geometry.PointCloud()
24 o3d_pcd.points = o3d.utility.Vector3dVector(pcd.view(-1, 3).detach().cpu().numpy())
25
26 # Create VoxelGrid from PointCloud
27 o3d_vox = o3d.geometry.VoxelGrid.create_from_point_cloud(o3d_pcd, voxel_size=voxel_size)
28
29 # Extract dense grid from VoxelGrid using get_voxel
30 voxels = o3d_vox.get_voxels()
31 max_index = np.array([vox.grid_index for vox in voxels]).max(axis=0) # !: for-loop
32 dense_grid = np.zeros((max_index[0] + 1, max_index[1] + 1, max_index[2] + 1))
33
34 for vox in voxels: # !: for-loop
35 dense_grid[vox.grid_index[0], vox.grid_index[1], vox.grid_index[2]] = 1
36
37 # Use marching cubes to obtain mesh from dense grid
38 vertices, triangles = mcubes.marching_cubes(dense_grid, 0.5)
39 vertices = vertices * voxel_size + o3d_vox.origin # resizing
40 return vertices, triangles
41
42
43def filter_global_points(points: dotdict[str, torch.Tensor]):

Callers 1

Calls 2

numpyMethod · 0.80
cpuMethod · 0.80

Tested by

no test coverage detected