Bezier Curve loses poles if created from TopoDS_Edge

Hello everyone,

I have a class called ObjectBezierCurve, which has a member (along with some other data) called myTopoDS_Edge (of course of type TopoDS_Edge).

The constructor gets an AIS_Shape, and the TopoDS_Edge is created as follows:

myTopoDS_Edge = TopoDS::Edge(theAIS_Shape->Shape());

To access myTopoDS_Edge, there is a function called get_TopoDS_Edge, which is by the way inherited from the superclass ObjectEdge. Then, this ObjectBezierCurve class is stored in a TColStd_HSequenceOfTransient sequence. In a completely different part of the program, I want to reconstruct the Bézier curve using myTopoDS_Edge of the class. This part looks like the following:

for(int i=1;iLength();i++)
{
Handle(Object) curObject = Handle(Object)::DownCast(myData->Value(i));
if(Object->GeometryType() == CurveObject)
{
Handle(ObjectEdge) curEdge = Handle(ObjectEdge)::DownCast(curObject);
TopoDS_Edge curTopoDS_Edge = curEdge->get_TopoDS_Edge();
Standard_Real startParam, endParam;
Handle(Geom_Curve) theGeom_Curve = BRep_Tool::Curve(curTopoDS_Edge,startParam,endParam);

The problem is now if I cast theGeom_Curve into a Geom_BezierCurve, the curve loses all its poles, and only the first two of them remain. The weird thing is that if I create a Geom_Curve from myTopoDS_Edge in the constructor of ObjectBezierCurve, and cast it to Geom_BezierCurve, it gives back the proper Bezier curve. However, in this other part of the program I do completely the same thing, and gives back a very different one. Is this a known bug or I am missing something?

Laszlo Kudela's picture

If someone is interested, I have found the answer to the question.

It turned out that the TopoDS_Shape returned by

theAIS_Shape->Shape();

contains a Handle to a memory space which is constantly modified in another part of the program. It turned out that the Geom_BezierCurve in this memory space is a Bezier Curve with 2 poles by default.

So in summary, I can say that if you crate an AIS_Shape based on a TopoDS_Shape be careful what Geom_***** entity you use. Make sure you do not modify this memory address somewhere else. If you do, and want your new shape to be a separate one, use the Copy() function that creates a completely new Geom_ entitiy in a different address.

So the solution was something like this:

Standard_Real a,b;
Handle(Geom_Curve) oldGeomCurve = Brep_Tool::Curve(myTopoDS_Edge,a,b);
Handle(Geom_Curve) newGeomCurve = Handle(Geom_Curve)::DownCast(oldGeomCurve->Copy());
BRepBuilderAPI_MakeEdge ME(newGeomCurve);
if(ME.IsDone())
{
myTopoDS_Edge = ME.Edge();
}