3D line plot

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
bernd
Posts: 10702
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

3D line plot

Postby bernd » Wed Mar 01, 2017 2:38 pm

Does someone know what is best to archive 3D line plots as they are used to show sectional forces on line analysises.

- is there may be something in some other FreeCAD workbench?
- does VTK/paraview support such post processing
- does some other python library support such plots

see the picture for example:
screen.jpg
screen.jpg (199.26 KiB) Viewed 1610 times
User avatar
yorik
Site Admin
Posts: 12011
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: 3D line plot

Postby yorik » Thu Mar 02, 2017 1:28 pm

If it was me, I think I would write a kind of wrapper library with a couple of convenience methods (plotCurve(), plotGraph() things like that), and inside, discretize everything and do everything with coin/pivy... There is also the plot workbench that has stuff to print curves, but I'm not sure if they render in the 3d view or not. In any case you should have a look at it first

It would be a killer if we get such graphs in freecad!
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: 3D line plot

Postby ian.rees » Fri Mar 03, 2017 9:11 pm

If there's not an existing solution, it might be worth considering implementing one as a matplotlib backend.
ulrich1a
Posts: 1958
Joined: Sun Jul 07, 2013 12:08 pm

Re: 3D line plot

Postby ulrich1a » Mon Mar 06, 2017 3:55 pm

Chris_G made some similar plots in FreeCAD to show the curvature of a B-Spline. Maybe his script can be used as a template to show the force and moment data. See here: https://forum.freecadweb.org/viewtopic.php?f=22&t=15313

Ulrich
HoWil
Posts: 1191
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: 3D line plot

Postby HoWil » Mon Mar 06, 2017 4:27 pm

ian.rees wrote:If there's not an existing solution, it might be worth considering implementing one as a matplotlib backend.
Matplotlib can nicely generate .svg wich could be placed equivalent to https://forum.freecadweb.org/viewtopic.php?f=10&t=20989

The advantage of matplotlib is having axis, grid, labels,.. Already available on a high level.
BR
Howil
User avatar
bernd
Posts: 10702
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: 3D line plot

Postby bernd » Mon Mar 06, 2017 7:01 pm

ulrich1a wrote:Chris_G made some similar plots in FreeCAD to show the curvature of a B-Spline. Maybe his script can be used as a template to show the force and moment data. See here: https://forum.freecadweb.org/viewtopic.php?f=22&t=15313
That's the stuff we need :D
User avatar
bernd
Posts: 10702
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: 3D line plot

Postby bernd » Mon Mar 06, 2017 7:01 pm

HoWil wrote:
ian.rees wrote:If there's not an existing solution, it might be worth considering implementing one as a matplotlib backend.
Matplotlib can nicely generate .svg wich could be placed equivalent to https://forum.freecadweb.org/viewtopic.php?f=10&t=20989
I have been searching the Internet but could not find how to create such plots by matplotlib.
User avatar
bernd
Posts: 10702
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: 3D line plot

Postby bernd » Mon Mar 06, 2017 7:07 pm

yorik wrote:It would be a killer if we get such graphs in freecad!
At some point in the future we just need such post processing. issue #2950
HoWil
Posts: 1191
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: 3D line plot

Postby HoWil » Mon Mar 06, 2017 8:35 pm

bernd wrote:
HoWil wrote:
ian.rees wrote:If there's not an existing solution, it might be worth considering implementing one as a matplotlib backend.
Matplotlib can nicely generate .svg wich could be placed equivalent to https://forum.freecadweb.org/viewtopic.php?f=10&t=20989
I have been searching the Internet but could not find how to create such plots by matplotlib.
Hi Bernd,

I have tried to produce such a plot but partly failed at the first attempt .... see https://forum.freecadweb.org/viewtopic. ... 45#p163745
Here my code for a small test macro ... maybe it is anyhow helpfull.

Code: Select all

# -*- coding: utf-8 -*-

####################################################
# creating a plot similar to the one at http://matplotlib.org/examples/pylab_examples/fill_between_demo.html
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0.0, 2, 0.01)
y1 = np.sin(2*np.pi*x)
y2 = 1.2*np.sin(4*np.pi*x)

# now fill between y1 and y2 where a logical condition is met.  Note
# this is different than calling
#   fill_between(x[where], y1[where],y2[where]
# because of edge effects over multiple contiguous regions.
fig = plt.figure(figsize=(100/25.4, 100/25.4))
ax = fig.add_subplot(211)
ax1 = fig.add_subplot(212)

ax.plot(x, y1, x, y2, color='black')
#ax.fill_between(x, y1, y2, where=y2 >= y1, facecolor='green', interpolate=True)
#ax.fill_between(x, y1, y2, where=y2 <= y1, facecolor='red', interpolate=True)
ax.set_title('fill between where')
#ax.set_axis_bgcolor(None)

# Test support for masked arrays.
y2 = np.ma.masked_greater(y2, 1.0)
ax1.plot(x, y1, x, y2, color='black')
#ax1.fill_between(x, y1, y2, where=y2 >= y1, facecolor='green', interpolate=True)
#ax1.fill_between(x, y1, y2, where=y2 <= y1, facecolor='red', interpolate=True)
ax1.set_title('Now regions with y2>1 are masked')
#ax1.set_axis_bgcolor(None)


ax.patch.set_visible(False) 
ax1.patch.set_visible(False) 
fig.patch.set_visible(False)

fig.savefig('/tmp/output.svg')


########################################################
# creating a box in FC
import FreeCAD
import Part

App.newDocument("Unnamed")
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.ActiveObject.Label = "Cube"
App.ActiveDocument.recompute()
FreeCAD.getDocument("Unnamed").getObject("Box").Length = '100 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Width = '100 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Height = '100 mm'

Gui.SendMsgToActiveView("ViewFit")

########################################################
# importing the plot into FC as described here https://forum.freecadweb.org/viewtopic.php?f=10&t=20989
from pivy import coin
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()

svg = coin.SoTexture2()
svg.filename = '/tmp/output.svg'

box = coin.SoVRMLBox()
box.size = (100,100,0)

imagePos = coin.SoTransform()
imagePos.translation.setValue([50,50,100])
imagePos.rotation = coin.SbRotation(0,0,0,0)
image = coin.SoSeparator()
image.addChild(imagePos)
image.addChild(svg)
image.addChild(box)
sg.addChild(image)

BR
HoWil
User avatar
cnirbhay
Posts: 116
Joined: Wed Aug 17, 2016 4:24 pm

Re: 3D line plot

Postby cnirbhay » Wed Mar 08, 2017 9:32 am

Does someone know what is best to archive 3D line plots as they are used to show sectional forces on line analysises.
Which software did you use to get these results? STAAD Pro also gives such post processing results with support reactions, deflections, SFD & BMD. It would be really great to get such analytical details in FreeCAD too. :-)

I guess results from Calculix in FEM workbench can be somehow used to obtain such details.