Radial Nurbs

Show off your FreeCAD projects here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
emills2
Posts: 875
Joined: Tue Apr 28, 2015 11:23 pm

Re: Radial Nurbs

Post by emills2 »

i know you made this for radial basis functions, but i hope you realize the boring old u,v basis function surfaces don't have any kind of interface this cool in FreeCAD right now.

I write macros that generate grids based on sketches, and if i could parametrically tie my grids/sketches to a realtime surface display tool like you made...that would kick some major ass.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Radial Nurbs

Post by looo »

Chris_G wrote:Another blender feature ? I didn't know it ...
Yes, I think it is activated by pressing shift x to drag in the dx = 0 plane. Blender has so many useful hidden key events:-) But once you know them blender is simple the best ui.
emills2 wrote:i know you made this for radial basis functions, but i hope you realize the boring old u,v basis function surfaces don't have any kind of interface this cool in FreeCAD right now.

I write macros that generate grids based on sketches, and if i could parametrically tie my grids/sketches to a realtime surface display tool like you made...that would kick some major ass.
I follow your work, but for me it's hard to get into this bspline stuff. We have made some really nice working bezier and bspline curves (not surfaces) written in python for the glider workbench (it is used for airfoils, merging-curves, shape,...) and can be found here. This works really good for us. And the theory behind this is really nice. But surfaces are a bit harder. And OCC-naming confuses. So I can't help with applying this interaction to OCC splines.
But if you have access to the controllpoints, it shouldn't be that hard to make them visible and apply some eventhandlers to it.

Attached is a picture comparing the pinning of radial and orthogonal spline surfaces: Maybe a better choose of base function would give a better output.
comparison_radial_orthogonal.png
comparison_radial_orthogonal.png (250.38 KiB) Viewed 3804 times
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Radial Nurbs

Post by Chris_G »

Hi Edward,
emills2 wrote:i know you made this for radial basis functions, but i hope you realize the boring old u,v basis function surfaces don't have any kind of interface this cool in FreeCAD right now.
I write macros that generate grids based on sketches, and if i could parametrically tie my grids/sketches to a realtime surface display tool like you made...that would kick some major ass.
I made a macro, some time ago, that created a parametric bezier curve : the 4 point coordinates being editable in the data tab.
The curve was automatically updated. It used a Part.BezierCurve on each change of a point coordinate.
Then I tried to do it with a Bezier surface, but the display was horribly laggy.

As looo's python code opens highly interesting perspectives, I searched for some code example to display a bezier surface directly with coin ( without going through a Part.BezierSurface ).
You can try this directly in the python console ( create a new document before ) :

Code: Select all

from pivy import coin
import FreeCADGui


# The control points for this surface
pts = (
   (-4.5, -2.0,  8.0),
   (-2.0,  1.0,  8.0),
   ( 2.0, -3.0,  6.0),
   ( 5.0, -1.0,  8.0),
   (-3.0,  3.0,  4.0),
   ( 0.0, -1.0,  4.0),
   ( 1.0, -1.0,  4.0),
   ( 3.0,  2.0,  4.0),
   (-5.0, -2.0, -2.0),
   (-2.0, -4.0, -2.0),
   ( 2.0, -1.0, -2.0),
   ( 5.0,  0.0, -2.0),
   (-4.5,  2.0, -6.0),
   (-2.0, -4.0, -5.0),
   ( 2.0,  3.0, -5.0),
   ( 4.5, -2.0, -6.0))

# The knot vector
knots = (0, 0, 0, 0, 1, 1, 1, 1)

# Create the nodes needed for the Bezier surface.
def makeSurface(com):
    surfSep = coin.SoSeparator()
    
    # Define the Bezier surface including the control
    # points and a complexity.
    complexity = coin.SoComplexity()
    controlPts = coin.SoCoordinate3()
    surface    = coin.SoNurbsSurface()
    complexity.value = com
    controlPts.point.setValues(0, 16, pts)
    surface.numUControlPoints = 4
    surface.numVControlPoints = 4
    surface.uKnotVector.setValues(0, 8, knots)
    surface.vKnotVector.setValues(0, 8, knots)
    surfSep.addChild(complexity)
    surfSep.addChild(controlPts)
    surfSep.addChild(surface)
    
    return surfSep

carpet = coin.SoSeparator()
surf   = makeSurface(0.8)

carpet.addChild(surf)

view = FreeCADGui.ActiveDocument.ActiveView

view.getSceneGraph().addChild(carpet)
Then you can play with the surface display complexity (value between 0 and 1) with :

Code: Select all

surf.getChild(0).value = 0.1
Maybe displaying the surface this way would be fast enough to use it realtime ?

Chris
emills2
Posts: 875
Joined: Tue Apr 28, 2015 11:23 pm

Re: Radial Nurbs

Post by emills2 »

Then I tried to do it with a Bezier surface, but the display was horribly laggy.
this is why i was so surprised by looo's realtime editing. Everytime i create a surface i wait almost a minute. Sure, i'm recalculating all the basis functions everytime, but i thought most of the work was in tessellating the surface.

Looo, your picture on the right is all i was asking for, it looks like a uv surface (you call it ortho basis functions). if that object is parametric and the control points can be set to sketch points, or assigned from a spreadsheet, that would be all that is needed.

I'm sure there are some obstacles that i can't see, but if understanding details of NURBS didn't stop you from making the radial basis version...
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Radial Nurbs

Post by Chris_G »

Hi Edward,
Here is a funny toy for you.
The zip file attached contains 2 files :
- loooMarkers.py ( a copy of looo's file here : https://github.com/looooo/freecad_glide ... new_new.py)
- SurfaceEdit.fcmacro
Copy the files in your macro folder. Create a new doc in FC and start "SurfaceEdit.fcmacro".
Select some points and grab them with 'g' key.
You can constraint the move to axis with 'x', 'y' and 'z' key during the mouse grab.
'q' to quit editing
If editing is laggy for you, you can try to reduce Surface Complexity on line 31of the macro.
Quick and dirty code, but a proof of concept ...
Bye
Chris
Surface-Edit.zip
(4 KiB) Downloaded 121 times
emills2
Posts: 875
Joined: Tue Apr 28, 2015 11:23 pm

Re: Radial Nurbs

Post by emills2 »

that is really fun! is there a way to stop the macro without killing FreeCAD?

i noticed that if i hit x before hitting g, it eats the selected markers and i can't get them back.
freecad freehand bezier surface.png
freecad freehand bezier surface.png (36.91 KiB) Viewed 3659 times
editing speed is awesome even on an old machine. actually, if i hold the x key down during the grab, it does this weird high speed flicker that looks kinda cool :lol:

the free hand editing is great, but this also has value for faster surface previews.

Down the line i could see having a parametric surface object that derives from sketches, and when you edit a sketch, it does this live preview of the final surface.

now i need to learn all this GUI stuff too! if we could define groups of these surfaces and maintain some level of patch to patch continuity AND do live edits that propagate across neighbor surfaces, that would be pretty badass!
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Radial Nurbs

Post by looo »

This looks really smooth.
emills2 wrote: if i hold the x key down during the grab, it does this weird high speed flicker that looks kinda cool :lol:
This toggles the "x-constrained". So the point jumps between constraint position and mouse position.
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Radial Nurbs

Post by Chris_G »

emills2 wrote:that is really fun! is there a way to stop the macro without killing FreeCAD?
I added the 'q' key event to stop editing
emills2 wrote:i noticed that if i hit x before hitting g, it eats the selected markers and i can't get them back.
The x key was already used for removing a point marker ...
looo, I suggest you to replace line 343 of your code from :

Code: Select all

if event.getKey() == ord("x"):
to

Code: Select all

if event.getKey() == ord(u"\uffff"):
This replaces the 'x' key (used for axis constraint) by the 'delete' key
emills2 wrote:Down the line i could see having a parametric surface object that derives from sketches, and when you edit a sketch, it does this live preview of the final surface.

now i need to learn all this GUI stuff too! if we could define groups of these surfaces and maintain some level of patch to patch continuity AND do live edits that propagate across neighbor surfaces, that would be pretty badass!
Yeah, there are lots of possible interesting uses ... but I really need to untangle all these Coin, events and Gui things first.
My poor old brain is not made for this kind of non-linear programming (I learned programming with BASIC on Sinclair ZX-81 :lol: )
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Radial Nurbs

Post by looo »

Chris_G wrote:The x key was already used for removing a point marker ...
looo, I suggest you to replace line 343 of your code from :
Thanks, I have changed this: commit

OT:
I am thinking about outsourcing this interactive stuff directly to pivy. I like the idea of a easy to use highlevel graphics api that simplify the pivy stuff and show how to use it.

maybe similar to matplotlib:

Code: Select all

from pivy import Graphics
Graphics.Line()
Graphics.Polygon()
....
Graphics.show()
mea08kw
Posts: 82
Joined: Sun Oct 09, 2022 6:22 am

Re: Radial Nurbs

Post by mea08kw »

Chris_G wrote: Sat Feb 06, 2016 9:32 pm Hi Edward,
Here is a funny toy for you.
The zip file attached contains 2 files :
- loooMarkers.py ( a copy of looo's file here : https://github.com/looooo/freecad_glide ... new_new.py)
- SurfaceEdit.fcmacro
Copy the files in your macro folder. Create a new doc in FC and start "SurfaceEdit.fcmacro".
Select some points and grab them with 'g' key.
You can constraint the move to axis with 'x', 'y' and 'z' key during the mouse grab.
'q' to quit editing
If editing is laggy for you, you can try to reduce Surface Complexity on line 31of the macro.
Quick and dirty code, but a proof of concept ...
Bye
Chris
Surface-Edit.zip
Hi Chris

I have tested your code, it's awesome and it is what I need.

By the way, currently I only can select multiple control points by pressing "ctrl" button.

If we could select those point with box selection, that would be much easier.

FreeCAD has box selection feature, but it is not specific for these control points.

Do you have any suggestions of creating a box selection to select those control points?

Many thanks.

Mea08kw
Post Reply