Skip to content

Commit 49dc5c6

Browse files
committed
feat: add point precompute example
1 parent dde9321 commit 49dc5c6

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import argparse
2+
3+
import neuroglancer
4+
import neuroglancer.cli
5+
6+
if __name__ == "__main__":
7+
ap = argparse.ArgumentParser()
8+
neuroglancer.cli.add_server_arguments(ap)
9+
args = ap.parse_args()
10+
neuroglancer.cli.handle_server_arguments(args)
11+
viewer = neuroglancer.Viewer()
12+
# We need first, RGB
13+
properties = [
14+
neuroglancer.AnnotationPropertySpec(
15+
id="color",
16+
description="Color of the annotation",
17+
type="rgb",
18+
default="#ff0000", # red
19+
),
20+
neuroglancer.AnnotationPropertySpec(
21+
id="size",
22+
description="Size of the annotation",
23+
type="float32",
24+
default=10,
25+
),
26+
neuroglancer.AnnotationPropertySpec(
27+
id="p_int8",
28+
type="int8",
29+
default=10,
30+
),
31+
neuroglancer.AnnotationPropertySpec(
32+
id="p_uint8",
33+
type="uint8",
34+
default=10,
35+
),
36+
neuroglancer.AnnotationPropertySpec(
37+
id="rgba_color",
38+
type="rgba",
39+
default="#00ff00ff", # green with full opacity
40+
),
41+
neuroglancer.AnnotationPropertySpec(
42+
id="p_enum1",
43+
type="uint16",
44+
default=0,
45+
enum_values=[0, 1, 2, 3],
46+
enum_labels=[
47+
"Option 0",
48+
"Option 1",
49+
"Option 2",
50+
"Option 3",
51+
],
52+
),
53+
neuroglancer.AnnotationPropertySpec(
54+
id="p_fnum32",
55+
type="float32",
56+
default=0.0,
57+
description="A float number property",
58+
enum_values=[0.0, 1.5, 2.6, 3.0],
59+
enum_labels=[
60+
"Zero",
61+
"One and a half",
62+
"Two point six",
63+
"Three",
64+
],
65+
),
66+
]
67+
68+
def random_values(i):
69+
return [i * t for t in range(300)]
70+
71+
with viewer.txn() as s:
72+
s.dimensions = neuroglancer.CoordinateSpace(
73+
names=["x", "y"], units="nm", scales=[1, 1]
74+
)
75+
s.position = [150, 150]
76+
s.layers.append(
77+
name="a",
78+
layer=neuroglancer.LocalAnnotationLayer(
79+
dimensions=s.dimensions,
80+
annotation_properties=properties,
81+
annotations=[
82+
neuroglancer.PointAnnotation(
83+
id="1",
84+
point=[150, 150],
85+
props=[
86+
"#00ff00", # green
87+
5, # size
88+
6, # p_int8
89+
7, # p_uint8
90+
"#ff00ffaa", # rgba_color
91+
2, # p_enum1 (Option 2)
92+
2.6, # p_fnum32 (Two point six)
93+
],
94+
),
95+
neuroglancer.PointAnnotation(
96+
id="2",
97+
point=[250, 100],
98+
props=[
99+
"#0000ff", # blue
100+
10, # size
101+
-5, # p_int8
102+
20, # p_uint8
103+
"#00ffffff", # yellow with full opacity
104+
1, # p_enum1 (Option 1)
105+
1.5, # p_fnum32 (One and a half)
106+
],
107+
),
108+
neuroglancer.PointAnnotation(
109+
id="3",
110+
point=[20, 20],
111+
),
112+
],
113+
shader="""
114+
void main() {
115+
setColor(prop_color());
116+
setPointMarkerSize(prop_size());
117+
}
118+
""",
119+
),
120+
)
121+
s.layout = "xy"
122+
s.selected_layer.layer = "a"
123+
print("Use `Control+right click` to display annotation details.")
124+
print(viewer)

0 commit comments

Comments
 (0)