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

Add Volume-Based Centroid computation to structure/meshes #1228

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JulianKnodt
Copy link

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 18, 2022
@bottler
Copy link
Contributor

bottler commented Jun 19, 2022

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

@JulianKnodt
Copy link
Author

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.

@bottler
Copy link
Contributor

bottler commented Jun 22, 2022

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.

@JulianKnodt
Copy link
Author

Should I add more tests?

@bottler
Copy link
Contributor

bottler commented Jul 13, 2022

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.

Add test and switch to padded instead of packed

Update test to include non-uniform case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants