From 92bbd333941984de4e9779e5d712b7c3da312ba1 Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 30 Sep 2010 23:30:22 +0000 Subject: [PATCH] Added function to compute the barycenter of the thin shell surface model. E.g. the barycenter of the mesh as if all the mass was concentrated over the surface of the mesh. Useful for computing barycenter of planar figures. --- vcg/complex/trimesh/stat.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/vcg/complex/trimesh/stat.h b/vcg/complex/trimesh/stat.h index aaf24946..06b9babe 100644 --- a/vcg/complex/trimesh/stat.h +++ b/vcg/complex/trimesh/stat.h @@ -94,6 +94,28 @@ class Stat } return minmax; } + + /** + \short compute the barycenter of the surface thin-shell. + E.g. it assume a 'empty' model where all the mass is located on the surface and compute the barycenter of that thinshell. + Works for any triangulated model (no problem with open, nonmanifold selfintersecting models). + Useful for computing the barycenter of 2D planar figures. + */ + static Point3 ComputeShellBarycenter(MeshType & m) + { + Point3 barycenter(0,0,0); + ScalarType areaSum=0; + FaceIterator fi; + for(fi = m.face.begin(); fi != m.face.end(); ++fi) + if(!(*fi).IsD()) + { + ScalarType area=DoubleArea(*fi); + barycenter += Barycenter(*fi)*area; + areaSum+=area; + } + return barycenter/areaSum; + } + static ScalarType ComputeMeshArea(MeshType & m) {