From 5cc3ca4d70cdba3b0fcc868558af075a830a1533 Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 22 Mar 2020 12:10:34 +1100 Subject: [PATCH] some minor changes over triangulate and smoothPCA --- vcg/complex/algorithms/polygonal_algorithms.h | 217 ++++++++++-------- 1 file changed, 123 insertions(+), 94 deletions(-) diff --git a/vcg/complex/algorithms/polygonal_algorithms.h b/vcg/complex/algorithms/polygonal_algorithms.h index 20834652..33eac195 100644 --- a/vcg/complex/algorithms/polygonal_algorithms.h +++ b/vcg/complex/algorithms/polygonal_algorithms.h @@ -72,12 +72,12 @@ This class is used to performs varisous kind of geometric optimization on generi template class PolygonalAlgorithm { - typedef typename PolyMeshType::FaceType FaceType; - typedef typename PolyMeshType::VertexType VertexType; - typedef typename PolyMeshType::VertexPointer VertexPointer; - typedef typename PolyMeshType::CoordType CoordType; - typedef typename PolyMeshType::ScalarType ScalarType; - typedef typename vcg::face::Pos PosType; + typedef typename PolyMeshType::FaceType FaceType; + typedef typename PolyMeshType::VertexType VertexType; + typedef typename PolyMeshType::VertexPointer VertexPointer; + typedef typename PolyMeshType::CoordType CoordType; + typedef typename PolyMeshType::ScalarType ScalarType; + typedef typename vcg::face::Pos PosType; public: static bool CollapseEdges(PolyMeshType &poly_m, const std::vector &CollapsePos, @@ -295,7 +295,29 @@ private: public: - + static void SelectIrregularInternal(PolyMeshType &poly_m) + { + vcg::tri::UpdateQuality::VertexValence(poly_m); + vcg::tri::UpdateSelection::VertexClear(poly_m); + for (size_t i=0;i::VertexValence(poly_m); + for (size_t i=0;i::FaceFace(GuideSurf); vcg::tri::UpdateFlags::FaceBorderFromFF(GuideSurf); - LaplacianReprojectBorder(poly_m,GuideSurf,nstep,Damp); + LaplacianReprojectBorder(poly_m,GuideSurf,nstep,Damp,Angle); } /*! \brief This function performs the reprojection of the polygonal mesh onto a triangular one passed as input parameter @@ -629,7 +650,7 @@ public: for (size_t i=0;i::VertexClearS(poly_m); + //vcg::tri::UpdateFlags::VertexClearS(poly_m); vcg::tri::UpdateTopology::FaceFace(poly_m); @@ -738,16 +760,16 @@ public: if (SharpEdge[i].size()>2)poly_m.vert[i].SetS(); } } - if (fixIrr) - { - vcg::tri::UpdateQuality::VertexValence(poly_m); - for (size_t i=0;i::VertexValence(poly_m); + // for (size_t i=0;i0); + poly_m.vert[i].P()=av_closest/sum; } - assert(sum>0); - poly_m.vert[i].P()=av_closest/sum; - } } + if (!FixB) + ReprojectBorder(poly_m,tri_mesh,true); UpdateFaceNormals(poly_m); vcg::tri::UpdateNormal::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:(GuideSurf,poly_m); TriangulateToTriMesh(poly_m,GuideSurf); vcg::tri::UpdateBounding::Box(GuideSurf); @@ -855,7 +884,7 @@ public: vcg::tri::UpdateFlags::FaceBorderFromFF(GuideSurf); //optimize it - vcg::PolygonalAlgorithm::SmoothReprojectPCA(poly_m,GuideSurf,relaxStep,fixIrr,Damp,SharpDeg,WeightByQuality); + vcg::PolygonalAlgorithm::SmoothReprojectPCA(poly_m,GuideSurf,relaxStep,fixS,Damp,SharpDeg,WeightByQuality,FixB); } static void Reproject(PolyMeshType &poly_m, @@ -1259,42 +1288,42 @@ public: } } - /*! \brief Triangulate a polygonal face with a triangle fan. - * \returns pointer to the newly added vertex. - */ - static VertexPointer Triangulate(PolyMeshType & poly_m, size_t IndexF) - { + /*! \brief Triangulate a polygonal face with a triangle fan. + * \returns pointer to the newly added vertex. + */ + static VertexPointer Triangulate(PolyMeshType & poly_m, size_t IndexF) + { - const CoordType bary = vcg::PolyBarycenter(poly_m.face[IndexF]); - size_t sizeV = poly_m.face[IndexF].VN(); + const CoordType bary = vcg::PolyBarycenter(poly_m.face[IndexF]); + size_t sizeV = poly_m.face[IndexF].VN(); - //add the new vertex - VertexPointer newV = &(*vcg::tri::Allocator::AddVertex(poly_m,bary)); + //add the new vertex + VertexPointer newV = &(*vcg::tri::Allocator::AddVertex(poly_m,bary)); - //then reupdate the faces - for (size_t j=0;j<(sizeV-1);j++) - { - VertexType * v0=poly_m.face[IndexF].V0(j); - VertexType * v1=poly_m.face[IndexF].V1(j); - VertexType * v2=newV; + //then reupdate the faces + for (size_t j=0;j<(sizeV-1);j++) + { + VertexType * v0=poly_m.face[IndexF].V0(j); + VertexType * v1=poly_m.face[IndexF].V1(j); + VertexType * v2=newV; - vcg::tri::Allocator::AddFaces(poly_m,1); + vcg::tri::Allocator::AddFaces(poly_m,1); - poly_m.face.back().Alloc(3); - poly_m.face.back().V(0)=v0; - poly_m.face.back().V(1)=v1; - poly_m.face.back().V(2)=v2; - } + poly_m.face.back().Alloc(3); + poly_m.face.back().V(0)=v0; + poly_m.face.back().V(1)=v1; + poly_m.face.back().V(2)=v2; + } - VertexType * v0=poly_m.face[IndexF].V0((sizeV-1)); - VertexType * v1=poly_m.face[IndexF].V1((sizeV-1)); - poly_m.face[IndexF].Dealloc(); - poly_m.face[IndexF].Alloc(3); - poly_m.face[IndexF].V(0)=v0; - poly_m.face[IndexF].V(1)=v1; - poly_m.face[IndexF].V(2)=newV; - return newV; - } + VertexType * v0=poly_m.face[IndexF].V0((sizeV-1)); + VertexType * v1=poly_m.face[IndexF].V1((sizeV-1)); + poly_m.face[IndexF].Dealloc(); + poly_m.face[IndexF].Alloc(3); + poly_m.face[IndexF].V(0)=v0; + poly_m.face[IndexF].V(1)=v1; + poly_m.face[IndexF].V(2)=newV; + return newV; + } static void ReorderFaceVert(FaceType &f,const size_t &StartI) {