Changed a few geodesic function from void to bool to return possible failures (like for exmple asking for border distance on a mesh without border)

This commit is contained in:
Paolo Cignoni 2009-05-26 22:31:58 +00:00
parent c0b0c7469c
commit b3e9a9e105
1 changed files with 12 additions and 5 deletions
vcg/complex/trimesh

View File

@ -35,10 +35,11 @@
#include <assert.h> #include <assert.h>
#include <vcg/math/base.h>
#include <vcg/container/simple_temporary_data.h> #include <vcg/container/simple_temporary_data.h>
#include <vcg/simplex/face/pos.h> #include <vcg/simplex/face/pos.h>
#include <vcg/simplex/face/topology.h> #include <vcg/simplex/face/topology.h>
#include <vcg/math/base.h> #include <vcg/complex/trimesh/update/quality.h>
#include <deque> #include <deque>
#include <vector> #include <vector>
#include <list> #include <list>
@ -297,7 +298,7 @@ public:
distance from the cloasest source to all the mesh vertices and returns the pointer to the farthest. distance from the cloasest source to all the mesh vertices and returns the pointer to the farthest.
Note: update the field Q() of the vertices Note: update the field Q() of the vertices
*/ */
static void FarthestVertex( MeshType & m, static bool FarthestVertex( MeshType & m,
std::vector<VertexPointer> & fro, std::vector<VertexPointer> & fro,
VertexPointer & farthest, VertexPointer & farthest,
ScalarType & distance, ScalarType & distance,
@ -305,10 +306,12 @@ public:
typename std::vector<VertexPointer>::iterator fi; typename std::vector<VertexPointer>::iterator fi;
std::vector<VertDist>fr; std::vector<VertDist>fr;
if(fro.empty()) return false;
for( fi = fro.begin(); fi != fro.end() ; ++fi) for( fi = fro.begin(); fi != fro.end() ; ++fi)
fr.push_back(VertDist(*fi,0.0)); fr.push_back(VertDist(*fi,0.0));
farthest = Visit(m,fr,distance,false,sources); farthest = Visit(m,fr,distance,false,sources);
return true;
} }
/* /*
Given a mesh and a pointers to a vertex-source (source), assigns the approximated geodesic Given a mesh and a pointers to a vertex-source (source), assigns the approximated geodesic
@ -364,7 +367,7 @@ public:
Assigns to each vertex of the mesh its distance to the closest vertex on the border Assigns to each vertex of the mesh its distance to the closest vertex on the border
Note: update the field Q() of the vertices Note: update the field Q() of the vertices
*/ */
static void DistanceFromBorder( MeshType & m, static bool DistanceFromBorder( MeshType & m,
ScalarType & distance, ScalarType & distance,
typename MeshType::template PerVertexAttributeHandle<VertexPointer> * sources = NULL typename MeshType::template PerVertexAttributeHandle<VertexPointer> * sources = NULL
){ ){
@ -374,7 +377,11 @@ public:
for(vi = m.vert.begin(); vi != m.vert.end(); ++vi) for(vi = m.vert.begin(); vi != m.vert.end(); ++vi)
if( (*vi).IsB()) if( (*vi).IsB())
fro.push_back(&(*vi)); fro.push_back(&(*vi));
FarthestVertex(m,fro,farthest,distance,sources); if(fro.empty()) return false;
tri::UpdateQuality<CMeshO>::VertexConstant(m,0);
return FarthestVertex(m,fro,farthest,distance,sources);
} }
}; };