-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpump_bracket.py
More file actions
126 lines (96 loc) · 3.19 KB
/
pump_bracket.py
File metadata and controls
126 lines (96 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import asyncio
import matplotlib.pyplot as plt
import numpy as np
from trame.app import asynchronous, get_server
from trame.ui.vuetify3 import SinglePageLayout
from trame.widgets import vuetify3 as vuetify
import pyvista as pv
from pyvista import examples
from pyvista.trame.ui import plotter_ui
pv.OFF_SCREEN = True
server = get_server()
state, ctrl = server.state, server.controller
state.trame__title = "Pump Bracket"
# -----------------------------------------------------------------------------
dataset = examples.download_pump_bracket()
cpos = [
(0.744, -0.502, -0.830),
(0.0520, -0.160, 0.0743),
(-0.180, -0.958, 0.224),
]
n_frames = 32
phases = np.linspace(0, 2 * np.pi, n_frames, endpoint=False)
pl = pv.Plotter()
pl.enable_anti_aliasing("fxaa")
# Add the undeformed pump bracket
pl.add_mesh(dataset, color="white", opacity=0.5)
# Add the deformed pump bracket with the mode shape
warped = dataset.copy()
actor = pl.add_mesh(warped, show_scalar_bar=False, ambient=0.2)
pl.camera_position = cpos
@state.change("cmap")
def update_cmap(cmap="viridis", **kwargs):
actor.mapper.lookup_table.cmap = cmap
ctrl.view_update()
@state.change("phase_index")
def update_phase(phase_index=0, **kwargs):
phase = phases[phase_index]
# feel free to change this to visualize different mode shapes
mode_shape = "disp_6"
# use the original unmodified points
warped.points = dataset.points + dataset[mode_shape] * np.cos(phase) * 0.05
ctrl.view_update()
@state.change("play")
@asynchronous.task
async def update_play(**kwargs):
while state.play:
with state:
if state.phase_index >= len(phases):
state.phase_index = 0
else:
state.phase_index += 1
update_phase(state.phase_index)
await asyncio.sleep(0.00001)
# -----------------------------------------------------------------------------
# GUI
# -----------------------------------------------------------------------------
with SinglePageLayout(server) as layout:
layout.icon.click = ctrl.view_reset_camera
layout.title.set_text(state.trame__title)
with layout.toolbar:
vuetify.VSpacer()
vuetify.VSelect(
label="Color map",
v_model=("cmap", "viridis"),
items=("array_list", plt.colormaps()),
hide_details=True,
dense=True,
outlined=True,
classes="pt-1 ml-2",
style="max-width: 250px",
)
vuetify.VSlider(
v_model=("phase_index", 0),
min=0,
max=len(phases) - 1,
hide_details=True,
dense=True,
style="max-width: 200px",
)
vuetify.VCheckbox(
v_model=("play", False),
off_icon="mdi-play",
on_icon="mdi-stop",
hide_details=True,
dense=True,
classes="mx-2",
)
with layout.content:
# Use PyVista UI template for Plotters
view = plotter_ui(pl)
ctrl.view_update = view.update
ctrl.view_update_image = view.update_image
ctrl.view_reset_camera = view.reset_camera
# hide footer
layout.footer.hide()
server.start()