-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_points_with_properties.py
More file actions
159 lines (148 loc) · 4.41 KB
/
write_points_with_properties.py
File metadata and controls
159 lines (148 loc) · 4.41 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import argparse
import os
import shutil
import neuroglancer
import neuroglancer.cli
import neuroglancer.static_file_server
import neuroglancer.write_annotations
import numpy as np
def write_some_annotations(
output_dir: str, coordinate_space: neuroglancer.CoordinateSpace
):
properties = [
neuroglancer.AnnotationPropertySpec(
id="color",
description="Color of the annotation",
type="rgb",
default="#ff0000", # red
),
neuroglancer.AnnotationPropertySpec(
id="size",
description="Size of the annotation",
type="float32",
),
neuroglancer.AnnotationPropertySpec(
id="p_int8",
type="int8",
default=10,
),
neuroglancer.AnnotationPropertySpec(
id="p_uint8",
type="uint8",
default=10,
),
neuroglancer.AnnotationPropertySpec(
id="rgba_color",
type="rgba",
default="#00ff00ff", # green with full opacity
),
neuroglancer.AnnotationPropertySpec(
id="p_enum1",
type="uint16",
default=0,
enum_values=[0, 1, 2, 3],
enum_labels=[
"Option 0",
"Option 1",
"Option 2",
"Option 3",
],
),
neuroglancer.AnnotationPropertySpec(
id="p_fnum32",
type="float32",
default=0.0,
description="A float number property",
enum_values=[0.0, 1.5, 2.6, 3.0],
enum_labels=[
"Zero",
"One and a half",
"Two point six",
"Three",
],
),
neuroglancer.AnnotationPropertySpec(
id="p_boola",
type="uint16",
default=1,
description="A boolean property",
enum_values=[0, 1],
enum_labels=["False", "True"],
),
]
writer = neuroglancer.write_annotations.AnnotationWriter(
coordinate_space=coordinate_space,
annotation_type="point",
properties=properties,
)
writer.add_point(
[20, 30, 40],
color=(0, 255, 0), # RGB color
size=10,
p_int8=1,
p_uint8=2,
rgba_color=(0, 255, 0, 255), # RGBA color with full opacity
p_enum1=1,
p_fnum32=1.5,
)
writer.add_point(
[50, 51, 52],
color=(255, 0, 0), # RGB color
size=30,
p_int8=2,
p_uint8=3,
rgba_color=(255, 0, 0, 255), # RGBA color with full opacity
p_enum1=2,
p_fnum32=2.6,
)
writer.add_point(
[40, 50, 20],
color="#0000ff", # RGB color
size=20,
p_int8=3,
p_uint8=4,
rgba_color=(0, 200, 255, 14), # RGBA color with part opacity
p_enum1=3,
p_fnum32=3.0,
p_boola=0,
)
writer.add_point([40, 50, 52])
writer.write(os.path.join(output_dir, "point"))
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()
tempdir = "/tmp/neuroglancer_annotations"
if os.path.exists(tempdir):
shutil.rmtree(tempdir)
os.makedirs(tempdir)
coordinate_space = neuroglancer.CoordinateSpace(
names=["x", "y", "z"], units=["nm", "nm", "nm"], scales=[10, 10, 10]
)
write_some_annotations(output_dir=tempdir, coordinate_space=coordinate_space)
server = neuroglancer.static_file_server.StaticFileServer(
static_dir=tempdir, bind_address=args.bind_address or "127.0.0.1", daemon=True
)
with viewer.txn() as s:
s.layers["image"] = neuroglancer.ImageLayer(
source=neuroglancer.LocalVolume(
data=np.full(fill_value=200, shape=(100, 100, 100), dtype=np.uint8),
dimensions=coordinate_space,
),
)
s.layers["points"] = neuroglancer.AnnotationLayer(
source=f"precomputed://{server.url}/point",
tab="rendering",
shader="""
void main() {
setColor(prop_color());
setPointMarkerSize(prop_size());
}
""",
)
s.selected_layer.layer = "points"
s.selected_layer.visible = True
s.show_slices = False
print(viewer)