0
$\begingroup$

I have points that are obtained by sampling a mesh(which is not watertight). Now, I would like to convert that mesh into voxel?

Does anyone have any suggestions for solving this problem?

$\endgroup$
3
  • 3
    $\begingroup$ This question gets asked a lot, I suggest looking up those answers, and if they are insufficient, clarify your question with specifics of why. $\endgroup$ Commented Jun 13, 2021 at 13:33
  • 2
    $\begingroup$ On top of what @pmw1234 said, I think you need to be more clear on precisely what the end goal is. Are you trying to resample the point cloud to a regular grid? Are you trying to recover the mesh? Are you trying to visualise the surface, or the volume? $\endgroup$ Commented Jun 16, 2021 at 5:47
  • 1
    $\begingroup$ You say point cloud and you say mesh. Be specific, these are different problems. $\endgroup$ Commented Sep 7, 2023 at 13:15

1 Answer 1

0
$\begingroup$

I don't quite get what you mean by voxel, but here you go. Please let me know if you need something special.

def voxelize(point_cloud, voxel_size): """ Voxelize an Open3D point cloud. Parameters: - point_cloud (open3d.geometry.PointCloud): Input point cloud. - voxel_size (float): Voxel size for downsampling. """ points_np = np.asarray(point_cloud.points) min_bound = np.min(points_np, axis=0) max_bound = np.max(points_np, axis=0) voxel_counts = np.ceil((max_bound - min_bound) / voxel_size).astype(int) voxel_indices = np.floor((points_np - min_bound) / voxel_size).astype(int) packed_indices = voxel_indices[:, 0] + voxel_indices[:, 1] * voxel_counts[0] + voxel_indices[:, 2] * voxel_counts[ 0] * voxel_counts[1] voxel_dict = {} voxel_to_point_index_dict = {} for i, index in enumerate(packed_indices): if index in voxel_dict: voxel_dict[index].append(points_np[i]) voxel_to_point_index_dict[index].append(i) else: voxel_dict[index] = [points_np[i]] voxel_to_point_index_dict[index] = [i] return voxel_dict, voxel_to_point_index_dict 

This function simply puts points to voxels, hash maps voxel_dict and voxel_to_point_index_dict should provide you two way access.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.