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
saso
Veteran
Posts: 1920
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Tips on improving techdraw performance

Post by saso »

wandererfan wrote: Wed Aug 14, 2019 3:30 pm I have played a bit in TD with making a view of a 2D object without going through the HLR and it is very fast.
Exactly what I wanted to point out, it is at least fast enough to be usable
wandererfan wrote: Wed Aug 14, 2019 3:30 pm I don't know much about the insides of Arch, but it looks like ArchSection might be using Something like BRepAlgo_Section to get the section line. This only returns the cut face outline and not the solid behind the cut so it is much faster.

We could make a "fast section" function that only draws the cut face if that is useful.
Not quite... In this post of yorik there are examples of three houses https://yorik.uncreated.net/?blog/2018-437 , download House 1 (casa_pala.FCStd), open it, select the "Vistas geradas" group and make its content visible. Now lets take a closer look for example at the sections "Corte trans visto" and "Corte trans cortado". If you select one of them and look in to the Data tab, you can see several properties to control what is visible, play a bit with the "Projection Mode" and "Hidden Lines" properties. And because they are fast you can even do such trick as is shown in this model, make several 2D shapes of the same view and set different properties for each of them, then place them all on top of each other ("Corte trans visto" and "Corte trans cortado" in this example). To push this even a bit further, select one of them (for example "Corte trans visto") and make a copy ctrl-c (when asked if you want to copy dependencies chose no) and paste ctrl-v, it should make a copy on the same place. Select your copy, make sure "Projection Mode" is set to Solid and set "Hidden Line" to true, now change to View tab and change the "Draw Style" of this copy to Dashed, select "Corte trans visto" and "Corte trans cortado" and change their "Line Width" to 3... One can see that there is quite a lot of room to play around and get different drawings out of this. For a floor plan for example one could make another view and flip it up and get also the ceiling plan... And all of it is quite fast and linked back to the model.

So, if we can place this now in a TD drawing and if it stays about as fast as it is, then we would already have something quite useful and if then we would be able to also use the new TD appearance tool to clean up the drawing even a bit more (architects are picky as f*ck :) ) then things would get really interesting...

However, even when this is quite fast, in architecture projects you can quickly have several dozen, very often even several hundreds of such views/drawings, so you would still not want to have them all refresh at the same time all the time. But I guess it should be possible to get this for example to refresh only for those that are placed in an opened TD drawing and maybe even only when they open and then manually.

But, when one has so many drawings, one needs to be able to manage them somehow, and this is where my second suggestion, to be able to have many documents inside the same FCStd file. It is possible to manage it in a similar way how yorik has it in this house example, that is to have them in a grupe and hide it when you don't need it, but it would IMO be much better if we would be able to place this out of the main model view space. This would also be useful not just for such generated 2D drawings of the model but for example one could also import some standard 2D details from dwg files and have them saved in the project but away from the main model...
dimitar wrote: Wed Aug 14, 2019 5:49 pm I know how the revit workflow works, but how does archicad work? What are the advantages of having stand alone 2d documents save in a seperate file?
This could actually also be linked to separate files... But I am talking here about to have may different documents in the same FCStd file, think of revit drafting view or legends, while all the other views are basically just different 3d views of the same model, this are sort of as separate, individual documents inside the same project file...

... So, this would be the second strategy, creating 2D shapes and preferably be able to have them saved not in the same space as the main model. There is however still quite a lot of refreshing going on in this, and anyone that ever used archicad will know that, specially if they also sometimes use revit where there is very little refreshing going on and the trick is that they simply don't do full 2D drawings of everything but use custom 3d views for most of it and do just minimal 2D work on top of it...

Both of this however have their pluses and minuses and it is why, at least in the long term, I would like to see them both in FreeCAD and then it is up to the user to use what s/he prefers.
Last edited by saso on Wed Aug 14, 2019 8:02 pm, edited 24 times in total.
User avatar
wandererfan
Veteran
Posts: 6265
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Tips on improving techdraw performance

Post by wandererfan »

dimitar wrote: Wed Aug 14, 2019 5:49 pm Is there away to have multi threaded hidden lines removal or is that an OCC feature?
Yes, it is inside OCC. There was a report that OCC was working on parallel processing for HLR, but I haven't seen any updates on this.
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Tips on improving techdraw performance

Post by freedman »

How do you guys work on a project with, say 20, 30 + sheets? Is it feasible yet in Freecad with the current TD speeds?
I wait until all my changes are made to the model, create a bunch of views in TechDraw, then make DXF's and catalog all the files in DXF folders. I use AutoCad to dim. and do some drawing editing. This way I can have multiple drawings open and the model and work fast. TechDraw has limits currently, speed issues and the fact that drawings can be corrupted if the model breaks has kept me using alternates.

I made this post just to address making multiple DXF's:
https://forum.freecadweb.org/viewtopic.php?f=22&t=38538

That's how I do it.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Tips on improving techdraw performance

Post by yorik »

This is a recurring subject me and @wandererfan have been breaking our heads on since a long time...

We can certainly gain a little bit of performance, but not to the levels we would need with Arch/BIM. We need basically to be able to produce 2D (cut) views of large building models that can contain easily a few thousand faces... And have sets of 20 or 30 sheets which contain many of those cut views... As wandererfan says, TechDraw was built for other purposes, basically one-part models. For this task it is performing extremely well.

But, the OCC algos we use both in TechDraw and in Arch (to produce Arch section views) are indeed way too slow to achieve the kind of results we need as above. But the archview system in TechDraw shows IMHO a good starting path: Most of the TechDraw tools are pretty generic and useful for any workflow. We just need to use a different "engine" to produce the actual view data.

There is one idea I definitely want to explore further: Our Coin-based 3D view in FreeCAD is able to produce a SVG rendering of itself, blind fast. There is still quite a lot of testing to do to be able to do what I want to do, which is basically: 1) create an offline (hidden) scene with a copy of the FreeCAD scenegraph, 2) set it to the desired parameters, camera orientation, object visibility, clipping, etc 3) produce an SVG out of it 4) find a way to rescale/size it and 5) update the corresponding TD view. Given that you can obtain really nice visual result in the 3D view, I think that could work well...

The problem so far is I'm not able to create an offscreen rendering of a coin view inside FreeCAD (it works well outside of it, though), and 2) the SVG output is a feature added to FreeCAD, it's not available in pure coin. But certainly it could be ported somehow. Also some useful features such as texture and hatching are not supported by that SVG engine yet

Another useful improvement would be to allow to manually provide a list of dimension anchor points and fillable faces to a techdraw view, together with an svg fragment. That would allow to remove most of the burden from TechDraw, but still be able to use most of its features...
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Tips on improving techdraw performance

Post by freedman »

This is a recurring subject me and @wandererfan have been breaking our heads on since a long time...
I know you guys have been working hard on this, thanks.
There is one idea I definitely want to explore further: Our Coin-based 3D view in FreeCAD is able to produce a SVG rendering of itself, blind fast.
I like this concept, maybe start with a direct output from the model to a open source SVG/DXF viewer, possible realtime viewing. Then make TechDraw2 that manipulates the model to get the drawing items selected correctly. These outputs could also contain some other needed info like date and model version numbers to link drawings & model.

I do agree that TechDraw works well for it's intended, but something like a 10 story building really needs it's files stored offline in multiple folders.
User avatar
saso
Veteran
Posts: 1920
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Tips on improving techdraw performance

Post by saso »

Question about parallel processing... Taking the above example of yorik's casa_pala.FCStd, there are 16 of such 2D generated drawings in there, I understand we are not able to use multi processors on each of them, but are we not able to even push one of them per procesor, so if someone has 4 cores, then 4 of them would recompute at once?
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Tips on improving techdraw performance

Post by yorik »

This simple script already produces interesting results:

Code: Select all

sg=Gui.ActiveDocument.ActiveView.getSceneGraph()
from pivy import coin
rn=coin.SoSeparator()
for n in sg.getChildren():
    if isinstance(n,coin.SoSeparator):
        rn.addChild(n.copy())
v=Gui.createViewer()
vv=v.getViewer()
vv.setBackgroundColor(1,1,1)
v.redraw()
vv.setSceneGraph(rn)
v.saveVectorGraphic("/home/yorik/test.svg")
This is what appears in the viewer once it's created:
Screenshot from 2019-08-14 19-52-01.png
Screenshot from 2019-08-14 19-52-01.png (49.67 KiB) Viewed 1621 times
and this is the SVG output (I reduced the line width in inkscape):
g51174.png
g51174.png (73.29 KiB) Viewed 1621 times
The advantage of this is that it all happens outside the main view, so it doesn't modify anything to it.. And being a FreeCAD viewer, it has SVG export capability.

The result is quite good I think. And it's almost instant. And even being a quite heavy SVG file, TechDraw manipulates it with extreme ease:
Screenshot from 2019-08-14 20-08-36.png
Screenshot from 2019-08-14 20-08-36.png (114.68 KiB) Viewed 1621 times
We might be on to something here I think...

Two further questions to explore:

1) See what happens when we add a clip plane, if the SVG rendering is still correct
2) We need to scale this thing correctly. The SVG contains a rectangle that has the proportion of the view background. But how to find out that size in real world units...
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Tips on improving techdraw performance

Post by freedman »

https://svgwg.org/svg2-draft/
Here is some good file format info.
User avatar
wandererfan
Veteran
Posts: 6265
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Tips on improving techdraw performance

Post by wandererfan »

yorik wrote: Wed Aug 14, 2019 11:13 pm 2) We need to scale this thing correctly. The SVG contains a rectangle that has the proportion of the view background. But how to find out that size in real world units...
Somewhere I have c++ code that determines the real world height of the viewPort. Assuming "backgound" == "viewport", then we have a potential solution to this one.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Tips on improving techdraw performance

Post by yorik »

Some progresses! I think we're holding something powerful!
Screenshot from 2019-08-15 12-33-00.png
Screenshot from 2019-08-15 12-33-00.png (811.08 KiB) Viewed 1545 times
Made a little script that demonstrates the whole process:

Code: Select all

import FreeCADGui
from pivy import coin
from PySide import QtCore,QtGui
import os,re

# a name to save a temp svg file
svgfile = os.path.join(os.path.dirname(FreeCAD.ActiveDocument.FileName),"render.svg")

# set object lighting to single face to get black fills inside cut areas
# but this creates artifacts in svg output, triangulation gets visible, so i turned it off for now
#ldict = {}
#for o in FreeCAD.ActiveDocument.Objects:
#    if hasattr(o,"ViewObject") and hasattr(o.ViewObject,"Lighting"):
#        ldict[o.Name] = o.ViewObject.Lighting
#        o.ViewObject.Lighting = "One side"

# gather nodes to render
sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
rn = coin.SoSeparator()
for n in sg.getChildren():
    if isinstance(n,coin.SoSeparator):
        ncopy = n.copy()
        rn.addChild(ncopy)

# reset lighting of objects
#for o in FreeCAD.ActiveDocument.Objects:
#    if o.Name in ldict:
#        o.ViewObject.Lighting = ldict[o.Name]

# create viewer
v = FreeCADGui.createViewer()
if hasattr(v,"setName"): # i just added this method yesterday
    v.setName("RenderViewer")

vv = v.getViewer()
vv.setBackgroundColor(1,1,1)
v.redraw()

# set clip plane
clip = coin.SoClipPlane()
clip.on = True
plane = coin.SbPlane(coin.SbVec3f(1,0,0),5000) #dir, position on dir
clip.plane.setValue(plane)
rn.insertChild(clip,0)

# set scenegraph
vv.setSceneGraph(rn)

# set camera
c = '#Inventor V2.1 ascii\n\n\nOrthographicCamera {\n  viewportMapping ADJUST_CAMERA\n  position -36733.652 -7668.0435 256.88913\n  orientation -0.57735038 0.57735038 0.57735038  4.1887903\n  nearDistance 5128.5186\n  farDistance 76777.062\n  aspectRatio 1\n  focalDistance 40917\n  height 11075.028\n\n}\n'
v.setCamera(c)

# save view
v.saveVectorGraphic(svgfile,1) # number is pixel size

# fix linewidths - the 1px default one is a bit too big...
f = open(svgfile,"r")
svg = f.read()
f.close()
svg = svg.replace("stroke-width:1.0;","stroke-width:0.2;")
svg = svg.replace("stroke-width=\"1px","stroke-width=\"0.2px")

# remove background rectangle, ie. the first path object found in the file:
svg = re.sub("<path.*?>","",svg,count=1,flags=re.MULTILINE|re.DOTALL)

# save modified result, for postmortem inspection
#f = open(svgfile,"w")
#f.write(svg)
#f.close()

# close viewer
mw = FreeCADGui.getMainWindow()
for mdi in mw.findChildren(QtGui.QMdiSubWindow):
    if mdi.windowTitle() == "RenderViewer":
        mdi.close()

# create TD page
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
template = FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
template.Template = os.path.join(FreeCAD.getResourceDir(),'Mod/TechDraw/Templates/A4_LandscapeTD.svg')
page.Template = template
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewSymbol','Symbol')
view.Symbol = svg
page.addView(view)
FreeCAD.ActiveDocument.recompute()
To test, open this file (in the script above some values are hard-coded for this file...)

https://www.dropbox.com/s/ykeyzbqlhaw5h ... FCStd?dl=0

and copy/paste the script above in the python console. You'll get a TD page created with a cross section

I think it works really well... There are many improvements to do to the SVG rendering but the code is really simple and easy to extend:
https://github.com/FreeCAD/FreeCAD/blob ... Action.cpp
we could also make it able to bypass the temp file and return a string directly.
wandererfan wrote: Thu Aug 15, 2019 12:00 pm Somewhere I have c++ code that determines the real world height of the viewPort. Assuming "backgound" == "viewport", then we have a potential solution to this one.
The background is a white rectangle added at the begin of the SVG file by the VectorizeSVGAction code above (that I stripped at the end of my script above). I'm thinking of adding a new mode to the Arch TD view to use the method above... So I think before passing the SVG to the ViewSymbol, we'll need to scale it properly, but I suppose it shouldn't be hard to either convert the C++ code you're referring to, or make a python binding for it. Only, I couldn't locate that code, could you give me some direction?
Post Reply