diff --git a/vcg/complex/trimesh/clean.h b/vcg/complex/trimesh/clean.h index af31c709..d4515faf 100644 --- a/vcg/complex/trimesh/clean.h +++ b/vcg/complex/trimesh/clean.h @@ -225,6 +225,7 @@ Initial Release #include #include #include +#include #include #include #include @@ -1339,6 +1340,46 @@ static bool ShareVertex(FaceType *f0,FaceType *f1) } +/** + This function merge all the vertices that are closer than the given radius +*/ +static int MergeCloseVertex(MeshType &m, const ScalarType radius) + { + typedef vcg::SpatialHashTable SampleSHT; + SampleSHT sht; + tri::VertTmark markerFunctor; + typedef vcg::vertex::PointDistanceFunctor VDistFunct; + std::vector closests; + int mergedCnt=0; + VDistFunct distFunctor; + Point3f closestPt; + 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()) + { + (*viv).SetV(); + Point3f p = viv->cP(); + Box3f bb(p-Point3f(radius,radius,radius),p+Point3f(radius,radius,radius)); + GridGetInBox(sht, markerFunctor, bb, closests); + // qDebug("Vertex %i has %i closest", &*viv - &*m.vert.begin(),closests.size()); + for(int i=0; icP()); + if(dist < radius && !closests[i]->IsV()) + { + mergedCnt++; + closests[i]->SetV(); + closests[i]->P()=p; + closests[i]->C()=Color4b::Green; + } + } + } + + RemoveDuplicateVertex(m,true); + return mergedCnt; + } + }; // end class /*@}*/