forked from uoip/pangolin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleMultiDisplay.py
113 lines (76 loc) · 3.13 KB
/
SimpleMultiDisplay.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# https://github.com/stevenlovegrove/Pangolin/blob/master/examples/SimpleMultiDisplay
import numpy as np
import OpenGL.GL as gl
import pangolin
def random_image(w, h):
return (np.ones((h, w, 3), 'uint8') *
np.random.randint(256, size=3, dtype='uint8'))
def main():
# Create OpenGL window in single line
pangolin.CreateWindowAndBind('Main', 640, 480)
# 3D Mouse handler requires depth testing to be enabled
gl.glEnable(gl.GL_DEPTH_TEST)
# Issue specific OpenGl we might need
gl.glEnable(gl.GL_BLEND)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
# Define Camera Render Object (for view / scene browsing)
proj = pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.1, 1000)
scam = pangolin.OpenGlRenderState(
proj, pangolin.ModelViewLookAt(1, 0.5, -2, 0, 0, 0, pangolin.AxisY))
scam2 = pangolin.OpenGlRenderState(
proj, pangolin.ModelViewLookAt(0, 0, -2, 0, 0, 0, pangolin.AxisY))
# Add named OpenGL viewport to window and provide 3D Handler
dcam1 = pangolin.Display('cam1')
dcam1.SetAspect(640 / 480.)
dcam1.SetHandler(pangolin.Handler3D(scam))
dcam2 = pangolin.Display('cam2')
dcam2.SetAspect(640 / 480.)
dcam2.SetHandler(pangolin.Handler3D(scam2))
dcam3 = pangolin.Display('cam3')
dcam3.SetAspect(640 / 480.)
dcam3.SetHandler(pangolin.Handler3D(scam))
dcam4 = pangolin.Display('cam4')
dcam4.SetAspect(640 / 480.)
dcam4.SetHandler(pangolin.Handler3D(scam2))
dimg1 = pangolin.Display('img1')
dimg1.SetAspect(640 / 480.)
dimg2 = pangolin.Display('img2')
dimg2.SetAspect(640 / 480.)
# LayoutEqual is an EXPERIMENTAL feature - it requires that all sub-displays
# share the same aspect ratio, placing them in a raster fasion in the
# viewport so as to maximise display size.
view = pangolin.Display('multi')
view.SetBounds(0.0, 1.0, 0.0, 1.0)
view.SetLayout(pangolin.LayoutEqual)
view.AddDisplay(dcam1)
view.AddDisplay(dimg1)
view.AddDisplay(dcam2)
view.AddDisplay(dimg2)
view.AddDisplay(dcam3)
view.AddDisplay(dcam4)
w, h = 64, 48
image_texture = pangolin.GlTexture(
w, h, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE)
# Default hooks for exiting (Esc) and fullscreen (tab)
while not pangolin.ShouldQuit():
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
gl.glColor3f(1.0, 1.0, 1.0)
dcam1.Activate(scam)
pangolin.glDrawColouredCube()
dcam2.Activate(scam2)
pangolin.glDrawColouredCube()
dcam3.Activate(scam)
pangolin.glDrawColouredCube()
dcam4.Activate(scam2)
pangolin.glDrawColouredCube()
dimg1.Activate()
gl.glColor4f(1.0, 1.0, 1.0, 1.0)
image_texture.Upload(random_image(w, h), gl.GL_RGB, gl.GL_UNSIGNED_BYTE)
image_texture.RenderToViewport()
dimg2.Activate()
gl.glColor4f(1.0, 1.0, 1.0, 1.0)
# image_texture.Upload(random_image(w, h), gl.GL_RGB, gl.GL_UNSIGNED_BYTE)
image_texture.RenderToViewport()
pangolin.FinishFrame()
if __name__ == '__main__':
main()