From 5f22a3f7b5645a3e91098c65f76461c0f1969fb4 Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 18 Apr 2012 21:12:12 +0000 Subject: [PATCH] added a very simple function wrapper to get a poisson disk distribution over a mesh with just function call --- vcg/complex/algorithms/point_sampling.h | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/vcg/complex/algorithms/point_sampling.h b/vcg/complex/algorithms/point_sampling.h index d8a39ba2..5e3fd792 100644 --- a/vcg/complex/algorithms/point_sampling.h +++ b/vcg/complex/algorithms/point_sampling.h @@ -1454,6 +1454,39 @@ static void SubdivideAndSample(MetroMesh & m, std::vector &pvec, const }; // end class + +// Yet another simpler wrapper for the Generation of a poisson disk distribution over a mesh. +// +template +void PoissonSampling(MeshType &m, // the mesh that has to be sampled + std::vector &poissonSamples, // the vector that will contain the set of points + int sampleNum, // the desired number sample, if zero you must set the radius to the wanted value + float &radius) // the Poisson Disk Radius (used if sampleNum==0, setted if sampleNum!=0) +{ + typedef tri::TrivialSampler BaseSampler; + if(sampleNum>0) radius = tri::SurfaceSampling::ComputePoissonDiskRadius(m,sampleNum); + if(radius>0 && sampleNum==0) sampleNum = tri::SurfaceSampling::ComputePoissonSampleNum(m,radius); + + poissonSamples.clear(); + std::vector MontecarloSamples; + MeshType MontecarloMesh; + + // First step build the sampling + BaseSampler mcSampler(MontecarloSamples); + BaseSampler pdSampler(poissonSamples); + + tri::SurfaceSampling::Montecarlo(m, mcSampler, std::max(10000,sampleNum*20)); + + tri::Allocator::AddVertices(MontecarloMesh,MontecarloSamples.size()); + for(size_t i=0;i::PoissonDiskParam pp; + + tri::SurfaceSampling::PoissonDiskPruning(m, pdSampler, m, radius,pp); +} + + } // end namespace tri } // end namespace vcg