TopoDS_Edge to Geom2d_Curve

I'm sure this is very basic, but I haven't found a solution yet. I have a TopoDS_Edge that was created using the BRepBuilderAPI_MakeEdge2d function. I would like to turn the TopoDS_Edge into a Geom2d_Curve. I noticed that this is straightforward in 3d: a TopoDS_Edge can be converted to a Geom_Curve. However, in 2d, the following code leads to a segmentation fault:

TopoDS_Edge myEdge = BRepBuilderAPI_MakeEdge2d( ... );
Handle(Geom2d_Curve) C;
Handle(Geom_Surface) surface;
TopLoc_Location location;
Standard_Real first, last;
C = BRep_Tool::CurveOnSurface(myEdge, surface, location, first, last);

Is there a simple conversion that I'm totally missing?


Venugopal Gudimetla's picture

Hi Lars,

I have the same problem, however, there is a reply another thread with similar Geom2d_Curve retrieval problem may be you can use the method to retrieve Geom2d_Curve in a different way. I didn't try it yet, please let me know if it works so I too can use.

Sharjith Naramparambath's picture

Hi Lars,

If you have shown the code here exactly as you are using in your program, it has every reason to bring up a segmentation fault. The only valid entity here is the myEdge variable that is pointing to an Edge. The surface onto which it is to be projected and the location are invalid. Look at the argument list of the method-- the first 3 are const references meaning that they are the required inputs which must point to valid data. From your code it looks like that you have not created a valid surface and location. Hope this helps.

Venugopal Gudimetla's picture

Hi Sharjith,

my initial reaction just that, but please take look the function implementation :

you will see that we don't need to provide another variables except for TopoDS_Edge as input and just of the variables are calculated from it.

I implemented it and my results look fine.


Venugopal Gudimetla's picture

and pardon my plingish, I don't check after typing :)

Sharjith Naramparambath's picture

yes, that looks fine. i just missed to see that version of the method.

Fabian Hachenberg's picture

in method BRep_Tool::CurveOnSurface there's the following line

// find the representation
BRep_ListIteratorOfListOfCurveRepresentation itcr

They're expecting a BRep_TEdge here and a TopoDS_Edge based on a 2d curve is propably not a BRep_TEdge (no supporting surface avaible!)

Fabian Hachenberg's picture


BRepBuilderAPI_MakeEdge2d actually creates instances of BRep_TEdge. In the course of creation of the edge, this routine in BRepLib is called

const Handle(Geom_Plane)& BRepLib::Plane()
if (thePlane.IsNull()) thePlane = new Geom_Plane(gp::XOY());
return thePlane;

So the 2d edges are actually 3d edges located on a xy plane. Therefore this doesn't seem to be the reason for the above mentioned seg fault...