distance.h
Go to the documentation of this file.
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.cP() - fp).Norm();
00066 
00067                         if (md <= minDist) 
00068                         {
00069                                 minDist = (SCALARTYPE)(md);             // minDist is updated to the closest distance
00070                                 q = v.cP();                                             // 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 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;            // minDist is updated to the closest distance
00145         q = v.P();                                              // q is the current closest point
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 }        // end namespace vertex
00157         
00158 }        // end namespace vcg
00159 
00160 
00161 #endif
00162 


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:30:35