added a wrapper for the getkclosest that does not need the edgeplane additional data structure

and corrected a bug in the function that shot a bunch ofrays
This commit is contained in:
Paolo Cignoni 2010-05-04 08:19:51 +00:00
parent ee38039e83
commit b6d2c330f2
1 changed files with 35 additions and 22 deletions

View File

@ -300,18 +300,33 @@ namespace vcg {
return (gr.template GetClosest <VDistFunct,MarkerVert>(fn,mv,_p,_maxDist,_minDist,_closestPt)); return (gr.template GetClosest <VDistFunct,MarkerVert>(fn,mv,_p,_maxDist,_minDist,_closestPt));
} }
template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER> template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER>
unsigned int GetKClosestFace(MESH & mesh,GRID & gr, const unsigned int _k, unsigned int GetKClosestFace(MESH & mesh,GRID & gr, const unsigned int _k,
const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist, const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist,
OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points) OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points)
{ {
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf; MarkerFace mf;
mf.SetMesh(&mesh); mf.SetMesh(&mesh);
vcg::face::PointDistanceFunctor<typename MESH::ScalarType> FDistFunct; vcg::face::PointDistanceFunctor<typename MESH::ScalarType> FDistFunct;
return (gr.GetKClosest /*<vcg::face::PointDistanceFunctor, MarkerFace,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>*/ return (gr.GetKClosest /*<vcg::face::PointDistanceFunctor, MarkerFace,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>*/
(FDistFunct,mf,_k,_p,_maxDist,_objectPtrs,_distances,_points)); (FDistFunct,mf,_k,_p,_maxDist,_objectPtrs,_distances,_points));
} }
// This version does not require that the face type has the
// EdgePlane component and use a less optimized (but more memory efficient) point-triangle distance
template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER>
unsigned int GetKClosestFaceBase(MESH & mesh,GRID & gr, const unsigned int _k,
const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist,
OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points)
{
typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf;
mf.SetMesh(&mesh);
vcg::face::PointDistanceBaseFunctor<typename MESH::ScalarType> FDistFunct;
return (gr.GetKClosest /*<vcg::face::PointDistanceFunctor, MarkerFace,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>*/
(FDistFunct,mf,_k,_p,_maxDist,_objectPtrs,_distances,_points));
}
template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER> template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER>
unsigned int GetKClosestVertex(MESH & mesh,GRID & gr, const unsigned int _k, unsigned int GetKClosestVertex(MESH & mesh,GRID & gr, const unsigned int _k,
@ -398,7 +413,8 @@ namespace vcg {
Ray3<typename GRID::ScalarType> _ray1=_ray; Ray3<typename GRID::ScalarType> _ray1=_ray;
_ray1.Normalize(); _ray1.Normalize();
typedef vcg::RayTriangleIntersectionFunctor<true> FintFunct; typedef vcg::RayTriangleIntersectionFunctor<true> FintFunct;
return(gr.DoRay(FintFunct(),mf,_ray1,_maxDist,_t)); FintFunct ff;
return(gr.DoRay(ff,mf,_ray1,_maxDist,_t));
} }
template <class MESH, class GRID> template <class MESH, class GRID>
@ -445,22 +461,19 @@ namespace vcg {
typedef typename MESH::FaceType FaceType; typedef typename MESH::FaceType FaceType;
typedef typename MESH::ScalarType ScalarType; typedef typename MESH::ScalarType ScalarType;
ScalarType delta_theta=_theta_interval/(ScalarType)(n_samples*2); ScalarType delta_theta=_theta_interval/(ScalarType)(n_samples*2);
ScalarType delta_phi=_phi_interval/(ScalarType)(n_samples*2); ScalarType delta_phi =_phi_interval/(ScalarType)(n_samples*2);
ScalarType theta_init; ScalarType theta_init,phi_init,ro;
ScalarType phi_init;
ScalarType ro;
typename GRID::CoordType dir0=_ray.Direction(); typename GRID::CoordType dir0=_ray.Direction();
dir0.ToPolar(ro,theta_init,phi_init); dir0.ToPolarRad(ro,theta_init,phi_init);
for (int x=-n_samples;x<=n_samples;x++) for (int x=-n_samples;x<=n_samples;x++)
for (int y=-n_samples;y<=n_samples;y++) for (int y=-n_samples;y<=n_samples;y++)
{ {
ScalarType theta=theta_init+x*delta_theta; ScalarType theta=theta_init+x*delta_theta;
if (theta<0) if (theta<0) theta=2.0*M_PI-theta;
theta=360-theta; ScalarType phi=phi_init+y*delta_phi;
ScalarType phi=phi_init+x*delta_phi;
typename GRID::CoordType dir; typename GRID::CoordType dir;
dir.FromPolar(ro,theta,phi); dir.FromxPolar(ro,theta,phi);
dir.Normalize(); dir.Normalize();
Ray3<typename GRID::ScalarType> curr_ray(_ray.Origin(),dir); Ray3<typename GRID::ScalarType> curr_ray(_ray.Origin(),dir);
typename GRID::ScalarType _t; typename GRID::ScalarType _t;