From 86e2eae13565f852585944107828273e300e3d08 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Thu, 1 Dec 2005 15:01:17 +0000 Subject: [PATCH] add: GetClosestVertex, GetKClosestVertex, GetInSphereVertex, GetInBoxVertex, ClosestIterator --- vcg/complex/vertexmesh/closest.h | 158 +++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 vcg/complex/vertexmesh/closest.h diff --git a/vcg/complex/vertexmesh/closest.h b/vcg/complex/vertexmesh/closest.h new file mode 100644 index 00000000..501b9640 --- /dev/null +++ b/vcg/complex/vertexmesh/closest.h @@ -0,0 +1,158 @@ +/**************************************************************************** +* 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. * +* * +****************************************************************************/ + + +#ifndef __VCG_VERTEXMESH_CLOSEST +#define __VCG_VERTEXMESH_CLOSEST +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace vcg { + namespace vertex { + + //**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 VertTmark:public Tmark + {}; + + //**CLOSEST FUNCTION DEFINITION**// + + /* + + aka MetroCore + data una mesh m e una ug sulle sue facce trova il punto di m piu' vicino ad + un punto dato. + */ + + // input: mesh, punto, griglia (gr), distanza limite (mdist) + // output: normale (interpolata) alla faccia e punto piu' vicino su di essa, e coord baricentriche del punto trovato + + // Nota che il parametro template GRID non ci dovrebbe essere, visto che deve essere + // UGrid, ma non sono riuscito a definirlo implicitamente + + + template + typename MESH::VertexType * GetClosestVertex( MESH & mesh,GRID & gr,const typename GRID::CoordType & _p, + const typename GRID::ScalarType & _maxDist,typename GRID::ScalarType & _minDist ) + { + typedef 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 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 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)); + } + + + //**ITERATORS DEFINITION**// + + template + class ClosestVertexIterator:public vcg::ClosestIterator > + { + public: + typedef typename GRID GridType; + typedef typename MESH MeshType; + typedef typename VertTmark MarkerVert; + typedef typename vcg::vertex::PointDistanceFunctor VDistFunct; + typedef typename vcg::ClosestIterator > ClosestBaseType; + + ClosestVertexIterator(GridType &_Si):ClosestBaseType(_Si,VDistFunct()){} + + void SetMesh(MeshType *m) + {tm.SetMesh(m);} + }; + + + } // end namespace vertex +} // end namespace vcg + +#endif