- added call of FarthestVertex with returning vertices within a specified interval

- added initial #define to avoid multiple inclusion
This commit is contained in:
Nico Pietroni 2011-04-19 09:40:04 +00:00
parent 95713e5723
commit c4cc235b52
1 changed files with 328 additions and 284 deletions

View File

@ -35,29 +35,32 @@
class for computing approximated geodesic distances on a mesh. class for computing approximated geodesic distances on a mesh.
basic example: farthest vertex from a specified one basic example: farthest vertex from a specified one
MyMesh m; MyMesh m;
MyMesh::VertexPointer seed,far; MyMesh::VertexPointer seed,far;
MyMesh::ScalarType dist; MyMesh::ScalarType dist;
vcg::Geo<MyMesh> g; vcg::Geo<MyMesh> g;
g.FarthestVertex(m,seed,far,d); g.FarthestVertex(m,seed,far,d);
*/ */
namespace vcg{ #ifndef __VCGLIB_GEODESIC
namespace tri{ #define __VCGLIB_GEODESIC
template <class MeshType> namespace vcg{
struct EuclideanDistance{ namespace tri{
template <class MeshType>
struct EuclideanDistance{
typedef typename MeshType::VertexType VertexType; typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::ScalarType ScalarType; typedef typename MeshType::ScalarType ScalarType;
EuclideanDistance(){} EuclideanDistance(){}
ScalarType operator()(const VertexType * v0, const VertexType * v1) const ScalarType operator()(const VertexType * v0, const VertexType * v1) const
{return vcg::Distance(v0->cP(),v1->cP());} {return vcg::Distance(v0->cP(),v1->cP());}
}; };
template <class MeshType, class DistanceFunctor = EuclideanDistance<MeshType> > template <class MeshType, class DistanceFunctor = EuclideanDistance<MeshType> >
class Geo{ class Geo{
public: public:
@ -163,9 +166,9 @@ class Geo{
ScalarType & max_distance, ScalarType & max_distance,
bool farthestOnBorder = false, bool farthestOnBorder = false,
ScalarType distance_threshold = std::numeric_limits<ScalarType>::max(), ScalarType distance_threshold = std::numeric_limits<ScalarType>::max(),
typename MeshType::template PerVertexAttributeHandle<VertexPointer> * sources = NULL typename MeshType::template PerVertexAttributeHandle<VertexPointer> * sources = NULL,
) std::vector<VertexPointer> *InInterval=NULL)
{ {
bool isLeaf; bool isLeaf;
std::vector<VertDist> frontier; std::vector<VertDist> frontier;
VertexPointer curr,farthest=0,pw1; VertexPointer curr,farthest=0,pw1;
@ -198,6 +201,9 @@ class Geo{
{ {
pop_heap(frontier.begin(),frontier.end(),pred()); pop_heap(frontier.begin(),frontier.end(),pred());
curr = (frontier.back()).v; curr = (frontier.back()).v;
if (InInterval!=NULL)
InInterval->push_back(curr);
curr_s = TD[curr].source; curr_s = TD[curr].source;
if(sources!=NULL) if(sources!=NULL)
(*sources)[curr] = curr_s; (*sources)[curr] = curr_s;
@ -259,17 +265,27 @@ class Geo{
}// end while }// end while
// Copy found distance onto the Quality (\todo parametric!) // Copy found distance onto the Quality (\todo parametric!)
if (InInterval==NULL)
{
for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) if(!(*vi).IsD()) for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) if(!(*vi).IsD())
(*vi).Q() = TD[&(*vi)].d; (*vi).Q() = TD[&(*vi)].d;
}
else
{
assert(InInterval->size()>0);
for(int i=0;i<InInterval->size();i++)
(*InInterval)[i]->Q() = TD[(*InInterval)[i]].d;
}
return farthest; return farthest;
} }
public: public:
/* /*
Given a mesh and a vector of pointers to vertices (sources), assigns the approximated geodesic Given a mesh and a vector of pointers to vertices (sources), assigns the approximated geodesic
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 vertices within the
specified interval
Note: update the field Q() of the vertices Note: update the field Q() of the vertices
*/ */
static bool FarthestVertex( MeshType & m, static bool FarthestVertex( MeshType & m,
@ -277,15 +293,21 @@ public:
VertexPointer & farthest, VertexPointer & farthest,
ScalarType & distance, ScalarType & distance,
ScalarType distance_thr = std::numeric_limits<ScalarType>::max(), ScalarType distance_thr = std::numeric_limits<ScalarType>::max(),
typename MeshType::template PerVertexAttributeHandle<VertexPointer> * sources = NULL){ typename MeshType::template PerVertexAttributeHandle<VertexPointer> * sources = NULL,
std::vector<VertexPointer> *InInterval=NULL)
{
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; 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,distance_thr,sources); /* if (InInterval==NULL)continue;
InInterval.push_back();*/
}
farthest = Visit(m,fr,distance,false,distance_thr,sources,InInterval);
return true; return true;
} }
/* /*
@ -297,18 +319,39 @@ public:
VertexPointer seed, VertexPointer seed,
VertexPointer & farthest, VertexPointer & farthest,
ScalarType & distance, ScalarType & distance,
ScalarType distance_thr = std::numeric_limits<ScalarType>::max()){ ScalarType distance_thr = std::numeric_limits<ScalarType>::max())
{
std::vector<VertexPointer> seedVec; std::vector<VertexPointer> seedVec;
seedVec.push_back( seed ); seedVec.push_back( seed );
VertexPointer v0; VertexPointer v0;
FarthestVertex(m,seedVec,v0,distance,distance_thr); FarthestVertex(m,seedVec,v0,distance,distance_thr);
farthest = v0; farthest = v0;
} }
/* /*
Given a mesh and a pointers to a vertex-source (source), assigns the approximated geodesic
distance from the vertex-source to all the mesh vertices and returns the vertices within the
specified interval
Note: update the field Q() of the vertices
*/
static void FarthestVertex( MeshType & m,
VertexPointer seed,
VertexPointer & farthest,
ScalarType & distance,
ScalarType distance_thr,
std::vector<VertexPointer> *InInterval=NULL)
{
std::vector<VertexPointer> seedVec;
seedVec.push_back( seed );
VertexPointer v0;
FarthestVertex(m,seedVec,v0,distance,distance_thr,NULL,InInterval);
farthest = v0;
}
/*
Same as FarthestPoint but the returned pointer is to a border vertex Same as FarthestPoint but the returned pointer is to a border vertex
Note: update the field Q() of the vertices Note: update the field Q() of the vertices
*/ */
static void FarthestBVertex(MeshType & m, static void FarthestBVertex(MeshType & m,
std::vector<VertexPointer> & seedVec, std::vector<VertexPointer> & seedVec,
VertexPointer & farthest, VertexPointer & farthest,
@ -322,11 +365,11 @@ public:
for( fi = seedVec.begin(); fi != seedVec.end() ; ++fi) for( fi = seedVec.begin(); fi != seedVec.end() ; ++fi)
fr.push_back(VertDist(*fi,-1)); fr.push_back(VertDist(*fi,-1));
farthest = Visit(m,fr,distance,true,sources); farthest = Visit(m,fr,distance,true,sources);
} }
/* /*
Same as FarthestPoint but the returned pointer is to a border vertex Same as FarthestPoint but the returned pointer is to a border vertex
Note: update the field Q() of the vertices Note: update the field Q() of the vertices
*/ */
static void FarthestBVertex( MeshType & m, static void FarthestBVertex( MeshType & m,
VertexPointer seed, VertexPointer seed,
VertexPointer & farthest, VertexPointer & farthest,
@ -339,10 +382,10 @@ public:
farthest = v0; farthest = v0;
} }
/* /*
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 bool 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
@ -358,8 +401,9 @@ public:
tri::UpdateQuality<MeshType>::VertexConstant(m,0); tri::UpdateQuality<MeshType>::VertexConstant(m,0);
return FarthestVertex(m,fro,farthest,distance,std::numeric_limits<ScalarType>::max(),sources); return FarthestVertex(m,fro,farthest,distance,std::numeric_limits<ScalarType>::max(),sources);
} }
}; };
};// end namespace tri };// end namespace tri
};// end namespace vcg };// end namespace vcg
#endif