pytorch3d icon indicating copy to clipboard operation
pytorch3d copied to clipboard

Check if point is inside mesh

Open sibowi opened this issue 5 years ago • 8 comments

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.

sibowi avatar Sep 03 '20 11:09 sibowi

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?

bottler avatar Sep 04 '20 14:09 bottler

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 avatar Sep 04 '20 15:09 sibowi

@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 avatar Sep 07 '20 13:09 gkioxari

@gkioxari Thanks, that sounds great!

And thanks for the pointers. I'm on it.

sibowi avatar Sep 18 '20 05:09 sibowi

@sibowi Hi sibowi,

Could you please share the experience of implementing this feature? Thank you very much!

ruoyuwangeel4930 avatar Mar 01 '21 03:03 ruoyuwangeel4930

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.

sibowi avatar Mar 01 '21 09:03 sibowi

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!

dendenxu avatar Dec 31 '21 10:12 dendenxu

@gkioxari This feature still not available right......

heathentw avatar Jul 19 '22 02:07 heathentw