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