Problem when trying to convert an Edge to a Geom_Curve


I need to convert an Edge to a Geom_Curve. I did that and there are not compilation error :

Handle(Geom_Curve) myCurve = BRep_Tool::Curve(myEdge, First, Last);
Handle(Geom_BSplineCurve) myBSplCurve = Handle(Geom_BSplineCurve)::DownCast( myCurve);

Standard_Integer ival = myBSplCurve->NbPoles();

When I execute the program I have an error on this last line.
Error at adress ... Memory cannot be "read".

Can someone help me.

Thanks in advance,

Rob Bachrach's picture

Are you sure your edge is based on a BSplineCurve? It is very possible that your DownCast is returning an invalid pointer (indicating an invalid cast). If you need it to be a BSpline, you
may want to look at the GeomConvert package.

Kreshnik's picture

Hi Rob,

Thanks for your quick answer. My edge is an edge of a cube that I've selected. In reality it's a segment. I cannot convert a segment in a BSplineCurve ???
I havn't this problem when I convert the cube face in a BSplineSurface !

Thanks for your answer.

Roman Lygin's picture

Use GeomConvert::CurveToBSplineCurve() to convert your line to BSpline first. Another method could be ShapeConvert::ConvertCurveToBSpline(). It offers more parameters (user-defined tolerance, max/min degree) and first tries to reapproximate with those parameters, and then calls GeomConvert if not successful. See the source code for details.