From 6715e4f658c17797e454f049d8349d246f29b799 Mon Sep 17 00:00:00 2001 From: mcallieri Date: Thu, 29 Oct 2015 13:44:25 +0000 Subject: [PATCH] - added a "only on selection" option to VertexUniform and AllVertex sampling functions - added a "isD" check to VertexUniform sampling function to be tested --- vcg/complex/algorithms/point_sampling.h | 53 ++++++++++++++++--------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/vcg/complex/algorithms/point_sampling.h b/vcg/complex/algorithms/point_sampling.h index b93bc39b..09090a93 100644 --- a/vcg/complex/algorithms/point_sampling.h +++ b/vcg/complex/algorithms/point_sampling.h @@ -505,14 +505,18 @@ static int Poisson(double lambda) static void AllVertex(MeshType & m, VertexSampler &ps) { - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) - { - if(!(*vi).IsD()) - { - ps.AddVert(*vi); - } - } + AllVertex(m, ps, false); +} + +static void AllVertex(MeshType & m, VertexSampler &ps, bool onlySelected) +{ + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) + if(!(*vi).IsD()) + if ((!onlySelected) || ((*vi).IsS())) + { + ps.AddVert(*vi); + } } /// Sample the vertices in a weighted way. Each vertex has a probability of being chosen @@ -603,18 +607,31 @@ static void FillAndShuffleVertexPointerVector(MeshType & m, std::vector= m.vn) { + AllVertex(m, ps, onlySelected); + return; + } + + std::vector vertVec; + FillAndShuffleVertexPointerVector(m, vertVec); + + int added = 0; + for (int i = 0; ((i < m.vn) && (added < sampleNum)); ++i) + if (!(*vertVec[i]).IsD()) + if ((!onlySelected) || (*vertVec[i]).IsS()) + { + ps.AddVert(*vertVec[i]); + added++; + } + +} + + static void VertexUniform(MeshType & m, VertexSampler &ps, int sampleNum) { - if(sampleNum>=m.vn) { - AllVertex(m,ps); - return; - } - - std::vector vertVec; - FillAndShuffleVertexPointerVector(m,vertVec); - - for(int i =0; i< sampleNum; ++i) - ps.AddVert(*vertVec[i]); + VertexUniform(m, ps, sampleNum, false); }