B-spline Construction Project

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: B-spline Construction Project

Post by onekk »

jnxd wrote: Wed Feb 15, 2023 10:53 am ...

There is some ways of explaining B-Splines-

OCCT seems to follow:

https://github.com/Open-Cascade-SAS/OCC ... eCurve.hxx

At the very end of the long comment there is also some bibliography.


And these forum posts by Chris_G suggest that is followed by FreeCAD too.

viewtopic.php?p=615621#p615621

viewtopic.php?p=561221#p561221


So probably to be consistent and useful even for who is using scripting and Macro, probably it will be a good thing to follow similar terminology.

And make maybe some Wiki pages describing this terminology too.


Maybe this could be also interesting when coding something:

viewtopic.php?p=567969#p567969

Hope it helps to add some useful things to the discussion.

Regards

Carlo D.
Last edited by onekk on Sat Feb 25, 2023 3:28 pm, edited 1 time in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
jonasb
Posts: 162
Joined: Tue Dec 22, 2020 7:57 pm

Re: B-spline Construction Project

Post by jonasb »

jnxd wrote: Wed Feb 15, 2023 10:53 am An inkscape-like tool maybe already possible with macros by changing knot multiplicity. Though I am often guilty of using "macro" as a word for some magic I imagine can be automated but haven't tried it myself. Also, I don't know how the inkscape tools exactly translate to B-spline terminology, so I need to work on that.
While I knew that one can quite easily convert between a Bézier and a Hermitian curve I was not aware that you can effectively represent a series of Bézier curves as a single B-spline! So inspired by your comment and this bit from the OCCT docs (thanks Carlo)...
https://github.com/Open-Cascade-SAS/OCCT/blob/master/src/Geom/Geom_BSplineCurve.hxx wrote: - "Piecewise Bezier" if all [knot-] multiplicities are equal to
Degree except the first and last knot which
have a multiplicity of Degree + 1, where
Degree is the degree of the BSpline curve. A
curve of this type is a concatenation of arcs of Bezier curves.
... I was indeed able to get some Inkscape-like interface based on Sketcher's existing capabilities (increase/decrease knot multiplicity, construction lines and angle constraints).
Adjusting the knot multiplicity as in the quote from OCCT docs, one gets the same as Inkscape's "corner node"
Adjusting the knot multiplicity as in the quote from OCCT docs, one gets the same as Inkscape's "corner node"
Bildschirmfoto 2023-02-15 um 19.46.09.png (86.36 KiB) Viewed 2241 times
Adjusting the knot multiplicity as in the quote from OCCT docs, and applying a 180° angle constraint, one gets the same as Inkscape's "smooth node"
Adjusting the knot multiplicity as in the quote from OCCT docs, and applying a 180° angle constraint, one gets the same as Inkscape's "smooth node"
Bildschirmfoto 2023-02-15 um 19.48.06.png (86.8 KiB) Viewed 2241 times
Adjusting the knot multiplicity as in the quote from OCCT docs, and applying a symmetric constraint, one gets the same as Inkscape's "symmetric node". In this picture, though, I reduced the node multiplicity again by one to get the same effect without the symmetric constraint.
Adjusting the knot multiplicity as in the quote from OCCT docs, and applying a symmetric constraint, one gets the same as Inkscape's "symmetric node". In this picture, though, I reduced the node multiplicity again by one to get the same effect without the symmetric constraint.
Bildschirmfoto 2023-02-15 um 19.49.08.png (83.3 KiB) Viewed 2241 times

So it seems that it is "only" a matter of the UI -- the OCCT base is there. By reducing some of the B-Splines degrees of freedom, namely by fixing its degree, the weight of the poles and the knot multiplicity, it can be coerced into an "SVG Path Style Series of Béziers". Or, with some minor transformation of the pole's positions, into a Hermitian Spline.
UX wise one could think about displaying what I've done with construction lines as "internal geometry", hide the circles for the pole's weight and put some special symbols instead of the 180° angle constraint and the symmetric constraint to express "corner node", "smooth node" and "symmetric node". And when moving some control point, the corresponding knot should be kept as sable as the other constraints permit. Right now "everything moves", which is explainable from a developer's point of view, but hugely counter-intuitive for a user.
User avatar
jnxd
Posts: 951
Joined: Mon Mar 30, 2015 2:30 pm
Contact:

Re: B-spline Construction Project

Post by jnxd »

UPDATE 25 February 2023

So work on this project (particularly direction 1) has officially started and the past 10 days have been significantly productive. It is already possible to provide a set of points and get a cubic B-spline pass through them.

phpBB [video]


Interested people please head over to issue #8529, and PR #8530. As I describe below, some user input is seriously needed, and following the latest contributing guidelines, I will be keeping more detailed discussion to those places.

The wording of the project has already been technically fulfilled. But the keen of you might notice that so far all I've done is exposed functionality already available in OCCT. In a sense, this development is a bit anticlimactic. Fear not, cause there are still some interesting developments needed, some of which can be done with the present OCCT framework, and some that may need a new algorithm to be developed. A non-exhaustive list here.
My latest (or last) project: B-spline Construction Project.
User avatar
jnxd
Posts: 951
Joined: Mon Mar 30, 2015 2:30 pm
Contact:

Re: B-spline Construction Project

Post by jnxd »

onekk wrote: Wed Feb 15, 2023 11:19 am ...
jonasb wrote: Wed Feb 15, 2023 7:45 pm While I knew that one can quite easily convert between a Bézier and a Hermitian curve I was not aware that you can effectively represent a series of Bézier curves as a single B-spline! So inspired by your comment and this bit from the OCCT docs (thanks Carlo)...
https://github.com/Open-Cascade-SAS/OCCT/blob/master/src/Geom/Geom_BSplineCurve.hxx wrote: - "Piecewise Bezier" if all [knot-] multiplicities are equal to
Degree except the first and last knot which
have a multiplicity of Degree + 1, where
Degree is the degree of the BSpline curve. A
curve of this type is a concatenation of arcs of Bezier curves.
Thanks @onekk and @jonasb for looking into this. I'm sorry for the delayed response, but I think my input isn't currently required or useful. In some uncharted future the tricks @jonasb added to make the inkscape equivalents (thanks for making the connections BTW) should be made automatic with the Bezier representation of the spline. But right now, if this works for you, that's great!
My latest (or last) project: B-spline Construction Project.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: B-spline Construction Project

Post by abdullah »

jnxd wrote: Sat Feb 25, 2023 1:54 pm Thanks @onekk and @jonasb for looking into this. I'm sorry for the delayed response, but I think my input isn't currently required or useful. In some uncharted future the tricks @jonasb added to make the inkscape equivalents (thanks for making the connections BTW) should be made automatic with the Bezier representation of the spline. But right now, if this works for you, that's great!
I had seen this before in the forums. What I am not fully aware is if there are limitations. I think there aren't, but I am not 100% sure.

If there aren't limitations, perhaps it is interesting to have a DSH to create b-splines, but only one piece, so a bézier, and add the handles. If differentiated treatment is necessary, it could be solved by a geometryextension. FreeCAD internally will see a B-Spline (unless checking the extension) and treat it so, including all solver parts. That is quite some code reuse.

At a first thought, handles could perhaps be made internal geometry for this specially constrained b-spline.

The alternative path is providing full support for OCCT supported béziers, which means quite some coding. At the end, those béziers will need to be constrained too, so it means they will have internal geometry. There is quite some coding there.

Just give it a thought.
Hologram
Posts: 201
Joined: Thu Nov 03, 2022 3:05 pm

Re: B-spline Construction Project

Post by Hologram »

The advantage of the 'inkscape spline' is that you can take a slightly different approach to constrain it. You can use the tangency handles for constraints as opposed to the CV and Hull method for the current spline creation method. In Fusion 360, you can also see the curvature handles if you drag a handle.
curvature on spline.gif
curvature on spline.gif (448.07 KiB) Viewed 1949 times
Since this inscape type of spline is naturally more restrictive if you have aligned handles, it is usually able to get the job done with fewer constraints than the CV Hull spline, from a user perspective. Both the current type of spline and the 'inscape spline' should support tangency and curvature constraints applied to the spline itself.
User avatar
jonasb
Posts: 162
Joined: Tue Dec 22, 2020 7:57 pm

Re: B-spline Construction Project

Post by jonasb »

Displaying the curvature circle as internal geometry for a given knot, and being able to apply a radius-constraint to it, is indeed an interesting option to constrain a spline.

I can imagine that e.g. rail- and road works could benefit from this. Maybe @Joel_graff or @HakanSeven12 from the Trails WB could give more details...
jwatkins672003
Posts: 65
Joined: Thu Nov 05, 2015 11:46 pm

B-spline Construction Project: tangency and curvature

Post by jwatkins672003 »

Regarding use for surface creation. 2D construction via B-splines is integral to good surface creation.

The current workaround to set a point within a B-spline tangent to a line can have serious issues later in modeling. The current workaround has you split the B-spline in two and set the line tangent to the endpoints of the two B-splines. This results in tangency continuity, however, you don't get curvature continuity between the two B-splines. Curvature continuity is broken. The same thing happens if you insert a knot at some point on the line to use it as the attachment point for your tangency line.

While this may seem trivial, you can discover later that this may create a big issue if you want to extrude a sketch or other geometry up to a surface and it crosses the two surfaces created because you needed that internal tangency and had to split the B-spline to get it. In my experience too many times it fails. Sometimes using boolean operators will work, sometimes it won't and then your stuck.

So, anytime you have to take a B-spline and split it, the number of faces will increase by number of splits + 1. Thus, creating extra for what could have been one continuous surface. Again my experience, 20+ years in welding helmet design, has shown that the models that behave the best have the fewest numbers of faces to define the shape.

An alternative solution is to allow two B-spline endpoints to be curvature continuous to each other. Back in the old CADKey days we'd do this with a specific command to make one curve curvature continuous to the other.

For most user applications this isn't a big issue, but for anything where how light shines off of final product surfaces affects perceived quality, like vehicles, this is very important.

So, I'd really like the construction project to address the B-spline internal tangency issue in Sketcher.
User avatar
jnxd
Posts: 951
Joined: Mon Mar 30, 2015 2:30 pm
Contact:

Re: B-spline Construction Project

Post by jnxd »

@jwatkins672003 It is now possible to set a tangent at a knot of the B-spline with a line. This should guarantee up to C2 continuity for cubic splines and extrude into a single face for the entire B-spline.
The same thing happens if you insert a knot at some point on the line to use it as the attachment point for your tangency line.
This should not cause an issue in curvature continuity. If that is really the case please attach an example file so I can see where the issue lies.

Curvature constraints are indeed something we should look into. It's not currently in my plan but it seems I should increase its priority from user feedback. There will probably also be some design/visualization questions.
My latest (or last) project: B-spline Construction Project.
User avatar
jnxd
Posts: 951
Joined: Mon Mar 30, 2015 2:30 pm
Contact:

Re: B-spline Construction Project

Post by jnxd »

UPDATE 24 March 2023

Earlier this evening (Indian time), the tools to create B-splines by interpolation got merged in master build, so they should be available in the next daily/weekly builds!

For completeness, here's the documentation of how it works:
  1. The tools (for both periodic and non-periodic B-splines) are in the "Create a B-spline" drop down in the toolbar, or in menu, or via shortcuts.
  2. After activating one of the tools, select the points through which the spline should pass by left clicking, and finish by pressing Esc or RMB.
    1. Every point can be auto-constrained if it is activated in settings (if you haven't deactivated it it's probably active by default).
    2. The B-spline created will be cubic.
  3. Press "M" to set the multiplicity of the last knot added. Note that this may not always be honored under the following circumstances:
    1. For a non-periodic spline, the first and last knots always have a multiplicity of 4.
    2. For a periodic spline, the first knot (coincident with last) always has a multiplicity of 2.
    3. If the points just before and just after have multiplicities >=3, the piece between these two is fully continuous, and this (middle) point will only be constrained with point-on-object.
My latest (or last) project: B-spline Construction Project.
Post Reply