Problem with Geom_BSplineCurve

Hi all,

I have a problem with Geom_BSplineCurve when I try to import a NURBS curve from another program.
I've written the values as comments:

Standard_Integer nbKnots = actNurbsCurve->KnotCount(); // 8
Standard_Integer nbPoles = actNurbsCurve->CVCount(); // 6
Standard_Integer Degree = actNurbsCurve->Order(); // 4
Standard_Boolean IsPeriodic = actNurbsCurve->IsPeriodic(); // Standard_False

TColgp_Array1OfPnt myPolesArray(0,nbPoles-1);
TColStd_Array1OfReal myKnotsArray(0,nbKnots-1);
TColStd_Array1OfReal myWeightsArray(0,nbPoles-1);
TColStd_Array1OfInteger myMultiplicitiesArray(0,nbKnots-1);

for (i = 0; i {
ON_3dPoint tmpON_Point;
Standard_Real weight;
bool result;
result = actNurbsCurve->GetCV(i, tmpON_Point);
gp_Pnt tmpPnt(gp_XYZ(tmpON_Point.x, tmpON_Point.y, tmpON_Point.z));
/* 0.0 0.0 9.0
2.0 -1.0 4.0
4.0 -2.0 1.0
6.0 -3.0 0.0
8.0 -4.0 1.0
10.0 -5.0 4.0
*/
weight = actNurbsCurve->Weight(i);
/* 1.0
1.0
1.0
1.0
1.0
1.0
*/
myPolesArray.SetValue(i, tmpPnt);
myWeightsArray.SetValue(i, weight);
}
for (i = 0; i {
Standard_Real knot;
Standard_Integer multiplicity;

knot = actNurbsCurve->Knot(i);
/*
0.0
0.0
0.0
1.5
2.3
4.0
4.0
4.0
*/
multiplicity = actNurbsCurve->KnotMultiplicity(i);
/*
3
3
3
1
3
1
3
3
*/
myKnotsArray.SetValue(i,knot);
myMultiplicitiesArray.SetValue(i,multiplicity);
}
Handle(Geom_BSplineCurve) myCurve;
try
{
myCurve = new Geom_BSplineCurve(myPolesArray, myWeightsArray, myKnotsArray, myMultiplicitiesArray, Degree /*, IsPeriodic */);

BRepBuilderAPI_MakeEdge ME(myCurve);
if (ME.IsDone())
{
tmpEdge = ME.Edge();
ResultShape = tmpEdge;
Result = Standard_True;
}
}
catch (Standard_ConstructionError e)
{
i = 0;
}
catch(Standard_Failure s)
{

}
catch (...)
{
};
}

Each time when I try to build the curve my application crashes. I am a not so firm with NURBS, perhaps anyone can see where my error is?

Best regards,

Patrik

Jeanmi B's picture

Hello Patrick,

According to the values you put in comments I understand the crash you got. There are several reasons :

1/ in OpenCascade nurbs curve, when you describe the knot vector you have to specify only the unique values. You must not repeat the multiple nodes. So in your case the knot vector has only a length of 4 and is equal to [0.0 1.5 2.3 4.0].

2/ The same reason apply to the multiplicity vector (also of length 4 of course) which in your case should be equal to [3 1 1 3]

3/ And finally the value you set as the Degree is in fact the Order (as the name of the function) which is the degree + 1. A general checking rule for non-periodic Nurbs curve is :
Sigmamult - nbPoles = Order = Degree + 1

with Sigmamult = the sum of the multiplicity values.

So for summarize :
PolesArray as you specified in your code is OK
WeightsArray as you specified is OK
KnotsArray[4] = {0.0 1.5 2.3 4.0}
MultArray[4] = {3 1 1 3}
Degree = 3

I don't know it will correspond to the curve you want but at least it should not raise anymore.

Best Regards.

Patrik Mueller's picture

Hi Jean Michel,

thanks - that was the hint I need! Now everything works fine!
But as I see now: does anyone knows some good ressources (web or books) about NURBS and NURBS surfaces?

Regards,

Patrik

a-helcman's picture

Les Piegl, Wayne Tiller: The NURBS Book (2nd Edition)
ISBN 3-540-61545-8

Baptiste Mazet's picture

Farin
Curves and surfaces
Last Version (near 63 euros)

Best Regards