-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestVis.py
80 lines (62 loc) · 2.22 KB
/
TestVis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import numpy as np
from vispy import app, gloo, visuals, scene
# Define a simple vertex shader. We use $template variables as placeholders for
# code that will be inserted later on.
vertex_shader = """
void main()
{
vec4 visual_pos = vec4($position, 1);
vec4 doc_pos = $visual_to_doc(visual_pos);
gl_Position = $doc_to_render(doc_pos);
}
"""
fragment_shader = """
void main() {
gl_FragColor = $color;
}
"""
# now build our visuals
class Plot3DVisual(visuals.Visual):
""" template """
def __init__(self, x, y, z):
""" plot 3D """
visuals.Visual.__init__(self, vertex_shader, fragment_shader)
# build Vertices buffer
data = np.c_[x, y, z]
v = gloo.VertexBuffer(data.astype(np.float32))
# bind data
self.shared_program.vert['position'] = v
self.shared_program.frag['color'] = (1.0, 0.0, 0.0, 1.0)
# config
self.set_gl_state('opaque', clear_color=(1, 1, 1, 1))
self._draw_mode = 'line_strip'
def _prepare_transforms(self, view):
""" This method is called when the user or the scenegraph has assigned
new transforms to this visual """
# Note we use the "additive" GL blending settings so that we do not
# have to sort the mesh triangles back-to-front before each draw.
tr = view.transforms
view_vert = view.view_program.vert
view_vert['visual_to_doc'] = tr.get_transform('visual', 'document')
view_vert['doc_to_render'] = tr.get_transform('document', 'render')
# build your visuals, that's all
Plot3D = scene.visuals.create_visual_node(Plot3DVisual)
# The real-things : plot using scene
# build canvas
canvas = scene.SceneCanvas(keys='interactive', show=True)
# Add a ViewBox to let the user zoom/rotate
view = canvas.central_widget.add_view()
view.camera = 'turntable'
view.camera.fov = 50
view.camera.distance = 5
LOL4 = generate_octaves((1024, 1024), 2, 0.6, 2)
# data
N = 1000
#x = np.sin(np.linspace(-10, 10, N)*np.pi)
#y = np.cos(np.linspace(-10, 10, N)*np.pi)
#z = np.linspace(-2, 2, N)
for i in range(1024):
# plot ! note the parent parameter
p1 = Plot3D(LOL4, z, parent=view.scene)
# run
app.run()