fixed uniform resampling of edge mesh
This commit is contained in:
parent
0f05ee423d
commit
62b7955f22
|
@ -645,6 +645,8 @@ static void EdgeMeshUniform(MeshType &m, VertexSampler &ps, float radius)
|
|||
{
|
||||
tri::RequireEEAdjacency(m);
|
||||
tri::RequireCompactness(m);
|
||||
tri::RequirePerEdgeFlags(m);
|
||||
tri::RequirePerVertexFlags(m);
|
||||
tri::UpdateTopology<MeshType>::EdgeEdge(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.
|
||||
{
|
||||
ep.NextE();
|
||||
if(ep.IsBorder()) break;
|
||||
if (ep.IsBorder())
|
||||
break;
|
||||
} while (startep != ep);
|
||||
if (!ep.IsBorder())
|
||||
{
|
||||
// it's a loop
|
||||
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;
|
||||
ep.FlipV();
|
||||
do // second loop to compute len of the chain.
|
||||
// second loop to compute length of the chain.
|
||||
do
|
||||
{
|
||||
ep.E()->SetV();
|
||||
totalLen+=Distance(ep.V()->P(),ep.VFlip()->P());
|
||||
totalLen += Distance(ep.V()->cP(), ep.VFlip()->cP());
|
||||
ep.NextE();
|
||||
} while (!ep.IsBorder() && ep.V() != startVertex);
|
||||
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.
|
||||
int sampleNum = floor(totalLen / radius);
|
||||
|
@ -682,14 +703,15 @@ static void EdgeMeshUniform(MeshType &m, VertexSampler &ps, float radius)
|
|||
ScalarType curLen = 0;
|
||||
int sampleCnt = 1;
|
||||
ps.AddEdge(*(ep.E()), ep.VInd() == 0 ? 0.0 : 1.0);
|
||||
ep.FlipV();
|
||||
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 d1 = d0 + edgeLen;
|
||||
|
||||
while(d1>sampleCnt*sampleDist)
|
||||
while (d1 > sampleCnt * sampleDist && sampleCnt < sampleNum)
|
||||
{
|
||||
ScalarType off = (sampleCnt * sampleDist - d0) / edgeLen;
|
||||
// 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++;
|
||||
}
|
||||
curLen += edgeLen;
|
||||
ep.NextE();
|
||||
} while(!ep.IsBorder() && ep.V() != startVertex);
|
||||
|
||||
if(ep.V() != startVertex)
|
||||
|
|
Loading…
Reference in New Issue