Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

I think I am correct that the psuedo code for the OpenSCAD importer's implementation of a Hull request is
  • Encounter hull request with objects to be hulled on Object Stack
  • Mesh the Objects to be hulled.
  • Pass Meshed Objects and hull request to command line OpenSCAD executable
  • Receive results from OpenSCAD as Mesh or DXF for 2D operations
  • Incorporate into FreeCAD document
Passing of data between FreeCAD importer and OpenSCAD is via physical files

Now my understanding is that OpenSCAD nowadays uses GCAL & OpenCSG http://opencsg.org under the covers, so one question I have is why don't we try and bypass the middle man and use OpenCSG directly i.e.
  • Encounter hull request with objects to be hulled on Object Stack
  • Mesh the Objects to be Hulled, could this be passed off to n threads where n is the number of objects to be hulled?
  • Call OpenCSG directly to perform the Hull request
  • Process resulting Mesh from OpenCSG thus avoiding all the file transfers etc.
(Would require creating python library/bindings for GCAL & OpenCSG )
There are research papers on parrallising 3D hull operations, so if going down this path it would be a good idea to allow for plugging in even better solutions that used CUDA say. i.e NVIDIA Jetson Nano runs Linux right so why not an option that exploited with FreeCAD running on it.

Research Papers
User avatar
chennes
Veteran
Posts: 3878
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by chennes »

If the goal is to incorporate Hull and Minkowski sum directly, I think it's just CGAL we need to look at. I don't think OpenCSG has anything to do with those -- as the name suggests, it's purely a CSG framework, it doesn't work on meshes as far as I am aware. So what you are really looking at is compiling CGAL into FreeCAD, and either using the pre-existing SWIG Python bindings for it, or creating your own. I have no idea what level of work we are talking about there, but I guess if it's a project you're interested in, I think a library dependency is preferable to an executable dependency, especially as we move to things like Snap packages for the executables.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

chennes wrote: Mon Apr 26, 2021 1:51 pm If the goal is to incorporate Hull and Minkowski sum directly, I think it's just CGAL we need to look at. I don't think OpenCSG has anything to do with those -- as the name suggests, it's purely a CSG framework, it doesn't work on meshes as far as I am aware. So what you are really looking at is compiling CGAL into FreeCAD, and either using the pre-existing SWIG Python bindings for it, or creating your own. I have no idea what level of work we are talking about there, but I guess if it's a project you're interested in, I think a library dependency is preferable to an executable dependency, especially as we move to things like Snap packages for the executables.
Was not sure if I needed OpenCSG or CGAL was based on somebody mentioning that OpenSCAD use OpenCSG, but your right it does look like just rendering, plus its not been updated for 5 years and CGAL looks like the right thing. Are there SWIG Python bindings for CGAL? That would be good.
Not looking to compile CGAL into FreeCAD would prefer just to make a Python Call that results in a call to a C++ library.
User avatar
chennes
Veteran
Posts: 3878
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by chennes »

There is some relatively recent work on CGAL Python bindings: https://github.com/CGAL/cgal-swig-bindings/wiki

Ultimately, to use them we'll have to link the CGAL library into FreeCAD (that is, we'll be introducing a compilation dependency on CGAL, which will have to be installed on the build machine, added to the LibPack, CMake, etc.).
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

chennes wrote: Mon Apr 26, 2021 1:51 pm If the goal is to incorporate Hull and Minkowski sum directly, I think it's just CGAL we need to look at. I don't think OpenCSG has anything to do with those -- as the name suggests, it's purely a CSG framework, it doesn't work on meshes as far as I am aware. So what you are really looking at is compiling CGAL into FreeCAD, and either using the pre-existing SWIG Python bindings for it, or creating your own. I have no idea what level of work we are talking about there, but I guess if it's a project you're interested in, I think a library dependency is preferable to an executable dependency, especially as we move to things like Snap packages for the executables.
Found cgal bindings but it seems to need CGAL and SWIG etc as pip -v install cgal-bindings gives errors,
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

chennes wrote: Mon Apr 26, 2021 3:28 pm There is some relatively recent work on CGAL Python bindings: https://github.com/CGAL/cgal-swig-bindings/wiki

Ultimately, to use them we'll have to link the CGAL library into FreeCAD (that is, we'll be introducing a compilation dependency on CGAL, which will have to be installed on the build machine, added to the LibPack, CMake, etc.).
Is that true? Yes to use one would have to install a C++ library and some Python Bindings, but I don't see why the library would have to be linked to FreeCAD, other software you can just install a library and bindings, call python functions.

In tried

Code: Select all

brew install cgal
brew install swig
but pip install cgal-bindings fails, does not find CGAL, maybe the brew install did not put it in a standard place
User avatar
chennes
Veteran
Posts: 3878
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by chennes »

You're right, if we are only using it from Python then CGAL gets linked into the Python wrapper library, but isn't needed by FreeCAD until runtime when you import it.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
duckmug
Posts: 126
Joined: Mon Jun 07, 2021 12:26 am

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by duckmug »

No intention of bumping this thread, but how are things looking on this front?

It would really be a game changer if hull was supported natively.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by keithsloan52 »

duckmug wrote: Wed Jun 16, 2021 5:01 am No intention of bumping this thread, but how are things looking on this front?

It would really be a game changer if hull was supported natively.
Not much - Too busy with distance learning Masters so lack of spare time.

Don't think all hull requests will ever be handled 'natively' more case of some specific cases. If you install https://github.com/KeithSloan/OpenSCAD_Alt_Import

Remember with it installed you have to perform a file load and then you will be prompted for which
importer to use. Then a few cases are handled but in a lot of cases there are still bugs, lots of bugs.

Examples of files with hull requests that should work are
Two-Spheres-Hull.csg
(178 Bytes) Downloaded 31 times
From_Finger.csg
(334 Bytes) Downloaded 30 times
Please feel free to contribute some test cases of specific hull requests that could be handled.
duckmug
Posts: 126
Joined: Mon Jun 07, 2021 12:26 am

Re: Discussion - Possible way ahead for OpenSCAD hull and Minkowski requests?

Post by duckmug »

I had no idea that this was around, I am so glad, will be definitely using it.

What makes it restricted to two spheres or two cylinders etc?

Why not support a combination of a cylinder and a cube for instance?
Post Reply