fixed policy to automatically choose fixed vertices in LSCM as a staring point for ARAP

This commit is contained in:
Luigi Malomo 2018-01-18 02:16:32 +01:00
parent a8227df267
commit 7c55e74ef7
1 changed files with 20 additions and 12 deletions

View File

@ -143,27 +143,35 @@ void InitializeArapWithLSCM(MeshType & m, unsigned int fixedMask = 0)
if (fixedMask == 0) if (fixedMask == 0)
{ {
// manually select fixed vertices // automatically select 2 vertices to fix
vcg::tri::UpdateFlags<MeshType>::Clear(m); vcg::tri::UpdateFlags<MeshType>::Clear(m);
int fixed0, fixed1 = -1; int fixed0, fixed1 = -1;
ScalarType minD0 = std::numeric_limits<ScalarType>::max(); auto p = m.bbox.Center();
ScalarType minD1 = std::numeric_limits<ScalarType>::max(); ScalarType maxDist = -1;
for (size_t i=0; i<m.vert.size(); i++) for (size_t i=0; i<m.vert.size(); i++)
{ {
const ScalarType testD0 =(m.vert[i].P() - m.bbox.min).Norm(); // farthest point from the center
const ScalarType testD1 =(m.vert[i].P() - m.bbox.max).Norm(); const ScalarType dist =(m.vert[i].cP() - p).Norm();
if (testD0 < minD0) if (dist > maxDist)
{ {
fixed0 = i; fixed0 = i;
minD0 = testD0; maxDist = dist;
}
if (testD1 < minD1)
{
fixed1 = i;
minD1 = testD1;
} }
} }
maxDist = -1;
p = m.vert[fixed0].cP();
for (size_t i=0; i<m.vert.size(); i++)
{
// farthest point from the previous
const ScalarType dist =(m.vert[i].cP() - p).Norm();
if (dist > maxDist)
{
fixed1 = i;
maxDist = dist;
}
}
assert(fixed0 >= 0); assert(fixed0 >= 0);
assert(fixed1 >= 0); assert(fixed1 >= 0);
assert(fixed0 != fixed1); assert(fixed0 != fixed1);