diff --git a/vcg/complex/algorithms/clean.h b/vcg/complex/algorithms/clean.h index 40c57dc6..25493000 100644 --- a/vcg/complex/algorithms/clean.h +++ b/vcg/complex/algorithms/clean.h @@ -436,33 +436,51 @@ public: return count_removed; } - static int SplitSelectedVertexOnEdgeMesh(MeshType& m) - { - tri::RequireCompactness(m); - tri::UpdateFlags::VertexClearV(m); - int count_split = 0; - for(size_t i=0;iIsS()) - { - if(!vp->IsV()) - { - m.edge[i].V(j) = &*(tri::Allocator::AddVertex(m,vp->P())); - ++count_split; - } - else - { - vp->SetV(); - } - - } - } - } - return count_split; - } + + static int SplitSelectedVertexOnEdgeMesh(MeshType& m) + { + tri::RequireCompactness(m); + + // count selected vertices references + std::unordered_map refCount; // selected vertex index -> reference count + size_t countSplit = 0; + for (size_t i=0; iIsS()) + { + const size_t refs = ++refCount[Index(m, m.edge[i].V(j))]; + if (refs > 1) { + countSplit++; + } + } + } + } + // actual split + if (countSplit > 0) + { + auto newVertIt = tri::Allocator::AddVertices(m, countSplit); + for (size_t i=0; iIsS()) + { + if (--refCount[vIdx] > 0) + { + newVertIt->ImportData(*vp); + m.edge[i].V(j) = &*(newVertIt++); + } + } + } + } + } + return int(countSplit); + } static void SelectNonManifoldVertexOnEdgeMesh(MeshType &m) @@ -485,6 +503,7 @@ public: tri::RequireCompactness(m); tri::RequireVEAdjacency(m); tri::UpdateTopology::VertexEdge(m); + tri::UpdateSelection::VertexClear(m); for(size_t i=0;i VVStarVec;