-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_polylines_many_properties.py
87 lines (83 loc) · 2.77 KB
/
add_polylines_many_properties.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
import argparse
import neuroglancer
import neuroglancer.cli
if __name__ == "__main__":
ap = argparse.ArgumentParser()
neuroglancer.cli.add_server_arguments(ap)
args = ap.parse_args()
neuroglancer.cli.handle_server_arguments(args)
viewer = neuroglancer.Viewer()
# Make lot of properties to test the performance
lots_of_properties = [
neuroglancer.AnnotationPropertySpec(
id=f"random_{t}",
type="float32",
default=10,
)
for t in range(300)
]
def random_values(i):
return [i * t for t in range(300)]
with viewer.txn() as s:
s.dimensions = neuroglancer.CoordinateSpace(
names=["x", "y"], units="nm", scales=[1, 1]
)
s.position = [150, 150]
s.layers.append(
name="a",
layer=neuroglancer.LocalAnnotationLayer(
dimensions=s.dimensions,
annotation_properties=[
neuroglancer.AnnotationPropertySpec(
id="color",
type="rgb",
default="red",
),
neuroglancer.AnnotationPropertySpec(
id="size",
type="float32",
default=10,
),
neuroglancer.AnnotationPropertySpec(
id="p_int8",
type="int8",
default=10,
),
neuroglancer.AnnotationPropertySpec(
id="p_uint8",
type="uint8",
default=10,
),
*lots_of_properties,
],
annotations=[
neuroglancer.PolyLineAnnotation(
id="1",
points=[[150, 150], [200, 100], [30, 40]],
props=["#0f0", 5, 6, 7, *random_values(1)],
),
neuroglancer.PolyLineAnnotation(
id="2",
points=[
[250, 100],
[20, 20],
[32, 42],
[50, 60],
[70, 80],
[90, 100],
],
props=["#ff0", 30, 7, 9, *random_values(2)],
),
],
shader="""
void main() {
setColor(prop_color());
setPolyEndpointMarkerSize(prop_size());
}
""",
),
)
s.layout = "xy"
s.selected_layer.layer = "a"
print("Use `Control+right click` to display annotation details.")
print(viewer)