zarquon42b / Rvcg

R-package providing mesh manipulation routines from VCGLIB
Other
25 stars 10 forks source link

Wish: Calculate centroid #36

Open dwoll opened 1 year ago

dwoll commented 1 year ago

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 commented 1 year ago

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

The centroid size can be computed byMorpho::cSize(mesh)

dwoll commented 1 year ago

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 commented 1 year ago

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

dwoll commented 1 year ago

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!