Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __VCGLIB_VERTEX_DISTANCE
00034 #define __VCGLIB_VERTEX_DISTANCE
00035
00036 #include <vcg/math/base.h>
00037 #include <vcg/space/point3.h>
00038
00039
00040 namespace vcg {
00041 namespace vertex{
00042
00043 template <class SCALARTYPE>
00044 class PointDistanceFunctor {
00045 public:
00046 typedef Point3<SCALARTYPE> QueryType;
00047 static inline const Point3<SCALARTYPE> & Pos(const QueryType & qt) {return qt;}
00048 template <class VERTEXTYPE>
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 inline bool operator () (const VERTEXTYPE & v, const Point3<SCALARTYPE> & p, SCALARTYPE & minDist, Point3<SCALARTYPE> & q) const
00060 {
00061
00062 const Point3<typename VERTEXTYPE::ScalarType> fp = Point3<typename VERTEXTYPE::ScalarType>::Construct(p);
00063
00064 typename VERTEXTYPE::ScalarType md;
00065 md = (v.cP() - fp).Norm();
00066
00067 if (md <= minDist)
00068 {
00069 minDist = (SCALARTYPE)(md);
00070 q = v.cP();
00071
00072 return true;
00073 }
00074
00075 return false;
00076 }
00077 };
00078
00079 template <class VERTYPE>
00080 class PointNormalDistanceFunctor {
00081 public:
00082 typedef VERTYPE QueryType;
00083 typedef typename VERTYPE::ScalarType ScalarType;
00084 static inline const Point3<typename VERTYPE::ScalarType> & Pos(const QueryType & qt) {return qt.P();}
00085
00086 static ScalarType & Alpha(){static ScalarType alpha = 1.0; return alpha;}
00087 static ScalarType & Beta(){static ScalarType beta= 1.0; return beta;}
00088 static ScalarType & Gamma(){static ScalarType gamma= 1.0; return gamma;}
00089 static ScalarType & InterPoint (){static ScalarType interpoint= 1.0; return interpoint;}
00090
00091 template <class VERTEXTYPE, class SCALARTYPE>
00092 inline bool operator () (const VERTEXTYPE & v, const VERTEXTYPE & vp, SCALARTYPE & minDist, Point3<SCALARTYPE> & q) {
00093
00094 float h = vcg::Distance(v.cP(),vp.P()) ;
00095 float dev = InterPoint() * ( pow((ScalarType) (1-v.cN().dot(vp.cN())), (ScalarType)Beta()) / (Gamma()*h +0.1));
00096 if(h+dev < minDist){
00097 minDist = h+dev;
00098 q = v.P();
00099 return true;
00100 }
00101
00102
00103
00104 return false;
00105 }
00106 };
00107
00108 template <class VERTEXYPE>
00109 class PointScaledDistanceFunctor {
00110 public:
00111 typedef typename VERTEXYPE::ScalarType ScalarType;
00112 typedef Point3<ScalarType> QueryType;
00113 static inline const Point3<ScalarType> & Pos(const QueryType & qt) {return qt;}
00114
00115 static Point3<ScalarType> & Cen(){static Point3<ScalarType> cen(0,0,0); return cen;}
00116
00117
00118 inline bool operator () (const VERTEXYPE & p, const QueryType & qp, ScalarType & minDist, Point3<ScalarType> & q) {
00119
00120 Point3<ScalarType> ed = (qp-p.P());
00121 Point3<ScalarType> dir = (p.P()-Cen()).Normalize();
00122 Point3<ScalarType> odir = (dir^((ed)^dir)).Normalize();
00123 ScalarType d = fabs(ed * dir) + fabs(ed *odir);
00124
00125 if(d < minDist){
00126 minDist = d;
00127 q = p.P();
00128 return true;
00129 }
00130 return false;
00131 }
00132 };
00133
00134 template <class VertexType>
00135 class ApproximateGeodesicDistanceFunctor {
00136 public:
00137 typedef typename VertexType::ScalarType ScalarType;
00138 static inline const Point3<ScalarType> & Pos(const VertexType & qt) {return qt.P();}
00139
00140 inline bool operator () (const VertexType & v, const VertexType & vp, ScalarType & minDist, Point3<ScalarType> & q) {
00141 ScalarType gd = ApproximateGeodesicDistance(v.cP(),v.cN(),vp.cP(),vp.cN());
00142 if (gd <= minDist)
00143 {
00144 minDist =gd;
00145 q = v.P();
00146 return true;
00147 }
00148 return false;
00149 }
00150 inline ScalarType operator () (const Point3<ScalarType>& p0, const Point3<ScalarType>& n0,
00151 const Point3<ScalarType>& p1, const Point3<ScalarType>& n1) {
00152 return ApproximateGeodesicDistance(p0,n0,p1,n1);
00153 }
00154 };
00155
00156 }
00157
00158 }
00159
00160
00161 #endif
00162