Tips on improving techdraw performance

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Tips on improving techdraw performance

Postby yorik » Fri Aug 16, 2019 1:49 pm

@wandererfan what about being able to do something like this:

Code: Select all

view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewSymbol','ViewSymbol')
view.Symbol = "<svg>... some svg fragment</svg>"
view.DimPoints = [(15.0,34.5),(256.65,45.76),...]
The last line would define points that are in the same coordinate system as the SVG, that would allow TD to use as dimension points, and therefore allow TD to place dimension on SymbolViews. Do you think that would be hard to implement?
wandererfan
Posts: 2881
Joined: Tue Nov 06, 2012 5:42 pm

Re: Tips on improving techdraw performance

Postby wandererfan » Fri Aug 16, 2019 1:57 pm

yorik wrote:
Fri Aug 16, 2019 1:43 pm
One thing, though, this code has the same limitation as the one I'm using now: the view size is obtained in pixels, which could give quite a lot of imprecision (enough to change the value of a dimension, for ex). But I suppose we'll have to live with it for now, there might be further checks we can apply later on to refine the scale factor.
QScreen::physicalDotsPerInchX() and QScreen::physicalDotsPerInchY()??
wandererfan
Posts: 2881
Joined: Tue Nov 06, 2012 5:42 pm

Re: Tips on improving techdraw performance

Postby wandererfan » Fri Aug 16, 2019 2:08 pm

yorik wrote:
Fri Aug 16, 2019 1:49 pm

Code: Select all

view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewSymbol','ViewSymbol')
view.Symbol = "<svg>... some svg fragment</svg>"
view.DimPoints = [(15.0,34.5),(256.65,45.76),...]
The last line would define points that are in the same coordinate system as the SVG, that would allow TD to use as dimension points, and therefore allow TD to place dimension on SymbolViews. Do you think that would be hard to implement?
Currently, DrawViewSymbol doesn't know anything about geometry. I wonder if I shouldn't make a "made to measure" feature that would use the Svg as a "background", then overlay a geometry llayer.

There is code in TD to post process Svg files. Can we drop to the Text nodes before making the Svg file, then add them as unexploded text before we display?

DrawAugmentedSvg(svgFile, dimPointsList, textList)???
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Tips on improving techdraw performance

Postby yorik » Fri Aug 16, 2019 6:02 pm

wandererfan wrote:
Fri Aug 16, 2019 1:57 pm
QScreen::physicalDotsPerInchX() and QScreen::physicalDotsPerInchY()??
The values would still be ints... That means a window of, say 800x600, would basically divide a length of possibly thousands of units into just 800 units... but maybe coin holds a more precise value, I'll look into it.
wandererfan wrote:
Fri Aug 16, 2019 2:08 pm
Currently, DrawViewSymbol doesn't know anything about geometry. I wonder if I shouldn't make a "made to measure" feature that would use the Svg as a "background", then overlay a geometry llayer.
The idea basically would be that TD doesn't have anymore to care about the geometry. It would receive a list of points that it would be able to highlight in green and put dimensions between those points (considering the view scale of course). Of course it wouldn't be able to dimension lines just yet, but hat would be a good start already...

That could even work with bitmaps... imagine a render engine providing a bitmap and a list of snappable points on it (blender would be able to do that I think)

The problem I think if we parse the SVG in TD to get geometry info is processing time... The engine that generates the svg could also build the points list in the same go, so we could have significant gains there
wandererfan
Posts: 2881
Joined: Tue Nov 06, 2012 5:42 pm

Re: Tips on improving techdraw performance

Postby wandererfan » Fri Aug 16, 2019 10:16 pm

yorik wrote:
Fri Aug 16, 2019 6:02 pm
The idea basically would be that TD doesn't have anymore to care about the geometry. It would receive a list of points that it would be able to highlight in green and put dimensions between those points (considering the view scale of course). Of course it wouldn't be able to dimension lines just yet, but hat would be a good start already...
Sorry, didn't express myself well. I meant that DrawViewSymbol would need a place to store the points in a way that the selection and dimension code could access it.

The points (and edges and faces) are stored in something called a GeometryObject.

In this case we would just move the points from the input parameter to the GeometryObject. No actual processing (except maybe scaling?)
wandererfan
Posts: 2881
Joined: Tue Nov 06, 2012 5:42 pm

Re: Tips on improving techdraw performance

Postby wandererfan » Sun Aug 18, 2019 12:20 pm

I've made some progress. This is 3D to Svg to TD. The Svg is untouched.
casa_pelaTD_markers.png
casa_pelaTD_markers.png (21.58 KiB) Viewed 223 times
Still having trouble with scaling and cropping.

Time to split the thread?
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Tips on improving techdraw performance

Postby yorik » Wed Aug 21, 2019 10:06 pm

wandererfan wrote:
Sun Aug 18, 2019 12:20 pm
Time to split the thread?
Maybe... :D

I also did some cool progress. With git commit f93a986b5a, TechDraw Arch views now have a third rendering mode called "Coin", besides Wireframe and Solid. It is still very unoptimized (some booleans are still performed, there could be more caching, etc...) but it works pretty well already!
Screenshot from 2019-08-21 18-42-22.png
Screenshot from 2019-08-21 18-42-22.png (252.2 KiB) Viewed 181 times
For who is curious about the implementation details, it all basically happens in this function https://github.com/FreeCAD/FreeCAD/blob ... ne.py#L617 which is an adaptation of the script I posted here earlier. For the cropping, I simply stripped the viewbox out, which makes TD recalculate the cropping area itself, which works well.

For the scaling, I found a better trick: before rendering, we add a "marker", that is, a line with a known size to the scene. We then measure it in the svg result and deduce the scaling to apply, and we remove the marker from the scene. At the moment, the marker is just a white line, so we must find something better otherwise any object with white edges could be confounded with the marker.

Also texts and annotations are not rendered, but added on top, directly in svg.

This is the file in the above screenshot (you need the commit above to test, of course): https://www.dropbox.com/s/ykeyzbqlhaw5h ... FCStd?dl=0 (there is aweird problem in that file with objects not updating, but it's related to the link merge I think, will investigate later)
triplus
Posts: 8605
Joined: Mon Dec 12, 2011 4:45 pm

Re: Tips on improving techdraw performance

Postby triplus » Wed Aug 21, 2019 10:40 pm

wandererfan wrote:
Fri Aug 16, 2019 10:16 pm
yorik wrote:
Fri Aug 16, 2019 6:02 pm
The idea basically would be that TD doesn't have anymore to care about the geometry. It would receive a list of points that it would be able to highlight in green and put dimensions between those points (considering the view scale of course). Of course it wouldn't be able to dimension lines just yet, but hat would be a good start already...
Sorry, didn't express myself well. I meant that DrawViewSymbol would need a place to store the points in a way that the selection and dimension code could access it.
I guess similar to TechDraw_CosmeticVertex functionality. Things like dimensioning arcs wouldn't be supported, though.

P.S. When it comes to dimensioning SVG i guess DrawingDimensioning module rings a bell.
wandererfan
Posts: 2881
Joined: Tue Nov 06, 2012 5:42 pm

Re: Tips on improving techdraw performance

Postby wandererfan » Wed Aug 21, 2019 11:53 pm

yorik wrote:
Wed Aug 21, 2019 10:06 pm
I also did some cool progress. With git commit f93a986b5a, TechDraw Arch views now have a third rendering mode called "Coin", besides Wireframe and Solid. It is still very unoptimized (some booleans are still performed, there could be more caching, etc...) but it works pretty well already!
Very cool indeed! <handsClapping \>

In my hacking at the problem, I've discovered some shortcomings (for my purposes anyway) in the existing SoFCVectorizeSVGAction code:
- output page is too small. width and height attributes have no unit attached so resulting "page" is in pixels instead of mm
- no viewbox specified, so if first item is corrected, page will be right size but image will be tiny. These two items make it difficult to predict the scale of the result.
- line widths are hard coded as "1px" which results in thick lines in output
- background is always opaque full page rectangle. An option to not draw background would allow transparent backgrounds.
- only standard ISO page sizes A0-A10 are supported. SoVectorizeAction will support arbitrary "page" sizes if the correct width, height and margin values are passed to it.

I'd like to maybe subclass SoFCVectorizeSVGAction to fix some of these without impacting the current functionality. Maybe we can reduce the amount of SVG parsing required, too.

There are some light/shadow/colour issues if we use a perspective camera (which architects might like?). As an Inventor/Coin beginner, I'm not sure what to do about this yet.
there is aweird problem in that file with objects not updating, but it's related to the link merge I think, will investigate later)
I've had updating problems for a while but I haven't addressed them because of the plan to make drawings only update on demand.
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Tips on improving techdraw performance

Postby yorik » Fri Aug 23, 2019 10:09 pm

wandererfan wrote:
Wed Aug 21, 2019 11:53 pm
I'd like to maybe subclass SoFCVectorizeSVGAction to fix some of these without impacting the current functionality. Maybe we can reduce the amount of SVG parsing required, too.
That would be cool! I don't think that functionality is used much (yet :) ) so probably it's relatively safe to extend...

Too bad that apparently transparency is not supported https://coininventor.github.io/doc/clas ... ml#details
triplus wrote:
Wed Aug 21, 2019 10:40 pm
I guess similar to TechDraw_CosmeticVertex functionality.
Yes, basically the same thing. What do you think would be needed to have such cosmetic points system on a TD ArchView @wandererfan? Also there would likely be many for a single view. Maybe all TD views could gain a property that holds such points? (CosmeticPoints?)