2012-03-09 17:38:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
Demonstrates GLVolumeItem for displaying volumetric data.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2012-03-09 17:38:15 +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-03-09 17:38:15 +00:00
|
|
|
|
2021-04-18 03:08:57 +00:00
|
|
|
import numpy as np
|
2021-01-27 18:59:07 +00:00
|
|
|
import pyqtgraph as pg
|
2012-03-09 17:38:15 +00:00
|
|
|
import pyqtgraph.opengl as gl
|
2021-04-20 05:12:05 +00:00
|
|
|
from pyqtgraph import functions as fn
|
2012-03-09 17:38:15 +00:00
|
|
|
|
2021-01-27 18:59:07 +00:00
|
|
|
app = pg.mkQApp("GLVolumeItem Example")
|
2012-03-09 17:38:15 +00:00
|
|
|
w = gl.GLViewWidget()
|
|
|
|
w.show()
|
2013-02-25 04:09:03 +00:00
|
|
|
w.setWindowTitle('pyqtgraph example: GLVolumeItem')
|
2021-07-17 09:37:38 +00:00
|
|
|
w.setCameraPosition(distance=200)
|
2012-03-09 17:38:15 +00:00
|
|
|
|
|
|
|
g = gl.GLGridItem()
|
|
|
|
g.scale(10, 10, 1)
|
|
|
|
w.addItem(g)
|
|
|
|
|
|
|
|
## Hydrogen electron probability density
|
|
|
|
def psi(i, j, k, offset=(50,50,100)):
|
|
|
|
x = i-offset[0]
|
|
|
|
y = j-offset[1]
|
|
|
|
z = k-offset[2]
|
2021-04-18 05:38:21 +00:00
|
|
|
th = np.arctan2(z, np.hypot(x, y))
|
|
|
|
r = np.sqrt(x**2 + y**2 + z **2)
|
2012-03-09 17:38:15 +00:00
|
|
|
a0 = 2
|
2021-05-16 06:12:58 +00:00
|
|
|
return (
|
|
|
|
(1.0 / 81.0)
|
|
|
|
* 1.0 / (6.0 * np.pi) ** 0.5
|
|
|
|
* (1.0 / a0) ** (3 / 2)
|
|
|
|
* (r / a0) ** 2
|
|
|
|
* np.exp(-r / (3 * a0))
|
|
|
|
* (3 * np.cos(th) ** 2 - 1)
|
|
|
|
)
|
2012-03-09 17:38:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
data = np.fromfunction(psi, (100,100,200))
|
2021-05-16 06:12:58 +00:00
|
|
|
with np.errstate(divide = 'ignore'):
|
|
|
|
positive = np.log(fn.clip_array(data, 0, data.max())**2)
|
|
|
|
negative = np.log(fn.clip_array(-data, 0, -data.min())**2)
|
2012-03-09 17:38:15 +00:00
|
|
|
|
|
|
|
d2 = np.empty(data.shape + (4,), dtype=np.ubyte)
|
|
|
|
d2[..., 0] = positive * (255./positive.max())
|
|
|
|
d2[..., 1] = negative * (255./negative.max())
|
|
|
|
d2[..., 2] = d2[...,1]
|
|
|
|
d2[..., 3] = d2[..., 0]*0.3 + d2[..., 1]*0.3
|
|
|
|
d2[..., 3] = (d2[..., 3].astype(float) / 255.) **2 * 255
|
2012-04-28 19:12:46 +00:00
|
|
|
|
|
|
|
d2[:, 0, 0] = [255,0,0,100]
|
|
|
|
d2[0, :, 0] = [0,255,0,100]
|
|
|
|
d2[0, 0, :] = [0,0,255,100]
|
|
|
|
|
2012-03-09 17:38:15 +00:00
|
|
|
v = gl.GLVolumeItem(d2)
|
|
|
|
v.translate(-50,-50,-100)
|
|
|
|
w.addItem(v)
|
|
|
|
|
2012-04-28 19:12:46 +00:00
|
|
|
ax = gl.GLAxisItem()
|
|
|
|
w.addItem(ax)
|
2012-03-09 17:38:15 +00:00
|
|
|
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
2021-05-13 21:28:22 +00:00
|
|
|
pg.exec()
|