Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute "distance from a mesh to point" #2062

Closed
josephinemonica opened this issue Jul 9, 2020 · 8 comments
Closed

Compute "distance from a mesh to point" #2062

josephinemonica opened this issue Jul 9, 2020 · 8 comments
Assignees

Comments

@josephinemonica
Copy link

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!

@GnnrMrkr
Copy link

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.

@griegler
Copy link
Contributor

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?

@griegler griegler self-assigned this Jul 29, 2020
@GnnrMrkr
Copy link

GnnrMrkr commented Aug 3, 2020

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 ;)

@mattj23
Copy link
Contributor

mattj23 commented Sep 23, 2020

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

@martinResearch
Copy link
Contributor

I tried trimesh's trimesh.proximity.closest_point as 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.

@mattj23
Copy link
Contributor

mattj23 commented Jan 12, 2021

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.

@bango123
Copy link

I tried trimesh's trimesh.proximity.closest_point as 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])

@theNded
Copy link
Contributor

theNded commented Nov 22, 2021

Should have been supported in the latest RayCastingScene. Closed for now, feel free to reopen.

@theNded theNded closed this as completed Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants