21
21
# -----------------------------------------------------------------------------
22
22
23
23
24
- def _load_vtp (filepath , fieldname = None ):
24
+ def _load_vtp (filepath , fieldname = None , point_arrays = [], cell_arrays = [] ):
25
25
reader = vtk .vtkXMLPolyDataReader ()
26
26
reader .SetFileName (filepath )
27
27
reader .Update ()
28
- if fieldname is None :
29
- return to_mesh_state (reader .GetOutput ())
30
- else :
31
- return to_mesh_state (reader .GetOutput (), fieldname )
28
+ return to_mesh_state (reader .GetOutput (), fieldname , point_arrays , cell_arrays )
32
29
33
30
34
31
# -----------------------------------------------------------------------------
@@ -45,13 +42,14 @@ def _load_vtp(filepath, fieldname=None):
45
42
# vehicle geometry
46
43
vehicle_vtk = []
47
44
for filename in glob .glob (os .path .join (DATA_PATH , "vehicle" ) + "/*.vtp" ):
48
- mesh = _load_vtp (filename )
45
+ mesh = _load_vtp (filename , point_arrays = [ "U" , "p" ] )
49
46
part_name = filename .split ("/" )[- 1 ].replace (".vtp" , "" )
50
47
child = dash_vtk .GeometryRepresentation (
51
48
id = f"{ part_name } -rep" ,
52
49
colorMapPreset = "erdc_rainbow_bright" ,
53
50
colorDataRange = [0 , 100 ],
54
- property = {"opacity" : 1 },
51
+ actor = {"visibility" : 1 },
52
+ mapper = {"scalarVisibility" : False },
55
53
children = [dash_vtk .Mesh (id = f"{ part_name } -mesh" , state = mesh ,)],
56
54
)
57
55
vehicle_vtk .append (child )
@@ -64,7 +62,8 @@ def _load_vtp(filepath, fieldname=None):
64
62
surf_name = filename .split ("/" )[- 1 ].replace (".vtp" , "" )
65
63
child = dash_vtk .GeometryRepresentation (
66
64
id = f"{ surf_name } -rep" ,
67
- property = {"opacity" : 0 , "color" : [1 , 0 , 0 ]},
65
+ property = {"color" : [1 , 0 , 0 ]},
66
+ actor = {"visibility" : 0 },
68
67
children = [dash_vtk .Mesh (id = f"{ surf_name } -mesh" , state = mesh ,)],
69
68
)
70
69
@@ -112,6 +111,7 @@ def _load_vtp(filepath, fieldname=None):
112
111
options = [
113
112
{"label" : "solid" , "value" : "solid" },
114
113
{"label" : "U" , "value" : "U" },
114
+ {"label" : "p" , "value" : "p" },
115
115
],
116
116
value = "solid" ,
117
117
),
@@ -165,12 +165,19 @@ def _load_vtp(filepath, fieldname=None):
165
165
# Handle controls
166
166
# -----------------------------------------------------------------------------
167
167
168
+ COLOR_RANGES = {
169
+ "solid" : [0 , 1 ],
170
+ "U" : [0 , 100 ],
171
+ "p" : [- 4464 , 1700 ],
172
+ }
173
+
168
174
169
175
@app .callback (
170
176
[Output ("vtk-view" , "triggerRender" )]
171
- + [Output (item .id .replace ("rep" , "mesh" ), "state" ) for item in vehicle_vtk ]
172
- + [Output (item .id , "property" ) for item in vehicle_vtk ]
173
- + [Output ("cp-rep" , "property" )],
177
+ + [Output (item .id , "mapper" ) for item in vehicle_vtk ]
178
+ + [Output (item .id , "actor" ) for item in vehicle_vtk ]
179
+ + [Output (item .id , "colorDataRange" ) for item in vehicle_vtk ]
180
+ + [Output ("cp-rep" , "actor" )],
174
181
[
175
182
Input ("geometry" , "value" ),
176
183
Input ("isosurfaces" , "value" ),
@@ -184,9 +191,9 @@ def update_scene(geometry, isosurfaces, surfcolor):
184
191
geo_viz , iso_viz = [], []
185
192
if triggered and "geometry" in triggered [0 ]["prop_id" ]:
186
193
geo_viz = [
187
- {"opacity " : 1 }
194
+ {"visibility " : 1 }
188
195
if part .id .replace ("-rep" , "" ).split ("_" )[0 ] in triggered [0 ]["value" ]
189
- else {"opacity " : 0 }
196
+ else {"visibility " : 0 }
190
197
for part in vehicle_vtk
191
198
]
192
199
else :
@@ -195,26 +202,31 @@ def update_scene(geometry, isosurfaces, surfcolor):
195
202
# update isosurface visibility
196
203
if triggered and "isosurfaces" in triggered [0 ]["prop_id" ]:
197
204
if "cp" in triggered [0 ]["value" ]:
198
- iso_viz = {"opacity " : 1 }
205
+ iso_viz = {"visibility " : 1 }
199
206
else :
200
- iso_viz = {"opacity " : 0 }
207
+ iso_viz = {"visibility " : 0 }
201
208
else :
202
209
iso_viz = dash .no_update
203
210
204
211
# update surface coloring
205
212
if triggered and "surfcolor" in triggered [0 ]["prop_id" ]:
206
- surf_state = []
207
-
208
- for filename in glob .glob (os .path .join (DATA_PATH , "vehicle" ) + "/*.vtp" ):
209
- if triggered [0 ]["value" ] == "solid" :
210
- mesh = _load_vtp (filename )
211
- else :
212
- mesh = _load_vtp (filename , triggered [0 ]["value" ])
213
- surf_state .append (mesh )
213
+ color_range = COLOR_RANGES [triggered [0 ]["value" ]]
214
+ mapper = {
215
+ "colorByArrayName" : triggered [0 ]["value" ],
216
+ "scalarMode" : 3 ,
217
+ "interpolateScalarsBeforeMapping" : True ,
218
+ "scalarVisibility" : True ,
219
+ }
220
+ if triggered [0 ]["value" ] == "solid" :
221
+ mapper = {"scalarVisibility" : False }
222
+
223
+ surf_state = [mapper for item in vehicle_vtk ]
224
+ color_ranges = [color_range for item in vehicle_vtk ]
214
225
else :
215
226
surf_state = [dash .no_update for item in vehicle_vtk ]
227
+ color_ranges = [dash .no_update for item in vehicle_vtk ]
216
228
217
- return [random .random ()] + surf_state + geo_viz + [iso_viz ]
229
+ return [random .random ()] + surf_state + geo_viz + color_ranges + [iso_viz ]
218
230
219
231
220
232
# -----------------------------------------------------------------------------
0 commit comments