def __compute_all_values(self): q_idx = self.dof_mapping[self.current_dof] x_axis, all_q = self.__generate_x_axis(q_idx) length = np.ndarray((self.n_point_for_q, self.n_mus)) moment_arm = np.ndarray((self.n_point_for_q, self.n_mus)) passive_forces = np.ndarray((self.n_point_for_q, self.n_mus)) active_forces = np.ndarray((self.n_point_for_q, self.n_mus)) emg = biorbd.StateDynamics(0, self.active_forces_slider.value() / 100) for i, q_mod in enumerate(all_q): self.model.UpdateKinematicsCustom(biorbd.GeneralizedCoordinates(q_mod)) muscles_length_jacobian = self.model.musclesLengthJacobian().to_array() for m in range(self.n_mus): if self.checkboxes_muscle[m].isChecked(): mus_group_idx, mus_idx, _ = self.muscle_mapping[self.checkboxes_muscle[m].text()] mus = self.model.muscleGroup(mus_group_idx).muscle(mus_idx) mus.updateOrientations(self.model, q_mod, 1) length[i, m] = mus.length(self.model, q_mod, False) moment_arm[i, m] = muscles_length_jacobian[mus_idx, q_idx] if mus.type() != biorbd.IDEALIZED_ACTUATOR: passive_forces[i, m] = biorbd.HillType(mus).FlPE() else: passive_forces[i, m] = 0 if mus.type() != biorbd.IDEALIZED_ACTUATOR: active_forces[i, m] = biorbd.HillType(mus).FlCE(emg) else: active_forces[i, m] = 0 return x_axis, length, moment_arm, passive_forces, active_forces
def __set_muscles_from_q(self): self.model.updateMuscles(self.model, self.Q, True) idx = 0 for group_idx in range(self.model.nbMuscleGroups()): for muscle_idx in range( self.model.muscleGroup(group_idx).nbMuscles()): musc_tp = self.model.muscleGroup(group_idx).muscle(muscle_idx) muscle_type = biorbd.Model.getMuscleType(musc_tp).getString() if muscle_type == "Hill": musc = biorbd.HillType(musc_tp) elif muscle_type == "HillThelen": musc = biorbd.HillTypeThelen(musc_tp) elif muscle_type == "HillSimple": musc = biorbd.HillTypeSimple(musc_tp) for k, pts in enumerate( musc.position().musclesPointsInGlobal()): self.muscles.get_frame(0)[idx][0:3, k] = pts.get_array() idx += 1 self.vtk_model.update_muscle(self.muscles)
def __init__(self, model_path=None, loaded_model=None, show_global_ref_frame=True, show_markers=True, show_global_center_of_mass=True, show_segments_center_of_mass=True, show_rt=True, show_muscles=True, show_meshes=True, show_options=True): """ Class that easily shows a biorbd model Args: loaded_model: reference to a biorbd loaded model (if both loaded_model and model_path, load_model is selected model_path: path of the model to load """ # Load and store the model if loaded_model is not None: if not isinstance(loaded_model, biorbd.Model): raise TypeError( "loaded_model should be of a biorbd.Model type") self.model = loaded_model elif model_path is not None: self.model = biorbd.Model(model_path) else: raise ValueError("loaded_model or model_path must be provided") # Create the plot self.vtk_window = VtkWindow(background_color=(.5, .5, .5)) self.vtk_model = VtkModel(self.vtk_window, markers_color=(0, 0, 1)) self.is_executing = False self.animation_warning_already_shown = False # Set Z vertical cam = self.vtk_window.ren.GetActiveCamera() cam.SetFocalPoint(0, 0, 0) cam.SetPosition(5, 0, 0) cam.SetRoll(-90) # Get the options self.show_markers = show_markers self.show_global_ref_frame = show_global_ref_frame self.show_global_center_of_mass = show_global_center_of_mass self.show_segments_center_of_mass = show_segments_center_of_mass self.show_rt = show_rt if self.model.nbMuscleTotal() > 0: self.show_muscles = show_muscles else: self.show_muscles = False if sum([ len(i) for i in self.model.meshPoints(np.zeros(self.model.nbQ())) ]) > 0: self.show_meshes = show_meshes else: self.show_meshes = 0 # Create all the reference to the things to plot self.nQ = self.model.nbQ() self.Q = np.zeros(self.nQ) self.markers = Markers3d(np.ndarray((3, self.model.nTags(), 1))) self.global_center_of_mass = Markers3d(np.ndarray((3, 1, 1))) self.segments_center_of_mass = Markers3d( np.ndarray((3, self.model.nbBone(), 1))) self.mesh = MeshCollection() for l, meshes in enumerate(self.model.meshPoints(self.Q)): tp = np.ndarray((3, len(meshes), 1)) for k, mesh in enumerate(meshes): tp[:, k, 0] = mesh.get_array() self.mesh.append(Mesh(vertex=tp)) self.model.updateMuscles(self.model, self.Q, True) self.muscles = MeshCollection() for group_idx in range(self.model.nbMuscleGroups()): for muscle_idx in range( self.model.muscleGroup(group_idx).nbMuscles()): musc_tp = self.model.muscleGroup(group_idx).muscle(muscle_idx) muscle_type = biorbd.Model.getMuscleType(musc_tp).getString() if muscle_type == "Hill": musc = biorbd.HillType(musc_tp) elif muscle_type == "HillThelen": musc = biorbd.HillTypeThelen(musc_tp) elif muscle_type == "HillSimple": musc = biorbd.HillTypeSimple(musc_tp) tp = np.ndarray( (3, len(musc.position().musclesPointsInGlobal()), 1)) for k, pts in enumerate( musc.position().musclesPointsInGlobal()): tp[:, k, 0] = pts.get_array() self.muscles.append(Mesh(vertex=tp)) self.rt = RotoTransCollection() for rt in self.model.globalJCS(self.Q): self.rt.append(RotoTrans(rt.get_array())) if self.show_global_ref_frame: self.vtk_model.create_global_ref_frame() self.show_options = show_options if self.show_options: self.muscle_analyses = [] self.palette_active = QPalette() self.palette_inactive = QPalette() self.set_viz_palette() self.animated_Q = [] self.play_stop_push_button = [] self.is_animating = False self.start_icon = QIcon( QPixmap(f"{os.path.dirname(__file__)}/ressources/start.png")) self.stop_icon = QIcon( QPixmap(f"{os.path.dirname(__file__)}/ressources/pause.png")) self.double_factor = 10000 self.sliders = list() self.movement_slider = [] self.active_analyses_widget = None self.analyses_layout = QHBoxLayout() self.analyses_muscle_widget = QWidget() self.add_options_panel() # Update everything at the position Q=0 self.set_q(self.Q)