Skip to content

Commit 6a58cbe

Browse files
committed
(rational) Bezier surface in netgen.occ
1 parent 0572886 commit 6a58cbe

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

libsrc/occ/python_occ_shapes.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <GeomAPI_PointsToBSplineSurface.hxx>
7171
#include <GeomLProp_SLProps.hxx>
7272
#include <Geom_BezierCurve.hxx>
73+
#include <Geom_BezierSurface.hxx>
7374
#include <Geom_BSplineCurve.hxx>
7475
#include <Geom_BSplineSurface.hxx>
7576
#include <Geom_Plane.hxx>
@@ -2474,6 +2475,36 @@ tangents : Dict[int, gp_Vec2d]
24742475
return BRepBuilderAPI_MakeEdge(curve).Edge();
24752476
}, py::arg("points"), "create Bezier curve");
24762477

2478+
m.def("BezierSurface", [](py::array_t<double> nppoles,
2479+
optional<py::array_t<double>> npweights,
2480+
double tol)
2481+
{
2482+
if(nppoles.ndim() != 3)
2483+
throw std::length_error("`poles` array must have dimension 3.");
2484+
if(nppoles.shape(2) != 3)
2485+
throw std::length_error("The third dimension must have size 3.");
2486+
if(npweights && npweights->ndim() != 2)
2487+
throw std::length_error("`weights` array must have dimension 2.");
2488+
2489+
auto deg_u = nppoles.shape(0) - 1;
2490+
auto deg_v = nppoles.shape(1) - 1;
2491+
TColgp_Array2OfPnt poles(1, deg_u + 1, 1, deg_v + 1);
2492+
TColStd_Array2OfReal weights(1, deg_u + 1, 1, deg_v + 1);
2493+
for(int i = 0; i < nppoles.shape(0); ++i)
2494+
for(int j = 0; j < nppoles.shape(1); ++j)
2495+
{
2496+
poles.SetValue(i + 1, j + 1, gp_Pnt(nppoles.at(i, j, 0), nppoles.at(i, j, 1), nppoles.at(i, j, 2)));
2497+
if(npweights)
2498+
weights.SetValue(i + 1, j + 1, npweights->at(i, j));
2499+
else
2500+
weights.SetValue(i + 1, j + 1, 1.0);
2501+
}
2502+
Handle(Geom_Surface) surface = new Geom_BezierSurface(poles, weights);
2503+
return BRepBuilderAPI_MakeFace(surface, tol).Face();
2504+
}, py::arg("poles"), py::arg("weights")=std::nullopt,
2505+
py::arg("tol")=1e-7,
2506+
"Creates a rational Bezier surface with the set of poles and the set of weights. The weights are defaulted to all being 1. If all the weights are identical the surface is considered as non rational. Raises ConstructionError if the number of poles in any direction is greater than MaxDegree + 1 or lower than 2 or CurvePoles and CurveWeights have not the same length or one weight value is lower or equal to Resolution. Returns an occ face with the given tolerance.");
2507+
24772508

24782509
m.def("SplineApproximation", [](const std::vector<gp_Pnt> &points, Approx_ParametrizationType approx_type, int deg_min,
24792510
int deg_max, GeomAbs_Shape continuity, double tol) {

0 commit comments

Comments
 (0)