00001 /**************************************************************************** 00002 * VCGLib o o * 00003 * Visual and Computer Graphics Library o o * 00004 * _ O _ * 00005 * Copyright(C) 2004 \/)\/ * 00006 * Visual Computing Lab /\/| * 00007 * ISTI - Italian National Research Council | * 00008 * \ * 00009 * All rights reserved. * 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This program is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 00020 * for more details. * 00021 * * 00022 ****************************************************************************/ 00023 // marco : 00024 // comments 00025 // corrected bug 00026 00027 00028 /**************************************************************************** 00029 History 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 * @param v [IN] is a reference to the current object being tested, 00052 * @param p [IN] is the query point, 00053 * @param minDist [IN/OUT] is in input the reject distance and in output the closest distance, 00054 * @param q [OUT] is the closest point. 00055 * 00056 * @remarks The operator returns true if the closest distance is less than input reject distance. 00057 * 00058 */ 00059 inline bool operator () (const VERTEXTYPE & v, const Point3<SCALARTYPE> & p, SCALARTYPE & minDist, Point3<SCALARTYPE> & q) const 00060 { 00061 // convert the coordinates of p from SCALARTYPE to VERTEXTYPE::ScalarType type 00062 const Point3<typename VERTEXTYPE::ScalarType> fp = Point3<typename VERTEXTYPE::ScalarType>::Construct(p); 00063 00064 typename VERTEXTYPE::ScalarType md; // distance between v and fp 00065 md = (v.P() - fp).Norm(); 00066 00067 if (md <= minDist) 00068 { 00069 minDist = (SCALARTYPE)(md); // minDist is updated to the closest distance 00070 q = v.P(); // q is the current closest point 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 // minDist = h +0.0* (1-v.cN()*vp.cN()) / (h + 0.1); 00103 00104 return false; 00105 } 00106 }; 00107 00108 } // end namespace vertex 00109 00110 } // end namespace vcg 00111 00112 00113 #endif 00114