The problem of converting a surface obtained by intersection of an ellipsoid and a cuboid into a B-spline surface

// Constructing the sphere
gp_Sphere SphereMir(gp_Ax3(gp_Pnt(0, 0, 0), gp::DZ()), m_RadiusX);
BRepBuilderAPI_MakeFace SphereMirMaker(SphereMir);
TopoDS_Shape SphereMirrorShape = SphereMirMaker.Shape();

// Define a transformation matrix for stretching the sphere in y and z directions
gp_GTrsf trsf;
trsf.SetValue(1, 1, 1.0);
trsf.SetValue(2, 2, m_RadiusY / m_RadiusX);
trsf.SetValue(3, 3, m_RadiusZ / m_RadiusX);
TopoDS_Shape ellipsoid = BRepBuilderAPI_GTransform(SphereMirrorShape, trsf).Shape();

// Create a cuboid
TopoDS_Shape box;
gp_Pnt pCentrol_Point(Point.X() -25, Point.Y()-50, Point.Z()-25); // This Point is a point on the surface of the ellipsoid
BRepPrimAPI_MakeBox makeBox(pCentrol_Point, 50, 100, 50);
box = makeBox.Shape();

// Obtain the faces obtained by the intersection
BRepAlgoAPI_Common section(ellipsoid, box);
section.Build();
TopoDS_Face Ellipface;
TopExp_Explorer explorer(Ellipintersection, TopAbs_FACE);
while (explorer.More()) {
Ellipface = TopoDS::Face(explorer.Current());
break;
}

// Convert to a B-spline surface
BRepBuilderAPI_NurbsConvert nc;
nc.Perform(Ellipface);
TopoDS_Shape shape = nc.Shape();
TopLoc_Location loc;
Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(shape), loc);
Handle(Geom_BSplineSurface) bsplineSurface = Handle(Geom_BSplineSurface)::DownCast(surf);

// Convert the B-spline surface back to TopoDS_Face
TopoDS_Face B_Face = BRepBuilderAPI_MakeFace(bsplineSurface, Precision::Confusion());

In theory, Ellipface and B_Face should be the same shape, but now B_Face shows the same shape as ellipsoid, as shown in the attached figure, the local face in the figure represents Ellipface.

Moreover, the above problem does not occur if the sphere is not stretched using gp_GTrsf.

But I need to define the ellipsoid by defining the radius of the x, y, and z axis, so I'm not sure how to solve this problem now? If there are experts who know this aspect, I hope to communicate with you.

Thanks in advance!

Attachments: 
Mikhail Sazonov's picture

You need to understand the difference between geometry and topology.
Geom_Surface returned by BRep_Tool::Surface is the geometry on which the topological face is built. If the original surface was a closed full ellipsoid it will remain the same. The face just applies restriction using its bound edges.

Guido-X's picture

First and foremost, thank you very much for your response!
Following your advice, I retrieved the resultant local faces for a variety of parameters before employing BRep_Tool::BRepTools::UVBounds(ellipsoidIntersectionFace, uMin, uMax, vMin, vMax); surface to extract Geom_Surface
To capture the geometry of a local face, use the range parameter:
Handle(Geom_Surface) surface = BRep_Tool::Surface(ellipsoidIntersectionFace); Handle(Geom_Surface) surface = BRep_Tool::Surface(ellipsoidIntersectionFace); new Geom_Rectangular trimmedSurface = new Geom_RectangularTrimmedSurface(surface, uMin, uMax, vMin, vMax); Finally, trimmedSurface is used to build our new geometry:
newFace = newFaceMaker.Face(); BRepBuilderAPI_MakeFace newFaceMaker(trimmedSurface, Precision::Confusion()); newFace = newFaceMaker.Face();
After these actions, transitioning to a B-spline surface will be simple. Thank you for your help!

Mikhail Sazonov's picture

The NurbsConvert algorithm makes conversion of different surface types to bspline surface. If the original surface is already a bspline (as in your case with ellipsoid) it will return the same, it will not make approximation of a new surface.

Adjei Ameyaw's picture

Hello Mikhail,
I am trying to obtain the edges that are created when you use the boolean section method. I want to use the intersected edges to create a profile which I will then extrude to get a surface. Can you help me with a code that can help me do that?
Thanks

Mikhail Sazonov's picture

If you want to get section edges and connect them into a set of chains (wires) in order to extrude them into shells, it is better to use Boolean Common instead of Section. It is because Section will just give you unordered compound of edges. And Common will get you a compound of faces. Then you can get wires of faces to extrude them and obtain shells, or just extrude faces to create solids.