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
This commit is contained in:
parent
c19fce46a3
commit
e58a99de93
|
@ -24,6 +24,10 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
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)
|
||||||
|
|
||||||
Revision 1.12 2005/09/21 09:24:30 pietroni
|
Revision 1.12 2005/09/21 09:24:30 pietroni
|
||||||
Added RayIterators.
|
Added RayIterators.
|
||||||
Added ClosestIterators on Triangles and Vertices.
|
Added ClosestIterators on Triangles and Vertices.
|
||||||
|
@ -79,207 +83,208 @@ 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/space/index/grid_static_ptr.h>
|
#include <vcg/space/intersection3.h>
|
||||||
#include <vcg/space/index/space_iterators.h>
|
#include <vcg/space/index/space_iterators.h>
|
||||||
#include <vcg/space/index/grid_closest.h>
|
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
namespace trimesh {
|
namespace trimesh {
|
||||||
|
|
||||||
//**MARKER CLASSES**//
|
//**MARKER CLASSES**//
|
||||||
template <class MESH_TYPE,class OBJ_TYPE>
|
template <class MESH_TYPE,class OBJ_TYPE>
|
||||||
class Tmark
|
class Tmark
|
||||||
{
|
{
|
||||||
MESH_TYPE *m;
|
MESH_TYPE *m;
|
||||||
public:
|
public:
|
||||||
Tmark(){}
|
Tmark(){}
|
||||||
void UnMarkAll(){m->UnMarkAll();}
|
void UnMarkAll(){m->UnMarkAll();}
|
||||||
bool IsMarked(OBJ_TYPE* obj){return (m->IsMarked(obj));}
|
bool IsMarked(OBJ_TYPE* obj){return (m->IsMarked(obj));}
|
||||||
void Mark(OBJ_TYPE* obj){m->Mark(obj);}
|
void Mark(OBJ_TYPE* obj){m->Mark(obj);}
|
||||||
void SetMesh(MESH_TYPE *_m)
|
void SetMesh(MESH_TYPE *_m)
|
||||||
{m=_m;}
|
{m=_m;}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class MESH_TYPE>
|
template <class MESH_TYPE>
|
||||||
class FaceTmark:public Tmark<MESH_TYPE,typename MESH_TYPE::FaceType>
|
class FaceTmark:public Tmark<MESH_TYPE,typename MESH_TYPE::FaceType>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template <class MESH_TYPE>
|
|
||||||
class VertTmark:public Tmark<MESH_TYPE,typename MESH_TYPE::VertexType>
|
|
||||||
{};
|
|
||||||
|
|
||||||
//**INTERSECTION FUNCTIONS**//
|
template <class MESH_TYPE>
|
||||||
///class of functor used to calculate the radius-triangle intersection
|
class VertTmark:public Tmark<MESH_TYPE,typename MESH_TYPE::VertexType>
|
||||||
template <class FACE_TYPE>
|
{};
|
||||||
class FaceIntersection {
|
|
||||||
typedef typename FACE_TYPE FaceType;
|
|
||||||
typedef typename FACE_TYPE::ScalarType ScalarType;
|
|
||||||
typedef typename vcg::Line3<ScalarType> RayType;
|
|
||||||
typedef typename FaceType::CoordType CoordType;
|
|
||||||
|
|
||||||
public:
|
///class of functor used to calculate the point triangle distance and nearest point
|
||||||
inline bool operator () (const FaceType & f, RayType r,CoordType & Int) {
|
template <class VERTEX_TYPE>
|
||||||
CoordType p0=f.V(0)->P();
|
class VertexDistance {
|
||||||
CoordType p1=f.V(1)->P();
|
typedef typename VERTEX_TYPE VertexType;
|
||||||
CoordType p2=f.V(2)->P();
|
typedef typename VERTEX_TYPE::ScalarType ScalarType;
|
||||||
///2 sides of normal test
|
typedef typename VERTEX_TYPE::CoordType CoordType;
|
||||||
if ((vcg::Intersection<ScalarType>(r,p0,p1,p2,Int))
|
|
||||||
||(vcg::Intersection<ScalarType>(r,p0,p2,p1,Int)))
|
|
||||||
return ((r.Direction()*(Int-r.Origin()))>0);///control side of intersection
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//**DISTANCE FUNCTIONS**//
|
public:
|
||||||
///class of functor used to calculate the point triangle distance and nearest point
|
bool operator () (const VertexType & v, const CoordType & pt, ScalarType & dist, CoordType & result) {
|
||||||
template <class FACE_TYPE>
|
ScalarType d=dist;
|
||||||
class FaceDistance {
|
dist=(v.P()-pt).Norm();
|
||||||
typedef typename FACE_TYPE FaceType;
|
result=pt;
|
||||||
typedef typename FACE_TYPE::ScalarType ScalarType;
|
return(d>dist);
|
||||||
typedef typename FaceType::CoordType CoordType;
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//**CLOSEST FUNCTION DEFINITION**//
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
aka MetroCore
|
||||||
|
data una mesh m e una ug sulle sue facce trova il punto di m piu' vicino ad
|
||||||
|
un punto dato.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// input: mesh, punto, griglia (gr), distanza limite (mdist)
|
||||||
|
// output: normale (interpolata) alla faccia e punto piu' vicino su di essa, e coord baricentriche del punto trovato
|
||||||
|
|
||||||
|
// Nota che il parametro template GRID non ci dovrebbe essere, visto che deve essere
|
||||||
|
// UGrid<MESH::FaceContainer >, ma non sono riuscito a definirlo implicitamente
|
||||||
|
|
||||||
|
template <class MESH, class GRID>
|
||||||
|
typename MESH::FaceType * GetClosest( 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)
|
||||||
|
{
|
||||||
|
typedef GRID::ScalarType ScalarType;
|
||||||
|
typedef Point3<ScalarType> Point3x;
|
||||||
|
|
||||||
|
typedef FaceTmark<MESH> MarkerFace;
|
||||||
|
MarkerFace mf;
|
||||||
|
mf.SetMesh(&mesh);
|
||||||
|
typedef vcg::face::PointDistanceFunctor FDistFunct;
|
||||||
|
_minDist=_maxDist;
|
||||||
|
typename MESH::FaceType* bestf= gr.GetClosest<FDistFunct,MarkerFace>(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
|
||||||
|
|
||||||
|
_minDist = fabs(_minDist);
|
||||||
|
return(bestf);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
///* RICONTROLLARE
|
||||||
|
/*template <class MESH, class GRID>
|
||||||
|
typename MESH::FaceType * GetClosest( MESH & mesh,GRID & gr,const Point3<SCALAR> & _p,
|
||||||
|
const SCALAR & _maxDist,SCALAR & _minDist,Point3<SCALAR> _closestPt,
|
||||||
|
Point3<SCALAR> & _normf)
|
||||||
|
{
|
||||||
|
Point3<SCALAR> _ip;
|
||||||
|
return (GetClosest<MESH,GRID>(mesh,gr,_p,_maxDist,_minDist,_closestPt,_normf,_ip));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/* RICONTROLLARE
|
||||||
|
template <class MESH, class GRID, class SCALAR>
|
||||||
|
void ClosestVertex( MESH & mesh, const Point3<SCALAR> & p, GRID & gr, SCALAR & mdist,
|
||||||
|
Point3<SCALAR> & normf, Point3<SCALAR> & bestq, typename MESH::VertexType * &v)
|
||||||
|
{
|
||||||
|
scalar error = mdist;
|
||||||
|
typedef VertTmark<MESH> MarkerVert;
|
||||||
|
MarkerVert t;
|
||||||
|
t.SetMesh(&mesh);
|
||||||
|
typedef typename VertexDistance<typename MESH::VertexType> PDistFunct;
|
||||||
|
v= vcg::GetClosest<GRID,PDistFunct,MarkerFace>(p,mdist,PDistFunct() ,error,bestq,t,gr);
|
||||||
|
}*/
|
||||||
|
|
||||||
public:
|
|
||||||
bool operator () (const FaceType & f, const CoordType & pt, ScalarType & mindist, CoordType & result) {
|
|
||||||
return (vcg::face::PointDistance<FaceType>(f,pt, mindist, result));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
///class of functor used to calculate the point triangle distance and nearest point
|
template <class MESH, class GRID, class OBJPTRCONTAINER,class DISTCONTAINER, class POINTCONTAINER>
|
||||||
template <class VERTEX_TYPE>
|
unsigned int GetKClosest(MESH & mesh,GRID & gr, const unsigned int _k,
|
||||||
class VertexDistance {
|
const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist,
|
||||||
typedef typename VERTEX_TYPE VertexType;
|
OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points)
|
||||||
typedef typename VERTEX_TYPE::ScalarType ScalarType;
|
{
|
||||||
typedef typename VERTEX_TYPE::CoordType CoordType;
|
typedef FaceTmark<MESH> MarkerFace;
|
||||||
|
MarkerFace mf;
|
||||||
|
mf.SetMesh(&mesh);
|
||||||
|
typedef vcg::face::PointDistanceFunctor FDistFunct;
|
||||||
|
return (gr.GetKClosest<FDistFunct,MarkerFace,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>
|
||||||
|
(FDistFunct(),mf,_k,_p,_maxDist,_objectPtrs,_distances,_points));
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
template <class MESH, class GRID>
|
||||||
bool operator () (const VertexType & v, const CoordType & pt, ScalarType & dist, CoordType & result) {
|
typename GRID::ObjPtr DoRay(MESH & mesh,GRID & gr, const Ray3<typename GRID::ScalarType> & _ray,
|
||||||
ScalarType d=dist;
|
const typename GRID::ScalarType & _maxDist, typename GRID::ScalarType & _t)
|
||||||
dist=(v.P()-pt).Norm();
|
{
|
||||||
result=pt;
|
typedef MESH::FaceType FaceType;
|
||||||
return(d>dist);
|
typedef MESH::ScalarType ScalarType;
|
||||||
}
|
typedef FaceTmark<MESH> MarkerFace;
|
||||||
};
|
MarkerFace mf;
|
||||||
|
mf.SetMesh(&mesh);
|
||||||
//**CLOSEST FUNCTION DEFINITION**//
|
typedef vcg::RayTriangleIntersectionFunctor<true> FintFunct;
|
||||||
|
return(gr.DoRay(FintFunct(),mf,_ray,_maxDist,_t));
|
||||||
/*
|
}
|
||||||
|
|
||||||
aka MetroCore
|
|
||||||
data una mesh m e una ug sulle sue facce trova il punto di m piu' vicino ad
|
|
||||||
un punto dato.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// input: mesh, punto, griglia (gr), distanza limite (mdist)
|
|
||||||
// output: normale (interpolata) alla faccia e punto piu' vicino su di essa, e coord baricentriche del punto trovato
|
|
||||||
|
|
||||||
// Nota che il parametro template GRID non ci dovrebbe essere, visto che deve essere
|
|
||||||
// UGrid<MESH::FaceContainer >, ma non sono riuscito a definirlo implicitamente
|
|
||||||
|
|
||||||
template <class MESH, class GRID, class SCALAR>
|
|
||||||
void Closest( MESH & mesh, const Point3<SCALAR> & p, GRID & gr, SCALAR & mdist,
|
|
||||||
Point3<SCALAR> & normf, Point3<SCALAR> & bestq, typename MESH::FaceType * &f, Point3<SCALAR> &ip)
|
|
||||||
{
|
|
||||||
typedef SCALAR ScalarType;
|
|
||||||
typedef Point3<ScalarType> Point3x;
|
|
||||||
typedef Box3<SCALAR> Box3x;
|
|
||||||
|
|
||||||
|
|
||||||
ScalarType error = mdist;
|
|
||||||
typedef FaceTmark<MESH> MarkerFace;
|
|
||||||
MarkerFace t;
|
|
||||||
t.SetMesh(&mesh);
|
|
||||||
typedef typename FaceDistance<typename MESH::FaceType> FDistFunct;
|
|
||||||
typename MESH::FaceType* bestf= vcg::GetClosest<GRID,FDistFunct,MarkerFace>(p,mdist,FDistFunct() ,error,bestq,t,gr);
|
|
||||||
|
|
||||||
if(mdist > ScalarType(fabs(error)))
|
|
||||||
{
|
|
||||||
f=bestf;
|
|
||||||
typename MESH::ScalarType alfa, beta, gamma;
|
|
||||||
//calcolo normale con interpolazione trilineare
|
|
||||||
bestf->InterpolationParameters(bestq, 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
|
|
||||||
|
|
||||||
mdist = ScalarType(fabs(error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MESH, class GRID, class SCALAR>
|
|
||||||
void Closest( MESH & mesh, const Point3<SCALAR> & p, GRID & gr, SCALAR & mdist,
|
|
||||||
Point3<SCALAR> & normf, Point3<SCALAR> & bestq, typename MESH::FaceType * &f)
|
|
||||||
{
|
|
||||||
Point3<SCALAR> ip;
|
|
||||||
Closest<MESH,GRID,SCALAR>(mesh,p,gr,mdist,normf,bestq,f,ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MESH, class GRID, class SCALAR>
|
|
||||||
void ClosestVertex( MESH & mesh, const Point3<SCALAR> & p, GRID & gr, SCALAR & mdist,
|
|
||||||
Point3<SCALAR> & normf, Point3<SCALAR> & bestq, typename MESH::VertexType * &v)
|
|
||||||
{
|
|
||||||
scalar error = mdist;
|
|
||||||
typedef VertTmark<MESH> MarkerVert;
|
|
||||||
MarkerVert t;
|
|
||||||
t.SetMesh(&mesh);
|
|
||||||
typedef typename VertexDistance<typename MESH::VertexType> PDistFunct;
|
|
||||||
v= vcg::GetClosest<GRID,PDistFunct,MarkerFace>(p,mdist,PDistFunct() ,error,bestq,t,gr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//**ITERATORS DEFINITION**//
|
//**ITERATORS DEFINITION**//
|
||||||
|
|
||||||
template <class GRID,class MESH>
|
template <class GRID,class MESH>
|
||||||
class ClosestFaceIterator:public vcg::ClosestIterator<GRID,FaceDistance<typename MESH::FaceType>,typename FaceTmark<MESH> >
|
class ClosestFaceIterator:public vcg::ClosestIterator<GRID,
|
||||||
{
|
vcg::face::PointDistanceFunctor,typename FaceTmark<MESH> >
|
||||||
public:
|
{
|
||||||
typedef typename GRID GridType;
|
public:
|
||||||
typedef typename MESH MeshType;
|
typedef typename GRID GridType;
|
||||||
typedef typename FaceTmark<MESH> MarkerFace;
|
typedef typename MESH MeshType;
|
||||||
typedef typename FaceDistance<typename MESH::FaceType> FDistFunct;
|
typedef typename FaceTmark<MESH> MarkerFace;
|
||||||
typedef typename vcg::ClosestIterator<GRID,FaceDistance<typename MESH::FaceType>,typename FaceTmark<MESH> > ClosestBaseType;
|
typedef typename vcg::face::PointDistanceFunctor PDistFunct;
|
||||||
|
typedef typename vcg::ClosestIterator<GRID,PDistFunct,typename FaceTmark<MESH> > ClosestBaseType;
|
||||||
|
typedef typename MESH::FaceType FaceType;
|
||||||
|
typedef typename MESH::ScalarType ScalarType;
|
||||||
|
|
||||||
ClosestFaceIterator(GridType &_Si):ClosestBaseType(_Si,FDistFunct()){}
|
//ClosestFaceIterator(GridType &_Si):ClosestBaseType(_Si,PDistFunct<FaceType,ScalarType>()){}
|
||||||
|
ClosestFaceIterator(GridType &_Si):ClosestBaseType(_Si,PDistFunct()){}
|
||||||
|
|
||||||
void SetMesh(MeshType *m)
|
void SetMesh(MeshType *m)
|
||||||
{tm.SetMesh(m);}
|
{tm.SetMesh(m);}
|
||||||
};
|
};
|
||||||
|
|
||||||
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,VertexDistance<typename MESH::VertexType>,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 VertexDistance<typename MESH::VertexType> VDistFunct;
|
||||||
typedef typename vcg::ClosestIterator<GRID,VertexDistance<typename MESH::VertexType>,typename VertTmark<MESH> > ClosestBaseType;
|
typedef typename vcg::ClosestIterator<GRID,VertexDistance<typename MESH::VertexType>,typename VertTmark<MESH> > ClosestBaseType;
|
||||||
|
|
||||||
ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,VDistFunct()){}
|
ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,VDistFunct()){}
|
||||||
|
|
||||||
void SetMesh(MeshType *m)
|
void SetMesh(MeshType *m)
|
||||||
{tm.SetMesh(m);}
|
{tm.SetMesh(m);}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class GRID,class MESH>
|
template <class GRID,class MESH>
|
||||||
class TriRayIterator:public vcg::RayIterator<GRID,FaceIntersection<typename MESH::FaceType>,typename FaceTmark<MESH> >
|
class TriRayIterator:public vcg::RayIterator<GRID,vcg::RayTriangleIntersectionFunctor<true>,typename FaceTmark<MESH> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename GRID GridType;
|
typedef typename GRID GridType;
|
||||||
typedef typename MESH MeshType;
|
typedef typename MESH MeshType;
|
||||||
typedef typename FaceTmark<MESH> MarkerFace;
|
typedef typename FaceTmark<MESH> MarkerFace;
|
||||||
typedef typename FaceIntersection<typename MESH::FaceType> FintFunct;
|
typedef typename vcg::RayTriangleIntersectionFunctor<true> FintFunct;
|
||||||
typedef typename vcg::RayIterator<GRID,FaceIntersection<typename MESH::FaceType>,typename FaceTmark<MESH> > RayBaseType;
|
typedef typename vcg::RayIterator<GRID,FintFunct,typename FaceTmark<MESH> > RayBaseType;
|
||||||
|
typedef typename MESH::FaceType FaceType;
|
||||||
|
typedef typename MESH::ScalarType ScalarType;
|
||||||
|
|
||||||
TriRayIterator(GridType &_Si):RayBaseType(_Si,FintFunct()){}
|
TriRayIterator(GridType &_Si):RayBaseType(_Si,FintFunct()){}
|
||||||
|
|
||||||
void SetMesh(MeshType *m)
|
void SetMesh(MeshType *m)
|
||||||
{tm.SetMesh(m);}
|
{tm.SetMesh(m);}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace trimesh
|
} // end namespace trimesh
|
||||||
} // end namespace vcg
|
} // end namespace vcg
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue