Can a wire cut a cap out of a sphere?

Hello!
According to the modelling data user guide, it should be possible to create a face from a surface and a wire. The wire is supposed to bound the face. If the wire is not embedded in the surface, it will be projected onto the surface.

This is the theory. In practice, I have not been able to cut a cap out of a spherical surface with a circular wire. Can somebody help to solve the problem? The code below can replace the MakeBottle() function in the opencascade tutorial. But when the created cap is added to the displayed compound (in the line "aBuilder.Add (aRes, cap);"), the application crashes:

$ run.sh
QImage::setColor: Index out of bound 2
Segmentation fault

What is wrong?

Thanks
Arno

Here is the code snippet:

TopoDS_Shape
MakeBottle(const Standard_Real myWidth , const Standard_Real myHeight ,
const Standard_Real myThickness)
{
//Create the face of a sphere
BRepPrimAPI_MakeSphere MS(1.);
TopoDS_Face aSphere = BRepPrimAPI_MakeSphere(1.);
//Get the spherical surface
Handle_Geom_Surface surf(BRep_Tool::Surface(aSphere));

//Create a circular wire, which lies on the spherical surface
gp_Pnt aP(0.5,0,0);
gp_Vec aV=gp::DX();
gp_Ax2 anAxes(aP, -aV);
gp_Circ aCirc(anAxes,sqrt(0.75));
BRepBuilderAPI_MakeEdge aCircle(aCirc);
BRepBuilderAPI_MakeWire MW(aCircle.Edge());

//Create a spherical cap, bounded by the circular wire
BRepBuilderAPI_MakeFace MF(surf,MW.Wire());
TopoDS_Face cap=MF.Face();

//Building the resulting compound
TopoDS_Compound aRes;
BRep_Builder aBuilder;
aBuilder.MakeCompound (aRes);
aBuilder.Add (aRes, cap);

//if the previous line is not commented, the application crashes:
//$ run.sh
//QImage::setColor: Index out of bound 2
//Segmentation fault

aBuilder.Add (aRes, MW.Wire());
return aRes;
}

Mikael Aronsson's picture

Not sure but one possibility is that you run into problems with the sphere because the poles of the sphere is degenerate, this for example often makes it difficult to use boolean operations on spheres around the poles, but this is just a wild guess.

arno-cad's picture

Thank you for the reply. My tests show that the poles and seam can indeed be a problem, but in this case they are not the reason for the failure. I have moved the position of the cutting circle so that it is separated from poles or seams, and the problem still remains.

I will split this question into smaller steps, because the segmentation fault can have several reasons. (By the way, the message "QImage::setColor: Index out of bound 2" has nothing to do with the problem - it is shown for valid code examples, too.)
So, I do not necessarily need an answer in this thread, but if somebody finds the bug, it is nonetheless appreciated.

Thanks
Arno