How to convert an Edge to an Open Inventor Nurbs curve?

Hi all,

I want to display TopoDS_Shape in Open Inventor.
Now I only want to get the edges of a body, so I convert them to Nurbs curve, but failed.
The following is my code. Can anyone help me what's wrong?
Thanks.

bool TopeEdge2Curve(const TopoDS_Edge& topoEdge, SoSeparator* pRootNode)
{
TopLoc_Location topLoc;
Standard_Real fStart, fEnd;
Handle_Geom_Curve hCurve = BRep_Tool::Curve(topoEdge, topLoc, fStart, fEnd);

if(hCurve.IsNull())
return false;

Handle(Geom_TrimmedCurve) myTrimmed = new Geom_TrimmedCurve(hCurve, fStart, fEnd);

Handle_Geom_BSplineCurve hBSpline = GeomConvert::CurveToBSplineCurve(myTrimmed);
if(hBSpline.IsNull() )
return false;

gp_Trsf transfom;
Standard_Boolean bIdentity = true;
if(!topLoc.IsIdentity())
{
bIdentity = false;
transfom = topLoc.Transformation();
}

// control points
Standard_Integer nCtrlPts = hBSpline->NbPoles();

CString szControl;
SbVec3f* pts = new SbVec3f[nCtrlPts];
for(int ii=1; ii {
gp_Pnt pt = hBSpline->Pole(ii);
if(!bIdentity)
pt.Transform(transfom);

pts[ii-1] = SbVec3f(pt.X(), pt.Y(), pt.Z());
}

// knots
Standard_Integer nKnots = hBSpline->NbKnots();
float* knots = new float[nKnots];
for( int kk=1; kk {
knots[kk-1] = hBSpline->Knot(kk);
}

SoSeparator *curveSep = new SoSeparator();
SoDrawStyle* pDrawStyle = new SoDrawStyle;
pDrawStyle->lineWidth.setValue(4.0f);
curveSep->addChild(pDrawStyle);

// and a complexity.
SoComplexity *complexity = new SoComplexity;
SoCoordinate3 *controlPts = new SoCoordinate3;
SoNurbsCurve *curve = new SoNurbsCurve;
complexity->value = 1.0f;
controlPts->point.setValues(0, nCtrlPts, pts);
curve->numControlPoints = nCtrlPts;
curve->knotVector.setValues(0, nKnots, knots);
curveSep->addChild(complexity);
curveSep->addChild(controlPts);
curveSep->addChild(curve);

pRootNode->addChild(curveSep);

delete[] pts;
delete[] knots;

return true;
}

opencad's picture

can anyone help me?

Bearloga's picture

Please, try using BRepBuilderAPI_NurbsConvert to convert all geometry of the shape to nurbs, and then explore on shape to get those nurbs.

opencad's picture

I'll try it.
Thank you very much, Bearloga.