From 60707fc256466e1e6691655bb8de563ab26db6ad Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 20 Aug 2015 08:49:22 +0200 Subject: [PATCH] + algorithm to split a segment from the mesh --- src/Mod/Mesh/Gui/MeshSelection.cpp | 52 ++++++++++++++++++++++++++++++ src/Mod/Mesh/Gui/MeshSelection.h | 1 + 2 files changed, 53 insertions(+) diff --git a/src/Mod/Mesh/Gui/MeshSelection.cpp b/src/Mod/Mesh/Gui/MeshSelection.cpp index 976ea2ee5..b3cb4524f 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.cpp +++ b/src/Mod/Mesh/Gui/MeshSelection.cpp @@ -249,6 +249,58 @@ bool MeshSelection::deleteSelection() return true; } +bool MeshSelection::deleteSelectionBorder() +{ + // delete all selected faces + bool deletion = false; + std::list views = getViewProviders(); + for (std::list::iterator it = views.begin(); it != views.end(); ++it) { + Mesh::Feature* mf = static_cast((*it)->getObject()); + + // mark the selected facet as visited + std::vector selection, remove; + std::set borderPoints; + MeshCore::MeshAlgorithm meshAlg(mf->Mesh.getValue().getKernel()); + meshAlg.GetFacetsFlag(selection, MeshCore::MeshFacet::SELECTED); + meshAlg.GetBorderPoints(selection, borderPoints); + std::vector border; + border.insert(border.begin(), borderPoints.begin(), borderPoints.end()); + + meshAlg.ResetFacetFlag(MeshCore::MeshFacet::VISIT); + meshAlg.SetFacetsFlag(selection, MeshCore::MeshFacet::VISIT); + meshAlg.ResetPointFlag(MeshCore::MeshPoint::VISIT); + meshAlg.SetPointsFlag(border, MeshCore::MeshPoint::VISIT); + + // collect neighbour facets that are not selected and that share a border point + const MeshCore::MeshPointArray& points = mf->Mesh.getValue().getKernel().GetPoints(); + const MeshCore::MeshFacetArray& faces = mf->Mesh.getValue().getKernel().GetFacets(); + unsigned long numFaces = faces.size(); + for (unsigned long i = 0; i < numFaces; i++) { + const MeshCore::MeshFacet& face = faces[i]; + if (!face.IsFlag(MeshCore::MeshFacet::VISIT)) { + for (int j=0; j<3; j++) { + if (points[face._aulPoints[j]].IsFlag(MeshCore::MeshPoint::VISIT)) { + remove.push_back(i); + break; + } + } + } + } + + if (!remove.empty()) { + deletion = true; + // remove duplicates + std::sort(remove.begin(), remove.end()); + remove.erase(std::unique(remove.begin(), remove.end()), remove.end()); + + (*it)->setSelection(remove); + (*it)->deleteSelection(); + } + } + + return deletion; +} + void MeshSelection::invertSelection() { std::list views = getViewProviders(); diff --git a/src/Mod/Mesh/Gui/MeshSelection.h b/src/Mod/Mesh/Gui/MeshSelection.h index ea31a3991..92a81a3f9 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.h +++ b/src/Mod/Mesh/Gui/MeshSelection.h @@ -49,6 +49,7 @@ public: void startDeselection(); void stopSelection(); bool deleteSelection(); + bool deleteSelectionBorder(); void fullSelection(); void clearSelection(); void invertSelection();