pytorch3d icon indicating copy to clipboard operation
pytorch3d copied to clipboard

Add Volume-Based Centroid computation to structure/meshes

Open JulianKnodt opened this issue 2 years ago • 5 comments

When operating on meshes, I found that I wanted to normalize it based on the center of the volume, as similar looking meshes may have different concentrations of points, and most tutorials use some measure of normalizing based on the average of all the points. While averaging all points is simple, it's not as simple to center based on the volume. I thought I'd add this, since it'd be convenient to use for normalization for others, and doesn't add much complexity to the overall API surface.

I'm not sure if the name is good, so if there's a better one let me know.

references: https://stackoverflow.com/questions/48918530/how-to-compute-the-centroid-of-a-mesh-with-triangular-faces https://discourse.vtk.org/t/how-to-compute-surface-and-volume-based-center-of-masses-for-3d-geometries/3215

JulianKnodt avatar Jun 18 '22 09:06 JulianKnodt

Are you aiming for the centroid of the surface defined by the mesh (like the first reference, and "surface-based" in the second) or the volume (which depends on tetrahedrons and is much more complicated, because you would have to find them)?

bottler avatar Jun 19 '22 15:06 bottler

I was aiming for a volume based centroid, as in the first reference's answer, which also suggests using the origin as the 4th point in each of the tetrahedrons.

JulianKnodt avatar Jun 20 '22 04:06 JulianKnodt

In that case, I think this does make sense, but the docstring should be made very clear. The function only makes sense (I think) for watertight meshes whose faces are consistently ordered, which should also be documented. Tests would be needed, including for a batch of more than one mesh. The use of clamp() needs reconsidering, because the net signed volume may be negative.

bottler avatar Jun 22 '22 15:06 bottler

Should I add more tests?

JulianKnodt avatar Jul 13 '22 06:07 JulianKnodt

I think this is a bit too specialised to live in the main Meshes object. It would make sense to add a new file, perhaps pytorch3d/ops/watertight.py for simple operations which are specialised for watertight meshes.

bottler avatar Jul 13 '22 14:07 bottler