Cleaned up small bug in the vertex clustering alg (crashed on empty sets and on non compacted meshes

This commit is contained in:
Paolo Cignoni 2011-05-31 08:37:13 +00:00
parent 5b6f8055f2
commit 5c358c02a4
1 changed files with 6 additions and 4 deletions

View File

@ -1513,13 +1513,15 @@ static int MergeCloseVertex(MeshType &m, const ScalarType radius)
static int ClusterVertex(MeshType &m, const ScalarType radius) static int ClusterVertex(MeshType &m, const ScalarType radius)
{ {
if(m.vn==0) return 0;
// some spatial indexing structure does not work well with deleted vertices...
tri::Allocator<MeshType>::CompactVertexVector(m);
typedef vcg::SpatialHashTable<VertexType, ScalarType> SampleSHT; typedef vcg::SpatialHashTable<VertexType, ScalarType> SampleSHT;
SampleSHT sht; SampleSHT sht;
tri::VertTmark<MeshType> markerFunctor; tri::VertTmark<MeshType> markerFunctor;
typedef vcg::vertex::PointDistanceFunctor<ScalarType> VDistFunct; typedef vcg::vertex::PointDistanceFunctor<ScalarType> VDistFunct;
std::vector<VertexType*> closests; std::vector<VertexType*> closests;
int mergedCnt=0; int mergedCnt=0;
Point3f closestPt;
sht.Set(m.vert.begin(), m.vert.end()); sht.Set(m.vert.begin(), m.vert.end());
UpdateFlags<MeshType>::VertexClearV(m); UpdateFlags<MeshType>::VertexClearV(m);
for(VertexIterator viv = m.vert.begin(); viv!= m.vert.end(); ++viv) for(VertexIterator viv = m.vert.begin(); viv!= m.vert.end(); ++viv)
@ -1535,7 +1537,7 @@ static int ClusterVertex(MeshType &m, const ScalarType radius)
float dist = Distance(p,closests[i]->cP()); float dist = Distance(p,closests[i]->cP());
if(dist < radius && !closests[i]->IsV()) if(dist < radius && !closests[i]->IsV())
{ {
printf("%f %f \n",dist,radius); // printf("%f %f \n",dist,radius);
mergedCnt++; mergedCnt++;
closests[i]->SetV(); closests[i]->SetV();
closests[i]->P()=p; closests[i]->P()=p;