GeomAPI_PointsToBSpline : the order of points matters or a bug?

Hello All,

I am using GeomAPI_PointsToBSpline​ to fit a set of 3D points into a Bspline curve.  If I put the points into the  TColgp_Array1OfPnt array in order (along the curve), a reasonable result was achieved as shown in Attachment1.  However, if I change the order of the points a little by switching the originally last point to the second place in the array, the result went crazy (Attachment2).  It feels that I was missing something obvious such as failed to set some parameters. I truly believe the fitting algorithm should not be related to the order in which the points were put into the array.  If it is, I think it would be a bug.

Any suggestions will be appreciated. 

Thanks.

 

 

 

Roman Lygin's picture

Hi Jim,

This behavior is as expected, the order does matter.This is an interpolation algorithm which returns a B-Spline (of degree 3 as long as the number of points > 3). The returned B-Spline is parametrized by default by chordal distance, i.e. any point Pi is reached at parameter t which is sum of segment lengths from P0 to Pi.

Likewise for GeomAPI_PointsToBSplineSurface which accepts a rectangular grid of points.

Hope this helps.

Roman

jim li's picture

Hi Roman,

Thank you very much for your response.  Since the fitting algorithm requires an ordered sequence of points in its input array, that means a sorting operation has to be applied to the point set along the anticipated curve before we can safely use the fitting routine.  I would imagine this fitting function has been used by many developers for many years, do you have any suggestions that any OCC functions can be used for this sorting purpose or we have  to come up with our own?

Thanks again,

Jim

Roman Lygin's picture

Hi Jim,

As a rule the order is defined by the data source. For instance, might receive sample points from some black box representing your curve and you can only query that black box without knowing the curve definition. Another option is some getting sample points from some discretization algorithm. Or a file in an external format which contains an ordered set of points, etc. 

Truth to be told, I might have mismatched GeomAPI_PointsToBSpline with the GeomAPI_Interpolate. The latter does real interpolation and provides length-based parametrization where as the former is expected to provide approximation only. Sorry for the confusion. Anyway the order of points matter in both cases. You can quickly experiment in DRAW using the commands appro and 2dappro, for instance:

DRAWEXE

Draw> pload MODELING

Draw> av2d

Draw> 2dapprox r 4 (and select 4 points in 2D view)

I am not sure if there is any order-agnostic approximation algorithm in OCC though.

Good luck!

Roman