-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnap.py
59 lines (46 loc) · 1.6 KB
/
nap.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
import json
import napari
import redis
from skimage import data
from magicgui import magicgui
from napari.utils.notifications import show_info
r = redis.Redis(host='localhost', port=6379, db=0)
@magicgui(call_button="Yaw")
def yaw_widget(viewer: napari.Viewer):
""" Start worker to communicate with device """
show_info('Starting yaw...')
# Callback for responding to angle changes
def callback(message):
orientation = json.loads(message['data'])
# angles = (
# -orientation['roll'],
# -orientation['yaw'],
# orientation['pitch'] + 90,
# )
# 𝛼: An angle can range between 0 and 360 degrees
# 𝛽: An Angle between −180 and 180 degrees
# 𝛾: An Angle between −90 to 90 degrees
# Experimentally determined
angles = (
# -orientation['roll'], # gamma Y
0,
-orientation['yaw'], # alpha Z
# orientation['pitch'], # beta X
90,
)
# Vispy Order: ZXY (yaw, pitch, roll), (alpha, beta, gamma)
# angles = (
# orientation['yaw'], # alpha Z
# orientation['pitch'], # beta X
# orientation['roll'], # gamma Y
# )
viewer.camera.angles = angles
pubsub = r.pubsub()
pubsub.subscribe(**{'orientation': callback})
pubsub.run_in_thread(sleep_time=1.0 / 24)
if __name__ == "__main__":
v = napari.Viewer(ndisplay=3)
v.add_image(data.brain(), colormap='inferno')
v.window.add_dock_widget(yaw_widget)
v.dims.ndisplay = 3
napari.run()