diff --git a/vcg/complex/algorithms/polygonal_algorithms.h b/vcg/complex/algorithms/polygonal_algorithms.h index 8c2f8b5b..7a7593ed 100644 --- a/vcg/complex/algorithms/polygonal_algorithms.h +++ b/vcg/complex/algorithms/polygonal_algorithms.h @@ -29,7 +29,7 @@ #include #include #include - +#include #include //define a temporary triangle mesh type @@ -362,14 +362,14 @@ public: //CoordType AVN(0,0,0); //CoordType AVN0(0,0,0); CoordType Origin(0,0,0); -// for (int j=0;jN(); + // for (int j=0;jN(); CoordType AVN=vcg::PolygonNormal(f); //AVN0.Normalize(); -// std::cout<<"AVN "<::VertexClearS(poly_m); + vcg::tri::UpdateTopology::FaceFace(poly_m); //UpdateBorderVertexFromPFFAdj(poly_m); vcg::tri::UpdateFlags::VertexBorderFromFaceAdj(poly_m); + std::vector > > SharpEdge(poly_m.vert.size()); + //first select sharp features + if (SharpDeg>0) + { + for (size_t i=0;i=poly_m.face[i].FFp(j))continue; + + CoordType N0=poly_m.face[i].N(); + CoordType N1=poly_m.face[i].FFp(j)->N(); + + ScalarType Angle=vcg::Angle(N0,N1); + if (fabs(Angle)>(SharpDeg* (M_PI / 180.0))) + { + CoordType Pos0=poly_m.face[i].V0(j)->P(); + CoordType Pos1=poly_m.face[i].V1(j)->P(); + CoordType Ori=Pos0; + CoordType Dir=Pos1-Pos0; + Dir.Normalize(); + vcg::Line3 L(Ori,Dir); + int Index0=vcg::tri::Index(poly_m,poly_m.face[i].V0(j)); + int Index1=vcg::tri::Index(poly_m,poly_m.face[i].V1(j)); + SharpEdge[Index0].push_back(L); + SharpEdge[Index1].push_back(L); + } + } + for (size_t i=0;i2)poly_m.vert[i].SetS(); + } + } + if (fixIrr) + { + vcg::tri::UpdateQuality::VertexValence(poly_m); + for (size_t i=0;i TriMeshGrid; TriMeshGrid grid; @@ -656,13 +713,13 @@ public: 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); + //poly_m.vert[i].N().Import(norm); } for(int k=0;k0); + poly_m.vert[i].P()=av_closest/sum; + } } + UpdateFaceNormals(poly_m); + vcg::tri::UpdateNormal::PerVertexFromCurrentFaceNormal(poly_m); } + + } + + + template + static void TriangulateToTriMesh(PolyMeshType &poly_m,TriMeshType &triangle_mesh) + { + triangle_mesh.Clear(); + + PolyMeshType PolySwap; + vcg::tri::Append::Mesh(PolySwap,poly_m); + Triangulate(PolySwap); + + //then copy onto the triangle mesh + vcg::tri::Append::Mesh(triangle_mesh,PolySwap); } /*! \brief This function performs the polygon regularization as in "Statics Aware Grid Shells" @@ -688,18 +780,21 @@ public: static void SmoothReprojectPCA(PolyMeshType &poly_m, int relaxStep=100, bool fixIrr=false, - ScalarType Damp=0.5) + ScalarType Damp=0.5, + ScalarType SharpDeg=0, + bool WeightByQuality=false) { //transform into triangular TempMesh GuideSurf; - vcg::tri::PolygonSupport::ImportFromPolyMesh(GuideSurf,poly_m); + //vcg::tri::PolygonSupport:(GuideSurf,poly_m); + TriangulateToTriMesh(poly_m,GuideSurf); vcg::tri::UpdateBounding::Box(GuideSurf); vcg::tri::UpdateNormal::PerVertexNormalizedPerFace(GuideSurf); vcg::tri::UpdateTopology::FaceFace(GuideSurf); vcg::tri::UpdateFlags::FaceBorderFromFF(GuideSurf); //optimize it - vcg::PolygonalAlgorithm::SmoothReprojectPCA(poly_m,GuideSurf,relaxStep,fixIrr,Damp); + vcg::PolygonalAlgorithm::SmoothReprojectPCA(poly_m,GuideSurf,relaxStep,fixIrr,Damp,SharpDeg,WeightByQuality); } /*! \brief This function return average edge size @@ -922,7 +1017,7 @@ public: for (size_t i=0;i - static void TriangulateToTriMesh(PolyMeshType &poly_m,TriMeshType &triangle_mesh) - { - triangle_mesh.Clear(); - - PolyMeshType PolySwap; - vcg::tri::Append::Mesh(PolySwap,poly_m); - Triangulate(PolySwap); - - //then copy onto the triangle mesh - vcg::tri::Append::Mesh(triangle_mesh,PolySwap); - } }; }//end namespace vcg