From 8ae63ef1c3cc460eed2b8782d9072cd92501088a Mon Sep 17 00:00:00 2001 From: ganovelli Date: Wed, 7 Jan 2009 14:25:46 +0000 Subject: [PATCH] - added optional parameter to return the closest vertex as a vertex attribute - added a tolerance to check triangle inequality --- vcg/complex/trimesh/geodesic.h | 43 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/vcg/complex/trimesh/geodesic.h b/vcg/complex/trimesh/geodesic.h index 600597f0..f6fe9885 100644 --- a/vcg/complex/trimesh/geodesic.h +++ b/vcg/complex/trimesh/geodesic.h @@ -161,7 +161,8 @@ class Geo{ MeshType & m, std::vector & _inputfrontier, ScalarType & max_distance, - bool farthestOnBorder = false + bool farthestOnBorder = false, + typename MeshType::PerVertexAttributeHandle * sources = NULL ) { bool isLeaf; @@ -205,6 +206,8 @@ class Geo{ pop_heap(frontier.begin(),frontier.end(),pred()); curr = (frontier.back()).v; curr_s = (*TD)[curr].source; + if(sources!=NULL) + (*sources)[curr] = curr_s; d_heap = (frontier.back()).d; frontier.pop_back(); @@ -235,12 +238,13 @@ class Geo{ const ScalarType & d_pw1 = (*TD)[pw1].d; { - ScalarType inter = (curr->P() - pw1->P()).Norm(); + const ScalarType inter = (curr->P() - pw1->P()).Norm(); + const ScalarType tol = (inter + d_curr + d_pw1)*.0001f; if ( ((*TD)[pw1].source != (*TD)[curr].source)||// not the same source - (inter + d_curr < d_pw1 ) || - (inter + d_pw1 < d_curr ) || - (d_curr + d_pw1 < inter ) // triangular inequality + (inter + d_curr < d_pw1 +tol ) || + (inter + d_pw1 < d_curr +tol ) || + (d_curr + d_pw1 < inter +tol ) // triangular inequality ) curr_d = d_curr + (pw->P()-curr->P()).Norm(); else @@ -283,14 +287,15 @@ public: static void FarthestVertex( MeshType & m, std::vector & fro, VertexPointer & farthest, - ScalarType & distance){ + ScalarType & distance, + typename MeshType::PerVertexAttributeHandle * sources = NULL){ typename std::vector::iterator fi; std::vectorfr; for( fi = fro.begin(); fi != fro.end() ; ++fi) - fr.push_back(VertDist(*fi,-1)); - farthest = Visit(m,fr,distance,false); + fr.push_back(VertDist(*fi,0.0)); + farthest = Visit(m,fr,distance,false,sources); } /* Given a mesh and a pointers to a vertex-source (source), assigns the approximated geodesic @@ -315,27 +320,30 @@ public: static void FarthestBVertex(MeshType & m, std::vector & fro, VertexPointer & farthest, - ScalarType & distance){ + ScalarType & distance, + typename MeshType::PerVertexAttributeHandle * sources = NULL + ){ typename std::vector::iterator fi; std::vectorfr; for( fi = fro.begin(); fi != fro.end() ; ++fi) fr.push_back(VertDist(*fi,-1)); - farthest = Visit(m,fr,distance,true); + farthest = Visit(m,fr,distance,true,sources); } /* Same as FarthestPoint but the returned pointer is to a border vertex Note: update the field Q() of the vertices */ - static void FarthestBVertex( MeshType & m, - VertexPointer seed, - VertexPointer & farthest, - ScalarType & distance){ + static void FarthestBVertex( MeshType & m, + VertexPointer seed, + VertexPointer & farthest, + ScalarType & distance, + typename MeshType::PerVertexAttributeHandle * sources = NULL){ std::vector fro; fro.push_back( seed ); VertexPointer v0; - FarthestBVertex(m,fro,v0,distance); + FarthestBVertex(m,fro,v0,distance,sources); farthest = v0; } @@ -344,7 +352,8 @@ public: Note: update the field Q() of the vertices */ static void DistanceFromBorder( MeshType & m, - ScalarType & distance + ScalarType & distance, + typename MeshType::PerVertexAttributeHandle * sources = NULL ){ std::vector fro; VertexIterator vi; @@ -352,7 +361,7 @@ public: for(vi = m.vert.begin(); vi != m.vert.end(); ++vi) if( (*vi).IsB()) fro.push_back(&(*vi)); - FarthestVertex(m,fro,farthest,distance); + FarthestVertex(m,fro,farthest,distance,sources); } };