Feature Request : BSplineCurve.interpolate() alternate method

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Chris_G
Veteran
Posts: 2528
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Feature Request : BSplineCurve.interpolate() alternate method

Post by Chris_G »

Hi,
I was reading about points interpolation yesterday.
The points to be interpolated by a BSpline Curve must be parametrized first :
http://www.cemyuksel.com/research/catmu ... ullrom.pdf
This piece of code shows that OCCT, and FC's Part.BSplineCurve.interpolate() default to "chord length" parameterization.

Code: Select all

import FreeCAD, Part
import math

pts = [FreeCAD.Vector(0,0,0),FreeCAD.Vector(10,50,-5),FreeCAD.Vector(12,52,0),FreeCAD.Vector(40,80,-50),FreeCAD.Vector(41,80,-50),FreeCAD.Vector(50,30,-20)]
Part.show(Part.makePolygon(pts))

def parameterization (pts, a):
    params = [0]
    for i in range(1,len(pts)):
        p = pts[i].sub(pts[i-1])
        pl = pow(p.Length,a)
        params.append(params[-1] + pl)
    max = params[-1]
    normalizedParams = []
    for p in params:
        normalizedParams.append(1. * p / max)
    print params
    return params

bs = Part.BSplineCurve()
bs.interpolate(pts)
Part.show(bs.toShape())

print "Part.BSplineCurve.interpolate parameterization"
print bs.getKnots()

print "Uniform parameterization"
p1 = parameterization (pts, 0.0) 

print "Centripetal parameterization"
p2 = parameterization (pts, 0.5)

print "Chord length parameterization"
p3 = parameterization (pts, 1.0)
From the PDF linked above, it seems that "chord length" is not always the best choice.
"Centripetal" ensures that the curve will not self intersect.
According to this file : https://github.com/FreeCAD/FreeCAD/blob ... ePyImp.cpp
FreeCAD uses the default GeomAPI_Interpolate method.
OCCT has a second method where the array of parameters can be passed to the function :
http://www.opencascade.com/doc/occt-6.9 ... 4e9f333440
Would it be possible, please, to implement this alternate method in FreeCAD.
Thanks a lot.
Chris
wmayer
Founder
Posts: 20113
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Feature Request : BSplineCurve.interpolate() alternate method

Post by wmayer »

OK but please open a new ticket in mantis because feature requests in forum disappear from the developers' radar very quickly due to the amount of posts each day. In the feature request add the link to this thread, please.
User avatar
Chris_G
Veteran
Posts: 2528
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Feature Request : BSplineCurve.interpolate() alternate method

Post by Chris_G »

OK.
Thanks, Werner.
EDIT : Feature Request here : http://www.freecadweb.org/tracker/view.php?id=2560
User avatar
Chris_G
Veteran
Posts: 2528
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Feature Request : BSplineCurve.interpolate() alternate method

Post by Chris_G »

Ticket closed.
Werner "Flash" Mayer strikes again :lol: :lol:
Thank you very much !
Chris
wmayer
Founder
Posts: 20113
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Feature Request : BSplineCurve.interpolate() alternate method

Post by wmayer »

Maybe you have realized that GeomAPI_Interpolate also offers two "Load" versions where you can set the tangent on start and end point (supported) and another version where you can define this for each point individually. Should we also support the latter version?
If yes, I would have to reimplement the parsing of the parameter tuple to support keywords to avoid a lot of code duplication. But then the doc string must be updated again.
User avatar
Chris_G
Veteran
Posts: 2528
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Feature Request : BSplineCurve.interpolate() alternate method

Post by Chris_G »

I, personally, won't have use for this right now.
But if do it, it will be my pleasure to update the doc accordingly.
I saw that BSplineSurface has unimplemented alternative methods too for approximation and interpolation, and I would like to give a try at adding them, as an exercise :
http://www.opencascade.com/doc/occt-6.9 ... ml#details
Post Reply