-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_data_point_transfer_function.py
85 lines (77 loc) · 2.42 KB
/
single_data_point_transfer_function.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
import neuroglancer
import numpy as np
from neuroglancer_utils.viewer_utils import (
launch_nglancer,
open_browser,
)
from neuroglancer_utils.layer_utils import add_render_panel
from time import sleep
def colormap_version(viewer):
shader = """
#uicontrol invlerp normalized
#uicontrol transferFunction colormap
void main() {
emitRGBA(colormap());
}
"""
shaderControls = {
"normalized": {
"range": [0, 100],
"window": [0, 100],
"channel": [],
},
"colormap": {
"controlPoints": [[0, "#000000", 0.0], [84, "#ffffff", 1.0]],
"window": [0, 50],
"channel": [],
"defaultColor": "#ff00ff",
},
}
with viewer.txn() as s:
s.dimensions = neuroglancer.CoordinateSpace(
names=["x", "y"], units="nm", scales=[1, 1]
)
s.position = [0.5, 0.5]
s.layers.append(
name="image",
layer=neuroglancer.ImageLayer(
source=neuroglancer.LocalVolume(
dimensions=s.dimensions,
data=np.full(shape=(1, 1), dtype=np.uint64, fill_value=63),
),
panels=[add_render_panel()],
),
visible=True,
shader=shader,
shader_controls=shaderControls,
opacity=1.0,
blend="additive",
)
s.layout = "xy"
s.cross_section_scale = 1e-6
s.show_axis_lines = False
if __name__ == "__main__":
viewer = launch_nglancer()
open_browser(viewer, hang=False)
sleep(2)
colormap_version(viewer)
with viewer.txn() as s:
layer = s.layers[0]
print(layer.shader_controls["normalized"])
print(layer.shader_controls["colormap"])
# inp = input("Press enter when ready to change the shader controls...")
# with viewer.txn() as s:
# layer = s.layers[0]
# print(layer.shader_controls["colormap"])
# layer.shader_controls = {
# "colormap": neuroglancer.TransferFunctionParameters(
# range=[0, 100],
# controlPoints=[
# {"input": 10, "color": "#0f00ff", "opacity": 0.4},
# {"input": 150, "color": "#ff00ff", "opacity": 0.1},
# ],
# channel=[],
# color="#ff0000",
# )
# }
# print(layer.shader_controls["colormap"])