Hi all,
i've started working on the "re-topology" plugin (just committed a
*very* initial version),
and i've got a question on how to use (correctly) the Uniform Grid object.
My goal is to get the closest point of a mesh from a given spatial
coord (not a vertex of
the mesh structure, just a free point over its surface),
and then use that point to build the retopologized mesh.
In order to do this, i've looked for some spatial indexing structures,
and found the
one that is called "GridStaticPtr", whitch seems to be exaclty what i needed.
So, once initialized the Grid object ("unifGrid"):
meshModel->updateDataMask(MeshModel::MM_FACEMARK);
unifGrid.Set(mesh->face.begin(), mesh->face.end());
markerFunctor.SetMesh(mesh);
i use this code to get the closest point:
float dist_upper_bound =mesh->bbox.Diag()/50;
float dist = dist_upper_bound;
const CMeshO::CoordType &startPt= toCheck;
CMeshO::FaceType *nearestF=0;
vcg::face::PointDistanceBaseFunctor PDistFunct;
nearestF = unifGrid.GetClosest(PDistFunct, markerFunctor, startPt,
dist_upper_bound, dist, closestPt);
Here i expect to get in "closestPt" the mesh surface point nearest to
"startPt", but this does
not happen for every starting point passed (expecially on hi-res meshes, the
returned point is not just the nonclosest, but it's also not a point
of the mesh).
Well, my question is: am i using "unifGrid" correctly?
And, if not, any suggestion on how to get the closest mesh point from
a given coord (using uniform grid or something else)?
Tanks in advance,
D.
|