fixed uniform resampling of edge mesh

This commit is contained in:
Luigi Malomo 2015-11-05 23:35:44 +00:00
parent 0f05ee423d
commit 62b7955f22
1 changed files with 76 additions and 55 deletions

View File

@ -645,6 +645,8 @@ static void EdgeMeshUniform(MeshType &m, VertexSampler &ps, float radius)
{ {
tri::RequireEEAdjacency(m); tri::RequireEEAdjacency(m);
tri::RequireCompactness(m); tri::RequireCompactness(m);
tri::RequirePerEdgeFlags(m);
tri::RequirePerVertexFlags(m);
tri::UpdateTopology<MeshType>::EdgeEdge(m); tri::UpdateTopology<MeshType>::EdgeEdge(m);
tri::UpdateFlags<MeshType>::EdgeClearV(m); tri::UpdateFlags<MeshType>::EdgeClearV(m);
@ -658,21 +660,40 @@ static void EdgeMeshUniform(MeshType &m, VertexSampler &ps, float radius)
do // first loop to search a boundary component. do // first loop to search a boundary component.
{ {
ep.NextE(); ep.NextE();
if(ep.IsBorder()) break; if (ep.IsBorder())
break;
} while (startep != ep); } while (startep != ep);
if (!ep.IsBorder()) if (!ep.IsBorder())
{
// it's a loop
startVertex = ep.V(); startVertex = ep.V();
}
else
{
// to keep the uniform resampling order-independent
// start from the border with 'lowest' point
edge::Pos<EdgeType> altEp = ep;
do {
altEp.NextE();
} while (!altEp.IsBorder());
if (altEp.V()->cP() < ep.V()->cP())
{
ep = altEp;
}
}
ScalarType totalLen = 0; ScalarType totalLen = 0;
ep.FlipV(); ep.FlipV();
do // second loop to compute len of the chain. // second loop to compute length of the chain.
do
{ {
ep.E()->SetV(); ep.E()->SetV();
totalLen+=Distance(ep.V()->P(),ep.VFlip()->P()); totalLen += Distance(ep.V()->cP(), ep.VFlip()->cP());
ep.NextE(); ep.NextE();
} while (!ep.IsBorder() && ep.V() != startVertex); } while (!ep.IsBorder() && ep.V() != startVertex);
ep.E()->SetV(); ep.E()->SetV();
totalLen+=Distance(ep.V()->P(),ep.VFlip()->P()); totalLen += Distance(ep.V()->cP(), ep.VFlip()->cP());
// Third loop actually perform the sampling. // Third loop actually perform the sampling.
int sampleNum = floor(totalLen / radius); int sampleNum = floor(totalLen / radius);
@ -682,14 +703,15 @@ static void EdgeMeshUniform(MeshType &m, VertexSampler &ps, float radius)
ScalarType curLen = 0; ScalarType curLen = 0;
int sampleCnt = 1; int sampleCnt = 1;
ps.AddEdge(*(ep.E()), ep.VInd() == 0 ? 0.0 : 1.0); ps.AddEdge(*(ep.E()), ep.VInd() == 0 ? 0.0 : 1.0);
ep.FlipV();
do do
{ {
ScalarType edgeLen = Distance(ep.V()->P(),ep.VFlip()->P()); ep.NextE();
assert(ep.E()->IsV());
ScalarType edgeLen = Distance(ep.V()->cP(), ep.VFlip()->cP());
ScalarType d0 = curLen; ScalarType d0 = curLen;
ScalarType d1 = d0 + edgeLen; ScalarType d1 = d0 + edgeLen;
while(d1>sampleCnt*sampleDist) while (d1 > sampleCnt * sampleDist && sampleCnt < sampleNum)
{ {
ScalarType off = (sampleCnt * sampleDist - d0) / edgeLen; ScalarType off = (sampleCnt * sampleDist - d0) / edgeLen;
// printf("edgeLen %f off %f samplecnt %i\n", edgeLen, off, sampleCnt); // printf("edgeLen %f off %f samplecnt %i\n", edgeLen, off, sampleCnt);
@ -697,7 +719,6 @@ static void EdgeMeshUniform(MeshType &m, VertexSampler &ps, float radius)
sampleCnt++; sampleCnt++;
} }
curLen += edgeLen; curLen += edgeLen;
ep.NextE();
} while(!ep.IsBorder() && ep.V() != startVertex); } while(!ep.IsBorder() && ep.V() != startVertex);
if(ep.V() != startVertex) if(ep.V() != startVertex)