From 40b878de4dcac36c064eab961364e88e5d58295c Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 8 Aug 2016 16:40:59 +0200 Subject: [PATCH] add method to get self-intersections of a mesh via Python --- src/Mod/Mesh/App/MeshPy.xml | 7 ++++++- src/Mod/Mesh/App/MeshPyImp.cpp | 36 +++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/Mod/Mesh/App/MeshPy.xml b/src/Mod/Mesh/App/MeshPy.xml index 564b5743d..5be3fd178 100644 --- a/src/Mod/Mesh/App/MeshPy.xml +++ b/src/Mod/Mesh/App/MeshPy.xml @@ -230,7 +230,12 @@ for c in mesh.getSeparatecomponents(): Check if the mesh intersects itself - + + + Returns a tuple of indices of intersecting triangles + + + Repair self-intersections diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index 9af26708c..3a799e088 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -583,7 +583,15 @@ PyObject* MeshPy::addFacet(PyObject *args) Py_Return; } - PyErr_SetString(Base::BaseExceptionFreeCADError, "set 9 floats or three vectors"); + PyErr_Clear(); + PyObject *f; + if (PyArg_ParseTuple(args, "O!",&(Mesh::FacetPy::Type), &f)) { + Mesh::FacetPy* face = static_cast(f); + getMeshObjectPtr()->addFacet(*face->getFacetPtr()); + Py_Return; + } + + PyErr_SetString(Base::BaseExceptionFreeCADError, "set 9 floats or three vectors or a facet"); return 0; } @@ -921,6 +929,32 @@ PyObject* MeshPy::hasSelfIntersections(PyObject *args) return Py_BuildValue("O", (ok ? Py_True : Py_False)); } +PyObject* MeshPy::getSelfIntersections(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + std::vector > selfIndices; + std::vector > selfPoints; + MeshCore::MeshEvalSelfIntersection eval(getMeshObjectPtr()->getKernel()); + eval.GetIntersections(selfIndices); + eval.GetIntersections(selfIndices, selfPoints); + + Py::Tuple tuple(selfIndices.size()); + if (selfIndices.size() == selfPoints.size()) { + for (std::size_t i=0; i