pytorch3d
pytorch3d copied to clipboard
Add Volume-Based Centroid computation to structure/meshes
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
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)?
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.
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.
Should I add more tests?
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.