diff --git a/vcg/complex/trimesh/closest.h b/vcg/complex/trimesh/closest.h index 1d611784..f7ab0747 100644 --- a/vcg/complex/trimesh/closest.h +++ b/vcg/complex/trimesh/closest.h @@ -24,6 +24,11 @@ History $Log: not supported by cvs2svn $ +Revision 1.14 2005/09/30 13:10:37 pietroni +used functor defined in face/distance.h for distance point-face +used functor defined in intersection3.h for ray-triangle intersection +added GetKClosest and DoRay Functions + Revision 1.13 2005/09/28 08:30:48 cignoni changed name of include, removed use of an undefined type (scalar instead of Scalar) removed unused code portions (the old closest code) @@ -83,6 +88,7 @@ header added #include #include #include +#include #include #include @@ -111,22 +117,6 @@ namespace vcg { class VertTmark:public Tmark {}; - ///class of functor used to calculate the point triangle distance and nearest point - template - class VertexDistance { - typedef typename VERTEX_TYPE VertexType; - typedef typename VERTEX_TYPE::ScalarType ScalarType; - typedef typename VERTEX_TYPE::CoordType CoordType; - - public: - bool operator () (const VertexType & v, const CoordType & pt, ScalarType & dist, CoordType & result) { - ScalarType d=dist; - dist=(v.P()-pt).Norm(); - result=pt; - return(d>dist); - } - }; - //**CLOSEST FUNCTION DEFINITION**// /* @@ -143,7 +133,7 @@ namespace vcg { // UGrid, ma non sono riuscito a definirlo implicitamente template - typename MESH::FaceType * GetClosest( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, + typename MESH::FaceType * GetClosestFace( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist, typename GRID::CoordType _closestPt,typename GRID::CoordType & _normf, typename GRID::CoordType & _ip) @@ -159,49 +149,64 @@ namespace vcg { typename MESH::FaceType* bestf= gr.GetClosest(FDistFunct(),mf,_p,_maxDist,_minDist,_closestPt); if(_maxDist> ScalarType(fabs(_minDist))) - { - // f=bestf; - typename MESH::ScalarType alfa, beta, gamma; - //calcolo normale con interpolazione trilineare - bestf->InterpolationParameters(_closestPt, alfa, beta, gamma); - _normf = (bestf->V(0)->cN())*alfa+ - (bestf->V(1)->cN())*beta+ - (bestf->V(2)->cN())*gamma ; - _ip=Point3x(alfa,beta,gamma); - //normf.Normalize(); inutile si assume le normali ai vertici benfatte + { + // f=bestf; + typename MESH::ScalarType alfa, beta, gamma; + //calcolo normale con interpolazione trilineare + bestf->InterpolationParameters(_closestPt, alfa, beta, gamma); + _normf = (bestf->V(0)->cN())*alfa+ + (bestf->V(1)->cN())*beta+ + (bestf->V(2)->cN())*gamma ; + _ip=Point3x(alfa,beta,gamma); + //normf.Normalize(); inutile si assume le normali ai vertici benfatte - _minDist = fabs(_minDist); - return(bestf); - } - return (0); + _minDist = fabs(_minDist); + return(bestf); + } + return (0); } - ///* RICONTROLLARE - /*template - typename MESH::FaceType * GetClosest( MESH & mesh,GRID & gr,const Point3 & _p, - const SCALAR & _maxDist,SCALAR & _minDist,Point3 _closestPt, - Point3 & _normf) + template + typename MESH::FaceType * GetClosestFace( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, + const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist, + typename GRID::CoordType _closestPt,typename GRID::CoordType & _normf) { Point3 _ip; - return (GetClosest(mesh,gr,_p,_maxDist,_minDist,_closestPt,_normf,_ip)); - }*/ + return (GetClosest(mesh,gr,_p,_maxDist,_minDist,_closestPt,_normf,ip)); + } - /* RICONTROLLARE - template - void ClosestVertex( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, - Point3 & normf, Point3 & bestq, typename MESH::VertexType * &v) + template + typename MESH::FaceType * GetClosestFace( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, + const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist, + typename GRID::CoordType _closestPt) { - scalar error = mdist; - typedef VertTmark MarkerVert; - MarkerVert t; - t.SetMesh(&mesh); - typedef typename VertexDistance PDistFunct; - v= vcg::GetClosest(p,mdist,PDistFunct() ,error,bestq,t,gr); - }*/ + typedef GRID::ScalarType ScalarType; + typedef Point3 Point3x; + typedef FaceTmark MarkerFace; + MarkerFace mf; + mf.SetMesh(&mesh); + typedef vcg::face::PointDistanceFunctor PDistFunct; + _minDist=_maxDist; + return (gr.GetClosest(PDistFunct(),mf,_p,_maxDist,_minDist,_closestPt)); + } + + template + typename MESH::VertexType * GetClosestVertex( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, + const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist, + typename GRID::CoordType _closestPt,typename GRID::CoordType & _normf) + { + typedef GRID::ScalarType ScalarType; + typedef Point3 Point3x; + typedef VertTmark MarkerVert; + MarkerVert mv; + mv.SetMesh(&mesh); + typedef vcg::vertex::PointDistanceFunctor VDistFunct; + _minDist=_maxDist; + return (gr.GetClosest(VDistFunct(),mv,_p,_maxDist,_minDist,_closestPt)); + } - template - unsigned int GetKClosest(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, OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points) { @@ -213,9 +218,80 @@ namespace vcg { (FDistFunct(),mf,_k,_p,_maxDist,_objectPtrs,_distances,_points)); } + template + unsigned int GetKClosestVertex(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 VertTmark MarkerVert; + MarkerVert mv; + mv.SetMesh(&mesh); + typedef vcg::vertex::PointDistanceFunctor VDistFunct; + return (gr.GetKClosest + (VDistFunct(),mv,_k,_p,_maxDist,_objectPtrs,_distances,_points)); + } + + template + unsigned int GetInSphereFace(MESH & mesh, + GRID & gr, + const typename GRID::CoordType & _p, + const typename GRID::ScalarType & _r, + OBJPTRCONTAINER & _objectPtrs, + DISTCONTAINER & _distances, + POINTCONTAINER & _points) + { + typedef FaceTmark MarkerFace; + MarkerFace mf; + mf.SetMesh(&mesh); + typedef vcg::face::PointDistanceFunctor FDistFunct; + return (gr.GetInSphere + (FDistFunct(),mf,_p,_r,_maxDist,_objectPtrs,_distances,_points)); + } + + template + unsigned int GetInSphereVertex(MESH & mesh, + GRID & gr, + const typename GRID::CoordType & _p, + const typename GRID::ScalarType & _r, + OBJPTRCONTAINER & _objectPtrs, + DISTCONTAINER & _distances, + POINTCONTAINER & _points) + { + typedef VertTmark MarkerVert; + MarkerVert mv; + mv.SetMesh(&mesh); + typedef vcg::vertex::PointDistanceFunctor VDistFunct; + return (gr.GetInSphere + (VDistFunct(),mv,_p,_r,_objectPtrs,_distances,_points)); + } + + template + unsigned int GetInBoxFace(MESH & mesh, + GRID & gr, + const vcg::Box3 _bbox, + OBJPTRCONTAINER & _objectPtrs) + { + typedef FaceTmark MarkerFace; + MarkerFace mf; + mf.SetMesh(&mesh); + return(gr.GetInBox(mf,_bbox,_objectPtrs)); + } + + template + unsigned int GetInBoxVertex(MESH & mesh, + GRID & gr, + const vcg::Box3 _bbox, + OBJPTRCONTAINER & _objectPtrs) + { + typedef VertTmark MarkerVert; + MarkerVert mv; + mv.SetMesh(&mesh); + return(gr.GetInBox(mv,_bbox,_objectPtrs)); + } + template - typename GRID::ObjPtr DoRay(MESH & mesh,GRID & gr, const Ray3 & _ray, - const typename GRID::ScalarType & _maxDist, typename GRID::ScalarType & _t) + typename GRID::ObjPtr DoRay(MESH & mesh,GRID & gr, const Ray3 & _ray, + const typename GRID::ScalarType & _maxDist, typename GRID::ScalarType & _t) { typedef MESH::FaceType FaceType; typedef MESH::ScalarType ScalarType; @@ -231,7 +307,7 @@ namespace vcg { template class ClosestFaceIterator:public vcg::ClosestIterator > + vcg::face::PointDistanceFunctor,typename FaceTmark > { public: typedef typename GRID GridType; @@ -250,14 +326,14 @@ namespace vcg { }; template - class ClosestVertexIterator:public vcg::ClosestIterator,typename VertTmark > + class ClosestVertexIterator:public vcg::ClosestIterator > { public: typedef typename GRID GridType; typedef typename MESH MeshType; typedef typename VertTmark MarkerVert; - typedef typename VertexDistance VDistFunct; - typedef typename vcg::ClosestIterator,typename VertTmark > ClosestBaseType; + typedef typename vcg::vertex::PointDistanceFunctor VDistFunct; + typedef typename vcg::ClosestIterator > ClosestBaseType; ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,VDistFunct()){}