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$
    – pmw1234
    Jun 13, 2021 at 13:33
  • 1
    $\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$
    – Pseudonym
    Jun 16, 2021 at 5:47
  • 1
    $\begingroup$ You say point cloud and you say mesh. Be specific, these are different problems. $\endgroup$
    – user1703
    Sep 7, 2023 at 13:15

2 Answers 2

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$
-1
$\begingroup$

If you're looking for a C++ solution, try this one:

https://github.com/sjhalayka/point_to_mesh_text

The input looks like:

-0.0757585 -0.136365 -1.16667
-0.0757585 -0.106062 -1.16667
-0.0757585 -0.0757585 -1.16667
-0.0757585 -0.0454555 -1.16667
-0.0757585 -0.0151525 -1.16667
-0.0757585 0.0151506 -1.16667
-0.0757585 0.0454536 -1.16667
-0.0757585 0.0757566 -1.16667
-0.0757585 0.10606 -1.16667
-0.0757585 0.136363 -1.16667
-0.0757585 0.166666 -1.16667
-0.0454555 -0.106062 -1.16667
-0.0454555 -0.0757585 -1.16667
-0.0454555 -0.0454555 -1.16667
...

and the resulting mesh looks like:

fractal mesh

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.