some minor changes over triangulate and smoothPCA

This commit is contained in:
nico 2020-03-22 12:10:34 +11:00
parent 75243d1cc2
commit 5cc3ca4d70
1 changed files with 123 additions and 94 deletions

View File

@ -295,6 +295,28 @@ private:
public:
static void SelectIrregularInternal(PolyMeshType &poly_m)
{
vcg::tri::UpdateQuality<PolyMeshType>::VertexValence(poly_m);
vcg::tri::UpdateSelection<PolyMeshType>::VertexClear(poly_m);
for (size_t i=0;i<poly_m.vert.size();i++)
{
if (poly_m.vert[i].IsB())continue;
if (poly_m.vert[i].Q()==4)continue;
poly_m.vert[i].SetS();
}
}
static void SelectIrregularBorder(PolyMeshType &poly_m)
{
vcg::tri::UpdateQuality<PolyMeshType>::VertexValence(poly_m);
for (size_t i=0;i<poly_m.vert.size();i++)
{
if (!poly_m.vert[i].IsB())continue;
if (poly_m.vert[i].Q()==2)continue;
poly_m.vert[i].SetS();
}
}
static CoordType GetFaceGetBary(FaceType &F)
{
@ -413,8 +435,6 @@ public:
ScalarType AvgArea=MeshArea/(ScalarType)poly_m.face.size();
PolyMeshType TestM;
if (WeightByQuality)
UpdateQuality(poly_m,QTemplate);
@ -578,7 +598,8 @@ public:
*/
static void LaplacianReprojectBorder(PolyMeshType &poly_m,
int nstep=100,
ScalarType Damp=0.5)
ScalarType Damp=0.5,
ScalarType Angle=100)
{
//transform into triangular
TempMesh GuideSurf;
@ -588,7 +609,7 @@ public:
vcg::tri::UpdateTopology<TempMesh>::FaceFace(GuideSurf);
vcg::tri::UpdateFlags<TempMesh>::FaceBorderFromFF(GuideSurf);
LaplacianReprojectBorder<TempMesh>(poly_m,GuideSurf,nstep,Damp);
LaplacianReprojectBorder<TempMesh>(poly_m,GuideSurf,nstep,Damp,Angle);
}
/*! \brief This function performs the reprojection of the polygonal mesh onto a triangular one passed as input parameter
@ -692,12 +713,13 @@ public:
static void SmoothReprojectPCA(PolyMeshType &poly_m,
TriMeshType &tri_mesh,
int relaxStep=100,
bool fixIrr=false,
bool fixS=false,
ScalarType Damp=0.5,
ScalarType SharpDeg=0,
bool WeightByQuality=false)
bool WeightByQuality=false,
bool FixB=true)
{
vcg::tri::UpdateFlags<PolyMeshType>::VertexClearS(poly_m);
//vcg::tri::UpdateFlags<PolyMeshType>::VertexClearS(poly_m);
vcg::tri::UpdateTopology<PolyMeshType>::FaceFace(poly_m);
@ -738,16 +760,16 @@ public:
if (SharpEdge[i].size()>2)poly_m.vert[i].SetS();
}
}
if (fixIrr)
{
vcg::tri::UpdateQuality<PolyMeshType>::VertexValence(poly_m);
for (size_t i=0;i<poly_m.vert.size();i++)
{
if (poly_m.vert[i].IsB())continue;
if (poly_m.vert[i].Q()==4)continue;
poly_m.vert[i].SetS();
}
}
// if (fixIrr)
// {
// vcg::tri::UpdateQuality<PolyMeshType>::VertexValence(poly_m);
// for (size_t i=0;i<poly_m.vert.size();i++)
// {
// if (poly_m.vert[i].IsB())continue;
// if (poly_m.vert[i].Q()==4)continue;
// poly_m.vert[i].SetS();
// }
// }
typedef typename TriMeshType::FaceType FaceType;
@ -763,22 +785,22 @@ public:
// for (size_t i=0;i<poly_m.face.size();i++)
// poly_m.face[i].Q()=vcg::PolyArea(poly_m.face[i]);
for (size_t i=0;i<poly_m.vert.size();i++)
{
typename TriMeshType::CoordType testPos;
testPos.Import(poly_m.vert[i].P());
typename TriMeshType::CoordType closestPt;
typename TriMeshType::ScalarType minDist;
typename TriMeshType::FaceType *f=NULL;
typename TriMeshType::CoordType norm,ip;
f=vcg::tri::GetClosestFaceBase(tri_mesh,grid,testPos,MaxD,minDist,closestPt,norm,ip);
//poly_m.vert[i].N().Import(norm);
}
// for (size_t i=0;i<poly_m.vert.size();i++)
// {
// typename TriMeshType::CoordType testPos;
// testPos.Import(poly_m.vert[i].P());
// typename TriMeshType::CoordType closestPt;
// typename TriMeshType::ScalarType minDist;
// typename TriMeshType::FaceType *f=NULL;
// typename TriMeshType::CoordType norm,ip;
// f=vcg::tri::GetClosestFaceBase(tri_mesh,grid,testPos,MaxD,minDist,closestPt,norm,ip);
// //poly_m.vert[i].N().Import(norm);
// }
for(int k=0;k<relaxStep;k++)
{
//smooth PCA step
SmoothPCA(poly_m,1,Damp,true,true,0.1,true,WeightByQuality);
SmoothPCA(poly_m,1,Damp,fixS,true,0.1,FixB,WeightByQuality);
//reprojection step
//laplacian smooth step
//Laplacian(poly_m,Damp,1);
@ -789,6 +811,9 @@ public:
testPos.Import(poly_m.vert[i].P());
typename TriMeshType::CoordType closestPt;
typename TriMeshType::ScalarType minDist;
if ((FixB)&&(poly_m.vert[i].IsB()))
{continue;}
else
if (SharpEdge[i].size()==0)//reproject onto original mesh
{
FaceType *f=NULL;
@ -815,6 +840,8 @@ public:
poly_m.vert[i].P()=av_closest/sum;
}
}
if (!FixB)
ReprojectBorder(poly_m,tri_mesh,true);
UpdateFaceNormals(poly_m);
vcg::tri::UpdateNormal<PolyMeshType>::PerVertexFromCurrentFaceNormal(poly_m);
}
@ -840,13 +867,15 @@ public:
*/
static void SmoothReprojectPCA(PolyMeshType &poly_m,
int relaxStep=100,
bool fixIrr=false,
bool fixS=false,
ScalarType Damp=0.5,
ScalarType SharpDeg=0,
bool WeightByQuality=false)
bool WeightByQuality=false,
bool FixB=true)
{
//transform into triangular
TempMesh GuideSurf;
//vcg::tri::PolygonSupport<TempMesh,PolyMeshType>:(GuideSurf,poly_m);
TriangulateToTriMesh<TempMesh>(poly_m,GuideSurf);
vcg::tri::UpdateBounding<TempMesh>::Box(GuideSurf);
@ -855,7 +884,7 @@ public:
vcg::tri::UpdateFlags<TempMesh>::FaceBorderFromFF(GuideSurf);
//optimize it
vcg::PolygonalAlgorithm<PolyMeshType>::SmoothReprojectPCA<TempMesh>(poly_m,GuideSurf,relaxStep,fixIrr,Damp,SharpDeg,WeightByQuality);
vcg::PolygonalAlgorithm<PolyMeshType>::SmoothReprojectPCA<TempMesh>(poly_m,GuideSurf,relaxStep,fixS,Damp,SharpDeg,WeightByQuality,FixB);
}
static void Reproject(PolyMeshType &poly_m,