From 3e89d13feade714dd7cd582f13032e8f0fd18faf Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Wed, 14 Sep 2005 12:56:47 +0000 Subject: [PATCH] used closest function from grid --- vcg/complex/trimesh/closest.h | 221 +++++++++++++++++++--------------- 1 file changed, 121 insertions(+), 100 deletions(-) diff --git a/vcg/complex/trimesh/closest.h b/vcg/complex/trimesh/closest.h index eb670e11..0260c89b 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.6 2005/08/26 09:12:48 cignoni +changed typedef A2UGridLink da 'GridStaticPtr::Link' a typedef 'GRID::Link' + Revision 1.5 2005/02/08 17:49:38 pietroni added if (!l->Elem()->IsD()) test on each element @@ -60,6 +63,18 @@ header added namespace vcg { namespace trimesh { + +template + class Tmark + { + MESH_TYPE m; + public: + Tmark(MESH_TYPE &_m):m(_m){} + void UnMarkAll(){m.UnMarkAll();} + bool IsMarked(OBJ_TYPE* obj){return (m.IsMarked(obj));} + void Mark(OBJ_TYPE* obj){m.Mark(obj);} + }; + /* aka MetroCore data una mesh m e una ug sulle sue facce trova il punto di m piu' vicino ad @@ -76,119 +91,125 @@ template void Closest( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, Point3 & normf, Point3 & bestq, typename MESH::FaceType * &f, Point3 &ip) { - typedef SCALAR scalar; - typedef Point3 Point3x; - typedef Box3 Box3x; + typedef SCALAR scalar; + typedef Point3 Point3x; + typedef Box3 Box3x; - if(!gr.bbox.IsIn(p)) return; - //typedef typename GridStaticPtr::Link A2UGridLink; - typedef typename GRID::Link A2UGridLink; - scalar ax = p[0] - gr.bbox.min[0]; // Real coodinate of point refer to - scalar ay = p[1] - gr.bbox.min[1]; - scalar az = p[2] - gr.bbox.min[2]; + //if(!gr.bbox.IsIn(p)) return; + ////typedef typename GridStaticPtr::Link A2UGridLink; + //typedef typename GRID::Link A2UGridLink; + // scalar ax = p[0] - gr.bbox.min[0]; // Real coodinate of point refer to + // scalar ay = p[1] - gr.bbox.min[1]; + // scalar az = p[2] - gr.bbox.min[2]; - int gx = int( ax/gr.voxel[0] ); // Integer coordinate of the point - int gy = int( ay/gr.voxel[1] ); // voxel - int gz = int( az/gr.voxel[2] ); + // int gx = int( ax/gr.voxel[0] ); // Integer coordinate of the point + // int gy = int( ay/gr.voxel[1] ); // voxel + // int gz = int( az/gr.voxel[2] ); - scalar vx = gr.bbox.min[0]+gx*gr.voxel[0]; // Real world coordinate of the Voxel - scalar vy = gr.bbox.min[1]+gy*gr.voxel[1]; // origin - scalar vz = gr.bbox.min[2]+gz*gr.voxel[2]; + // scalar vx = gr.bbox.min[0]+gx*gr.voxel[0]; // Real world coordinate of the Voxel + // scalar vy = gr.bbox.min[1]+gy*gr.voxel[1]; // origin + //scalar vz = gr.bbox.min[2]+gz*gr.voxel[2]; - scalar dx = math::Min(p[0] - vx, vx+gr.voxel[0]-p[0]); // Dist from the voxel - scalar dy = math::Min(p[1] - vy, vy+gr.voxel[1]-p[1]); - scalar dz = math::Min(p[2] - vz, vz+gr.voxel[2]-p[2]); + //scalar dx = math::Min(p[0] - vx, vx+gr.voxel[0]-p[0]); // Dist from the voxel + // scalar dy = math::Min(p[1] - vy, vy+gr.voxel[1]-p[1]); + // scalar dz = math::Min(p[2] - vz, vz+gr.voxel[2]-p[2]); - scalar vdist,vstep; + //scalar vdist,vstep; - if(dxElem()->IsD()) - { - if( ! mesh.IsMarked( &*(l->Elem())) ) - { - if( face::PointDistance((*(l->Elem())), p, error, q) ) - { - bestq = q; - bestf = l->Elem(); - } + //int mxsd = gr.siz[0]; + //if(mxsdElem()->IsD()) + // { + // if( ! mesh.IsMarked( &*(l->Elem())) ) + // { + // if( face::PointDistance((*(l->Elem())), p, error, q) ) + // { + // bestq = q; + // bestf = l->Elem(); + // } - mesh.Mark( &*(l->Elem()) ); - } - } - } - else - { - for(int ix=gx-s;ix<=gx+s;++ix) - if( ix>=0 && ix=0 && iy=0 && izElem()->IsD()) - { - if( ! mesh.IsMarked( &*(l->Elem())) ) - { - if( vcg::face::PointDistance((*(l->Elem())), p, error, q) ) - { - bestq = q; - bestf = l->Elem(); - } - mesh.Mark(&*l->Elem()); - } - } - } - } - } - } + // mesh.Mark( &*(l->Elem()) ); + // } + // } + // } + // else + // { + // for(int ix=gx-s;ix<=gx+s;++ix) + // if( ix>=0 && ix=0 && iy=0 && izElem()->IsD()) + // { + // if( ! mesh.IsMarked( &*(l->Elem())) ) + // { + // if( vcg::face::PointDistance((*(l->Elem())), p, error, q) ) + // { + // bestq = q; + // bestf = l->Elem(); + // } + // mesh.Mark(&*l->Elem()); + // } + // } + // } + // } + // } + // } + + // if( fabs(error) Marker; + Marker t=Marker(mesh); + MESH::FaceType* bestf= gr.GetClosest(p,mdist,bestq,t); - if( fabs(error) scalar(fabs(error))) { - f=&*bestf; + f=bestf; typename MESH::ScalarType alfa, beta, gamma; //calcolo normale con interpolazione trilineare bestf->InterpolationParameters(bestq, alfa, beta, gamma);