improve generatePoissonDisk performances
This commit is contained in:
parent
226d111f9c
commit
ce6e4023c5
|
@ -688,19 +688,16 @@ static bool checkPoissonDisk(MetroMesh & vmesh, SampleSHT & sht, Point3<ScalarTy
|
||||||
mv.SetMesh(&vmesh);
|
mv.SetMesh(&vmesh);
|
||||||
typedef vcg::vertex::PointDistanceFunctor<ScalarType> VDistFunct;
|
typedef vcg::vertex::PointDistanceFunctor<ScalarType> VDistFunct;
|
||||||
VDistFunct fn;
|
VDistFunct fn;
|
||||||
/* int nsamples = sht.GetInSphere/*<VDistFunct,MarkerVert,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>
|
|
||||||
(fn, mv,p,radius,closests,distances,points);
|
|
||||||
|
|
||||||
*/
|
|
||||||
Box3f bb(p-Point3f(radius,radius,radius),p+Point3f(radius,radius,radius));
|
Box3f bb(p-Point3f(radius,radius,radius),p+Point3f(radius,radius,radius));
|
||||||
int nsamples = GridGetInBox(sht, mv, bb, closests);
|
int nsamples = GridGetInBox(sht, mv, bb, closests);
|
||||||
|
|
||||||
ScalarType r2 = radius*radius;
|
ScalarType r2 = radius*radius;
|
||||||
int badSamples=0;
|
for(int i=0; i<closests.size(); ++i)
|
||||||
for(int i=0;i<closests.size();++i)
|
if(SquaredDistance(p,closests[i]->cP()) < r2)
|
||||||
if(SquaredDistance(p,closests[i]->cP())<r2) ++badSamples;
|
return false;
|
||||||
return badSamples==0; // return true if the disk is ok
|
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a Poisson-disk sampling of the surface.
|
/** Compute a Poisson-disk sampling of the surface.
|
||||||
|
@ -751,6 +748,10 @@ static void Poissondisk(MetroMesh &origMesh, VertexSampler &ps, MetroMesh &monte
|
||||||
|
|
||||||
ScalarType cellsize = r / sqrt(3.0);
|
ScalarType cellsize = r / sqrt(3.0);
|
||||||
|
|
||||||
|
// inflating
|
||||||
|
origMesh.bbox.min -= Point3<ScalarType>(cellsize, cellsize, cellsize);
|
||||||
|
origMesh.bbox.max += Point3<ScalarType>(cellsize, cellsize, cellsize);
|
||||||
|
|
||||||
int sizeX = origMesh.bbox.DimX() / cellsize;
|
int sizeX = origMesh.bbox.DimX() / cellsize;
|
||||||
int sizeY = origMesh.bbox.DimY() / cellsize;
|
int sizeY = origMesh.bbox.DimY() / cellsize;
|
||||||
int sizeZ = origMesh.bbox.DimZ() / cellsize;
|
int sizeZ = origMesh.bbox.DimZ() / cellsize;
|
||||||
|
@ -798,6 +799,8 @@ static void Poissondisk(MetroMesh &origMesh, VertexSampler &ps, MetroMesh &monte
|
||||||
// extract a cell (C) from the active cell list (with probability proportional to cell's volume)
|
// extract a cell (C) from the active cell list (with probability proportional to cell's volume)
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
supportMesh.vert.reserve(montecarloMesh.vn);
|
||||||
|
|
||||||
// create active cell list
|
// create active cell list
|
||||||
for (it = montecarloSHT.AllocatedCells.begin(); it != montecarloSHT.AllocatedCells.end(); it++)
|
for (it = montecarloSHT.AllocatedCells.begin(); it != montecarloSHT.AllocatedCells.end(); it++)
|
||||||
{
|
{
|
||||||
|
@ -818,7 +821,6 @@ static void Poissondisk(MetroMesh &origMesh, VertexSampler &ps, MetroMesh &monte
|
||||||
activeCells[index2] = temp;
|
activeCells[index2] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
supportMesh.vert.reserve(montecarloMesh.vn);
|
|
||||||
// with a probability proportional to the intersection between the surface and the cell
|
// with a probability proportional to the intersection between the surface and the cell
|
||||||
// generate a sample inside C by choosing one of the contained pre-generated samples
|
// generate a sample inside C by choosing one of the contained pre-generated samples
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -842,6 +844,7 @@ static void Poissondisk(MetroMesh &origMesh, VertexSampler &ps, MetroMesh &monte
|
||||||
checkSHT.Add(&supportMesh.vert.back());
|
checkSHT.Add(&supportMesh.vert.back());
|
||||||
|
|
||||||
samplesaccepted[level]++;
|
samplesaccepted[level]++;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue