From 875a7d1aac6a5cd174ad4400f022f33cf1b0056b Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 28 Aug 2014 01:54:32 +0000 Subject: [PATCH] Added RestrictedVoronoiRelaxing mode to the voronoi framework --- vcg/complex/algorithms/voronoi_processing.h | 57 +++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/vcg/complex/algorithms/voronoi_processing.h b/vcg/complex/algorithms/voronoi_processing.h index de10a159..3ca9e8a8 100644 --- a/vcg/complex/algorithms/voronoi_processing.h +++ b/vcg/complex/algorithms/voronoi_processing.h @@ -1178,6 +1178,57 @@ static void FixVertexVector(MeshType &m, std::vector &vertToFixVec fixed[vertToFixVec[i]]=true; } + +static int RestrictedVoronoiRelaxing(MeshType &m, std::vector &seedVec, + int relaxStep, + VoronoiProcessingParameter &vpp, + vcg::CallBackPos *cb=0) +{ + PerVertexPointerHandle sources = tri::Allocator:: template GetPerVertexAttribute (m,"sources"); + PerVertexBoolHandle fixed = tri::Allocator:: template GetPerVertexAttribute (m,"fixed"); + + std::vector seedPosVec; + for(size_t i=0;iP()); + + bool changed=false; + assert(m.vn > seedPosVec.size()*20); + int i; + + for(i=0;i > vdw(seedPosVec); + KdTree seedTree(vdw); + + std::vector > sumVec(seedPosVec.size(),std::make_pair(0,CoordType(0,0,0))); + for(typename MeshType::VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) + { + unsigned int seedInd; + ScalarType sqdist; + seedTree.doQueryClosest(vi->P(),seedInd,sqdist); + vi->Q()=sqrt(sqdist); + sources[vi]=seedVec[seedInd]; + sumVec[seedInd].first++; + sumVec[seedInd].second+=vi->cP(); + } + + vector newseedVec; + + for(int i=0;i::PerVertexQualityRamp(m); + + qDebug("performed %i relax step on %i",i,relaxStep); + } + + SeedToVertexConversion(m,seedPosVec,seedVec); +} + /// \brief Perform a Lloyd relaxation cycle over a mesh /// It uses two conventions: /// 1) a few vertexes can remain fixed, you have to set a per vertex bool attribute named 'fixed' @@ -1204,10 +1255,8 @@ static int VoronoiRelaxing(MeshType &m, std::vector &seedVec, tri::UpdateFlags::FaceBorderFromVF(m); tri::UpdateFlags::VertexBorderFromFace(m); - typename MeshType::template PerVertexAttributeHandle sources; - sources = tri::Allocator:: template GetPerVertexAttribute (m,"sources"); - typename MeshType::template PerVertexAttributeHandle fixed; - fixed = tri::Allocator:: template GetPerVertexAttribute (m,"fixed"); + PerVertexPointerHandle sources = tri::Allocator:: template GetPerVertexAttribute (m,"sources"); + PerVertexBoolHandle fixed = tri::Allocator:: template GetPerVertexAttribute (m,"fixed"); int iter; for(iter=0;iter