Skip to content

Commit 34ad345

Browse files
author
Xing Han Lu
authored
Merge pull request #607 from plotly/fix-dash-vehicle-geometry
Fix dash vehicle geometry Former-commit-id: bad1428
2 parents 4d00294 + af4463d commit 34ad345

File tree

1 file changed

+53
-15
lines changed
  • apps/dash-vehicle-geometry

1 file changed

+53
-15
lines changed

apps/dash-vehicle-geometry/app.py

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
3232
# GUI setup
3333
# -----------------------------------------------------------------------------
3434

35-
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
35+
app = dash.Dash(
36+
__name__,
37+
external_stylesheets=[dbc.themes.BOOTSTRAP],
38+
suppress_callback_exceptions=True,
39+
)
3640
server = app.server
3741

3842
# -----------------------------------------------------------------------------
@@ -41,6 +45,9 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
4145

4246
# vehicle geometry
4347
vehicle_vtk = []
48+
vehicle_mesh_ids = []
49+
vehicle_meshes = []
50+
4451
for filename in glob.glob(os.path.join(DATA_PATH, "vehicle") + "/*.vtp"):
4552
mesh = _load_vtp(filename, point_arrays=["U", "p"])
4653
part_name = filename.split("/")[-1].replace(".vtp", "")
@@ -50,12 +57,19 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
5057
colorDataRange=[0, 100],
5158
actor={"visibility": 1},
5259
mapper={"scalarVisibility": False},
53-
children=[dash_vtk.Mesh(id=f"{part_name}-mesh", state=mesh,)],
60+
children=[dash_vtk.Mesh(id=f"{part_name}-mesh", state=mesh)],
61+
# children=[dash_vtk.Mesh(id=f"{part_name}-mesh")],
5462
)
5563
vehicle_vtk.append(child)
5664

65+
vehicle_mesh_ids.append(f"{part_name}-mesh")
66+
vehicle_meshes.append(mesh)
67+
5768
# isosurfaces
5869
isosurfs_vtk = []
70+
isomesh_ids = []
71+
isosurfs_meshes = []
72+
5973
for filename in glob.glob(os.path.join(DATA_PATH, "isosurfaces") + "/*.vtp"):
6074
mesh = _load_vtp(filename)
6175

@@ -64,16 +78,22 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
6478
id=f"{surf_name}-rep",
6579
property={"color": [1, 0, 0]},
6680
actor={"visibility": 0},
67-
children=[dash_vtk.Mesh(id=f"{surf_name}-mesh", state=mesh,)],
81+
children=[dash_vtk.Mesh(id=f"{surf_name}-mesh", state=mesh)],
82+
# children=[dash_vtk.Mesh(id=f"{surf_name}-mesh")],
6883
)
6984

7085
isosurfs_vtk.append(child)
7186

87+
isomesh_ids.append(f"{surf_name}-mesh")
88+
isosurfs_meshes.append(mesh)
89+
90+
7291
# -----------------------------------------------------------------------------
7392
# 3D Viz
7493
# -----------------------------------------------------------------------------
7594

76-
vtk_view = dash_vtk.View(id="vtk-view", children=vehicle_vtk + isosurfs_vtk)
95+
# vtk_view = dash_vtk.View(id="vtk-view", children=vehicle_vtk + isosurfs_vtk)
96+
vtk_view = dash_vtk.View(id="vtk-view")
7797

7898
# -----------------------------------------------------------------------------
7999
# Control UI
@@ -95,7 +115,7 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
95115
],
96116
labelStyle={"display": "block"},
97117
value=["body", "drive-train", "front-wing", "rear-wing"],
98-
),
118+
)
99119
]
100120
),
101121
]
@@ -114,7 +134,7 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
114134
{"label": "p", "value": "p"},
115135
],
116136
value="solid",
117-
),
137+
)
118138
]
119139
),
120140
]
@@ -130,7 +150,7 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
130150
options=[{"label": " Cp", "value": "cp"}],
131151
labelStyle={"display": "block"},
132152
value=[],
133-
),
153+
)
134154
]
135155
),
136156
]
@@ -152,7 +172,19 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
152172
dbc.Col(
153173
width=8,
154174
children=[
155-
html.Div(vtk_view, style={"height": "100%", "width": "100%"})
175+
html.Div(
176+
dbc.Spinner(
177+
html.Div(
178+
id="vtk-view-container",
179+
style={
180+
"height": "calc(100vh - 230px)",
181+
"width": "100%",
182+
},
183+
),
184+
color="light",
185+
),
186+
style={"background-color": "#334c66"},
187+
)
156188
],
157189
),
158190
],
@@ -165,11 +197,16 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
165197
# This Handle controls
166198
# -----------------------------------------------------------------------------
167199

168-
COLOR_RANGES = {
169-
"solid": [0, 1],
170-
"U": [0, 100],
171-
"p": [-4464, 1700],
172-
}
200+
COLOR_RANGES = {"solid": [0, 1], "U": [0, 100], "p": [-4464, 1700]}
201+
202+
203+
@app.callback(Output("vtk-view-container", "children"), [Input("geometry", "value")])
204+
def initial_loading(geometry):
205+
triggered = dash.callback_context.triggered
206+
if triggered:
207+
return dash.no_update
208+
209+
return dash_vtk.View(id="vtk-view", children=vehicle_vtk + isosurfs_vtk)
173210

174211

175212
@app.callback(
@@ -183,6 +220,7 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
183220
Input("isosurfaces", "value"),
184221
Input("surfcolor", "value"),
185222
],
223+
prevent_initial_call=True,
186224
)
187225
def update_scene(geometry, isosurfaces, surfcolor):
188226
triggered = dash.callback_context.triggered
@@ -223,8 +261,8 @@ def update_scene(geometry, isosurfaces, surfcolor):
223261
surf_state = [mapper for item in vehicle_vtk]
224262
color_ranges = [color_range for item in vehicle_vtk]
225263
else:
226-
surf_state = [dash.no_update for item in vehicle_vtk]
227-
color_ranges = [dash.no_update for item in vehicle_vtk]
264+
surf_state = [dash.no_update] * len(vehicle_vtk)
265+
color_ranges = [dash.no_update] * len(vehicle_vtk)
228266

229267
return [random.random()] + surf_state + geo_viz + color_ranges + [iso_viz]
230268

0 commit comments

Comments
 (0)