Skip to content

Commit 1b87ebc

Browse files
author
Xing Han Lu
authored
Merge pull request #556 from plotly/update-vtk-cfd
Updates to vtk-cfd demo Former-commit-id: 71091a5
2 parents a8d924e + dcfd964 commit 1b87ebc

6 files changed

Lines changed: 34 additions & 45 deletions

File tree

apps/dash-vtk-explorer/demos/pyvista-point-cloud/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import pyvista as pv
99
from pyvista import examples
1010

11+
np.random.seed(42)
12+
1113
# Get point cloud data from PyVista
1214
dataset = examples.download_lidar()
1315
subset = 0.2

apps/dash-vtk-explorer/demos/slice-rendering/app.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@
2626
volume_state = to_volume_state(reader.GetOutput())
2727

2828

29-
def custom_card(children):
30-
return dbc.Card(
31-
html.Div(children, style={"height": "100%"}),
32-
body=True,
33-
style={"height": "100%"},
34-
)
35-
36-
3729
sliders = {
3830
"Slice i": dcc.Slider(id="slider-i", min=0, max=256, value=128),
3931
"Slice j": dcc.Slider(id="slider-j", min=0, max=256, value=128),
@@ -84,23 +76,6 @@ def custom_card(children):
8476
)
8577

8678

87-
volume_view = dash_vtk.View(
88-
id="volume-view",
89-
background=[0, 0, 0],
90-
cameraPosition=[1, 0, 0],
91-
cameraViewUp=[0, 0, -1],
92-
cameraParallelProjection=False,
93-
children=[
94-
dash_vtk.VolumeRepresentation(
95-
[
96-
html.Div(dash_vtk.VolumeController(), style={"display": "none"}),
97-
dash_vtk.ShareDataSet(),
98-
]
99-
)
100-
],
101-
)
102-
103-
10479
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
10580
server = app.server
10681

@@ -112,13 +87,7 @@ def custom_card(children):
11287
style={"height": "20%", "display": "flex", "align-items": "center"},
11388
children=[html.Br(), controls, html.Br(),],
11489
),
115-
dbc.Row(
116-
style={"height": "80%"},
117-
children=[
118-
dbc.Col(width=6, children=custom_card(slice_view)),
119-
dbc.Col(width=6, children=custom_card(volume_view)),
120-
],
121-
),
90+
html.Div(slice_view, style={"height": "80%"}),
12291
],
12392
)
12493

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
# If you skipped `pip install -e ../../`, the package below will be retrieved from pypi:
2-
dash-vtk
3-
dash
2+
dash-vtk

apps/dash-vtk-explorer/demos/usage-vtk-cfd/app.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,33 @@ def getSeedState(self):
139139
# Control UI
140140
# -----------------------------------------------------------------------------
141141

142+
high = 0.6
143+
low = -0.55
144+
142145
controls = [
143146
dbc.Card(
144147
[
145148
dbc.CardHeader("Seeds"),
146149
dbc.CardBody(
147150
[
148-
html.P("Seed line:"),
151+
html.P("Line seed position (from bottom):"),
149152
dcc.Slider(
150153
id="point-1",
151-
min=-1,
152-
max=1,
153-
step=0.01,
154+
min=low,
155+
max=high,
156+
step=0.05,
154157
value=0,
155-
marks={-1: "-1", 1: "+1"},
158+
marks={low: str(low), high: str(high)},
156159
),
160+
html.Br(),
161+
html.P("Line seed position (from top):"),
157162
dcc.Slider(
158163
id="point-2",
159-
min=-1,
160-
max=1,
161-
step=0.01,
164+
min=low,
165+
max=high,
166+
step=0.05,
162167
value=0,
163-
marks={-1: "-1", 1: "+1"},
168+
marks={low: str(low), high: str(high)},
164169
),
165170
html.Br(),
166171
html.P("Line resolution:"),
@@ -244,14 +249,28 @@ def getSeedState(self):
244249
Output("vtk-view", "triggerRender"),
245250
],
246251
[
252+
Input("point-1", "drag_value"),
253+
Input("point-2", "drag_value"),
247254
Input("point-1", "value"),
248255
Input("point-2", "value"),
249256
Input("seed-resolution", "value"),
250257
Input("color-by", "value"),
251258
Input("preset", "value"),
252259
],
253260
)
254-
def update_seeds(y1, y2, resolution, colorByField, presetName):
261+
def update_seeds(y1_drag, y2_drag, y1, y2, resolution, colorByField, presetName):
262+
triggered = dash.callback_context.triggered
263+
264+
if triggered and "drag_value" in triggered[0]["prop_id"]:
265+
viz.updateSeedPoints(y1_drag, y2_drag, resolution)
266+
return [
267+
viz.getSeedState(),
268+
dash.no_update,
269+
dash.no_update,
270+
dash.no_update,
271+
random.random(), # trigger a render
272+
]
273+
255274
viz.updateSeedPoints(y1, y2, resolution)
256275
return [
257276
viz.getSeedState(),

apps/dash-vtk-explorer/demos/usage-vtk-cfd/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# If you skipped `pip install -e ../../`, the package below will be retrieved from pypi:
2+
dash >= 1.19.0
23
dash-vtk
34
dash-bootstrap-components
45
pyvista
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# If you skipped `pip install -e ../../`, the package below will be retrieved from pypi:
22
dash-vtk
3-
dash
43
vtk
54
numpy

0 commit comments

Comments
 (0)