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

Wish: Calculate centroid #36

Open
dwoll opened this issue Nov 5, 2022 · 4 comments
Open

Wish: Calculate centroid #36

dwoll opened this issue Nov 5, 2022 · 4 comments

Comments

@dwoll
Copy link

dwoll commented Nov 5, 2022

First of all, many thanks for developing Rvcg! It proves extremely useful in radiation oncology where comparison of target structures as contoured by AI vs. experts is currently an important issue. Would it be possible to add a function to obtain the centroid of a mesh, similar to the vcgVolume() function? Example calculations based on other libraries are here:

https://github.com/CGAL/cgal/blob/40fdc6c6bc48eec140353fca3e930f578745f18b/Principal_component_analysis_LGPL/include/CGAL/centroid.h#L516

https://github.com/libigl/libigl/blob/574ab1a3a819b3798cf452fa44bcb47704a529c6/include/igl/centroid.cpp#L11

Thanks in advance for considering!

@zarquon42b
Copy link
Owner

Computing the centroid is trivial:
colMeans(Morpho::vert2points(mesh))

The centroid size can be computed by Morpho::cSize(mesh)

@dwoll
Copy link
Author

dwoll commented Nov 7, 2022

Thanks for looking into this! I'm sorry I wasn't precise. I meant the center of mass. For meshes with varying vertex density, the centroid will be drawn to regions with higher density. I've encountered meshes with higher vertex density in high-curvature regions. It would be nice to get the center of mass - CGAL is weighting the individual contributions by triangle size, the reference given by libigl is "Calculating the volume and centroid of a polyhedron in 3d" [Nuernberg 2013]". Many thanks in advance!

@zarquon42b
Copy link
Owner

Rvcg is an interface to vcglib. I am not sure if this is included.

@dwoll
Copy link
Author

dwoll commented Nov 7, 2022

Center of mass calculation is very similar to volume calculation. Again, my C++ is weak, but I think VCG is doing the weighting in this function (note that function Mass() as used by Rvcg in Rmeshvol is defined right above:

https://github.com/cnr-isti-vclab/vcglib/blob/e4950d12e2db7f6ec3e587b06b2a0474b4f08d96/vcg/complex/algorithms/inertia.h#L242

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants