@@ -32,7 +32,11 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
32
32
# GUI setup
33
33
# -----------------------------------------------------------------------------
34
34
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
+ )
36
40
server = app .server
37
41
38
42
# -----------------------------------------------------------------------------
@@ -41,6 +45,9 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
41
45
42
46
# vehicle geometry
43
47
vehicle_vtk = []
48
+ vehicle_mesh_ids = []
49
+ vehicle_meshes = []
50
+
44
51
for filename in glob .glob (os .path .join (DATA_PATH , "vehicle" ) + "/*.vtp" ):
45
52
mesh = _load_vtp (filename , point_arrays = ["U" , "p" ])
46
53
part_name = filename .split ("/" )[- 1 ].replace (".vtp" , "" )
@@ -50,12 +57,19 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
50
57
colorDataRange = [0 , 100 ],
51
58
actor = {"visibility" : 1 },
52
59
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")],
54
62
)
55
63
vehicle_vtk .append (child )
56
64
65
+ vehicle_mesh_ids .append (f"{ part_name } -mesh" )
66
+ vehicle_meshes .append (mesh )
67
+
57
68
# isosurfaces
58
69
isosurfs_vtk = []
70
+ isomesh_ids = []
71
+ isosurfs_meshes = []
72
+
59
73
for filename in glob .glob (os .path .join (DATA_PATH , "isosurfaces" ) + "/*.vtp" ):
60
74
mesh = _load_vtp (filename )
61
75
@@ -64,16 +78,22 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
64
78
id = f"{ surf_name } -rep" ,
65
79
property = {"color" : [1 , 0 , 0 ]},
66
80
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")],
68
83
)
69
84
70
85
isosurfs_vtk .append (child )
71
86
87
+ isomesh_ids .append (f"{ surf_name } -mesh" )
88
+ isosurfs_meshes .append (mesh )
89
+
90
+
72
91
# -----------------------------------------------------------------------------
73
92
# 3D Viz
74
93
# -----------------------------------------------------------------------------
75
94
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" )
77
97
78
98
# -----------------------------------------------------------------------------
79
99
# Control UI
@@ -95,7 +115,7 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
95
115
],
96
116
labelStyle = {"display" : "block" },
97
117
value = ["body" , "drive-train" , "front-wing" , "rear-wing" ],
98
- ),
118
+ )
99
119
]
100
120
),
101
121
]
@@ -114,7 +134,7 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
114
134
{"label" : "p" , "value" : "p" },
115
135
],
116
136
value = "solid" ,
117
- ),
137
+ )
118
138
]
119
139
),
120
140
]
@@ -130,7 +150,7 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
130
150
options = [{"label" : " Cp" , "value" : "cp" }],
131
151
labelStyle = {"display" : "block" },
132
152
value = [],
133
- ),
153
+ )
134
154
]
135
155
),
136
156
]
@@ -152,7 +172,19 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
152
172
dbc .Col (
153
173
width = 8 ,
154
174
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
+ )
156
188
],
157
189
),
158
190
],
@@ -165,11 +197,16 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
165
197
# This Handle controls
166
198
# -----------------------------------------------------------------------------
167
199
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 )
173
210
174
211
175
212
@app .callback (
@@ -183,6 +220,7 @@ def _load_vtp(filepath, fieldname=None, point_arrays=[], cell_arrays=[]):
183
220
Input ("isosurfaces" , "value" ),
184
221
Input ("surfcolor" , "value" ),
185
222
],
223
+ prevent_initial_call = True ,
186
224
)
187
225
def update_scene (geometry , isosurfaces , surfcolor ):
188
226
triggered = dash .callback_context .triggered
@@ -223,8 +261,8 @@ def update_scene(geometry, isosurfaces, surfcolor):
223
261
surf_state = [mapper for item in vehicle_vtk ]
224
262
color_ranges = [color_range for item in vehicle_vtk ]
225
263
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 )
228
266
229
267
return [random .random ()] + surf_state + geo_viz + color_ranges + [iso_viz ]
230
268
0 commit comments