Skip to content

Commit ff68f64

Browse files
authored
Examples (#51)
* Add more features to all_features.py example * add clim feature to all_featues.py example * rename an example
1 parent a5d97d4 commit ff68f64

File tree

2 files changed

+82
-9
lines changed

2 files changed

+82
-9
lines changed

examples/all_features.py

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from dash_slicer import VolumeSlicer
1010
from dash.dependencies import Input, Output, State, ALL
1111
import imageio
12+
from skimage import measure
1213

1314

1415
app = dash.Dash(__name__, update_title=None)
@@ -67,16 +68,36 @@
6768
dcc.Graph(id="3Dgraph", figure=go.Figure()),
6869
]
6970
),
71+
html.Div(
72+
[
73+
html.Div("Threshold level"),
74+
dcc.Slider(id="level", max=2000, value=500),
75+
html.Div("Contrast limits"),
76+
dcc.RangeSlider(id="clim", max=2000, value=(0, 800)),
77+
]
78+
),
7079
dcc.Markdown(
7180
"""
7281
Take note of:
73-
* Full-res thumbnails for axis 0.
74-
* Very low-res thumbnails for axis 1.
75-
* Default low-res thumbnails for axis 2.
76-
* The `reverse_y` is false for axis 1.
77-
* Elongated voxels for axis 1 and 2.
78-
* An origin in the thousands, visible in the 3D view.
79-
* A custom brighter green for axis 2.
82+
83+
Axis 0:
84+
* Full-res thumbnails.
85+
86+
Axis 1:
87+
* Very low-res thumbnails.
88+
* Elongated voxels.
89+
* The `reverse_y` is false.
90+
* Yellow overlay based on threshold.
91+
92+
Axis 2:
93+
* Default low-res thumbnails.
94+
* Elongated voxels.
95+
* Yellow contour based on threshold..
96+
* A custom brighter green indicator.
97+
98+
3D view:
99+
* An origin in the thousands.
100+
80101
"""
81102
),
82103
],
@@ -101,7 +122,9 @@
101122
let s = {
102123
type: 'scatter3d',
103124
x: xyz[0], y: xyz[1], z: xyz[2],
104-
mode: 'lines', line: {color: state.color}
125+
mode: 'lines', line: {color: state.color},
126+
hoverinfo: 'skip',
127+
showlegend: false,
105128
};
106129
traces.push(s);
107130
}
@@ -116,6 +139,54 @@
116139
)
117140

118141

142+
# Callback to add overlay in axis 1
143+
@app.callback(
144+
Output(slicer1.overlay_data.id, "data"),
145+
[Input("level", "value")],
146+
)
147+
def update_overlay(level):
148+
return slicer1.create_overlay_data(vol > level, "#ffff00")
149+
150+
151+
# Callback to add contours in axes 2
152+
@app.callback(
153+
Output(slicer2.extra_traces.id, "data"),
154+
[Input(slicer2.state.id, "data"), Input("level", "value")],
155+
)
156+
def update_contour(state, level):
157+
if not state:
158+
return dash.no_update
159+
slice = vol[:, :, state["index"]]
160+
contours = measure.find_contours(slice, level)
161+
traces = []
162+
for contour in contours:
163+
traces.append(
164+
{
165+
"type": "scatter",
166+
"mode": "lines",
167+
"line": {"color": "yellow", "width": 3},
168+
"x": contour[:, 1] * spacing[1] + ori[1],
169+
"y": contour[:, 0] * spacing[0] + ori[0],
170+
"hoverinfo": "skip",
171+
"showlegend": False,
172+
}
173+
)
174+
return traces
175+
176+
177+
# Callback to set contrast limits
178+
@app.callback(
179+
[
180+
Output(slicer0.clim.id, "data"),
181+
Output(slicer1.clim.id, "data"),
182+
Output(slicer2.clim.id, "data"),
183+
],
184+
[Input("clim", "value")],
185+
)
186+
def update_clim(clim):
187+
return [clim, clim, clim]
188+
189+
119190
if __name__ == "__main__":
120191
# Note: dev_tools_props_check negatively affects the performance of VolumeSlicer
121192
app.run_server(debug=True, dev_tools_props_check=False)

examples/get_and_set_position.py renamed to examples/set_slicer_position_simple.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
2-
An example that demonstrates how the slicer's index can be both read and written.
2+
An simple example that demonstrates how the slicer's index can be both read and written.
3+
4+
See set_slicer_position_interactively.py for a more advanced / realistic example.
35
"""
46

57
import dash

0 commit comments

Comments
 (0)