added GetInSphere and GetInBox functions

rensmed Functions respectively with Face suffix or Vertex suffix for query on vertex or faces
This commit is contained in:
Nico Pietroni 2005-10-03 13:59:39 +00:00
parent 3a54e6d7c3
commit 805b84bf43
1 changed files with 133 additions and 57 deletions

View File

@ -24,6 +24,11 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.13 2005/09/28 08:30:48 cignoni
changed name of include, removed use of an undefined type (scalar instead of Scalar) changed name of include, removed use of an undefined type (scalar instead of Scalar)
removed unused code portions (the old closest code) removed unused code portions (the old closest code)
@ -83,6 +88,7 @@ header added
#include <vcg/space/point4.h> #include <vcg/space/point4.h>
#include <vcg/math/base.h> #include <vcg/math/base.h>
#include <vcg/simplex/face/distance.h> #include <vcg/simplex/face/distance.h>
#include <vcg/simplex/vertex/distance.h>
#include <vcg/space/intersection3.h> #include <vcg/space/intersection3.h>
#include <vcg/space/index/space_iterators.h> #include <vcg/space/index/space_iterators.h>
@ -111,22 +117,6 @@ namespace vcg {
class VertTmark:public Tmark<MESH_TYPE,typename MESH_TYPE::VertexType> class VertTmark:public Tmark<MESH_TYPE,typename MESH_TYPE::VertexType>
{}; {};
///class of functor used to calculate the point triangle distance and nearest point
template <class VERTEX_TYPE>
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**// //**CLOSEST FUNCTION DEFINITION**//
/* /*
@ -143,7 +133,7 @@ namespace vcg {
// UGrid<MESH::FaceContainer >, ma non sono riuscito a definirlo implicitamente // UGrid<MESH::FaceContainer >, ma non sono riuscito a definirlo implicitamente
template <class MESH, class GRID> template <class MESH, class GRID>
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, const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist,
typename GRID::CoordType _closestPt,typename GRID::CoordType & _normf, typename GRID::CoordType _closestPt,typename GRID::CoordType & _normf,
typename GRID::CoordType & _ip) typename GRID::CoordType & _ip)
@ -176,32 +166,47 @@ namespace vcg {
return (0); return (0);
} }
///* RICONTROLLARE template <class MESH, class GRID>
/*template <class MESH, class GRID> typename MESH::FaceType * GetClosestFace( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p,
typename MESH::FaceType * GetClosest( MESH & mesh,GRID & gr,const Point3<SCALAR> & _p, const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist,
const SCALAR & _maxDist,SCALAR & _minDist,Point3<SCALAR> _closestPt, typename GRID::CoordType _closestPt,typename GRID::CoordType & _normf)
Point3<SCALAR> & _normf)
{ {
Point3<SCALAR> _ip; Point3<SCALAR> _ip;
return (GetClosest<MESH,GRID>(mesh,gr,_p,_maxDist,_minDist,_closestPt,_normf,_ip)); return (GetClosest<MESH,GRID>(mesh,gr,_p,_maxDist,_minDist,_closestPt,_normf,ip));
}*/ }
/* RICONTROLLARE template <class MESH, class GRID>
template <class MESH, class GRID, class SCALAR> typename MESH::FaceType * GetClosestFace( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p,
void ClosestVertex( MESH & mesh, const Point3<SCALAR> & p, GRID & gr, SCALAR & mdist, const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist,
Point3<SCALAR> & normf, Point3<SCALAR> & bestq, typename MESH::VertexType * &v) typename GRID::CoordType _closestPt)
{ {
scalar error = mdist; typedef GRID::ScalarType ScalarType;
typedef VertTmark<MESH> MarkerVert; typedef Point3<ScalarType> Point3x;
MarkerVert t; typedef FaceTmark<MESH> MarkerFace;
t.SetMesh(&mesh); MarkerFace mf;
typedef typename VertexDistance<typename MESH::VertexType> PDistFunct; mf.SetMesh(&mesh);
v= vcg::GetClosest<GRID,PDistFunct,MarkerFace>(p,mdist,PDistFunct() ,error,bestq,t,gr); typedef vcg::face::PointDistanceFunctor PDistFunct;
}*/ _minDist=_maxDist;
return (gr.GetClosest<FDistFunct,MarkerFace>(PDistFunct(),mf,_p,_maxDist,_minDist,_closestPt));
}
template <class MESH, class GRID>
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<ScalarType> Point3x;
typedef VertTmark<MESH> MarkerVert;
MarkerVert mv;
mv.SetMesh(&mesh);
typedef vcg::vertex::PointDistanceFunctor VDistFunct;
_minDist=_maxDist;
return (gr.GetClosest<VDistFunct,MarkerFace>(VDistFunct(),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 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, const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist,
OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points) OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points)
{ {
@ -213,6 +218,77 @@ namespace vcg {
(FDistFunct(),mf,_k,_p,_maxDist,_objectPtrs,_distances,_points)); (FDistFunct(),mf,_k,_p,_maxDist,_objectPtrs,_distances,_points));
} }
template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER>
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<MESH> MarkerVert;
MarkerVert mv;
mv.SetMesh(&mesh);
typedef vcg::vertex::PointDistanceFunctor VDistFunct;
return (gr.GetKClosest<VDistFunct,MarkerFace,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>
(VDistFunct(),mv,_k,_p,_maxDist,_objectPtrs,_distances,_points));
}
template <class MESH, class GRID, class OBJPTRCONTAINER, class DISTCONTAINER, class POINTCONTAINER>
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<MESH> MarkerFace;
MarkerFace mf;
mf.SetMesh(&mesh);
typedef vcg::face::PointDistanceFunctor FDistFunct;
return (gr.GetInSphere<FDistFunct,MarkerFace,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>
(FDistFunct(),mf,_p,_r,_maxDist,_objectPtrs,_distances,_points));
}
template <class MESH, class GRID, class OBJPTRCONTAINER, class DISTCONTAINER, class POINTCONTAINER>
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<MESH> MarkerVert;
MarkerVert mv;
mv.SetMesh(&mesh);
typedef vcg::vertex::PointDistanceFunctor VDistFunct;
return (gr.GetInSphere<VDistFunct,MarkerVert,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>
(VDistFunct(),mv,_p,_r,_objectPtrs,_distances,_points));
}
template <class MESH, class GRID, class OBJPTRCONTAINER>
unsigned int GetInBoxFace(MESH & mesh,
GRID & gr,
const vcg::Box3<typename GRID::ScalarType> _bbox,
OBJPTRCONTAINER & _objectPtrs)
{
typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf;
mf.SetMesh(&mesh);
return(gr.GetInBox<MarkerFace,OBJPTRCONTAINER>(mf,_bbox,_objectPtrs));
}
template <class MESH, class GRID, class OBJPTRCONTAINER>
unsigned int GetInBoxVertex(MESH & mesh,
GRID & gr,
const vcg::Box3<typename GRID::ScalarType> _bbox,
OBJPTRCONTAINER & _objectPtrs)
{
typedef VertTmark<MESH> MarkerVert;
MarkerVert mv;
mv.SetMesh(&mesh);
return(gr.GetInBox<MarkerVert,OBJPTRCONTAINER>(mv,_bbox,_objectPtrs));
}
template <class MESH, class GRID> template <class MESH, class GRID>
typename GRID::ObjPtr DoRay(MESH & mesh,GRID & gr, const Ray3<typename GRID::ScalarType> & _ray, typename GRID::ObjPtr DoRay(MESH & mesh,GRID & gr, const Ray3<typename GRID::ScalarType> & _ray,
const typename GRID::ScalarType & _maxDist, typename GRID::ScalarType & _t) const typename GRID::ScalarType & _maxDist, typename GRID::ScalarType & _t)
@ -250,14 +326,14 @@ namespace vcg {
}; };
template <class GRID,class MESH> template <class GRID,class MESH>
class ClosestVertexIterator:public vcg::ClosestIterator<GRID,VertexDistance<typename MESH::VertexType>,typename VertTmark<MESH> > class ClosestVertexIterator:public vcg::ClosestIterator<GRID,vcg::vertex::PointDistanceFunctor,typename VertTmark<MESH> >
{ {
public: public:
typedef typename GRID GridType; typedef typename GRID GridType;
typedef typename MESH MeshType; typedef typename MESH MeshType;
typedef typename VertTmark<MESH> MarkerVert; typedef typename VertTmark<MESH> MarkerVert;
typedef typename VertexDistance<typename MESH::VertexType> VDistFunct; typedef typename vcg::vertex::PointDistanceFunctor VDistFunct;
typedef typename vcg::ClosestIterator<GRID,VertexDistance<typename MESH::VertexType>,typename VertTmark<MESH> > ClosestBaseType; typedef typename vcg::ClosestIterator<GRID,VDistFunct,typename VertTmark<MESH> > ClosestBaseType;
ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,VDistFunct()){} ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,VDistFunct()){}