diff --git a/vcg/complex/algorithms/voronoi_clustering.h b/vcg/complex/algorithms/voronoi_clustering.h index 6e6da328..45a8925b 100644 --- a/vcg/complex/algorithms/voronoi_clustering.h +++ b/vcg/complex/algorithms/voronoi_clustering.h @@ -279,7 +279,23 @@ static void VoronoiRelaxing(MeshType &m, std::vector &seedVec, int sources = tri::Allocator:: template AddPerVertexAttribute (m,"sources"); tri::Geodesic::Compute(m,seedVec,std::numeric_limits::max(),0,&sources); - + + // Delete all the (hopefully) small regions that have not been reached by the seeds; + tri::UpdateFlags::VertexClearV(m); + for(int i=0;iV(0)->IsV() || fi->V(1)->IsV() || fi->V(2)->IsV() ) + { + face::VFDetach(*fi); + tri::Allocator::DeleteFace(m,*fi); + } + qDebug("Deleted faces not reached: %i -> %i",int(m.face.size()),m.fn); + tri::Clean::RemoveUnreferencedVertex(m); + tri::Allocator::CompactFaceVector(m); + tri::Allocator::CompactVertexVector(m); + std::pair zz(0,0); std::vector< std::pair > regionArea(m.vert.size(),zz); std::vector borderVec; @@ -305,7 +321,7 @@ static void VoronoiRelaxing(MeshType &m, std::vector &seedVec, int std::vector< std::pair > seedMaxima(m.vert.size(),zz); for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) { - int seedIndex = sources[vi] - &*m.vert.begin(); + int seedIndex = tri::Index(m,sources[vi]); if(seedMaxima[seedIndex].first < (*vi).Q()) { seedMaxima[seedIndex].first=(*vi).Q();