# """ # Example script for animating a model # """ import numpy as np from bioviz import Viz b = Viz(model_path="pyomecaman.bioMod") animate_by_hand = 0 if animate_by_hand == 0: n_frames = 200 all_q = np.zeros((b.nQ, n_frames)) all_q[4, :] = np.linspace(0, np.pi / 2, n_frames) b.load_movement(all_q) b.exec() elif animate_by_hand == 1: n_frames = 200 Q = np.zeros((b.nQ, n_frames)) Q[4, :] = np.linspace(0, np.pi / 2, n_frames) i = 0 while b.vtk_window.is_active: b.set_q(Q[:, i]) i = (i + 1) % n_frames else: b.exec()
for j in range(m.muscleGroup(i).nbMuscles()): plt.subplot(3, 6, cmp + 1) utils.plot_piecewise_constant(t_final, all_u[cmp, :]) plt.title(m.muscleGroup(i).muscle(j).name().to_string()) plt.ylim((0, 1)) cmp += 1 else: nb_row = np.max(muscle_plot_mapping, axis=0)[3] + 1 nb_col = np.max(muscle_plot_mapping, axis=0)[4] + 1 created_axes = [None] * nb_col * nb_row for muscle_map in muscle_plot_mapping: idx_axis = muscle_map[3] * nb_col + muscle_map[4] if created_axes[idx_axis]: plt.sca(created_axes[idx_axis]) else: created_axes[idx_axis] = plt.subplot(nb_row, nb_col, idx_axis + 1) utils.plot_piecewise_constant(t_final, all_u[muscle_map[0], :]) # plt.title(m.muscleGroup(map[1]).muscle(map[2]).name().getString()) plt.title(muscle_plot_names[muscle_map[5]]) plt.ylim((0, 1)) plt.tight_layout(w_pad=-1.0, h_pad=-1.0) plt.show() # Animate the model b = Viz(loaded_model=m, markers_size=0.003) # b = Viz(loaded_model=m) b.load_movement(q_interp) b.exec()
import time import pickle import sys from bioviz import Viz file_path = 0 if len(sys.argv) > 1: file_path = str(sys.argv[1]) if not isinstance(file_path, str): t = time.localtime(time.time()) file_path = f"results/{t.tm_year}_{t.tm_mon}_{t.tm_mday}_upDown.bob" with open(file_path, "rb") as file: data = pickle.load(file) data_interpolate, _ = data["data"] b = Viz("../models/BrasViolon.bioMod", markers_size=0.0002, show_segments_center_of_mass=False, show_local_ref_frame=False, show_global_ref_frame=False, show_muscles=False) b.load_movement(data_interpolate["q"].T, ) b.exec()
method='RK45', atol=1e-8, rtol=1e-6) t_interp2, q_interp2 = utils.interpolate_integration(nb_frames=1000, t_int=integrated_tp2.t, y_int=integrated_tp2.y) from matplotlib import pyplot as plt plt.plot(t_interp, q_interp) plt.plot(t_interp2, q_interp2, '-.') plt.show() bioviz = Viz(loaded_model=biorbd_model) bioviz2 = Viz(loaded_model=biorbd_model) bioviz.load_movement(q_interp) bioviz2.load_movement(q_interp2) bioviz.is_executing = True bioviz2.is_executing = True while bioviz.vtk_window.is_active and bioviz2.vtk_window.is_active: if bioviz.show_options and bioviz.is_animating: bioviz.movement_slider[0].setValue( (bioviz.movement_slider[0].value() + 1) % bioviz.movement_slider[0].maximum()) if bioviz2.show_options and bioviz2.is_animating: bioviz2.movement_slider[0].setValue( (bioviz2.movement_slider[0].value() + 1) % bioviz2.movement_slider[0].maximum()) bioviz.refresh_window() bioviz2.refresh_window()