Hi
I'm relativity new to pyqtgraph but find its speed very useful for some of my applications.
I am currently trying to animate a GLViewWidget. I would like to programatically update the data of an isosurface and the camera view.
The code below is my attempt to update and display a new orbit position.
I don't receive any errors when it runs but the display window does not update. I have several related questions:
1. how can I 'refresh' the display after changing the view widget's orbit setting using the timer connect
2. Is using setMeshData the correct way to update the isosurface?
3. I havent tried to code it - but can the resulting displays be exported to create a GIF?
Thanks Rob
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np
## create the column and add to view
def mycolumn(i,j,k, offi=0, offj=0, offk=0):
x = i-offi
y = j-offj
z = k-offk
col = (x**2 + y**2 + np.abs(z))**0.5
return col
dimensions = [100,100,100]
# Make Graph window
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 600
w.show()
w.setWindowTitle('orbit test')
ax = gl.GLAxisItem()
w.addItem(ax)
g = gl.GLGridItem()
g.scale(1,1,1)
w.addItem(g)
data = np.abs(np.fromfunction(mycolumn, (dimensions[0],dimensions[1],dimensions[0]), offi=dimensions[0]/2, offj=dimensions[1]/2, offk=0))
print("Generating isosurface..")
verts, faces = pg.isosurface(data, data.max()/6.)
md = gl.MeshData(vertexes=verts, faces=faces)
colors = np.ones((md.faceCount(), 4), dtype=float)
colors[:,3] = 0.3
colors[:,0] = np.linspace(0, 1, colors.shape[0])
md.setFaceColors(colors)
m1 = gl.GLMeshItem(meshdata=md, smooth=False, shader='balloon')
m1.setGLOptions('additive')
m1.translate(-dimensions[0]/2, -dimensions[1]/3, 0)
w.addItem(m1)
def update():
global w, m1, data
[cent, dist, ele, azi] = w.cameraPosition()
ele = ele + 1
azi = azi + 1
w.orbit(azi,ele)
verts, faces = pg.isosurface(data, data.max()/np.abs(ele/10.0))
m1.setMeshData(vertexes=verts, faces=faces)
#w.update()
#w.show()
t = QtCore.QTimer()
t.setSingleShot(False)
t.timeout.connect(update)
t.start(1000)
## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()