From f560398f30af59b1592ded50d21f5e28363437cf Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 2 Mar 2017 22:33:38 +0100 Subject: [PATCH] add boolean parameter to MeshKernel::AddFacets to disable check for manifold edges of new faces --- src/Mod/Mesh/App/Core/MeshKernel.cpp | 25 ++++++++++++++++++++++--- src/Mod/Mesh/App/Core/MeshKernel.h | 5 +++-- src/Mod/Mesh/App/Core/TopoAlgorithm.cpp | 2 +- src/Mod/Mesh/App/Exporter.cpp | 4 ++-- src/Mod/Mesh/App/Mesh.cpp | 15 +++++++++------ src/Mod/Mesh/App/Mesh.h | 9 ++++++--- src/Mod/Mesh/App/MeshPyImp.cpp | 5 +++-- src/Mod/Mesh/Gui/MeshEditor.cpp | 2 +- src/Mod/Mesh/Gui/ViewProvider.cpp | 2 +- 9 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/Mod/Mesh/App/Core/MeshKernel.cpp b/src/Mod/Mesh/App/Core/MeshKernel.cpp index f84965840..32308f876 100644 --- a/src/Mod/Mesh/App/Core/MeshKernel.cpp +++ b/src/Mod/Mesh/App/Core/MeshKernel.cpp @@ -173,12 +173,29 @@ void MeshKernel::AddFacets(const std::vector &rclFAry) Merge(tmp); } -unsigned long MeshKernel::AddFacets(const std::vector &rclFAry) +unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, + bool checkManifolds) { // Build map of edges of the referencing facets we want to append #ifdef FC_DEBUG unsigned long countPoints = CountPoints(); #endif + + // if the manifold check shouldn't be done then just add all faces + if (!checkManifolds) { + unsigned long countFacets = CountFacets(); + unsigned long countValid = rclFAry.size(); + _aclFacetArray.reserve(countFacets + countValid); + + // just add all faces now + for (std::vector::const_iterator pF = rclFAry.begin(); pF != rclFAry.end(); ++pF) { + _aclFacetArray.push_back(*pF); + } + + RebuildNeighbours(countFacets); + return _aclFacetArray.size(); + } + this->_aclPointArray.ResetInvalid(); unsigned long k = CountFacets(); std::map, std::list > edgeMap; @@ -316,12 +333,14 @@ unsigned long MeshKernel::AddFacets(const std::vector &rclFAry) return _aclFacetArray.size(); } -unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, const std::vector& rclPAry) +unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, + const std::vector& rclPAry, + bool checkManifolds) { for (std::vector::const_iterator it = rclPAry.begin(); it != rclPAry.end(); ++it) _clBoundBox.Add(*it); this->_aclPointArray.insert(this->_aclPointArray.end(), rclPAry.begin(), rclPAry.end()); - return this->AddFacets(rclFAry); + return this->AddFacets(rclFAry, checkManifolds); } void MeshKernel::Merge(const MeshKernel& rKernel) diff --git a/src/Mod/Mesh/App/Core/MeshKernel.h b/src/Mod/Mesh/App/Core/MeshKernel.h index a229b40e1..821392cf0 100644 --- a/src/Mod/Mesh/App/Core/MeshKernel.h +++ b/src/Mod/Mesh/App/Core/MeshKernel.h @@ -290,7 +290,7 @@ public: * This method might be useful to close gaps or fill up holes in a mesh. * @note This method is quite expensive and should be rarely used. */ - unsigned long AddFacets(const std::vector &rclFAry); + unsigned long AddFacets(const std::vector &rclFAry, bool checkManifolds); /** * Adds new points and facets to the data structure. The client programmer must make sure * that all new points are referenced by the new facets. @@ -306,7 +306,8 @@ public: * @note This method is quite expensive and should be rarely used. */ unsigned long AddFacets(const std::vector &rclFAry, - const std::vector& rclPAry); + const std::vector& rclPAry, + bool checkManifolds); /** * Adds all facets and referenced points to the underlying mesh structure. The client programmer * must be sure that both meshes don't have geometric overlaps, otherwise the resulting mesh might diff --git a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp index ed043c293..4d75e8a8a 100644 --- a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp +++ b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp @@ -1337,7 +1337,7 @@ void MeshTopoAlgorithm::FillupHoles(int level, AbstractPolygonTriangulator& cTri addFacets.push_back(*it); } } - _rclMesh.AddFacets(addFacets); + _rclMesh.AddFacets(addFacets, true); } } diff --git a/src/Mod/Mesh/App/Exporter.cpp b/src/Mod/Mesh/App/Exporter.cpp index bea12f40e..b769082b6 100644 --- a/src/Mod/Mesh/App/Exporter.cpp +++ b/src/Mod/Mesh/App/Exporter.cpp @@ -179,7 +179,7 @@ bool MergeExporter::addPartFeat(App::DocumentObject *obj, float tol) std::vector aTopo; geoData->getFaces(aPoints, aTopo, tol); - mesh->addFacets(aTopo, aPoints); + mesh->addFacets(aTopo, aPoints, false); if (countFacets == 0) mergingMesh = *mesh; else @@ -268,7 +268,7 @@ bool AmfExporter::addPartFeat(App::DocumentObject *obj, float tol) std::vector aTopo; geoData->getFaces(aPoints, aTopo, tol); - mesh->addFacets(aTopo, aPoints); + mesh->addFacets(aTopo, aPoints, false); } else { return false; } diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 4b353ce39..468f26191 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -519,19 +519,22 @@ void MeshObject::addFacets(const std::vector& facets) _kernel.AddFacets(facets); } -void MeshObject::addFacets(const std::vector &facets) +void MeshObject::addFacets(const std::vector &facets, + bool checkManifolds) { - _kernel.AddFacets(facets); + _kernel.AddFacets(facets, checkManifolds); } void MeshObject::addFacets(const std::vector &facets, - const std::vector& points) + const std::vector& points, + bool checkManifolds) { - _kernel.AddFacets(facets, points); + _kernel.AddFacets(facets, points, checkManifolds); } void MeshObject::addFacets(const std::vector &facets, - const std::vector& points) + const std::vector& points, + bool checkManifolds) { std::vector facet_v; facet_v.reserve(facets.size()); @@ -550,7 +553,7 @@ void MeshObject::addFacets(const std::vector &facet point_v.push_back(p); } - _kernel.AddFacets(facet_v, point_v); + _kernel.AddFacets(facet_v, point_v, checkManifolds); } void MeshObject::setFacets(const std::vector& facets) diff --git a/src/Mod/Mesh/App/Mesh.h b/src/Mod/Mesh/App/Mesh.h index dacb8dc7b..1cfcb8549 100644 --- a/src/Mod/Mesh/App/Mesh.h +++ b/src/Mod/Mesh/App/Mesh.h @@ -169,11 +169,14 @@ public: //@{ void addFacet(const MeshCore::MeshGeomFacet& facet); void addFacets(const std::vector& facets); - void addFacets(const std::vector &facets); void addFacets(const std::vector &facets, - const std::vector& points); + bool checkManifolds); + void addFacets(const std::vector &facets, + const std::vector& points, + bool checkManifolds); void addFacets(const std::vector &facets, - const std::vector& points); + const std::vector& points, + bool checkManifolds); void setFacets(const std::vector& facets); void setFacets(const std::vector &facets, const std::vector& points); diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index cc44ef83e..d6373575c 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -678,7 +678,8 @@ PyObject* MeshPy::addFacets(PyObject *args) } PyErr_Clear(); - if (PyArg_ParseTuple(args, "O!", &PyTuple_Type, &list)) { + PyObject *check = Py_True; + if (PyArg_ParseTuple(args, "O!|O!", &PyTuple_Type, &list, &PyBool_Type, &check)) { Py::Tuple tuple(list); Py::List list_v(tuple.getItem(0)); std::vector vertices; @@ -708,7 +709,7 @@ PyObject* MeshPy::addFacets(PyObject *args) faces.push_back(face); } - getMeshObjectPtr()->addFacets(faces, vertices); + getMeshObjectPtr()->addFacets(faces, vertices, PyObject_IsTrue(check) ? true : false); Py_Return; } diff --git a/src/Mod/Mesh/Gui/MeshEditor.cpp b/src/Mod/Mesh/Gui/MeshEditor.cpp index 038ceb7c1..35efd14ed 100644 --- a/src/Mod/Mesh/Gui/MeshEditor.cpp +++ b/src/Mod/Mesh/Gui/MeshEditor.cpp @@ -231,7 +231,7 @@ void MeshFaceAddition::addFace() f._aulPoints[2] = faceView->index[2]; std::vector faces; faces.push_back(f); - mesh->addFacets(faces); + mesh->addFacets(faces, true); mf->Mesh.finishEditing(); doc->commitTransaction(); diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index c31bc7c0b..eb0e995e1 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -1609,7 +1609,7 @@ void ViewProviderMesh::fillHole(unsigned long uFacet) //add the facets to the mesh and open a transaction object for the undo/redo stuff Gui::Application::Instance->activeDocument()->openCommand("Fill hole"); Mesh::MeshObject* kernel = fea->Mesh.startEditing(); - kernel->addFacets(newFacets, newPoints); + kernel->addFacets(newFacets, newPoints, true); fea->Mesh.finishEditing(); Gui::Application::Instance->activeDocument()->commitCommand(); }