forked from google/neuroglancer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_add_cube.py
55 lines (49 loc) · 1.74 KB
/
example_add_cube.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
import argparse
import neuroglancer
import neuroglancer.cli
import neuroglancer.random_token
if __name__ == "__main__":
cube_size_meters = 10e-6
ap = argparse.ArgumentParser()
neuroglancer.cli.add_server_arguments(ap)
args = ap.parse_args()
neuroglancer.cli.handle_server_arguments(args)
viewer = neuroglancer.Viewer()
def add_cube(s):
with viewer.txn() as state:
scale = state.dimensions.scales
center_point = s.mouse_voxel_coordinates * scale / 1e-9
layer = state.layers["annotations"]
layer.annotations.append(
neuroglancer.AxisAlignedBoundingBoxAnnotation(
id=neuroglancer.random_token.make_random_token(),
point_a=center_point - cube_size_meters * 1e9,
point_b=center_point + cube_size_meters * 1e9,
)
)
viewer.actions.add("add-cube", add_cube)
with viewer.config_state.txn() as s:
s.input_event_bindings.viewer["keyt"] = "add-cube"
with viewer.txn() as s:
s.dimensions = neuroglancer.CoordinateSpace(
names=["x", "y", "z"],
units="nm",
scales=[8, 8, 8],
)
s.layers.append(
name="image",
layer=neuroglancer.ImageLayer(
source="precomputed://gs://neuroglancer-public-data/flyem_fib-25/image",
),
)
s.layers.append(
name="annotations",
layer=neuroglancer.LocalAnnotationLayer(
dimensions=neuroglancer.CoordinateSpace(
names=["x", "y", "z"],
units="nm",
scales=[1, 1, 1],
),
),
)
print(viewer)