From 184edbcc3f24f533e5229e30478be011152a3772 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Wed, 26 Jul 2006 08:09:09 +0000 Subject: [PATCH] first release version --- vcg/complex/edgemesh/closest.h | 171 +++++++++++++++++++++++++++++++++ vcg/simplex/edge/distance.h | 82 ++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 vcg/complex/edgemesh/closest.h create mode 100644 vcg/simplex/edge/distance.h diff --git a/vcg/complex/edgemesh/closest.h b/vcg/complex/edgemesh/closest.h new file mode 100644 index 00000000..bdbb7f72 --- /dev/null +++ b/vcg/complex/edgemesh/closest.h @@ -0,0 +1,171 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + + +****************************************************************************/ + +#ifndef __VCG_EDGEMESH_CLOSEST +#define __VCG_EDGEMESH_CLOSEST +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace vcg { + namespace edgemesh { + + //**MARKER CLASSES**// + template + class Tmark + { + MESH_TYPE *m; + public: + Tmark(){} + void UnMarkAll(){m->UnMarkAll();} + bool IsMarked(OBJ_TYPE* obj){return (m->IsMarked(obj));} + void Mark(OBJ_TYPE* obj){m->Mark(obj);} + void SetMesh(MESH_TYPE *_m) + {m=_m;} + }; + + template + class EdgeTmark:public Tmark + {}; + + template + class VertTmark:public Tmark + {}; + + //**CLOSEST FUNCTION DEFINITION**// + + template + typename MESH::EdgeType * GetClosestEdge( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, + const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist, + typename GRID::CoordType &_closestPt) + { + typedef typename GRID::ScalarType ScalarType; + typedef Point3 Point3x; + typedef EdgeTmark MarkerEdge; + MarkerEdge mf; + mf.SetMesh(&mesh); + vcg::edge::PointDistanceFunctor PDistFunct; + _minDist=_maxDist; + return (gr.GetClosest(PDistFunct,mf,_p,_maxDist,_minDist,_closestPt)); + } + + template + typename MESH::VertexType * GetClosestVertex( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, + const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist ) + { + typedef typename GRID::ScalarType ScalarType; + typedef Point3 Point3x; + typedef VertTmark MarkerVert; + MarkerVert mv; + mv.SetMesh(&mesh); + typedef vcg::vertex::PointDistanceFunctor VDistFunct; + _minDist=_maxDist; + Point3x _closestPt; + return (gr.GetClosest/**/(VDistFunct(),mv,_p,_maxDist,_minDist,_closestPt)); + } + + template + unsigned int GetKClosestEdge(MESH & mesh,GRID & gr, const unsigned int _k, + const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist, + OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points) + { + typedef EdgeTmark MarkerEdge; + MarkerEdge mf; + mf.SetMesh(&mesh); + vcg::face::PointDistanceFunctor FDistFunct; + return (gr.GetKClosest /**/ + (FDistFunct,mf,_k,_p,_maxDist,_objectPtrs,_distances,_points)); + } + + template + unsigned int GetKClosestVertex(MESH & mesh,GRID & gr, const unsigned int _k, + const typename GRID::CoordType & _p, const typename GRID::ScalarType & _maxDist, + OBJPTRCONTAINER & _objectPtrs,DISTCONTAINER & _distances, POINTCONTAINER & _points) + { + typedef VertTmark MarkerVert; + MarkerVert mv; + mv.SetMesh(&mesh); + typedef vcg::vertex::PointDistanceFunctor VDistFunct; + return (gr.GetKClosest/* */ + (VDistFunct(),mv,_k,_p,_maxDist,_objectPtrs,_distances,_points)); + } + + + template + unsigned int GetInSphereVertex(MESH & mesh, + GRID & gr, + const typename GRID::CoordType & _p, + const typename GRID::ScalarType & _r, + OBJPTRCONTAINER & _objectPtrs, + DISTCONTAINER & _distances, + POINTCONTAINER & _points) + { + typedef VertTmark MarkerVert; + MarkerVert mv; + mv.SetMesh(&mesh); + typedef vcg::vertex::PointDistanceFunctor VDistFunct; + return (gr.GetInSphere/**/ + (VDistFunct(),mv,_p,_r,_objectPtrs,_distances,_points)); + } + + template + unsigned int GetInBoxEdge(MESH & mesh, + GRID & gr, + const vcg::Box3 _bbox, + OBJPTRCONTAINER & _objectPtrs) + { + typedef EdgeTmark EdgeTmark; + EdgeTmark mf; + mf.SetMesh(&mesh); + return(gr.GetInBox/**/(mf,_bbox,_objectPtrs)); + } + + template + unsigned int GetInBoxVertex(MESH & mesh, + GRID & gr, + const vcg::Box3 _bbox, + OBJPTRCONTAINER & _objectPtrs) + { + typedef VertTmark MarkerVert; + MarkerVert mv; + mv.SetMesh(&mesh); + return(gr.GetInBox/**/(mv,_bbox,_objectPtrs)); + } + + + } // end namespace edgemesh +} // end namespace vcg + +#endif diff --git a/vcg/simplex/edge/distance.h b/vcg/simplex/edge/distance.h new file mode 100644 index 00000000..d0158091 --- /dev/null +++ b/vcg/simplex/edge/distance.h @@ -0,0 +1,82 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + + +****************************************************************************/ + +#ifndef __VCGLIB_EDGE_DISTANCE +#define __VCGLIB_EDGE_DISTANCE + +#include +#include +#include + + +namespace vcg { + namespace edge{ + /*Point edge distance*/ + + template + bool PointDistance( const EdgeType &e, + const vcg::Point3 & q, + typename EdgeType::ScalarType & dist, + vcg::Point3 & p ) + { + vcg::Segment3 s; + s.P0()=e.V(0)->P(); + s.P1()=e.V(1)->P(); + EdgeType::CoordType near; + vcg::ClosestPoint(s,near); + EdgeType::ScalarType d=(q-p).Norm(); + if (d + inline bool operator () (const EDGETYPE & e, const Point3 & p, SCALARTYPE & minDist, Point3 & q) { + const Point3 fp = Point3::Construct(p); + Point3 fq; + typename EDGETYPE::ScalarType md = (typename EDGETYPE::ScalarType)(minDist); + const bool ret = PointDistance(e, fp, md, fq); + minDist = (SCALARTYPE)(md); + q = Point3::Construct(fq); + return (ret); + } + }; + +} // end namespace edge + +} // end namespace vcg + + +#endif +