1# -*- coding: utf-8 -*-
2"""
3Demonstration of some of the shader programs included with pyqtgraph that can be
4used to affect the appearance of a surface.
5"""
6
7
8
9## Add path to library (just for examples; you do not need this)
10import initExample
11
12import numpy as np
13from pyqtgraph.Qt import QtCore, QtGui
14import pyqtgraph as pg
15import pyqtgraph.opengl as gl
16
17app = pg.mkQApp("GLShaders Example")
18w = gl.GLViewWidget()
19w.show()
20w.setWindowTitle('pyqtgraph example: GL Shaders')
21w.setCameraPosition(distance=15, azimuth=-90)
22
23g = gl.GLGridItem()
24g.scale(2,2,1)
25w.addItem(g)
26
27md = gl.MeshData.sphere(rows=10, cols=20)
28x = np.linspace(-8, 8, 6)
29
30m1 = gl.GLMeshItem(meshdata=md, smooth=True, color=(1, 0, 0, 0.2), shader='balloon', glOptions='additive')
31m1.translate(x[0], 0, 0)
32m1.scale(1, 1, 2)
33w.addItem(m1)
34
35m2 = gl.GLMeshItem(meshdata=md, smooth=True, shader='normalColor', glOptions='opaque')
36m2.translate(x[1], 0, 0)
37m2.scale(1, 1, 2)
38w.addItem(m2)
39
40m3 = gl.GLMeshItem(meshdata=md, smooth=True, shader='viewNormalColor', glOptions='opaque')
41m3.translate(x[2], 0, 0)
42m3.scale(1, 1, 2)
43w.addItem(m3)
44
45m4 = gl.GLMeshItem(meshdata=md, smooth=True, shader='shaded', glOptions='opaque')
46m4.translate(x[3], 0, 0)
47m4.scale(1, 1, 2)
48w.addItem(m4)
49
50m5 = gl.GLMeshItem(meshdata=md, smooth=True, color=(1, 0, 0, 1), shader='edgeHilight', glOptions='opaque')
51m5.translate(x[4], 0, 0)
52m5.scale(1, 1, 2)
53w.addItem(m5)
54
55m6 = gl.GLMeshItem(meshdata=md, smooth=True, color=(1, 0, 0, 1), shader='heightColor', glOptions='opaque')
56m6.translate(x[5], 0, 0)
57m6.scale(1, 1, 2)
58w.addItem(m6)
59
60
61
62
63#def psi(i, j, k, offset=(25, 25, 50)):
64    #x = i-offset[0]
65    #y = j-offset[1]
66    #z = k-offset[2]
67    #th = np.arctan2(z, (x**2+y**2)**0.5)
68    #phi = np.arctan2(y, x)
69    #r = (x**2 + y**2 + z **2)**0.5
70    #a0 = 1
71    ##ps = (1./81.) * (2./np.pi)**0.5 * (1./a0)**(3/2) * (6 - r/a0) * (r/a0) * np.exp(-r/(3*a0)) * np.cos(th)
72    #ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1)
73
74    #return ps
75
76    ##return ((1./81.) * (1./np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * (r/a0) * np.exp(-r/(3*a0)) * np.sin(th) * np.cos(th) * np.exp(2 * 1j * phi))**2
77
78
79#print("Generating scalar field..")
80#data = np.abs(np.fromfunction(psi, (50,50,100)))
81
82
83##data = np.fromfunction(lambda i,j,k: np.sin(0.2*((i-25)**2+(j-15)**2+k**2)**0.5), (50,50,50));
84#print("Generating isosurface..")
85#verts = pg.isosurface(data, data.max()/4.)
86
87#md = gl.MeshData.MeshData(vertexes=verts)
88
89#colors = np.ones((md.vertexes(indexed='faces').shape[0], 4), dtype=float)
90#colors[:,3] = 0.3
91#colors[:,2] = np.linspace(0, 1, colors.shape[0])
92#m1 = gl.GLMeshItem(meshdata=md, color=colors, smooth=False)
93
94#w.addItem(m1)
95#m1.translate(-25, -25, -20)
96
97#m2 = gl.GLMeshItem(vertexes=verts, color=colors, smooth=True)
98
99#w.addItem(m2)
100#m2.translate(-25, -25, -50)
101
102if __name__ == '__main__':
103    pg.exec()
104