Geom_BSplineSurface basic usage


I have a grid op points in X, Y-coordinates with corresponding z values, as well as points that describe the border around the surface.
My aim is to get a TopoDS_Face out of it.
What I tried to understand how it works ist to use this python example and translate it to C++

TColgp_Array2OfPnt array1 = TColgp_Array2OfPnt(1, 4, 1, 4);

array1.SetValue(1, 1, gp_Pnt(1, 1, -1));
array1.SetValue(1, 2, gp_Pnt(2, 1, 0));
array1.SetValue(1, 3, gp_Pnt(3, 1, -1));
array1.SetValue(1, 4, gp_Pnt(4, 1, 0));
array1.SetValue(2, 1, gp_Pnt(1, 2, 3));
array1.SetValue(2, 2, gp_Pnt(2, 2, 5));
array1.SetValue(2, 3, gp_Pnt(3, 2, 2));
array1.SetValue(2, 4, gp_Pnt(4, 2, 3));
array1.SetValue(3, 1, gp_Pnt(1, 3, 2));
array1.SetValue(3, 2, gp_Pnt(2, 3, 1));
array1.SetValue(3, 3, gp_Pnt(3, 3, 0));
array1.SetValue(3, 4, gp_Pnt(4, 3, 1));
array1.SetValue(4, 1, gp_Pnt(1, 4, 0));
array1.SetValue(4, 2, gp_Pnt(2, 4, -1));
array1.SetValue(4, 3, gp_Pnt(3, 4, 0));
array1.SetValue(4, 4, gp_Pnt(4, 4, -1));

Geom_BezierSurface BZ1 = Geom_BezierSurface(array1);

TColGeom_Array2OfBezierSurface bezierarray = TColGeom_Array2OfBezierSurface(1,1,1,1);
bezierarray.SetValue(1,1, &BZ1);

GeomConvert_CompBezierSurfacesToBSplineSurface BB = GeomConvert_CompBezierSurfacesToBSplineSurface(bezierarray);
if (BB.IsDone())
    TColgp_Array2OfPnt poles = BB.Poles()->Array2();
    TColStd_Array1OfReal uknots = BB.UKnots()->Array1();
    TColStd_Array1OfReal vknots = BB.VKnots()->Array1();
    TColStd_Array1OfInteger umult = BB.UMultiplicities()->Array1();
    TColStd_Array1OfInteger vmult = BB.VMultiplicities()->Array1();
    Standard_Integer udeg = BB.UDegree();
    Standard_Integer vdeg = BB.VDegree();

    Geom_BSplineSurface BSplineSurf = Geom_BSplineSurface( poles, uknots, vknots, umult, vmult, udeg, vdeg, 0, 0 );

    BRepBuilderAPI_MakeFace Face(&BZ1, 0.1);

    aBuilder.Add(*m_cad_part, Face);

Howevet that code crashes at

TColGeom_Array2OfBezierSurface bezierarray = TColGeom_Array2OfBezierSurface(1,1,1,1);

and I do not understand what that array is supposed for?
Further I'm not sure if the approach even makes sense for my task.

So is there maybe some c++ example on how to make a free-formed surface using BSpline or any other method that works?

I could solve the problem myself. The error I got was caused due to bezierarray running out of scope at the end of the function and i did not allocate the array correctly via new operator and handle.

Mikhail Sazonov's picture


The example with python is not appropriate to solve the aimed task.
To solve the task it is better to use a special class GeomPlate_BuildPlateSurface. With it, you can define an initial surface like simple plane that is average for all points, put all constraint points and boundaries, and build the target bspline surface.
As for example with code got from python, it is needed to use handles to operate with objects, e.g. use

Handle(Geom_BezierSurface) BZ1 = new Geom_BezierSurface(array1);

instead of

Geom_BezierSurface BZ1 = Geom_BezierSurface(array1);

It is the main cause of the crash.

For additional consulting please use our support programs -

Best Regards,
Mikhail Sazonov
Open Cascade Architect