From 2380e1d9a1e88acc5d5c53cd357efbed66262dc1 Mon Sep 17 00:00:00 2001 From: cignoni Date: Mon, 24 Jan 2005 11:47:23 +0000 Subject: [PATCH] Now used also by the official Metro Removed using namespace (NEVER IN HEADERS!) Made the computation of barycentric coords only when necessary Renamed Mindistpoint to Closest --- vcg/complex/trimesh/closest.h | 67 +++++++++++++++-------------------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/vcg/complex/trimesh/closest.h b/vcg/complex/trimesh/closest.h index 3d104547..f05c6aa8 100644 --- a/vcg/complex/trimesh/closest.h +++ b/vcg/complex/trimesh/closest.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2005/01/21 17:13:09 pietroni +included distance.h changed Dist to vcg::face::PointDistance + Revision 1.1 2004/10/04 15:32:16 ganovelli moved from metro core @@ -32,8 +35,8 @@ header added ****************************************************************************/ -#ifndef __VCG_CLOSEST -#define __VCG_CLOSEST +#ifndef __VCG_TRIMESH_CLOSEST +#define __VCG_TRIMESH_CLOSEST #include #include @@ -43,18 +46,16 @@ header added #include #include - -using namespace vcg; - - +namespace vcg { + namespace trimesh { /* 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, distanza limite -// output: normale alla faccia e punto piu' vicino su di essa +// 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 @@ -118,7 +119,6 @@ void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, { if(s==0) { - A2UGridLink *first, *last, *l; gr.Grid( gx, gy, gz, first, last ); for(l=first;l!=last;++l) @@ -129,21 +129,6 @@ void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, { bestq = q; bestf = l->Elem(); - typename MESH::ScalarType alfa=1, beta=1, gamma=1; - - //bestf->InterpolationParameters(q, alfa, beta); - //calcolo normale con interpolazione trilineare - /*normf = (1-(alfa+beta))*(bestf->V(0)->Normal())+ - (alfa*(bestf->V(1)->Normal()))+ - (beta*(bestf->V(2)->Normal()));*/ - bestf->InterpolationParameters(q, alfa, beta, gamma); - //assert(ret); - normf = (bestf->V(0)->cN())*alfa+ - (bestf->V(1)->cN())*beta+ - (bestf->V(2)->cN())*gamma; - normf.Normalize(); - ip[0]=alfa;ip[1]=beta;ip[2]=gamma; - } mesh.Mark( &*(l->Elem()) ); @@ -171,16 +156,7 @@ void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, { bestq = q; bestf = l->Elem(); - typename MESH::ScalarType alfa, beta, gamma; - //bestf->InterpolationParameters(q, alfa, beta); - //calcolo normale con interpolazione trilineare - bestf->InterpolationParameters(q, alfa, beta, gamma); - normf = (bestf->V(0)->cN())*alfa+ - (bestf->V(1)->cN())*beta+ - (bestf->V(2)->cN())*gamma ; - ip[0]=alfa;ip[1]=beta;ip[2]=gamma; - //normf.Normalize(); inutile si assume le normali ai vertici benfatte - } + } mesh.Mark(&*l->Elem()); } } @@ -192,15 +168,30 @@ void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, break; vdist += vstep; } - f=&*bestf; - mdist = scalar(fabs(error)); + if(mdist > scalar(fabs(error))) + { + f=&*bestf; + typename MESH::ScalarType alfa, beta, gamma; + //calcolo normale con interpolazione trilineare + bestf->InterpolationParameters(bestq, alfa, beta, gamma); + normf = (bestf->V(0)->cN())*alfa+ + (bestf->V(1)->cN())*beta+ + (bestf->V(2)->cN())*gamma ; + ip=Point3x(alfa,beta,gamma); + //normf.Normalize(); inutile si assume le normali ai vertici benfatte + + mdist = scalar(fabs(error)); + } } template -void MinDistPoint( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, +void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, Point3 & normf, Point3 & bestq, typename MESH::face_type * &f) { Point3 ip; - MinDistPoint(mesh,p,gr,mdist,normf,bestq,f,ip); + Closest(mesh,p,gr,mdist,normf,bestq,f,ip); } +} // end namespace trimesh +} // end namespace vcg + #endif