(WORKAROUND) Speed ​​by techdraw

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Speed ​​by techdraw

Post by uwestoehr »

wandererfan wrote: Sun Jul 03, 2022 2:07 pm We already know why this is slow. The OCC HLR algo does thousands of edge and face intersection calculations sequentially.
OK, but is there an option where the user can turn off the HLR? I mean there is often no need to remove the hidden lines.

Besides this, the second issue is the unresponsiveness. As I wrote , this is on Windows a big issue since the OS will sooner or later try to kill FC because it detects it as unresponsiveness. The the users this action appears as if FC crashed.
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Speed ​​by techdraw

Post by wandererfan »

uwestoehr wrote: Sun Jul 03, 2022 2:36 pm OK, but is there an option where the user can turn off the HLR? I mean there is often no need to remove the hidden lines.
Not really, no. Even if you only want the visible lines, you still need to figure out what faces occlude which lines, where the occlusion takes place, and how much of the line is still visible. HLR does all this, plus the projection onto the page.

The only speed-up option provided by OCC is the coarse (polygon) method which turns all the lines into segments and is useless for dimensioning.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Speed ​​by techdraw

Post by uwestoehr »

wandererfan wrote: Sun Jul 03, 2022 3:24 pm Not really, no.
So we cannot do anything here regarding the speed.
That is sad. However, then we should mention this in the Wiki that people are aware of this. Since you have the background knowledge, could you maybe add a paragraph to https://wiki.freecadweb.org/TechDraw_Wo ... imitations ?
User avatar
thomas-neemann
Veteran
Posts: 11801
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: (WORKAROUND) Speed ​​by techdraw

Post by thomas-neemann »

thanks to everyone for the effort. as computers are getting faster and faster, the problem should also become smaller and smaller
Gruß Dipl.-Ing. (FH) Thomas Neemann

https://www.youtube.com/@thomasneemann5 ... ry=freecad
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: (WORKAROUND) Speed ​​by techdraw

Post by wmayer »

So we cannot do anything here regarding the speed.
This depends on how the HLR algorithm is implemented. In case it internally uses static or global variables then there is no way to run the algorithms in parallel. But if there is no such limitation we can run the actual algorithm in a thread. The code to do so would be of this form:

Code: Select all

QFuture<TopoDS_Shape> future = QtConcurrent::mapped(myShapes, [](const TopoDS_Shape& shape) {
        // put here the call of the HLR algorithm
}));
QFutureWatcher<TopoDS_Shape> watcher;
watcher.setFuture(future);
watcher.waitForFinished();
for (QFuture<TopoDS_Shape>::const_iterator it = future.begin(); it != future.end(); ++it) {
    // use the results
}
If needed the QFutureWatcher can be combined with an QEventLoop to keep the application responsive.
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: (WORKAROUND) Speed ​​by techdraw

Post by wandererfan »

wmayer wrote: Sun Jul 03, 2022 4:52 pm If needed the QFutureWatcher can be combined with an QEventLoop to keep the application responsive.
Thanks for the clues.

I made a quick proof of concept using QtConcurrent::run to execute a modified GeometryObject::projectShape in a separate thread and it seems to work fine. Of course, this is a blocking situation so it didn't actually do anything to solve the actual problem.

I'll have to figure out how to run projectShape asynchronously so the main thread can continue on.

Still not sure how to get progress reporting. We can't partition the workload by shape (as in your sample code) since hlr needs the whole input shape at the same time to calculate the occlusions. We might be able to separate disjoint shapes, but that isn't the standard use case.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: (WORKAROUND) Speed ​​by techdraw

Post by wmayer »

I'll have to figure out how to run projectShape asynchronously so the main thread can continue on.
You can try it this way:

Code: Select all

QFutureWatcher<TopoDS_Shape> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<TopoDS_Shape>::finished, &loop, &QEventLoop::quit);
loop.exec();
for (QFuture<TopoDS_Shape>::const_iterator it = future.begin(); it != future.end(); ++it) {
    // use the results
}
Still not sure how to get progress reporting. We can't partition the workload by shape (as in your sample code) since hlr needs the whole input shape at the same time to calculate the occlusions.
If you have a single shape only then there is no way to show a progress indicator. There we would have to wait for OCC to implement it. However, if you have several shapes to be processed you can use the class Base::FutureWatcherProgress

Code: Select all

Base::FutureWatcherProgress progress("Hidden line removal...", numberOfShapes);
QFutureWatcher<TopoDS_Shape> watcher;
QObject::connect(&watcher, &QFutureWatcher<TopoDS_Shape>::progressValueChanged,
                             &progress, &Base::FutureWatcherProgress::progressValueChanged);
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<TopoDS_Shape>::finished, &loop, &QEventLoop::quit);
loop.exec();
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: (WORKAROUND) Speed ​​by techdraw

Post by wandererfan »

a quick update for anybody following this saga...

I have an async prototype working that sends hlr off to a separate thread, returns control to the main thread so the gui is freed up, then updates the view when the separate thread completes.

next steps:
- move the face finding logic (the second biggest time consumer) off to a separate thread,
- investigate progress reporting,
- refactor the messy prototype code into something maintainable.
chrisb
Veteran
Posts: 53926
Joined: Tue Mar 17, 2015 9:14 am

Re: (WORKAROUND) Speed ​​by techdraw

Post by chrisb »

wandererfan wrote: Fri Jul 08, 2022 1:07 pm I have an async prototype working that sends hlr off to a separate thread,
That sounds promising! Thanks for the work!
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
user1234
Veteran
Posts: 3339
Joined: Mon Jul 11, 2016 5:08 pm

Re: (WORKAROUND) Speed ​​by techdraw

Post by user1234 »

wandererfan wrote: Fri Jul 08, 2022 1:07 pm I have an async prototype working that sends hlr off to a separate thread, returns control to the main thread so the gui is freed up, then updates the view when the separate thread completes.
With that your are better then the most commercial CADs. Incredible!

Greetings
user1234
Post Reply