|
70 | 70 | #include <GeomAPI_PointsToBSplineSurface.hxx> |
71 | 71 | #include <GeomLProp_SLProps.hxx> |
72 | 72 | #include <Geom_BezierCurve.hxx> |
| 73 | +#include <Geom_BezierSurface.hxx> |
73 | 74 | #include <Geom_BSplineCurve.hxx> |
74 | 75 | #include <Geom_BSplineSurface.hxx> |
75 | 76 | #include <Geom_Plane.hxx> |
@@ -2474,6 +2475,36 @@ tangents : Dict[int, gp_Vec2d] |
2474 | 2475 | return BRepBuilderAPI_MakeEdge(curve).Edge(); |
2475 | 2476 | }, py::arg("points"), "create Bezier curve"); |
2476 | 2477 |
|
| 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 | + |
2477 | 2508 |
|
2478 | 2509 | m.def("SplineApproximation", [](const std::vector<gp_Pnt> &points, Approx_ParametrizationType approx_type, int deg_min, |
2479 | 2510 | int deg_max, GeomAbs_Shape continuity, double tol) { |
|
0 commit comments