Skip to content

Commit

Permalink
Part: add functions to return the number of nodes and triangles of a …
Browse files Browse the repository at this point in the history
…tessellation
  • Loading branch information
wwmayer committed Apr 11, 2023
1 parent 88ee605 commit 122ab14
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Mod/Part/App/TopoShapeEdgePy.xml
Expand Up @@ -347,6 +347,11 @@ Part.show(s)
</UserDocu>
</Documentation>
</Methode>
<Methode Name="countNodes" Const="true">
<Documentation>
<UserDocu>Returns the number of nodes of the 3D polygon of the edge.</UserDocu>
</Documentation>
</Methode>
<Methode Name="split" Const="true">
<Documentation>
<UserDocu>Splits the edge at the given parameter values and builds a wire out of it
Expand Down
17 changes: 17 additions & 0 deletions src/Mod/Part/App/TopoShapeEdgePyImp.cpp
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/Mod/Part/App/TopoShapeFacePy.xml
Expand Up @@ -107,6 +107,16 @@ validate()
</UserDocu>
</Documentation>
</Methode>
<Methode Name="countNodes" Const="true">
<Documentation>
<UserDocu>Returns the number of nodes of the triangulation.</UserDocu>
</Documentation>
</Methode>
<Methode Name="countTriangles" Const="true">
<Documentation>
<UserDocu>Returns the number of triangles of the triangulation.</UserDocu>
</Documentation>
</Methode>
<Methode Name="curveOnSurface" Const="true">
<Documentation>
<UserDocu>Returns the curve associated to the edge in the parametric space of the face.
Expand Down
34 changes: 34 additions & 0 deletions src/Mod/Part/App/TopoShapeFacePyImp.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 122ab14

Please sign in to comment.