Wed, 06/02/2010 - 00:24

Hi,

I just started using this powerful OCC library (on a LINUX system) and I would very appreciate your help with the following problem: I am generating a curve from a given set of points by two methods: The points are interpolated or set as control points. Both curves seems to be generated as expected. In case of control points and writing points to file in between curve.FirstParameter() and curve.LastParameter() the curve is too short at both ends, as to see in the attached figure.

Any suggestions where this comes from?

The curve is generated with the following code:

int i;

int degree=0;

// Determine the degree

if (controlPoints->Length() == 1)

{

cout
exit(0);

}

if (controlPoints->Length() > maxDegree )

degree = maxDegree;

else if (controlPoints->Length() == 2)

degree = 1;

else if (controlPoints->Length() == 3)

degree = 2;

cout
TColgp_Array1OfPnt A_Poles(1, controlPoints->Length());

TColStd_Array1OfReal A_Weights(1, controlPoints->Length());

TColStd_Array1OfReal A_Knots(1, controlPoints->Length()+degree+1-2*(degree-1));

TColStd_Array1OfInteger A_Mult(1, controlPoints->Length()+degree+1-2*(degree-1));

for (i=1;iLength();i++)

{

A_Poles.SetValue(i,controlPoints->Value(i));

A_Weights.SetValue(i,1.0);

}

for (i=1; i
{

A_Knots.SetValue(i,(double)(i-1)/(A_Knots.Length()-1));

if(i==1 || i==A_Knots.Length())

{

A_Mult.SetValue(i, degree);

}

else

{

A_Mult.SetValue(i,1);

}

cout
}

return new Geom_BSplineCurve(A_Poles, A_Weights, A_Knots, A_Mult, degree, 0);

Wed, 06/02/2010 - 20:12

Here the figure with the curve (plotted inbetween curve.FirstParameter() and curve.LastParameter()) and the control polygone.

Wed, 06/02/2010 - 20:29

This is the expected behaviour when constructing a new nurbs curve. What you are looking for is probably Geom_Interpolate

Wed, 06/02/2010 - 22:04

Jelle, thanks for helping! I actually want to use both methods of curve construction:

a) Array is taken as CONTROL POINTS: In this case I have the problem that the resulting curve is too short in case I use curve.FirstParameter() and curve.LastParameter() to get points. But, as to see from the latest figure, the curve looks nice!

b) Array is to be INTERPOLATED: The resulting curve (see the latest figure) looks somewhat strange, especially at the second points. I used the following code:

TColgp_HArray1OfPnt *array = new TColgp_HArray1OfPnt(1, arrayIn->Length()); // sizing harray

for (i=1; i<=arrayIn->Length(); i++)

array->SetValue(i , arrayIn->Value(i));

GeomAPI_Interpolate anInterpolation(array, /* Periodicity */Standard_False, /* Precision */ Precision::Approximation());

anInterpolation.Perform();

return anInterpolation.Curve();

Any ideas for my problems?

Wed, 06/02/2010 - 22:10

Sure thing.

With Geom_Interpolate you can set tangent directions. If you do that for the first and last vertices you should be able to get a better result.

Finally, what happens if you go with the 1st method and use a curve of degree 2?

-jelle

Thu, 06/03/2010 - 07:21

Ulrich,

For bspline curve to start and end in the first and last control points, you need to set multiplicity of first and last knots to degree+1, not degree as you do in the code snapshot above.

Andrey