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?
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?
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.