diff --git a/vcg/complex/trimesh/closest.h b/vcg/complex/trimesh/closest.h index 4533c456..7a444baa 100644 --- a/vcg/complex/trimesh/closest.h +++ b/vcg/complex/trimesh/closest.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.11 2005/09/19 13:36:24 pietroni +added ray iterator of faces + Revision 1.10 2005/09/16 11:53:51 cignoni Small gcc compliling issues @@ -73,10 +76,12 @@ header added #include //#include #include +#include namespace vcg { namespace trimesh { +//**MARKER CLASSES**// template class Tmark { @@ -98,6 +103,7 @@ template class VertTmark:public Tmark {}; +//**INTERSECTION FUNCTIONS**// ///class of functor used to calculate the radius-triangle intersection template class FaceIntersection { @@ -119,6 +125,38 @@ template } }; +//**DISTANCE FUNCTIONS**// + ///class of functor used to calculate the point triangle distance and nearest point + template + class FaceDistance { + typedef typename FACE_TYPE FaceType; + typedef typename FACE_TYPE::ScalarType ScalarType; + typedef typename FaceType::CoordType CoordType; + + public: + bool operator () (const FaceType & f, const CoordType & pt, ScalarType & mindist, CoordType & result) { + return (vcg::face::PointDistance(f,pt, mindist, result)); + } + }; + + ///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**// + /* aka MetroCore @@ -136,7 +174,7 @@ template void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, Point3 & normf, Point3 & bestq, typename MESH::FaceType * &f, Point3 &ip) { - typedef SCALAR scalar; + typedef SCALAR ScalarType; typedef Point3 Point3x; typedef Box3 Box3x; @@ -247,11 +285,12 @@ void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, // vdist += vstep; //} - scalar error = mdist; + ScalarType error = mdist; typedef FaceTmark MarkerFace; MarkerFace t; t.SetMesh(&mesh); - typename MESH::FaceType* bestf= gr.GetClosest(p,error,bestq,t); + typedef typename FaceDistance FDistFunct; + typename MESH::FaceType* bestf= vcg::GetClosest(p,mdist,FDistFunct() ,error,bestq,t,gr); if(mdist > scalar(fabs(error))) { @@ -271,12 +310,59 @@ void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, template void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, - Point3 & normf, Point3 & bestq, typename MESH::face_type * &f) + Point3 & normf, Point3 & bestq, typename MESH::FaceType * &f) { Point3 ip; - Closest(mesh,p,gr,mdist,normf,bestq,f,ip); + Closest(mesh,p,gr,mdist,normf,bestq,f,ip); } +template +void ClosestVertex( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, + Point3 & normf, Point3 & bestq, typename MESH::VertexType * &v) +{ + 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); +} + + +//**ITERATORS DEFINITION**// + +template +class ClosestFaceIterator:public vcg::ClosestIterator,typename FaceTmark > +{ +public: + typedef typename GRID GridType; + typedef typename MESH MeshType; + typedef typename FaceTmark MarkerFace; + typedef typename FaceDistance FDistFunct; + typedef typename vcg::ClosestIterator,typename FaceTmark > ClosestBaseType; + + ClosestFaceIterator(GridType &_Si):ClosestBaseType(_Si,FDistFunct()){} + + void SetMesh(MeshType *m) + {tm.SetMesh(m);} +}; + +template +class ClosestVertexIterator:public vcg::ClosestIterator,typename VertTmark > +{ +public: + typedef typename GRID GridType; + typedef typename MESH MeshType; + typedef typename VertTmark MarkerVert; + typedef typename VertexDistance VDistFunct; + typedef typename vcg::ClosestIterator,typename VertTmark > ClosestBaseType; + + ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,VDistFunct()){} + + void SetMesh(MeshType *m) + {tm.SetMesh(m);} +}; + template class TriRayIterator:public vcg::RayIterator,typename FaceTmark > { @@ -292,11 +378,6 @@ public: void SetMesh(MeshType *m) {tm.SetMesh(m);} - - /*void Init(RayType _r,MeshType &mesh) - { - __super::Init(_r); - }*/ }; } // end namespace trimesh