From fbdfeef2a3db7d2c694f71c31bff2d6bcbf666f0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 9 May 2015 00:58:07 +0200 Subject: [PATCH] + add method getPolesAndWeights() to NURBS surfaces and curves --- src/Mod/Part/App/BSplineCurvePy.xml | 5 ++++ src/Mod/Part/App/BSplineCurvePyImp.cpp | 32 +++++++++++++++++++++ src/Mod/Part/App/BSplineSurfacePy.xml | 5 ++++ src/Mod/Part/App/BSplineSurfacePyImp.cpp | 36 ++++++++++++++++++++++++ 4 files changed, 78 insertions(+) diff --git a/src/Mod/Part/App/BSplineCurvePy.xml b/src/Mod/Part/App/BSplineCurvePy.xml index 6977773ee..2e5cb2ff5 100644 --- a/src/Mod/Part/App/BSplineCurvePy.xml +++ b/src/Mod/Part/App/BSplineCurvePy.xml @@ -201,6 +201,11 @@ to the pole of index Index in the poles table. Get all weights of the B-Spline curve. + + + Returns the table of poles and weights in homogenous ccordinates. + + Computes for this B-Spline curve the parametric tolerance (UTolerance) diff --git a/src/Mod/Part/App/BSplineCurvePyImp.cpp b/src/Mod/Part/App/BSplineCurvePyImp.cpp index fbb3c062b..15c62b21c 100644 --- a/src/Mod/Part/App/BSplineCurvePyImp.cpp +++ b/src/Mod/Part/App/BSplineCurvePyImp.cpp @@ -435,6 +435,38 @@ PyObject* BSplineCurvePy::getPoles(PyObject * args) } } +PyObject* BSplineCurvePy::getPolesAndWeights(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + TColgp_Array1OfPnt p(1,curve->NbPoles()); + curve->Poles(p); + TColStd_Array1OfReal w(1,curve->NbPoles()); + curve->Weights(w); + + Py::List poles; + for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) { + gp_Pnt pnt = p(i); + double weight = w(i); + Py::Tuple t(4); + t.setItem(0, Py::Float(pnt.X())); + t.setItem(1, Py::Float(pnt.Y())); + t.setItem(2, Py::Float(pnt.Z())); + t.setItem(3, Py::Float(weight)); + poles.append(t); + } + return Py::new_reference_to(poles); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + PyObject* BSplineCurvePy::setWeight(PyObject * args) { int index; diff --git a/src/Mod/Part/App/BSplineSurfacePy.xml b/src/Mod/Part/App/BSplineSurfacePy.xml index 4b73d4bf8..f21c7b9dd 100644 --- a/src/Mod/Part/App/BSplineSurfacePy.xml +++ b/src/Mod/Part/App/BSplineSurfacePy.xml @@ -491,6 +491,11 @@ Returns the table of weights of the poles for this B-Spline surface. + + + Returns the table of poles and weights in homogenous ccordinates. + + diff --git a/src/Mod/Part/App/BSplineSurfacePyImp.cpp b/src/Mod/Part/App/BSplineSurfacePyImp.cpp index fc14b0a00..c77de2012 100644 --- a/src/Mod/Part/App/BSplineSurfacePyImp.cpp +++ b/src/Mod/Part/App/BSplineSurfacePyImp.cpp @@ -917,6 +917,42 @@ PyObject* BSplineSurfacePy::getWeights(PyObject *args) } } +PyObject* BSplineSurfacePy::getPolesAndWeights(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BSplineSurface surf = Handle_Geom_BSplineSurface::DownCast + (getGeometryPtr()->handle()); + TColgp_Array2OfPnt p(1,surf->NbUPoles(),1,surf->NbVPoles()); + surf->Poles(p); + TColStd_Array2OfReal w(1,surf->NbUPoles(),1,surf->NbVPoles()); + surf->Weights(w); + + Py::List poles; + for (Standard_Integer i=p.LowerRow(); i<=p.UpperRow(); i++) { + Py::List row; + for (Standard_Integer j=p.LowerCol(); j<=p.UpperCol(); j++) { + const gp_Pnt& pole = p(i,j); + double weight = w(i,j); + Py::Tuple t(4); + t.setItem(0, Py::Float(pole.X())); + t.setItem(1, Py::Float(pole.Y())); + t.setItem(2, Py::Float(pole.Z())); + t.setItem(3, Py::Float(weight)); + row.append(t); + } + poles.append(row); + } + return Py::new_reference_to(poles); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + PyObject* BSplineSurfacePy::getResolution(PyObject *args) { double tol;