I've added a gladevcp based tab to the axis gui where I used the manual-example.ui from the sample config sim.axis.gladevcp as an example. In the def __init__ function I've added code to open up a window with a 3D plot from matplotlib showing a 3D model:
from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
self.nhits = 3
pyplot.ion()
figure = pyplot.figure()
axes = figure.gca(projection='3d')
your_mesh = mesh.Mesh.from_file('HalfDonut.stl')
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors, facecolors='b', edgecolor='k', linewidth=0.2))
# Auto scale to the mesh size
scale = your_mesh.points.flatten(-1)
axes.auto_scale_xyz(scale, scale, scale)
self.axes = axes
this basically works fine. Means: When axis comes up there is my new tab inside axis with my gladevcp UI and a separate window displaying a 3D Plot from matplotlib.
In my tab there is a button with an event handler that just changes the parameter dist (zoom factor of the separate window's 3D Plot) and send a signal to redraw:
def on_replot_pressed(self,widget,data=None):
print "on_button_press called"
self.nhits += 1
# Show the plot to the screen
pyplot.show()
self.axes.dist = self.nhits
pyplot.pause(0.01)
pyplot.draw()
this often works fine. The zoom factor is changed and the 3D Plot redrawed in the separate window but sometimes it crashes - means I can press the button several times and it works but when pressing again the separate window disappears and the gladevcp tab inside axis is blanked out - there is nothing in the tab any more. Looking at DMESG it brings up an error:
gladevcp[4709]: segfault at c ip 080b65ab sp bfcb2f10 error 4 in python2.7[8048000+245000]
Probably there is not somebody using the same combination of gladevcp + matplotlib + numpy but maybe this looks familiar to you and somebody can give me a hint what is going wrong.
Does the gladevcp loosing somehow a handle to the other window and the garbage collector is deleting my 3D plot instance - maybe a stupid comment.
Would be nice if somebody with more experience in gladevcp can help me here since I need the matplotlib to visualize where I am with my robot on linuxcnc in a 3D model.
Many thanks!