minor changes in isotropic remesher

This commit is contained in:
korialis 2020-11-12 16:38:56 +01:00
parent 0488a0242a
commit 8409535255
1 changed files with 1272 additions and 1250 deletions

View File

@ -185,7 +185,30 @@ private:
vcg::Triangle3<ScalarType> t1(f.P(longestIdx), f.P1(longestIdx), f.P2(longestIdx)), t2(g->P(k), g->P1(k), g->P2(k)),
t3(f.P(longestIdx), g->P2(k), f.P2(longestIdx)), t4(g->P(k), f.P2(longestIdx), g->P2(k));
if ( std::min( QualityFace(t1), QualityFace(t2) ) <= std::min( QualityFace(t3), QualityFace(t4) ))
auto n1 = vcg::TriangleNormal(t1);
auto n2 = vcg::TriangleNormal(t2);
auto n3 = vcg::TriangleNormal(t3);
auto n4 = vcg::TriangleNormal(t4);
auto biggestSmallest = vcg::DoubleArea(t1) > vcg::DoubleArea(t2) ? std::make_pair(t1, t2) : std::make_pair(t2, t1);
auto areaRatio = vcg::DoubleArea(biggestSmallest.first) / vcg::DoubleArea(biggestSmallest.second);
bool normalCheck = true;
// if (n1.Norm() > 0.001 && n2.Norm() > 0.001)
{
auto referenceNormal = vcg::NormalizedTriangleNormal(biggestSmallest.first);
normalCheck &= vcg::NormalizedTriangleNormal(t3) * referenceNormal >= 0.95;
normalCheck &= vcg::NormalizedTriangleNormal(t4) * referenceNormal >= 0.95;
}
bool areaCheck = false;
if (areaRatio > 1000)
{
areaCheck |= vcg::DoubleArea(t3) / vcg::DoubleArea(biggestSmallest.second) > 1000 && vcg::DoubleArea(t4) / vcg::DoubleArea(biggestSmallest.second) > 1000;
}
if ((normalCheck) && (areaCheck || std::min( QualityFace(t1), QualityFace(t2) ) <= std::min( QualityFace(t3), QualityFace(t4))))
{
ScalarType dist;
CoordType closest;
@ -203,7 +226,8 @@ private:
}
}
}
} while (count && ++iter < 50);
} while (count && ++iter < 75);
}
static void cleanMesh(MeshType & m, Params & params)
@ -374,15 +398,16 @@ private:
return (int)(std::ceil(angleSumRad / (M_PI/3.0f)));
}
static bool testHausdorff (MeshType & m, StaticGrid & grid, const std::vector<CoordType> & verts, const ScalarType maxD)
static bool testHausdorff (MeshType & m, StaticGrid & grid, const std::vector<CoordType> & verts, const ScalarType maxD, const CoordType checkOrientation = CoordType(0,0,0))
{
for (CoordType v : verts)
{
CoordType closest;
CoordType closest, normal, ip;
ScalarType dist = 0;
FaceType* fp = GetClosestFaceBase(m, grid, v, maxD, dist, closest);
if (fp == NULL)
//you can't use this kind of orientation check, since when you stand on edges it fails
if (fp == NULL /*|| (checkOrientation != CoordType(0,0,0) && checkOrientation * fp->N() < 0.5)*/)
{
return false;
}
@ -411,7 +436,7 @@ private:
double qualityAdj = vcg::QualityRadii(ffAdj->cP(0), ffAdj->cP(1), ffAdj->cP(2));
bool qualityCheck = quality > 0.00000001 && qualityAdj > 0.00000001;
// bool areaCheck = vcg::DoubleArea(*ff) > 0.000001 && vcg::DoubleArea(*ffAdj) > 0.000001;
// bool areaCheck = vcg::DoubleArea(*ff) > 0.000001 && vcg::DoubleArea(*ffAdj) > 0.000001;
if (!params.userSelectedCreases && (testCreaseEdge(p, params.creaseAngleCosThr) /*&& areaCheck*//* && qualityCheck*/) || p.IsBorder())
{
@ -611,7 +636,7 @@ private:
tri::UpdateTopology<MeshType>::FaceFace(m);
tri::UpdateTopology<MeshType>::VertexFace(m);
ForEachFace(m, [&] (FaceType & f) {
// if (face::IsManifold(f, 0) && face::IsManifold(f, 1) && face::IsManifold(f, 2))
// if (face::IsManifold(f, 0) && face::IsManifold(f, 1) && face::IsManifold(f, 2))
for (int i = 0; i < 3; ++i)
{
if (&f > f.cFFp(i))
@ -737,7 +762,7 @@ private:
int incidentFeatures = 0;
for (size_t i = 0; i < faces.size(); ++i)
// if (faces[i] != p.F() && faces[i] != p.FFlip())
// if (faces[i] != p.F() && faces[i] != p.FFlip())
{
if (faces[i]->IsFaceEdgeS(VtoE(vIdxes[i], (vIdxes[i]+1)%3)))
{
@ -782,7 +807,7 @@ private:
ScalarType newQ = Quality(mp, v1->P(), v2->P());
ScalarType oldQ = Quality(v0->P(), v1->P(), v2->P());
if( newQ <= 0.5*oldQ )
if(newQ <= 0.5*oldQ)
return false;
}
@ -794,8 +819,10 @@ private:
Point3<ScalarType> oldN = NormalizedTriangleNormal(*(pi.F()));
Point3<ScalarType> newN = Normal(mp, v1->P(), v2->P()).Normalize();
float div = fastAngle(oldN, newN);
if(div < .0f ) return false;
// float div = fastAngle(oldN, newN);
// if(div < .9f ) return false;
if (oldN * newN < 0.8f)
return false;
// // check on new face distance from original mesh
if (params.surfDistCheck)
@ -805,7 +832,7 @@ private:
points[1] = (v1->cP() + mp) / 2.;
points[2] = (v2->cP() + mp) / 2.;
points[3] = mp;
if (!testHausdorff(*(params.mProject), params.grid, points, params.maxSurfDist))
if (!testHausdorff(*(params.mProject), params.grid, points, params.maxSurfDist, newN))
return false;
}
}
@ -841,11 +868,6 @@ private:
assert(int(false) == 0);
mp = (p0.V()->cP() * int(moveable1) + p1.V()->cP() * int(moveable0)) / (int(moveable0) + int(moveable1));
if (!moveable0)
p = p0;
else
p = p1;
if (checkFacesAfterCollapse(ff0, p0, mp, params, relaxed))
return checkFacesAfterCollapse(ff1, p1, mp, params, relaxed);
@ -1155,17 +1177,17 @@ private:
//this aspect ratio check doesn't work on cadish meshes (long thin triangles spanning whole mesh)
ForEachFace(m, [&] (FaceType & f) {
if (vcg::Quality(f.cP(0), f.cP(1), f.cP(2)) < params.aspectRatioThr || vcg::DoubleArea(f) < 0.00001)
{
if (creaseVerts[vcg::tri::Index(m, f.V(0))] == 0)
f.V(0)->SetS();
if (creaseVerts[vcg::tri::Index(m, f.V(1))] == 0)
f.V(1)->SetS();
if (creaseVerts[vcg::tri::Index(m, f.V(2))] == 0)
f.V(2)->SetS();
}
});
// ForEachFace(m, [&] (FaceType & f) {
// if (vcg::Quality(f.cP(0), f.cP(1), f.cP(2)) < params.aspectRatioThr || vcg::DoubleArea(f) < 0.00001)
// {
// if (creaseVerts[vcg::tri::Index(m, f.V(0))] == 0)
// f.V(0)->SetS();
// if (creaseVerts[vcg::tri::Index(m, f.V(1))] == 0)
// f.V(1)->SetS();
// if (creaseVerts[vcg::tri::Index(m, f.V(2))] == 0)
// f.V(2)->SetS();
// }
// });
ForEachFace(m, [&] (FaceType & f) {
@ -1225,8 +1247,8 @@ private:
if (moving)
{
// const CoordType oldN = vcg::NormalizedTriangleNormal(*fi);
// const CoordType newN = vcg::Normal(newPos[0], newPos[1], newPos[2]).Normalize();
// const CoordType oldN = vcg::NormalizedTriangleNormal(*fi);
// const CoordType newN = vcg::Normal(newPos[0], newPos[1], newPos[2]).Normalize();
newPos[3] = (newPos[0] + newPos[1] + newPos[2]) / 3.;
if (/*(strict || oldN * newN > 0.99) &&*/ (!params.surfDistCheck || testHausdorff(*params.mProject, params.grid, newPos, maxDist)))
@ -1344,8 +1366,8 @@ private:
if(!(*vi).IsD())
{
Point3<ScalarType> newP, normP, barP;
ScalarType maxDist = params.maxSurfDist * 1.5f, minDist = 0.f;
FaceType* fp = GetClosestFaceBase(*params.mProject, params.grid, vi->cP(), maxDist, minDist, newP, normP, barP);
ScalarType maxDist = params.maxSurfDist * 2.5f, minDist = 0.f;
FaceType* fp = GetClosestFaceBase(*params.mProject, params.grid, vi->cP(), maxDist, minDist, newP/*, normP, barP*/);
if (fp != NULL)
{