From b79c323a77fa890a2cad33ee2a561c1baf0862a2 Mon Sep 17 00:00:00 2001 From: cignoni Date: Fri, 9 May 2014 21:50:28 +0000 Subject: [PATCH] Added relaxOnlyConstrainedFlag to the voronoi processing relax procedure that allow to relax only the vertexes that are constrainted (onto their domain) ignoring all the other samples (except the fixed one). It allows to get more even distributions on the constrains. --- vcg/complex/algorithms/voronoi_processing.h | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/vcg/complex/algorithms/voronoi_processing.h b/vcg/complex/algorithms/voronoi_processing.h index 8c8c6517..2f5644fd 100644 --- a/vcg/complex/algorithms/voronoi_processing.h +++ b/vcg/complex/algorithms/voronoi_processing.h @@ -57,6 +57,7 @@ struct VoronoiProcessingParameter triangulateRegion=false; unbiasedSeedFlag = true; geodesicRelaxFlag = true; + relaxOnlyConstrainedFlag=false; refinementRatio = 5.0f; } int colorStrategy; @@ -72,6 +73,8 @@ struct VoronoiProcessingParameter /// domains, for example moving only along some linear features /// like border of creases. + bool relaxOnlyConstrainedFlag; + bool preserveFixedSeed; /// If true the 'fixed' seeds are not moved during relaxation. /// \see FixVertexVector function to see how to fix a set of seeds. @@ -1176,7 +1179,9 @@ static void FixVertexVector(MeshType &m, std::vector &vertToFixVec } /// \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' +/// 2) /// static int VoronoiRelaxing(MeshType &m, std::vector &seedVec, @@ -1188,6 +1193,14 @@ static int VoronoiRelaxing(MeshType &m, std::vector &seedVec, tri::RequireCompactness(m); for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) assert(vi->VFp() && "Require mesh without unreferenced vertexes\n"); + std::vector selectedVec; + if(vpp.relaxOnlyConstrainedFlag) + { + for(size_t i=0;iIsS()) + selectedVec.push_back(seedVec[i]); + std::swap(seedVec,selectedVec); + } tri::UpdateFlags::FaceBorderFromVF(m); tri::UpdateFlags::VertexBorderFromFace(m); @@ -1246,6 +1259,18 @@ static int VoronoiRelaxing(MeshType &m, std::vector &seedVec, if(iter==relaxIter) tri::Geodesic::Compute(m, seedVec, df,std::numeric_limits::max(),0,&sources); + if(vpp.relaxOnlyConstrainedFlag) + { + std::swap(seedVec,selectedVec); + int i=0,j=0; + for(i=0,j=0;iIsS()) + { + seedVec[i]=selectedVec[j]; + ++j; + } + } + } return iter; }