added a missing RequirePerFaceMark in the Marker Class

This commit is contained in:
Paolo Cignoni 2014-04-17 08:51:53 +00:00
parent c280fd8e23
commit 309d1e3289
1 changed files with 348 additions and 345 deletions

View File

@ -8,7 +8,7 @@
* \ * * \ *
* All rights reserved. * * All rights reserved. *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
@ -37,183 +37,186 @@
#include <vcg/complex/complex.h> #include <vcg/complex/complex.h>
namespace vcg { namespace vcg {
namespace tri { namespace tri {
//**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(){}
Tmark( MESH_TYPE *m) {SetMesh(m);} Tmark( MESH_TYPE *m) {SetMesh(m);}
void UnMarkAll(){ vcg::tri::UnMarkAll(*m);} void UnMarkAll(){ vcg::tri::UnMarkAll(*m);}
bool IsMarked(OBJ_TYPE* obj){return (vcg::tri::IsMarked(*m,obj));} bool IsMarked(OBJ_TYPE* obj){return (vcg::tri::IsMarked(*m,obj));}
void Mark(OBJ_TYPE* obj){ vcg::tri::Mark(*m,obj);} void Mark(OBJ_TYPE* obj){ vcg::tri::Mark(*m,obj);}
void SetMesh(MESH_TYPE *_m) void SetMesh(MESH_TYPE *_m)
{m=_m;} {
}; tri::RequirePerFaceMark(*_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>
{ {
public: public:
FaceTmark(){} FaceTmark(){}
FaceTmark(MESH_TYPE *m) {this->SetMesh(m);} FaceTmark(MESH_TYPE *m) {this->SetMesh(m);}
}; };
template <class MESH_TYPE> template <class MESH_TYPE>
class VertTmark class VertTmark
{ {
public: public:
typedef typename MESH_TYPE::VertexType VertexType; typedef typename MESH_TYPE::VertexType VertexType;
inline VertTmark(){} inline VertTmark(){}
inline VertTmark(MESH_TYPE *){} inline VertTmark(MESH_TYPE *){}
inline void UnMarkAll() const {} inline void UnMarkAll() const {}
inline bool IsMarked(VertexType*) const { return false; } inline bool IsMarked(VertexType*) const { return false; }
inline void Mark(VertexType*) const {} inline void Mark(VertexType*) const {}
inline void SetMesh(void * /*m=0*/) const {} inline void SetMesh(void * /*m=0*/) const {}
}; };
//**CLOSEST FUNCTION DEFINITION**// //**CLOSEST FUNCTION DEFINITION**//
/* /*
aka MetroCore aka MetroCore
data una mesh m e una ug sulle sue facce trova il punto di m piu' vicino ad data una mesh m e una ug sulle sue facce trova il punto di m piu' vicino ad
un punto dato. un punto dato.
*/ */
// input: mesh, punto, griglia (gr), distanza limite (mdist) // 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 // 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 // Nota che il parametro template GRID non ci dovrebbe essere, visto che deve essere
// 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 * GetClosestFaceEP( MESH & mesh, GRID & gr, const typename GRID::CoordType & _p, typename MESH::FaceType * GetClosestFaceEP( 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)
{ {
typedef typename GRID::ScalarType ScalarType; typedef typename GRID::ScalarType ScalarType;
typedef Point3<ScalarType> Point3x; typedef Point3<ScalarType> Point3x;
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf(&mesh); MarkerFace mf(&mesh);
vcg::face::PointDistanceEPFunctor<ScalarType> FDistFunct; vcg::face::PointDistanceEPFunctor<ScalarType> FDistFunct;
_minDist=_maxDist; _minDist=_maxDist;
typename MESH::FaceType* bestf= gr.GetClosest(FDistFunct, mf, _p, _maxDist, _minDist, _closestPt); typename MESH::FaceType* bestf= gr.GetClosest(FDistFunct, mf, _p, _maxDist, _minDist, _closestPt);
if(_maxDist> ScalarType(fabs(_minDist))) if(_maxDist> ScalarType(fabs(_minDist)))
{ {
// f=bestf; // f=bestf;
//calcolo normale con interpolazione trilineare //calcolo normale con interpolazione trilineare
InterpolationParameters<typename MESH::FaceType,typename MESH::ScalarType>(*bestf,bestf->N(),_closestPt, _ip); InterpolationParameters<typename MESH::FaceType,typename MESH::ScalarType>(*bestf,bestf->N(),_closestPt, _ip);
_normf = (bestf->V(0)->cN())*_ip[0]+ _normf = (bestf->V(0)->cN())*_ip[0]+
(bestf->V(1)->cN())*_ip[1]+ (bestf->V(1)->cN())*_ip[1]+
(bestf->V(2)->cN())*_ip[2] ; (bestf->V(2)->cN())*_ip[2] ;
_minDist = fabs(_minDist); _minDist = fabs(_minDist);
return(bestf); return(bestf);
} }
return (0); return (0);
} }
template <class MESH, class GRID> template <class MESH, class GRID>
typename MESH::FaceType * GetClosestFaceBase( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, typename MESH::FaceType * GetClosestFaceBase( 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 &_closestPt)
{ {
typedef typename GRID::ScalarType ScalarType; typedef typename GRID::ScalarType ScalarType;
typedef Point3<ScalarType> Point3x; typedef Point3<ScalarType> Point3x;
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf; MarkerFace mf;
mf.SetMesh(&mesh); mf.SetMesh(&mesh);
vcg::face::PointDistanceBaseFunctor<ScalarType> PDistFunct; vcg::face::PointDistanceBaseFunctor<ScalarType> PDistFunct;
_minDist=_maxDist; _minDist=_maxDist;
return (gr.GetClosest(PDistFunct,mf,_p,_maxDist,_minDist,_closestPt)); return (gr.GetClosest(PDistFunct,mf,_p,_maxDist,_minDist,_closestPt));
} }
template <class MESH, class GRID> template <class MESH, class GRID>
typename MESH::FaceType * GetClosestFaceEP( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, typename MESH::FaceType * GetClosestFaceEP( 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 &_closestPt)
{ {
typedef typename GRID::ScalarType ScalarType; typedef typename GRID::ScalarType ScalarType;
typedef Point3<ScalarType> Point3x; typedef Point3<ScalarType> Point3x;
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf; MarkerFace mf;
mf.SetMesh(&mesh); mf.SetMesh(&mesh);
vcg::face::PointDistanceEPFunctor<ScalarType> PDistFunct; vcg::face::PointDistanceEPFunctor<ScalarType> PDistFunct;
_minDist=_maxDist; _minDist=_maxDist;
return (gr.GetClosest(PDistFunct,mf,_p,_maxDist,_minDist,_closestPt)); return (gr.GetClosest(PDistFunct,mf,_p,_maxDist,_minDist,_closestPt));
} }
template <class MESH, class GRID> template <class MESH, class GRID>
typename MESH::FaceType * GetClosestFaceNormal(MESH & mesh,GRID & gr,const typename MESH::VertexType & _p, typename MESH::FaceType * GetClosestFaceNormal(MESH & mesh,GRID & gr,const typename MESH::VertexType & _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 &_closestPt)
{ {
typedef typename GRID::ScalarType ScalarType; typedef typename GRID::ScalarType ScalarType;
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf; MarkerFace mf;
mf.SetMesh(&mesh); mf.SetMesh(&mesh);
typedef vcg::face::PointNormalDistanceFunctor<typename MESH::VertexType> PDistFunct; typedef vcg::face::PointNormalDistanceFunctor<typename MESH::VertexType> PDistFunct;
PDistFunct fn; PDistFunct fn;
_minDist=_maxDist; _minDist=_maxDist;
//return (gr.GetClosest(PDistFunct,mf,_p,_maxDist,_minDist,_closestPt.P())); //return (gr.GetClosest(PDistFunct,mf,_p,_maxDist,_minDist,_closestPt.P()));
return (gr.template GetClosest <PDistFunct,MarkerFace>(fn,mf,_p,_maxDist,_minDist,_closestPt)); return (gr.template GetClosest <PDistFunct,MarkerFace>(fn,mf,_p,_maxDist,_minDist,_closestPt));
} }
template <class MESH, class GRID> template <class MESH, class GRID>
typename MESH::VertexType * GetClosestVertex( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, typename MESH::VertexType * GetClosestVertex( 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 )
{ {
typedef typename GRID::ScalarType ScalarType; typedef typename GRID::ScalarType ScalarType;
typedef Point3<ScalarType> Point3x; typedef Point3<ScalarType> Point3x;
typedef VertTmark<MESH> MarkerVert; typedef VertTmark<MESH> MarkerVert;
MarkerVert mv; MarkerVert mv;
mv.SetMesh(&mesh); mv.SetMesh(&mesh);
typedef vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType> VDistFunct; typedef vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType> VDistFunct;
VDistFunct fn; VDistFunct fn;
_minDist=_maxDist; _minDist=_maxDist;
Point3x _closestPt; Point3x _closestPt;
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> template <class MESH, class GRID>
typename MESH::VertexType * GetClosestVertexScale( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, typename MESH::VertexType * GetClosestVertexScale( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p,
const typename MESH::CoordType & center, const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist ) const typename MESH::CoordType & center, const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist )
{ {
typedef typename GRID::ScalarType ScalarType; typedef typename GRID::ScalarType ScalarType;
typedef Point3<ScalarType> Point3x; typedef Point3<ScalarType> Point3x;
typedef VertTmark<MESH> MarkerVert; typedef VertTmark<MESH> MarkerVert;
MarkerVert mv; MarkerVert mv;
mv.SetMesh(&mesh); mv.SetMesh(&mesh);
typedef vcg::vertex::PointScaledDistanceFunctor<typename MESH::VertexType> VDistFunct; typedef vcg::vertex::PointScaledDistanceFunctor<typename MESH::VertexType> VDistFunct;
VDistFunct fn; VDistFunct fn;
fn.Cen() = center; fn.Cen() = center;
_minDist=_maxDist; _minDist=_maxDist;
Point3x _closestPt; Point3x _closestPt;
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> template <class MESH, class GRID>
typename MESH::VertexType * GetClosestVertexNormal( MESH & mesh,GRID & gr,const typename MESH::VertexType & _p, typename MESH::VertexType * GetClosestVertexNormal( MESH & mesh,GRID & gr,const typename MESH::VertexType & _p,
const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist ) const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist )
{ {
typedef typename GRID::ScalarType ScalarType; typedef typename GRID::ScalarType ScalarType;
typedef Point3<ScalarType> Point3x; typedef Point3<ScalarType> Point3x;
typedef VertTmark<MESH> MarkerVert; typedef VertTmark<MESH> MarkerVert;
MarkerVert mv; MarkerVert mv;
mv.SetMesh(&mesh); mv.SetMesh(&mesh);
typedef vcg::vertex::PointNormalDistanceFunctor<typename MESH::VertexType> VDistFunct; typedef vcg::vertex::PointNormalDistanceFunctor<typename MESH::VertexType> VDistFunct;
VDistFunct fn; VDistFunct fn;
_minDist=_maxDist; _minDist=_maxDist;
Point3x _closestPt; Point3x _closestPt;
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 GetKClosestFaceEP(MESH & mesh,GRID & gr, const unsigned int _k, unsigned int GetKClosestFaceEP(MESH & mesh,GRID & gr, const unsigned int _k,
@ -243,236 +246,236 @@ 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> 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,
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 VertTmark<MESH> MarkerVert; typedef VertTmark<MESH> MarkerVert;
MarkerVert mv; MarkerVert mv;
mv.SetMesh(&mesh); mv.SetMesh(&mesh);
typedef vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType> VDistFunct; typedef vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType> VDistFunct;
VDistFunct distFunct; VDistFunct distFunct;
return (gr.GetKClosest/* <VDistFunct,MarkerVert,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>*/ return (gr.GetKClosest/* <VDistFunct,MarkerVert,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>*/
(distFunct,mv,_k,_p,_maxDist,_objectPtrs,_distances,_points)); (distFunct,mv,_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 GetInSphereFaceBase(MESH & mesh, unsigned int GetInSphereFaceBase(MESH & mesh,
GRID & gr, GRID & gr,
const typename GRID::CoordType & _p, const typename GRID::CoordType & _p,
const typename GRID::ScalarType & _r, const typename GRID::ScalarType & _r,
OBJPTRCONTAINER & _objectPtrs, OBJPTRCONTAINER & _objectPtrs,
DISTCONTAINER & _distances, DISTCONTAINER & _distances,
POINTCONTAINER & _points) POINTCONTAINER & _points)
{ {
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf; MarkerFace mf;
mf.SetMesh(&mesh); mf.SetMesh(&mesh);
typedef vcg::face::PointDistanceBaseFunctor<typename MESH::ScalarType> FDistFunct; typedef vcg::face::PointDistanceBaseFunctor<typename MESH::ScalarType> FDistFunct;
return (gr.GetInSphere/*<FDistFunct,MarkerFace,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>*/ return (gr.GetInSphere/*<FDistFunct,MarkerFace,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>*/
(FDistFunct(),mf,_p,_r,_objectPtrs,_distances,_points)); (FDistFunct(),mf,_p,_r,_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 GetInSphereVertex(MESH & mesh, unsigned int GetInSphereVertex(MESH & mesh,
GRID & gr, GRID & gr,
const typename GRID::CoordType & _p, const typename GRID::CoordType & _p,
const typename GRID::ScalarType & _r, const typename GRID::ScalarType & _r,
OBJPTRCONTAINER & _objectPtrs, OBJPTRCONTAINER & _objectPtrs,
DISTCONTAINER & _distances, DISTCONTAINER & _distances,
POINTCONTAINER & _points) POINTCONTAINER & _points)
{ {
typedef VertTmark<MESH> MarkerVert; typedef VertTmark<MESH> MarkerVert;
MarkerVert mv; MarkerVert mv;
mv.SetMesh(&mesh); mv.SetMesh(&mesh);
typedef vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType> VDistFunct; typedef vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType> VDistFunct;
VDistFunct fn; VDistFunct fn;
return (gr.GetInSphere/*<VDistFunct,MarkerVert,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>*/ return (gr.GetInSphere/*<VDistFunct,MarkerVert,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER>*/
(fn, mv,_p,_r,_objectPtrs,_distances,_points)); (fn, mv,_p,_r,_objectPtrs,_distances,_points));
} }
template <class MESH, class GRID, class OBJPTRCONTAINER> template <class MESH, class GRID, class OBJPTRCONTAINER>
unsigned int GetInBoxFace(MESH & mesh, unsigned int GetInBoxFace(MESH & mesh,
GRID & gr, GRID & gr,
const vcg::Box3<typename GRID::ScalarType> _bbox, const vcg::Box3<typename GRID::ScalarType> _bbox,
OBJPTRCONTAINER & _objectPtrs) OBJPTRCONTAINER & _objectPtrs)
{ {
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf(&mesh); MarkerFace mf(&mesh);
return(gr.GetInBox/*<MarkerFace,OBJPTRCONTAINER>*/(mf,_bbox,_objectPtrs)); return(gr.GetInBox/*<MarkerFace,OBJPTRCONTAINER>*/(mf,_bbox,_objectPtrs));
} }
template <class MESH, class GRID, class OBJPTRCONTAINER> template <class MESH, class GRID, class OBJPTRCONTAINER>
unsigned int GetInBoxVertex(MESH & mesh, unsigned int GetInBoxVertex(MESH & mesh,
GRID & gr, GRID & gr,
const vcg::Box3<typename GRID::ScalarType> _bbox, const vcg::Box3<typename GRID::ScalarType> _bbox,
OBJPTRCONTAINER & _objectPtrs) OBJPTRCONTAINER & _objectPtrs)
{ {
typedef VertTmark<MESH> MarkerVert; typedef VertTmark<MESH> MarkerVert;
MarkerVert mv; MarkerVert mv;
mv.SetMesh(&mesh); mv.SetMesh(&mesh);
return(gr.GetInBox/*<MarkerVert,OBJPTRCONTAINER>*/(mv,_bbox,_objectPtrs)); 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)
{ {
typedef typename MESH::FaceType FaceType; typedef typename MESH::FaceType FaceType;
typedef typename MESH::ScalarType ScalarType; typedef typename MESH::ScalarType ScalarType;
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf; MarkerFace mf;
mf.SetMesh(&mesh); mf.SetMesh(&mesh);
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;
FintFunct ff; FintFunct ff;
return(gr.DoRay(ff,mf,_ray1,_maxDist,_t)); return(gr.DoRay(ff,mf,_ray1,_maxDist,_t));
} }
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, const typename GRID::ScalarType & _maxDist,
typename GRID::ScalarType & _t, typename GRID::ScalarType & _t,
typename GRID::CoordType & _normf) typename GRID::CoordType & _normf)
{ {
typedef typename MESH::FaceType FaceType; typedef typename MESH::FaceType FaceType;
typedef typename MESH::ScalarType ScalarType; typedef typename MESH::ScalarType ScalarType;
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
MarkerFace mf; MarkerFace mf;
mf.SetMesh(&mesh); mf.SetMesh(&mesh);
typedef vcg::RayTriangleIntersectionFunctor<true> FintFunct; typedef vcg::RayTriangleIntersectionFunctor<true> FintFunct;
FintFunct fintfunct; FintFunct fintfunct;
Ray3<typename GRID::ScalarType> _ray1=_ray; Ray3<typename GRID::ScalarType> _ray1=_ray;
_ray1.Normalize(); _ray1.Normalize();
FaceType *f=gr.DoRay(fintfunct,mf,_ray1,_maxDist,_t); FaceType *f=gr.DoRay(fintfunct,mf,_ray1,_maxDist,_t);
typename GRID::CoordType dir=_ray.Direction(); typename GRID::CoordType dir=_ray.Direction();
dir.Normalize(); dir.Normalize();
typename GRID::CoordType int_point=_ray.Origin()+_ray1.Direction()*_t; typename GRID::CoordType int_point=_ray.Origin()+_ray1.Direction()*_t;
if (f!=NULL) if (f!=NULL)
{ {
Point3<typename GRID::ScalarType> bary; Point3<typename GRID::ScalarType> bary;
InterpolationParameters<FaceType,ScalarType>(*f,f->N(),int_point, bary); InterpolationParameters<FaceType,ScalarType>(*f,f->N(),int_point, bary);
_normf = (f->V(0)->cN())*bary.X()+ _normf = (f->V(0)->cN())*bary.X()+
(f->V(1)->cN())*bary.Y()+ (f->V(1)->cN())*bary.Y()+
(f->V(2)->cN())*bary.Z() ; (f->V(2)->cN())*bary.Z() ;
} }
return f; return f;
} }
///Iteratively Do Ray sampling on spherical coordinates ///Iteratively Do Ray sampling on spherical coordinates
///sampling along the two angles ///sampling along the two angles
template <class MESH, class GRID, class OBJPTRCONTAINER, class COORDCONTAINER> template <class MESH, class GRID, class OBJPTRCONTAINER, class COORDCONTAINER>
void RaySpherical(MESH & mesh,GRID & gr, const Ray3<typename GRID::ScalarType> & _ray, void RaySpherical(MESH & mesh,GRID & gr, const Ray3<typename GRID::ScalarType> & _ray,
const typename GRID::ScalarType & _maxDist, const typename GRID::ScalarType & _maxDist,
const typename GRID::ScalarType & _theta_interval, const typename GRID::ScalarType & _theta_interval,
const typename GRID::ScalarType & _phi_interval, const typename GRID::ScalarType & _phi_interval,
const int &n_samples, const int &n_samples,
OBJPTRCONTAINER & _objectPtrs, OBJPTRCONTAINER & _objectPtrs,
COORDCONTAINER & _pos, COORDCONTAINER & _pos,
COORDCONTAINER & _norm) COORDCONTAINER & _norm)
{ {
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,phi_init,ro; ScalarType theta_init,phi_init,ro;
typename GRID::CoordType dir0=_ray.Direction(); typename GRID::CoordType dir0=_ray.Direction();
dir0.ToPolarRad(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) theta=2.0*M_PI-theta; if (theta<0) theta=2.0*M_PI-theta;
ScalarType phi=phi_init+y*delta_phi; ScalarType phi=phi_init+y*delta_phi;
typename GRID::CoordType dir; typename GRID::CoordType dir;
dir.FromxPolar(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;
typename GRID::ObjPtr f=NULL; typename GRID::ObjPtr f=NULL;
f=DoRay(mesh,gr,curr_ray,_maxDist,_t); f=DoRay(mesh,gr,curr_ray,_maxDist,_t);
if (f!=NULL) if (f!=NULL)
{ {
typename GRID::CoordType pos=curr_ray.Origin()+curr_ray.Direction()*_t; typename GRID::CoordType pos=curr_ray.Origin()+curr_ray.Direction()*_t;
_objectPtrs.push_back(f); _objectPtrs.push_back(f);
_pos.push_back(pos); _pos.push_back(pos);
///find the normal ///find the normal
typename GRID::ScalarType alfa,beta,gamma; typename GRID::ScalarType alfa,beta,gamma;
InterpolationParameters<FaceType,ScalarType>(*f,*f.N(),pos, alfa, beta, gamma); InterpolationParameters<FaceType,ScalarType>(*f,*f.N(),pos, alfa, beta, gamma);
typename GRID::CoordType norm = (f->V(0)->cN())*alfa+ typename GRID::CoordType norm = (f->V(0)->cN())*alfa+
(f->V(1)->cN())*beta+ (f->V(1)->cN())*beta+
(f->V(2)->cN())*gamma ; (f->V(2)->cN())*gamma ;
_norm.push_back(norm); _norm.push_back(norm);
} }
} }
} }
//**ITERATORS DEFINITION**// //**ITERATORS DEFINITION**//
template <class GRID,class MESH> template <class GRID,class MESH>
class ClosestFaceEPIterator:public vcg::ClosestIterator<GRID, class ClosestFaceEPIterator:public vcg::ClosestIterator<GRID,
vcg::face::PointDistanceEPFunctor<typename MESH::ScalarType>, FaceTmark<MESH> > vcg::face::PointDistanceEPFunctor<typename MESH::ScalarType>, FaceTmark<MESH> >
{ {
public: public:
typedef GRID GridType; typedef GRID GridType;
typedef MESH MeshType; typedef MESH MeshType;
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
typedef vcg::face::PointDistanceEPFunctor<typename MESH::ScalarType> PDistFunct; typedef vcg::face::PointDistanceEPFunctor<typename MESH::ScalarType> PDistFunct;
typedef vcg::ClosestIterator<GRID,PDistFunct, FaceTmark<MESH> > ClosestBaseType; typedef vcg::ClosestIterator<GRID,PDistFunct, FaceTmark<MESH> > ClosestBaseType;
typedef typename MESH::FaceType FaceType; typedef typename MESH::FaceType FaceType;
typedef typename MESH::ScalarType ScalarType; typedef typename MESH::ScalarType ScalarType;
//ClosestFaceIterator(GridType &_Si):ClosestBaseType(_Si,PDistFunct<FaceType,ScalarType>()){} //ClosestFaceIterator(GridType &_Si):ClosestBaseType(_Si,PDistFunct<FaceType,ScalarType>()){}
ClosestFaceEPIterator(GridType &_Si):ClosestBaseType(_Si,PDistFunct()){} ClosestFaceEPIterator(GridType &_Si):ClosestBaseType(_Si,PDistFunct()){}
// Commented out: it seems unuseful and make gcc complain. p. // Commented out: it seems unuseful and make gcc complain. p.
void SetMesh(MeshType *m) void SetMesh(MeshType *m)
{this->tm.SetMesh(m);} {this->tm.SetMesh(m);}
}; };
template <class GRID,class MESH> template <class GRID,class MESH>
class ClosestVertexIterator:public vcg::ClosestIterator<GRID, vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType>, VertTmark<MESH> > class ClosestVertexIterator:public vcg::ClosestIterator<GRID, vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType>, VertTmark<MESH> >
{ {
public: public:
typedef GRID GridType; typedef GRID GridType;
typedef MESH MeshType; typedef MESH MeshType;
typedef VertTmark<MESH> MarkerVert; typedef VertTmark<MESH> MarkerVert;
typedef vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType> VDistFunct; typedef vcg::vertex::PointDistanceFunctor<typename MESH::ScalarType> VDistFunct;
typedef vcg::ClosestIterator<GRID, VDistFunct, VertTmark<MESH> > ClosestBaseType; typedef vcg::ClosestIterator<GRID, VDistFunct, VertTmark<MESH> > ClosestBaseType;
VDistFunct fn; VDistFunct fn;
ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,fn){} ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,fn){}
// Commented out: it seems unuseful and make gcc complain. p. // Commented out: it seems unuseful and make gcc complain. p.
void SetMesh(MeshType *m) void SetMesh(MeshType *m)
{this->tm.SetMesh(m);} {this->tm.SetMesh(m);}
}; };
template <class GRID,class MESH> template <class GRID,class MESH>
class TriRayIterator:public vcg::RayIterator<GRID,vcg::RayTriangleIntersectionFunctor<true>,FaceTmark<MESH> > class TriRayIterator:public vcg::RayIterator<GRID,vcg::RayTriangleIntersectionFunctor<true>,FaceTmark<MESH> >
{ {
public: public:
typedef GRID GridType; typedef GRID GridType;
typedef MESH MeshType; typedef MESH MeshType;
typedef FaceTmark<MESH> MarkerFace; typedef FaceTmark<MESH> MarkerFace;
typedef vcg::RayTriangleIntersectionFunctor<true> FintFunct; typedef vcg::RayTriangleIntersectionFunctor<true> FintFunct;
typedef vcg::RayIterator<GRID,FintFunct, FaceTmark<MESH> > RayBaseType; typedef vcg::RayIterator<GRID,FintFunct, FaceTmark<MESH> > RayBaseType;
typedef typename MESH::FaceType FaceType; typedef typename MESH::FaceType FaceType;
typedef typename MESH::ScalarType ScalarType; typedef typename MESH::ScalarType ScalarType;
TriRayIterator(GridType &_Si,const ScalarType &max_d):RayBaseType(_Si,FintFunct(),max_d){} TriRayIterator(GridType &_Si,const ScalarType &max_d):RayBaseType(_Si,FintFunct(),max_d){}
// Commented out: it seems unuseful and make gcc complain. p. // Commented out: it seems unuseful and make gcc complain. p.
void SetMesh(MeshType *m) void SetMesh(MeshType *m)
{this->tm.SetMesh(m);} {this->tm.SetMesh(m);}
}; };
} // end namespace tri } // end namespace tri
} // end namespace vcg } // end namespace vcg
#endif #endif