Freecad fails to be serious CAD because of poor language choice

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!
andremiv
Posts: 56
Joined: Thu Sep 02, 2021 10:45 am
Location: France

Re: Freecad fails to be serious CAD because of poor language choice

Post by andremiv »

You are still ignoring all the posts telling you that not Python is the bottleneck. So speeding up the Python stuff would not speed up the whole FreeCAD performance. It would probably speed up a rather neglectable part. And interpreting your C-like scripting language would make it slower too, wouldn't it?
You convinced me at 80%, I trust your expertise of the Freecad program but...

the STL to brep converter in the part module is way too slow, I think there is a problem here. Was'nt able to identify the file that manage that on the freecad repo, I assume it would be in src/part but did not find it. Don't tell me it is the fault of the API for this one

A research on the API uses of binutils vs breputils suggest part of Freecad uses ascii brep. Am I right on this one ?




You don't interpret C like scripting language, you compile it and linked against it at run time, For instance, you could have a script that accept a valid C maths function to program points. Of course the user should not program in C, only enter the math functions and basis that generate points for a point generator script. Then this custom C script function is inserted in a template C file that is compiled then freecad calls it if compilation was suscessful, seems hard to do but not at all. Only require a gcc dependancy like python scripts need a python depandancy.

EDIT : To be clear it does'nt require restarting of the program, the compiled function can be called provided the compilation succeded, compilation should take less than one sec

EDIT 2 : It is not linked at runtime, wrong formulation, you load dynamically your "C script" generated object when Freecad is already running

EDIT3 : You use dlopen dlsym for linux and dllopen and getprocadress for windows
Last edited by andremiv on Thu Feb 03, 2022 3:08 pm, edited 3 times in total.
A new era of point programmation has come !
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Freecad fails to be serious CAD because of poor language choice

Post by chrisb »

andremiv wrote: Fri Jan 21, 2022 12:26 am the STL to brep converter in the part module is way too slow, I think there is a problem here. Was'nt able to identify the file that manage that on the freecad repo, I assume it would be in src/part but did not find it. Don't tell me it is the fault of the API for this one
There you have something that well may need some love. Furthermore it seems to be rather isolated, so with your knowledge in STL format I would say stop whining, roll up your sleeves and start coding! The FreeCAD community sure will be thankful for an improvement. And I'm sure someone can guide you to the corresponding source code.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Freecad fails to be serious CAD because of poor language choice

Post by Kunda1 »

andremiv wrote: Fri Jan 21, 2022 12:26 am You convinced me at 80%
Time for to revise this thread topic ?
May i suggest:
"Parts of FreeCAD could be optimized better (Was: a prejudged/uninformed opinion about programming language choices in regards to FreeCAD)
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Freecad fails to be serious CAD because of poor language choice

Post by openBrain »

andremiv wrote: Thu Jan 20, 2022 11:36 pm Sorry Openbrain but I have my preferences about languages, why should I have skills in object programming languages like C++ and python when C can do everything
Obviously no skill is required to expose own preferences. But when starting to advise or assess which language is better for which purpose, a pretty good knowledge is required IMO.
1) You can create a kind of a C based language script to make everything faster that clearly exposes API and make it simpler to learn and way faster than python
Wrong. Having such a script language won't allow you to expose FreeCAD API.
2) Python is way harder than C, even from beginners from my point of view, maybe it is an affair of taste, we could have a poll to see what people thinks
Wrong. Just asks two beginners to code a cross-platform GUI software, one with Python and one with C. You'll see. ;) Moreover there are complex things in C that Python abstracted to the user (just an example : memory management).
3) The C language based script would loses only a small fraction of speed compared to the special purpose program. The cost of generality is maybe a factor 2 at most, mind you that a special purpose code is only an application of a more general theory. In freecad the cost is a factor 100. That is to say, it is 100 to 1000 times slower, it's unacceptable.

The C based language script idea is just a call to C compiler in a formatted text, then runtime linking to the C script object so not too difficult to implemant.
If it's so simple, please do (or wonder why it has never been done already). I'd be curious to see how you link against a binary without having the symbols...
Also remember we are talking about an importer. So not just need to call main binary APIs, but also need to be called from main binary.
EDIT: Freecad needs python dependancy, so a C compiler dependancy like gcc should not be a problem
I guess you have no idea what pain it would be to embed something like GCC that purpose isn't to be embedded as a 3rd party lib. Probably I you tried something like this, TCC would be a better choice.
andremiv wrote: Fri Jan 21, 2022 12:26 am the STL to brep converter in the part module is way too slow, I think there is a problem here. Was'nt able to identify the file that manage that on the freecad repo, I assume it would be in src/part but did not find it. Don't tell me it is the fault of the API for this one
https://github.com/FreeCAD/FreeCAD/blob ... O.cpp#L240
A research on the API uses of binutils vs breputils suggest part of Freecad uses ascii brep. Am I right on this one ?
Don't know, but found no trace of breputils in the active code.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Freecad fails to be serious CAD because of poor language choice

Post by wmayer »

the STL to brep converter in the part module is way too slow, I think there is a problem here. Wasn't able to identify the file that manage that on the freecad repo, I assume it would be in src/part but did not find it. Don't tell me it is the fault of the API for this one
The slow part is the sewing of the created faces (see BRepBuilderAPI_Sewing) and that's done by the CAD kernel. In v0.20 this algorithm has been optimized by using the topological information that we have for a mesh so that BRepBuilderAPI_Sewing doesn't have to restore all this information again..

This alone reduced the computation time by 30%. If the user accepts a compound of faces instead of a compound of shells as a result the computation time can by reduced by 90%.

For more details have a look at: https://forum.freecadweb.org/viewtopic. ... 86#p533186

But keep in mind that this 1:1 conversion of mesh triangles to BRep faces is a dumb method because it doesn't restore the mathematically correct geometry but only an approximation of it.
andremiv
Posts: 56
Joined: Thu Sep 02, 2021 10:45 am
Location: France

Re: Freecad fails to be serious CAD because of poor language choice

Post by andremiv »

Openbrain you are not understanding me right, just wait and see, I have already done this kind of things, for instance I wanted to do a General AI where given the text interaction with user, the program could self program itself and create it's own tree branch and load everything dynamically, for instance you could input "Calculate 2+3 !" to the machine, the machine would decompose text and will question you to try to make a program out of your instructions. The idea was that online chat bots lacked logic, you could tell them that "bob's cat is blue" and then ask them "what is the color of bob's cat ?" and they would not be able to answer because for me they lacked dynamicall self programmation which is one pillar (for me) of General AI. Short story you can do it, seriously very easy, not a problem.

I think I can implemant a "point generator C script" where user enter a valid C math formula, parameters and define basis for generating complex sweep / rotating stuff, this point generator C script could allow user to create complex shapes like the globoids. The cost of generality should be at most 2 times slower for the same reason that a custom code is only an application of a more general theory.

Because the C script ask you to fill fields to be included in a template C file, it kind of exposes the API of what you can do with it, maybe my idea is misformulated

As chrisb pointed out, I have to code and propose my ameliorations. As I said it is hard for me to help because I have to learn python and C++ just to interface my C code with Freecad. Moreover I still need to learn some of the API and understand the structure and program flow of Freecad code. I also have to think about the possibility of writing my own API in C and compute shaders/Vulkan for the tasks I need and to somehow see how it could be interfaced with freecad, not easy.

André Miville
A new era of point programmation has come !
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Freecad fails to be serious CAD because of poor language choice

Post by openBrain »

Hopefully you're young enough (and I'll live old enough) so that we can see it for real. :)
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Freecad fails to be serious CAD because of poor language choice

Post by Kunda1 »

wmayer wrote: Fri Jan 21, 2022 1:29 pm
the STL to brep converter in the part module is way too slow, I think there is a problem here. Wasn't able to identify the file that manage that on the freecad repo, I assume it would be in src/part but did not find it. Don't tell me it is the fault of the API for this one
The slow part is the sewing of the created faces (see BRepBuilderAPI_Sewing) and that's done by the CAD kernel. In v0.20 this algorithm has been optimized by using the topological information that we have for a mesh so that BRepBuilderAPI_Sewing doesn't have to restore all this information again..
I really wish this part of the source was commented in more depth. It looks impenetrable.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
andremiv
Posts: 56
Joined: Thu Sep 02, 2021 10:45 am
Location: France

Re: Freecad fails to be serious CAD because of poor language choice

Post by andremiv »

From occt API : Sewing provides methods to :

identify possible contiguous boundaries (for control afterwards (of continuity: C0, C1, ...))
assemble contiguous shapes into one shape. Only manifold shapes will be found. Sewing will not be done in case of multiple edges.

Not sure to understand why Freecad need to do sewing on my stl points because my shared points (that appartain to multiple triangles) are exactly at the same points.

By the way Is it just me or their documentation of the Brep file Format is extremely bad. I don't like their Brep file format. You can see that the Brep wants to do too much at the same time. Let the programmers build structures themselves, dont impose your structure to other ! I don't love the OCC kernel.

I won't follow their standard and way of doing things, I will do my own and continue with C programming CAD for the moment. I am very disappointed with the OCC.

I think if Freecad wants to evolve for the good, it has to completely abondon the OCC kernel and develop an API of its own from scratch. Look at the OCC guys, they sell the good stuff and release the rest for free. It seems slower to comply and use their API than to develop your own, it makes wrapers on wrapers on wrapers, how many layers, sublayers, toplayers, parents child, In C none of this mess seriously STOP!

Yes Openbrain, we all hope to see General AI but require lots of time indeed

André Miville
A new era of point programmation has come !
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Freecad fails to be serious CAD because of poor language choice

Post by Kunda1 »

Mod edit: Redacted user1234's comment because it was offensive and unnecessarily confrontational
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply