From d8293c0c055ac046f8a69a868893e05d8cdcd5c0 Mon Sep 17 00:00:00 2001 From: cignoni Date: Sat, 30 Aug 2014 07:50:22 +0000 Subject: [PATCH] Updated RestrictedVoronoiRelaxing to use area weighted sum of nearest vertexes to compute barycenter --- vcg/complex/algorithms/voronoi_processing.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/vcg/complex/algorithms/voronoi_processing.h b/vcg/complex/algorithms/voronoi_processing.h index 03a2018a..c8144523 100644 --- a/vcg/complex/algorithms/voronoi_processing.h +++ b/vcg/complex/algorithms/voronoi_processing.h @@ -113,6 +113,7 @@ public: typedef typename MeshType::template PerVertexAttributeHandle PerVertexPointerHandle; typedef typename MeshType::template PerVertexAttributeHandle PerVertexBoolHandle; + typedef typename MeshType::template PerVertexAttributeHandle PerVertexFloatHandle; typedef typename MeshType::template PerFaceAttributeHandle PerFacePointerHandle; @@ -1186,6 +1187,7 @@ static int RestrictedVoronoiRelaxing(MeshType &m, std::vector &see { PerVertexPointerHandle sources = tri::Allocator:: template GetPerVertexAttribute (m,"sources"); PerVertexBoolHandle fixed = tri::Allocator:: template GetPerVertexAttribute (m,"fixed"); + PerVertexFloatHandle area = tri::Allocator:: template GetPerVertexAttribute (m,"area"); std::vector fixedVec; std::vector seedPosVec; for(size_t i=0;i &see fixedVec.push_back(fixed[seedVec[i]]); } + for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) + area[vi]=0; + + for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) + { + ScalarType a3 = DoubleArea(*fi)/6.0; + for(int i=0;i<3;++i) + area[fi->V(i)]+=a3; + } + assert(m.vn > seedPosVec.size()*20); int i; @@ -1202,16 +1214,16 @@ static int RestrictedVoronoiRelaxing(MeshType &m, std::vector &see VectorConstDataWrapper > 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) + std::vector > sumVec(seedPosVec.size(),std::make_pair(0,CoordType(0,0,0))); + for(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(); + sumVec[seedInd].first+=area[vi]; + sumVec[seedInd].second+=vi->cP()*area[vi]; } vector newseedVec;