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 /****************************************************************************
00024   History
00025 
00026 
00027 ****************************************************************************/
00028 
00029 #ifndef __VCGLIB_EDGE_DISTANCE
00030 #define __VCGLIB_EDGE_DISTANCE
00031 
00032 #include <vcg/math/base.h>
00033 #include <vcg/space/point3.h>
00034 #include <vcg/space/distance3.h>
00035 #include <vcg/space/segment3.h>
00036 
00037 
00038 namespace vcg {
00039         namespace edge{
00040         /*Point edge distance*/
00041 
00042         template <class EdgeType>
00043         bool PointDistance(     const EdgeType &e, 
00044                                                         const vcg::Point3<typename EdgeType::ScalarType> & q, 
00045                                                         typename EdgeType::ScalarType & dist, 
00046                                                         vcg::Point3<typename EdgeType::ScalarType> & p )
00047         {
00048                 vcg::Segment3<typename EdgeType::ScalarType> s;
00049                 s.P0()=e.V(0)->P();
00050                 s.P1()=e.V(1)->P();
00051                 typename EdgeType::CoordType nearest;
00052                 typename EdgeType::ScalarType d;
00053 //              nearest=vcg::ClosestPoint<typename EdgeType::ScalarType>(s,q);
00054 //              d=(q-nearest).Norm();
00055                 vcg::SegmentPointDistance(s,q ,nearest,d); 
00056                 
00057                 if (d<dist){
00058                         dist=d;
00059                         p=nearest;
00060                         return true;
00061                 }
00062                 else 
00063                         return false;
00064         }
00065 
00066         template <class S>
00067         class PointDistanceFunctor {
00068         public:
00069                 typedef S ScalarType;
00070                 typedef Point3<ScalarType> QueryType;
00071                 static inline const Point3<ScalarType> &  Pos(const QueryType & qt)  {return qt;}
00072         
00073                 template <class EDGETYPE, class SCALARTYPE>
00074                 inline bool operator () (const EDGETYPE & e, const Point3<SCALARTYPE> & p, SCALARTYPE & minDist, Point3<SCALARTYPE> & q) {
00075                         const Point3<typename EDGETYPE::ScalarType> fp = Point3<typename EDGETYPE::ScalarType>::Construct(p);
00076                         Point3<typename EDGETYPE::ScalarType> fq;
00077                         typename EDGETYPE::ScalarType md = (typename EDGETYPE::ScalarType)(minDist);
00078                         const bool ret = vcg::edge::PointDistance(e, fp, md, fq);
00079                         minDist = (SCALARTYPE)(md);
00080                         q = Point3<SCALARTYPE>::Construct(fq);
00081                         return (ret);
00082                 }
00083         };
00084 
00085         template <class EdgeType> 
00086         typename EdgeType::ScalarType Length(const EdgeType &e)
00087         {
00088                 return Distance(e.cV(0)->cP(),e.cV(1)->cP());
00089         }
00090 
00091         template <class EdgeType> 
00092         typename EdgeType::VertexType::CoordType Center(const EdgeType &e)
00093         {
00094                 return (e.cV(0)->cP()+e.cV(1)->cP())/2.0;
00095         }
00096 
00097         
00098 }        // end namespace edge
00099         
00100 }        // end namespace vcg
00101 
00102 
00103 #endif
00104 


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