diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 6111dc5271..0138a99eda 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -1436,6 +1436,32 @@ bool MeshObject::hasSelfIntersections() const return !cMeshEval.Evaluate(); } +MeshObject::TFacePairs MeshObject::getSelfIntersections() const +{ + MeshCore::MeshEvalSelfIntersection eval(getKernel()); + MeshObject::TFacePairs pairs; + eval.GetIntersections(pairs); + return pairs; +} + +std::vector MeshObject::getSelfIntersections(const MeshObject::TFacePairs& facets) const +{ + MeshCore::MeshEvalSelfIntersection eval(getKernel()); + using Section = std::pair; + std::vector
selfPoints; + eval.GetIntersections(facets, selfPoints); + + std::vector lines; + lines.reserve(selfPoints.size()); + + Base::Matrix4D mat(getTransform()); + std::transform(selfPoints.begin(), selfPoints.end(), std::back_inserter(lines), [&mat](const Section& l){ + return Base::Line3d(mat * Base::convertTo(l.first), + mat * Base::convertTo(l.second)); + }); + return lines; +} + void MeshObject::removeSelfIntersections() { std::vector > selfIntersections; diff --git a/src/Mod/Mesh/App/Mesh.h b/src/Mod/Mesh/App/Mesh.h index 5e1f472c74..79ed1f030b 100644 --- a/src/Mod/Mesh/App/Mesh.h +++ b/src/Mod/Mesh/App/Mesh.h @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -88,9 +88,12 @@ public: enum GeometryType {PLANE, CYLINDER, SPHERE}; enum CutType {INNER, OUTER}; + using TFacePair = std::pair; + using TFacePairs = std::vector; + // typedef needed for cross-section - typedef std::pair TPlane; - typedef std::list > TPolylines; + using TPlane = std::pair; + using TPolylines = std::list>; MeshObject(); explicit MeshObject(const MeshCore::MeshKernel& Kernel); @@ -308,6 +311,8 @@ public: void removeNonManifolds(); void removeNonManifoldPoints(); bool hasSelfIntersections() const; + TFacePairs getSelfIntersections() const; + std::vector getSelfIntersections(const TFacePairs&) const; void removeSelfIntersections(); void removeSelfIntersections(const std::vector&); void removeFoldsOnSurface(); diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index b3df908f5c..46b527b307 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -1043,19 +1043,19 @@ PyObject* MeshPy::getSelfIntersections(PyObject *args) return nullptr; std::vector > selfIndices; - std::vector > selfPoints; - MeshCore::MeshEvalSelfIntersection eval(getMeshObjectPtr()->getKernel()); - eval.GetIntersections(selfIndices); - eval.GetIntersections(selfIndices, selfPoints); + std::vector selfLines; + + selfIndices = getMeshObjectPtr()->getSelfIntersections(); + selfLines = getMeshObjectPtr()->getSelfIntersections(selfIndices); Py::Tuple tuple(selfIndices.size()); - if (selfIndices.size() == selfPoints.size()) { + if (selfIndices.size() == selfLines.size()) { for (std::size_t i=0; i