added a function for calculating the barycenter of a pointcloud mesh (with uniform weight, or using vertex quality as vertex weight).

This commit is contained in:
Marco Callieri 2016-01-04 13:53:15 +00:00
parent 1f22183b90
commit d32b8eb287
1 changed files with 28 additions and 0 deletions

View File

@ -114,6 +114,34 @@ public:
return minmax; return minmax;
} }
/**
\short compute the pointcloud barycenter.
E.g. it assume each vertex has a mass. If useQualityAsWeight is true, vertex quality is the mass of the vertices
*/
static Point3<ScalarType> ComputeCloudBarycenter(MeshType & m, bool useQualityAsWeight=false)
{
if (useQualityAsWeight)
tri::RequirePerVertexQuality(m);
Point3<ScalarType> barycenter(0, 0, 0);
Point3d accumulator(0.0, 0.0, 0.0);
double weightSum = 0;
VertexIterator vi;
for (vi = m.vert.begin(); vi != m.vert.end(); ++vi)
if (!(*vi).IsD())
{
ScalarType weight = useQualityAsWeight ? (*vi).Q() : 1.0;
accumulator[0] += (double)((*vi).P()[0] * weight);
accumulator[1] += (double)((*vi).P()[1] * weight);
accumulator[2] += (double)((*vi).P()[2] * weight);
weightSum += weight;
}
barycenter[0] = (ScalarType)(accumulator[0] / weightSum);
barycenter[1] = (ScalarType)(accumulator[1] / weightSum);
barycenter[2] = (ScalarType)(accumulator[2] / weightSum);
return barycenter;
}
/** /**
\short compute the barycenter of the surface thin-shell. \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. E.g. it assume a 'empty' model where all the mass is located on the surface and compute the barycenter of that thinshell.