From 122ab14d92ff2ec11dba58a793488e52f9042070 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 11 Apr 2023 12:32:34 +0200 Subject: [PATCH] Part: add functions to return the number of nodes and triangles of a tessellation --- src/Mod/Part/App/TopoShapeEdgePy.xml | 5 ++++ src/Mod/Part/App/TopoShapeEdgePyImp.cpp | 17 +++++++++++++ src/Mod/Part/App/TopoShapeFacePy.xml | 10 ++++++++ src/Mod/Part/App/TopoShapeFacePyImp.cpp | 34 +++++++++++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/src/Mod/Part/App/TopoShapeEdgePy.xml b/src/Mod/Part/App/TopoShapeEdgePy.xml index 8b56e40f09..e4dfa01168 100644 --- a/src/Mod/Part/App/TopoShapeEdgePy.xml +++ b/src/Mod/Part/App/TopoShapeEdgePy.xml @@ -347,6 +347,11 @@ Part.show(s) + + + Returns the number of nodes of the 3D polygon of the edge. + + Splits the edge at the given parameter values and builds a wire out of it diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index 67e4ea5bba..6a2da3a0e7 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -630,6 +630,23 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds) return nullptr; } +PyObject* TopoShapeEdgePy::countNodes(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + const TopoDS_Shape& shape = this->getTopoShapePtr()->getShape(); + TopoDS_Edge aEdge = TopoDS::Edge(shape); + TopLoc_Location aLoc; + const Handle(Poly_Polygon3D)& aPoly = BRep_Tool::Polygon3D(aEdge, aLoc); + int count = 0; + if (!aPoly.IsNull()) { + count = aPoly->NbNodes(); + } + + return Py::new_reference_to(Py::Long(count)); +} + PyObject* TopoShapeEdgePy::split(PyObject *args) { PyObject* float_or_list; diff --git a/src/Mod/Part/App/TopoShapeFacePy.xml b/src/Mod/Part/App/TopoShapeFacePy.xml index cc6c1655f6..1ce5a796d7 100644 --- a/src/Mod/Part/App/TopoShapeFacePy.xml +++ b/src/Mod/Part/App/TopoShapeFacePy.xml @@ -107,6 +107,16 @@ validate() + + + Returns the number of nodes of the triangulation. + + + + + Returns the number of triangles of the triangulation. + + Returns the curve associated to the edge in the parametric space of the face. diff --git a/src/Mod/Part/App/TopoShapeFacePyImp.cpp b/src/Mod/Part/App/TopoShapeFacePyImp.cpp index 127e41db41..1192deef5e 100644 --- a/src/Mod/Part/App/TopoShapeFacePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeFacePyImp.cpp @@ -757,6 +757,40 @@ PyObject* TopoShapeFacePy::validate(PyObject *args) } } +PyObject* TopoShapeFacePy::countNodes(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + const TopoDS_Shape& shape = this->getTopoShapePtr()->getShape(); + TopoDS_Face aFace = TopoDS::Face(shape); + TopLoc_Location aLoc; + const Handle(Poly_Triangulation)& aTriangulation = BRep_Tool::Triangulation(aFace, aLoc); + int count = 0; + if (!aTriangulation.IsNull()) { + count = aTriangulation->NbNodes(); + } + + return Py::new_reference_to(Py::Long(count)); +} + +PyObject* TopoShapeFacePy::countTriangles(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + const TopoDS_Shape& shape = this->getTopoShapePtr()->getShape(); + TopoDS_Face aFace = TopoDS::Face(shape); + TopLoc_Location aLoc; + const Handle(Poly_Triangulation)& aTriangulation = BRep_Tool::Triangulation(aFace, aLoc); + int count = 0; + if (!aTriangulation.IsNull()) { + count = aTriangulation->NbTriangles(); + } + + return Py::new_reference_to(Py::Long(count)); +} + PyObject* TopoShapeFacePy::curveOnSurface(PyObject *args) { PyObject* e;