add method to get u,v nodes of the tessellation of a face

add method to get the nodes of the tessellation of an edge
This commit is contained in:
wmayer
2018-01-14 15:52:08 +01:00
parent 327957110a
commit 9980b74816
4 changed files with 118 additions and 2 deletions

View File

@@ -114,7 +114,17 @@ Returns:
</UserDocu>
</Documentation>
</Methode>
<Methode Name="parameterAt" Const="true">
<Methode Name="parameters" Const="true">
<Documentation>
<UserDocu>
parameters([face]) --&gt; list
Get the list of parameters of the tessellation of an edge. If the edge is part of
a face then this face is required as argument.
An exception is raised if the edge has no polygon.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="parameterAt" Const="true">
<Documentation>
<UserDocu>Float = parameterAt(Vertex) - Get the parameter at the given vertex if lying on the edge</UserDocu>
</Documentation>

View File

@@ -49,11 +49,17 @@
# include <gp_Hypr.hxx>
# include <gp_Parab.hxx>
# include <gp_Lin.hxx>
# include <Poly_Polygon2D.hxx>
# include <Poly_Polygon3D.hxx>
# include <Poly_Triangulation.hxx>
# include <Poly_PolygonOnTriangulation.hxx>
# include <TColStd_Array1OfReal.hxx>
# include <TopExp.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Shape.hxx>
# include <TopoDS_Edge.hxx>
# include <TopoDS_Vertex.hxx>
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
# include <ShapeAnalysis_Edge.hxx>
# include <Standard_Failure.hxx>
# include <Standard_Version.hxx>
@@ -221,6 +227,65 @@ PyObject* TopoShapeEdgePy::valueAt(PyObject *args)
return new Base::VectorPy(new Base::Vector3d(V.X(),V.Y(),V.Z()));
}
PyObject* TopoShapeEdgePy::parameters(PyObject *args)
{
PyObject* pyface = 0;
if (!PyArg_ParseTuple(args, "|O!", &(TopoShapeFacePy::Type), &pyface))
return 0;
const TopoDS_Edge& e = TopoDS::Edge(getTopoShapePtr()->getShape());
TopLoc_Location aLoc;
Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(e, aLoc);
if (!aPoly.IsNull()) {
Py::List list;
if (!aPoly->HasParameters()) {
return Py::new_reference_to(list);
}
const TColStd_Array1OfReal& aNodes = aPoly->Parameters();
for (int i=aNodes.Lower(); i<=aNodes.Upper(); i++) {
list.append(Py::Float(aNodes(i)));
}
return Py::new_reference_to(list);
}
else if (pyface) {
// build up map edge->face
const TopoDS_Shape& face = static_cast<TopoShapeFacePy*>(pyface)->getTopoShapePtr()->getShape();
TopTools_IndexedDataMapOfShapeListOfShape edge2Face;
TopExp::MapShapesAndAncestors(TopoDS::Face(face), TopAbs_EDGE, TopAbs_FACE, edge2Face);
if (edge2Face.Contains(e)) {
Handle(Poly_Triangulation) aPolyTria = BRep_Tool::Triangulation(TopoDS::Face(face),aLoc);
if (!aPolyTria.IsNull()) {
Handle(Poly_PolygonOnTriangulation) aPoly = BRep_Tool::PolygonOnTriangulation(e, aPolyTria, aLoc);
if (!aPoly.IsNull()) {
if (!aPoly->HasParameters()) {
Py::List list;
return Py::new_reference_to(list);
}
Handle(TColStd_HArray1OfReal) aNodes = aPoly->Parameters();
if (!aNodes.IsNull()) {
Py::List list;
for (int i=aNodes->Lower(); i<=aNodes->Upper(); i++) {
list.append(Py::Float(aNodes->Value(i)));
}
return Py::new_reference_to(list);
}
}
}
}
else {
PyErr_SetString(PyExc_ValueError, "Edge is not part of the face");
return 0;
}
}
PyErr_SetString(PyExc_RuntimeError, "Edge has no polygon");
return 0;
}
PyObject* TopoShapeEdgePy::parameterAt(PyObject *args)
{
PyObject* pnt;

View File

@@ -19,7 +19,16 @@
<UserDocu>Offset the face by a given amount. Returns Compound of Wires. Deprecated - use makeOffset2D instead.</UserDocu>
</Documentation>
</Methode>
<Methode Name="tangentAt" Const="true">
<Methode Name="getUVNodes" Const="true">
<Documentation>
<UserDocu>
getUVNodes() --&gt; list
Get the list of (u,v) nodes of the tessellation
An exception is raised if the face is not triangulated.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="tangentAt" Const="true">
<Documentation>
<UserDocu>Get the tangent in u and v isoparametric at the given point if defined</UserDocu>
</Documentation>

View File

@@ -43,6 +43,7 @@
# include <Geom_ToroidalSurface.hxx>
# include <Geom_Surface.hxx>
# include <Geom2d_Curve.hxx>
# include <Poly_Triangulation.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
# include <TopoDS_Wire.hxx>
@@ -56,6 +57,7 @@
# include <Standard_Version.hxx>
# include <ShapeFix_Shape.hxx>
# include <ShapeFix_Wire.hxx>
# include <TColgp_Array1OfPnt2d.hxx>
# include <TopExp_Explorer.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
#endif
@@ -433,6 +435,36 @@ PyObject* TopoShapeFacePy::normalAt(PyObject *args)
}
}
PyObject* TopoShapeFacePy::getUVNodes(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
const TopoDS_Face& f = TopoDS::Face(getTopoShapePtr()->getShape());
TopLoc_Location aLoc;
Handle (Poly_Triangulation) mesh = BRep_Tool::Triangulation(f,aLoc);
if (mesh.IsNull()) {
PyErr_SetString(PyExc_RuntimeError, "Face has no triangulation");
return 0;
}
Py::List list;
if (!mesh->HasUVNodes()) {
return Py::new_reference_to(list);
}
const TColgp_Array1OfPnt2d& aNodesUV = mesh->UVNodes();
for (int i=aNodesUV.Lower(); i<=aNodesUV.Upper(); i++) {
gp_Pnt2d pt2d = aNodesUV(i);
Py::Tuple uv(2);
uv.setItem(0, Py::Float(pt2d.X()));
uv.setItem(1, Py::Float(pt2d.Y()));
list.append(uv);
}
return Py::new_reference_to(list);
}
PyObject* TopoShapeFacePy::tangentAt(PyObject *args)
{
double u,v;