B-Spline surfaces?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
jserup
Posts: 2
Joined: Wed May 13, 2015 6:25 pm

B-Spline surfaces?

Postby jserup » Wed May 13, 2015 6:34 pm

Hi,

I am looking at creating B-Spline surfaces and 3D Free form deformations using FreeCAD. For now I have only found:
viewtopic.php?t=2479

And looking at:
src/Mod/Part/App/BSplineSurfacePyImp.cpp
src/Mod/Draft/DraftTools.py

Does FreeCAD support B-Spline surfaces/3D Free form deformations? If not I am considering to look at extending FreeCAD with this functionality, would that be of any interest?

I am also reading this thread:
viewtopic.php?f=10&t=8488&start=40

Seems work has already been done on the surface part for bezier
emills2
Posts: 631
Joined: Tue Apr 28, 2015 11:23 pm

Re: B-Spline surfaces?

Postby emills2 » Thu May 14, 2015 9:02 pm

Here's an angle i've been working on. Since i'm an engineer, not a programmer, my version probably won't go beyond python with minimal UI. Since it shows my desired workflow, i wish someone else would do the hard stuff :), like making good selection tools (find four points in the selection no matter how they happen to be nested in the doc...), setup numeric input boxes for weights and parameter values to perform various operations on...

Anyway, my strategy is to implement a exhaustive biccubic bezier patch setup. cubic is a good start because:
- it covers a lot of actual use cases
- if you specify the tangents, a reasonable and stable algorithm for internal control points is possible, so you get G1 out of the box
- many designers are familiar with illustrator/inkscape like joining of curves, and this carries over directly to bicubic patches
- with weights in addition to tangent lengths, you have a lot to work with to achieve G2, and maybe even G3 in some cases.

what i have so far:
-convert sketch polygons to cubics
-automatically converts arcs to cubic
-pick four curves, get a surface
-if all curves were tangent, the surfaces are as well (G1)
-matching control points across patch corners can give G2 with some work.

see below: Part workbench surface from edges above, and my scripted surface below. No efort to go beyond G1 here, just a test file
quick compare.JPG
quick compare.JPG (20.69 KiB) Viewed 6333 times
quick compare 02.JPG
quick compare 02.JPG (23.29 KiB) Viewed 6333 times
emills2
Posts: 631
Joined: Tue Apr 28, 2015 11:23 pm

Re: B-Spline surfaces?

Postby emills2 » Thu May 14, 2015 9:11 pm

a more dramatic comparison of default behavior. Note the curves are fully 3d, not just planar; there is no way to create non planar curves in the UI though.

Here you can see really well that the surface is G1, but the curvature discontinuity really jumps out.
pytest 01.JPG
pytest 01.JPG (29.01 KiB) Viewed 6331 times
UI workflow:
sketches of three line segments. note you have to match all corners by hand, because of sketch linking restrictions. This prevents me from doing anything really interesting, but Deepsoic/ new part design is going to fix that real soon
cubic sketch.JPG
cubic sketch.JPG (23.71 KiB) Viewed 6331 times
make cubics out of the sketches
bezier 04.JPG
bezier 04.JPG (20.18 KiB) Viewed 6331 times
cont.
emills2
Posts: 631
Joined: Tue Apr 28, 2015 11:23 pm

Re: B-Spline surfaces?

Postby emills2 » Thu May 14, 2015 9:17 pm

when you have enough curves, make a quick visualization of the control patch. This just show the control points that will be used in the patch. If the polygon looks ok, make a patch.
here you can see my next todo: make better three sided patches....this one is really crappy :) in the last pictures, you can see G2 coming down across the front...and the serious problems on the top left transition triangle
bezier 01.JPG
bezier 01.JPG (40.16 KiB) Viewed 6329 times
bezier 02.JPG
bezier 02.JPG (25.29 KiB) Viewed 6329 times
bezier 05.JPG
bezier 05.JPG (15.96 KiB) Viewed 6329 times
emills2
Posts: 631
Joined: Tue Apr 28, 2015 11:23 pm

Re: B-Spline surfaces?

Postby emills2 » Thu May 14, 2015 9:32 pm

Sorry for hijacking your thread, i'm just hoping to get some people on board so i can have my desired workflow.

I think the cubic curves belong directly in Sketcher. The polygon thing is just a really good way to constrain them (i think Werner suggested it one time as well). This way, splines are a theoretically easy add on to the Sketcher...no new solving involved.

the bicubic patch tool belongs directly in Part workbench.

My own personal goal is to make a numerical solver that would take tangency as given, and look at curvature functions across each boundary to find G2/G3 solutions for tangent length and weights.

After working with solidworks and autodesk inventor for a long time, i have found that even with guiding curves, lofting strategies are brittle. In the end, i decided that specifying each patch completely was the least amount of rework.
jserup
Posts: 2
Joined: Wed May 13, 2015 6:25 pm

Re: B-Spline surfaces?

Postby jserup » Fri May 15, 2015 6:24 am

Hi not quite sure from the above posts what it is that you have already done, what can already be done in FreeCAD and what you would like to have added to FreeCAD.

I am also looking at doing the work in ogre3d since it could be interesting to move it to the GPU
emills2
Posts: 631
Joined: Tue Apr 28, 2015 11:23 pm

Re: B-Spline surfaces?

Postby emills2 » Fri May 15, 2015 8:02 pm

Hi, sorry that my posts were confusing. I'll try to answer your questions/points in reverse order.

No one else seemed interested in my ideas, so it's possible i'm doing it all wrong ;) oh well. I'm just having fun and learning.

1. Ogre 3d or FreeCAD?
Just took a quick look at Ogre3d. Looks interesting. My understanding is it mesh based, with the exception of "Biquadric Bezier patches for curved surfaces". So they could definitely use your help :)
FreeCAD is a parametric brep modeler. For an engineer interested in 'water tight' models and 'analytic' surfaces, FreeCAD is a better starting point by leaps and bounds.

2. What FreeCAD has already.
FreeCAD is NURBS at the core already, but more UI tools are needed. NURBS is the only current valid way to do free form modeling for engineering. The other way, subdivision surfaces, uses b splines (URBS), but hides them from the user. Subdivision is good enough for animation and movies, but cannot produce 'class A' surfaces.

NURBS in FreeCAD come from Open Cascade, which is the geometry kernel the application uses at its core. The developers have already given complete access to the basic NURBS entity through python bindings (this is what i used to make the pictures i posted before). They have also implemented/linked many of the standard tools to manipulate NURBS, but not all of them.

Here are some tools FreeCAD has:

Draft workbench:
-planar b splines
-planar bezier splines
(you can then extrude them, revolve them, etc)

Part workbench:
-ruled surface (join any two edges with a surface)
-sweep (drag a profile along a path)
-loft (make a surface that goes through a series of profiles)
-build surface from edges (found in Part menu > shape builder)
(there are more all over the place, for example, the fillet tool)

Open Cascade has even more advanced tools available, but not all of them have been bound to python or added to the UI (i think?)

Something many people have been asking for is "loft with guiding rails". This is to say: instead of just passing through all profiles, i also want to control the shape from profile TO profile.

As you mentioned before, forum user Balazs seemed to be about to implement 'everything and the kitchen sink' but then his thread died down.

3. what have i done? I'm just tinkering with python in my very limited time.
Using the existing python bindings, i made a few 'prototypes' of UI functions i would like:
-pick 4 points on a sketch > create a cubic bezier curve (pinned degree 3 NURBS)
-pick an arc (pinned degree 2 NURBS) > convert to degree 3 by using built in function 'increaseDegree()'
-pick 4 bezier curves that form a loop > make a surface that follows the tangents of the curves.

I made my own bezier curves instead of using the Draft workbench version because i wanted to get familiar and understand the innards. The surface tool can be adapted to use any bezier made by any workbench

By making everything degree 3, i can use straight lines, arcs, parabolas, ellipses, hyperbolas, and 'real' cubic beziers as edges in the same surface. this work is not 100% complete though, i need to fix weights for arcs.

By using the tangents at the corners of the curves to define the surface, i can make one piece by itself. Later i can make another piece right next to it, and if i set the new curves tangent to the first piece, the transition is always smooth (G1). If i make the curve/curve junction even smoother, the surface junction will be even smoother.

This is my way of doing what i thought the 'shape builder tool' would do, but doesn't. (compare the two surface in the first picture of my first reply)
This framework also gives me "loft with guiding rails" capability, but limited to cubic curves, and very labor intensive.

the workflow: sketch > curve > surface > shell is pretty common, and i like it.

What i'll do is finish these tools for cubic, and then come back and expand them for degree 4....then degree 5...then all other degrees.
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: B-Spline surfaces?

Postby ian.rees » Sat May 16, 2015 9:02 am

I'm not in a place to be comitting to any more projects at the moment, but this looks really good to me! -Ian-
eanema
Posts: 5
Joined: Mon Feb 27, 2017 4:26 pm

Re: B-Spline surfaces?

Postby eanema » Thu Mar 02, 2017 1:31 pm

I assume there has been no moment on this? Otherwise the thread would have been updated, right?
User avatar
kkremitzki
Posts: 2169
Joined: Thu Mar 03, 2016 9:52 pm
Location: Texas

Re: B-Spline surfaces?

Postby kkremitzki » Thu Mar 02, 2017 2:00 pm

Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.