1# -*- coding: utf-8 -*- 2""" 3Use GLImageItem to display image data on rectangular planes. 4 5In this example, the image data is sampled from a volume and the image planes 6placed as if they slice through the volume. 7""" 8## Add path to library (just for examples; you do not need this) 9import initExample 10 11from pyqtgraph.Qt import QtCore, QtGui 12import pyqtgraph.opengl as gl 13import pyqtgraph as pg 14import numpy as np 15 16app = pg.mkQApp("GLImageItem Example") 17w = gl.GLViewWidget() 18w.show() 19w.setWindowTitle('pyqtgraph example: GLImageItem') 20w.setCameraPosition(distance=200) 21 22## create volume data set to slice three images from 23shape = (100,100,70) 24data = pg.gaussianFilter(np.random.normal(size=shape), (4,4,4)) 25data += pg.gaussianFilter(np.random.normal(size=shape), (15,15,15))*15 26 27## slice out three planes, convert to RGBA for OpenGL texture 28levels = (-0.08, 0.08) 29tex1 = pg.makeRGBA(data[shape[0]//2], levels=levels)[0] # yz plane 30tex2 = pg.makeRGBA(data[:,shape[1]//2], levels=levels)[0] # xz plane 31tex3 = pg.makeRGBA(data[:,:,shape[2]//2], levels=levels)[0] # xy plane 32#tex1[:,:,3] = 128 33#tex2[:,:,3] = 128 34#tex3[:,:,3] = 128 35 36## Create three image items from textures, add to view 37v1 = gl.GLImageItem(tex1) 38v1.translate(-shape[1]/2, -shape[2]/2, 0) 39v1.rotate(90, 0,0,1) 40v1.rotate(-90, 0,1,0) 41w.addItem(v1) 42v2 = gl.GLImageItem(tex2) 43v2.translate(-shape[0]/2, -shape[2]/2, 0) 44v2.rotate(-90, 1,0,0) 45w.addItem(v2) 46v3 = gl.GLImageItem(tex3) 47v3.translate(-shape[0]/2, -shape[1]/2, 0) 48w.addItem(v3) 49 50ax = gl.GLAxisItem() 51w.addItem(ax) 52 53if __name__ == '__main__': 54 pg.exec() 55