added a very simple function wrapper to get a poisson disk distribution over a mesh with just function call

This commit is contained in:
Paolo Cignoni 2012-04-18 21:12:12 +00:00
parent 508c733bd4
commit 5f22a3f7b5
1 changed files with 33 additions and 0 deletions

View File

@ -1454,6 +1454,39 @@ static void SubdivideAndSample(MetroMesh & m, std::vector<Point3f> &pvec, const
}; // end class
// Yet another simpler wrapper for the Generation of a poisson disk distribution over a mesh.
//
template <class MeshType>
void PoissonSampling(MeshType &m, // the mesh that has to be sampled
std::vector<Point3f> &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<MeshType> BaseSampler;
if(sampleNum>0) radius = tri::SurfaceSampling<MeshType,BaseSampler>::ComputePoissonDiskRadius(m,sampleNum);
if(radius>0 && sampleNum==0) sampleNum = tri::SurfaceSampling<MeshType,BaseSampler>::ComputePoissonSampleNum(m,radius);
poissonSamples.clear();
std::vector<Point3f> MontecarloSamples;
MeshType MontecarloMesh;
// First step build the sampling
BaseSampler mcSampler(MontecarloSamples);
BaseSampler pdSampler(poissonSamples);
tri::SurfaceSampling<MeshType,BaseSampler>::Montecarlo(m, mcSampler, std::max(10000,sampleNum*20));
tri::Allocator<MeshType>::AddVertices(MontecarloMesh,MontecarloSamples.size());
for(size_t i=0;i<MontecarloSamples.size();++i)
MontecarloMesh.vert[i].P()=MontecarloSamples[i];
typename tri::SurfaceSampling<MeshType, BaseSampler>::PoissonDiskParam pp;
tri::SurfaceSampling<MeshType,BaseSampler>::PoissonDiskPruning(m, pdSampler, m, radius,pp);
}
} // end namespace tri
} // end namespace vcg