pytorch3d
pytorch3d copied to clipboard
Check if point is inside mesh
Feature
Method to check if a point is located inside a mesh.
Motivation
When working with meshes in general this is a very common problem to tackle. It would be great to have method for this in PyTorch. Making an implementation for the Meshes-class in the PyTorch3d library seems ideal.
When you say "inside", do you mean totally surrounded by faces in a watertight way such that there is no path to infinity from the point without crossing a face (like a generalised winding number) or something weaker like every straight ray from the point hits a face, or most rays hit a face?
Yes, exactly. I mean totally surrounded by faces in a watertight way such that there is no path to infinity from the point without crossing a face (like a generalised winding number).
@sibowi This is a great feature request and we will add it to our list.
Note that while we don't have the function ready-to-use we have all the components so that you can easily implement this yourself if you need it faster. We have all the functionality to compute point to triangle distances in 3D and all you need to check is that a ray starting from the point of interest intersects with a watertight mesh an odd number of times.
@gkioxari Thanks, that sounds great!
And thanks for the pointers. I'm on it.
@sibowi Hi sibowi,
Could you please share the experience of implementing this feature? Thank you very much!
Hi @ruoyuwangeel4930
I did make an implementation for segmenting a mesh into voxel-space (a use case of the "check if point is inside mesh"-issue), but haven't had the time to write it up for a proper integration with the pytorch3d library (I'm sorry!).
You can find my code here.
The "check if point is inside mesh"-functionality is coded in the check_ray_triangle_intersection-function. The implementation is made to optimize the speed of the specific use case in the check_if_voxel_corners_are_inside_mesh-function.
The code is speed-optimized for elongated meshes. I.e., if your mesh is elongated along the z-direction, the mesh2voxel-functionality will run significantly faster. If that is not the case the performance is still not bad. This is explained a bit more in the tutorial.
I validated the method on the two example meshes (also seen in these figures). And a colleague of mine has validated it on the meshes she is working with. No issues have come up (yet).
I hope this will be useful for you.
Hi, @sibowi I implemented a batched version of your check_ray_triangle_intersection-function, hope it can help : ] !
It's not well optimized but I think it should be enough to get the job done!
@gkioxari This feature still not available right......