Compute "distance from a mesh to point"
It would be really nice to have computes distance from a mesh to a point (or pointcloud).
The API will look something like in trimesh library
(closest_points, distances, triangle_id) = mesh.nearest.on_surface(points)
Can get some inspiration from PyGEL3D code
Thanks!
As a workaround, it is possible to sample the mesh with an arbitrarily high number of points:
pcd = mesh.sample_points_uniformly(number_of_points=10000000)
Then you can iterate over your other point cloud to find each nearest neighbor with KDTree.
I did this for the exact same use-case (comparison of mesh and point cloud) and the results were pretty good.
Right, there is no direct method for this purpose in Open3D at the moment. @josephinemonica and @GnnrMrkr would anybody of you be interested in contributing such functionality with our aid?
I have never contributed to such a big project, but I'd like to try it out!
Unfortunately, I'll be very busy until early / mid October. Keep me updated, if this is still an issue then. But feel free to tackle this without me ;)
@griegler, fyi, the triangle intersection code I'm working on will trivially accommodate this feature: the only difference is that the point checked on the triangle bounds is created via projecting a point to a plane vs intersecting a ray with that plane.
I tried trimesh's trimesh.proximity.closest_point as an alternative, but unfortunately it does not scale well to large meshes yet https://github.com/Toblerity/rtree/issues/178. It would be great to have a faster implementation in Open3D.
I was working on this a few months ago and have code which performs the checks against triangles, but Open3D was in the middle of the push to 0.10 and things kept breaking and then I got pulled away into other things.
If there's still interest I don't mind resurrecting that work. The main issue is going to be that having the checks alone isn't going to make for a fast computation. It will require an acceleration structure.
I had built a BVH at the time for raytraycing and had started looking to generalize it before getting pulled away. The closest point search on a BVH is a little more complicated than an intersection test but it is still doable. If there's interest and it still fits into the scope of Open3D I'll make some time for it.
I tried trimesh's
trimesh.proximity.closest_pointas an alternative, but unfortunately it does not scale well to large meshes yet Toblerity/rtree#178. It would be great to have a faster implementation in Open3D.
Just to follow up to this post, here is a quick example to help others with this work around:
import open3d as o3d
import numpy as np
import trimesh
mesh_box = o3d.geometry.TriangleMesh.create_box(width=1.0, height=5.0, depth=1.0)
tri_mesh_box = trimesh.Trimesh(vertices=np.asarray(mesh_box.vertices), faces=np.asarray(mesh_box.triangles))
sdf_tri_mesh = trimesh.proximity.ProximityQuery(tri_mesh_box)
points = np.array([[2,0,0], [0.25,0.25,0.25]])
sdf_tri_mesh.signed_distance(points)
which results:
array([-1. , 0.25])
Should have been supported in the latest RayCastingScene. Closed for now, feel free to reopen.