throwing an instance of 'Standard_NullObject' when executing BRepFill_Pipe

Dear all, I have encountered a problem when using the BRepFill_Pipe function.

I created a face that I want to sweep along a wire. Once, the wire is a straight line -- and that works -- and once the wire is a twisted helix -- that does not work. The runtime error that I get in the command BRepFill_Pipe(aHelixWire,ptFace) is the following: terminate called after throwing an instance of 'Standard_NullObject'.

The figure shows the successfully swept face along the straight line and what the helix looks like. I have rendered all kinds of shapes and they all look fine.

Here is a snippet of code:

   // Helix
   Handle_Geom_CylindricalSurface aCylinder = new Geom_CylindricalSurface(gp::XOY(), myPinDiameter/2.0);
   gp_Lin2d aLine2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(-2.0*M_PI, -myP));
   Handle_Geom2d_TrimmedCurve aSegment = GCE2d_MakeSegment(aLine2d, 0.0, M_PI);
   TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aSegment, aCylinder, 0.0, myPinLength/myP * sqrt(pow(2.0*M_PI,2) + pow(myP,2)));
   TopoDS_Wire aHelixWire = BRepBuilderAPI_MakeWire(aHelixEdge);

   // Line
   TopoDS_Edge aLineEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(myD2,0.0,0),gp_Pnt(myD2,2.0,0));
   TopoDS_Wire aLineWire = BRepBuilderAPI_MakeWire(aLineEdge);

   // Trepazoid
   gp_Pnt pntV1(myD2, 0.0, -myP/ 4.0);
   gp_Pnt pntV2(myD , 0.0, -myP/16.0);
   gp_Pnt pntV3(myD , 0.0,  myP/16.0);
   gp_Pnt pntV4(myD2, 0.0,  myP/ 4.0);
   Handle(Geom_TrimmedCurve) segV12 = GC_MakeSegment(pntV1, pntV2);
   Handle(Geom_TrimmedCurve) segV23 = GC_MakeSegment(pntV2, pntV3);
   Handle(Geom_TrimmedCurve) segV34 = GC_MakeSegment(pntV3, pntV4);
   Handle(Geom_TrimmedCurve) segV41 = GC_MakeSegment(pntV4, pntV1);
   TopoDS_Edge ed1 = BRepBuilderAPI_MakeEdge(segV12);
   TopoDS_Edge ed2 = BRepBuilderAPI_MakeEdge(segV23);
   TopoDS_Edge ed3 = BRepBuilderAPI_MakeEdge(segV34);
   TopoDS_Edge ed4 = BRepBuilderAPI_MakeEdge(segV41);
   TopoDS_Wire ptWire = BRepBuilderAPI_MakeWire(ed1,ed2,ed3,ed4);
   TopoDS_Face ptFace = BRepBuilderAPI_MakeFace(ptWire);

   // does not work :(
   TopoDS_Shape aHelixPipe = BRepFill_Pipe(aHelixWire,ptFace).Shape();

   // does work ;)
   TopoDS_Shape aLinePipe = BRepFill_Pipe(aLineWire,ptFace).Shape();

What could I have done wrongly? Any help is appreciated.

Attachments: 
Dmitrii Pasukhin's picture

Hello, just as a recommendation. Do not ask for Shape before checking for success operation. Needs to check IsDone before exraction result.

But as for your case the exception because calculation is not performed for some reason, Please create a bug inside a tracker.

Another thing, please check the shape:

// Assuming you have a TopoDS_Shape object named 'shape'
TopoDS_Shape shape;

// Create an analyzer for the shape
BRepCheck_Analyzer analyzer(shape);

// Check if the shape is valid
if (analyzer.IsValid()) {
    std::cout << "The shape is valid." << std::endl;
} else {
    std::cout << "The shape is not valid." << std::endl;
}

And another thing, please try to fix shape using ShapeFix_Shape in case of problems. Any deep analyzing can be only on the working on bug stage :(

Best regards, Dmitrii.

Henning V's picture

Dear Dmitrii, I have used the BRepCheck_Analyzer to see if I have any invalid shapes and it turns out that the edge containing the helix (aHelixEdge) that was generated by this line

TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aSegment, aCylinder, 0.0, myPinLength/myP * sqrt(pow(2.0*M_PI,2) + pow(myP,2)));

is, in fact, not a valid shape. Subsequently the wire (aHelixWire) is not valid either.

How can I see from the analyzer what exactly is wrong with the edge and/or is there a straightforward way to fix the edge (even without knowing what is wrong)? I had a look at the Shape-Healing documentation but it's a bit confusing. I don't know where to start...

Thanks, Henning

Henning V's picture

Finally found a solution. What I was missing was the creation of a 3D curve from the 2D parametrized one.

BRepLib::BuildCurve3d(aHelixEdge);

This was the tip that got me there. https://dev.opencascade.org/node/73442#comment-3905