2012-10-19 03:18:20 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
Use GLImageItem to display image data on rectangular planes.
|
|
|
|
|
|
|
|
In this example, the image data is sampled from a volume and the image planes
|
|
|
|
placed as if they slice through the volume.
|
|
|
|
"""
|
2012-10-19 03:18:20 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
2012-12-26 22:51:52 +00:00
|
|
|
import initExample
|
2012-10-19 03:18:20 +00:00
|
|
|
|
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
|
|
|
import pyqtgraph.opengl as gl
|
|
|
|
import pyqtgraph as pg
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
w = gl.GLViewWidget()
|
|
|
|
w.opts['distance'] = 200
|
|
|
|
w.show()
|
2013-02-25 04:09:03 +00:00
|
|
|
w.setWindowTitle('pyqtgraph example: GLImageItem')
|
2012-10-19 03:18:20 +00:00
|
|
|
|
|
|
|
## create volume data set to slice three images from
|
|
|
|
shape = (100,100,70)
|
2014-03-11 23:01:34 +00:00
|
|
|
data = pg.gaussianFilter(np.random.normal(size=shape), (4,4,4))
|
|
|
|
data += pg.gaussianFilter(np.random.normal(size=shape), (15,15,15))*15
|
2012-10-19 03:18:20 +00:00
|
|
|
|
2013-04-07 13:16:21 +00:00
|
|
|
## slice out three planes, convert to RGBA for OpenGL texture
|
2012-10-19 03:18:20 +00:00
|
|
|
levels = (-0.08, 0.08)
|
2018-03-30 18:48:05 +00:00
|
|
|
tex1 = pg.makeRGBA(data[shape[0]//2], levels=levels)[0] # yz plane
|
|
|
|
tex2 = pg.makeRGBA(data[:,shape[1]//2], levels=levels)[0] # xz plane
|
|
|
|
tex3 = pg.makeRGBA(data[:,:,shape[2]//2], levels=levels)[0] # xy plane
|
2013-04-07 13:16:21 +00:00
|
|
|
#tex1[:,:,3] = 128
|
|
|
|
#tex2[:,:,3] = 128
|
|
|
|
#tex3[:,:,3] = 128
|
2012-10-19 03:18:20 +00:00
|
|
|
|
|
|
|
## Create three image items from textures, add to view
|
|
|
|
v1 = gl.GLImageItem(tex1)
|
|
|
|
v1.translate(-shape[1]/2, -shape[2]/2, 0)
|
|
|
|
v1.rotate(90, 0,0,1)
|
|
|
|
v1.rotate(-90, 0,1,0)
|
|
|
|
w.addItem(v1)
|
|
|
|
v2 = gl.GLImageItem(tex2)
|
|
|
|
v2.translate(-shape[0]/2, -shape[2]/2, 0)
|
|
|
|
v2.rotate(-90, 1,0,0)
|
|
|
|
w.addItem(v2)
|
|
|
|
v3 = gl.GLImageItem(tex3)
|
|
|
|
v3.translate(-shape[0]/2, -shape[1]/2, 0)
|
|
|
|
w.addItem(v3)
|
|
|
|
|
|
|
|
ax = gl.GLAxisItem()
|
|
|
|
w.addItem(ax)
|
|
|
|
|
|
|
|
## Start Qt event loop unless running in interactive mode.
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|