diff --git a/vcg/simplex/face/distance.h b/vcg/simplex/face/distance.h index 607b4c99..d64f281d 100644 --- a/vcg/simplex/face/distance.h +++ b/vcg/simplex/face/distance.h @@ -253,6 +253,43 @@ namespace vcg { } }; + + + template + class PointNormalDistanceFunctor { + public: + typedef typename S::ScalarType ScalarType; + typedef S QueryType; + static inline const Point3 & Pos(const QueryType & qt) {return qt.P();} + + + static ScalarType & Alpha(){static ScalarType alpha = 1.0; return alpha;} + static ScalarType & Beta (){static ScalarType beta = 1.0; return beta;} + static ScalarType & Gamma(){static ScalarType gamma = 1.0; return gamma;} + static ScalarType & InterPoint(){static ScalarType interpoint= 1.0; return interpoint;} + + + template + inline bool operator () (const FACETYPE &f, const typename FACETYPE::VertexType &p, + SCALARTYPE & minDist,Point3 & q) + { + const Point3 fp = Point3::Construct(p.cP()); + const Point3 fn = Point3::Construct(p.cN()); + Point3 fq; + typename FACETYPE::ScalarType md = (typename FACETYPE::ScalarType)(minDist); + const bool ret=PointDistance(f,fp,md,fq); + + SCALARTYPE dev=InterPoint()*(pow((ScalarType)(1-f.cN().dot(fn)),(ScalarType)Beta())/(Gamma()*md+0.1)); + + if (md+dev < minDist){ + minDist = (SCALARTYPE)(md+dev); + q = Point3::Construct(fq); + //q.N() = f.N(); + return (ret); + } + return false; + } + }; /// BASIC VERSION of the Point-face distance that does not require the EdgePlane Additional data. /// Given a face and a point, returns the closest point of the face to p.