diff --git a/.gitignore b/.gitignore index f51ca78..0842d39 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,5 @@ venv.bak/ /.idea *altair-data* + +*.npy diff --git a/examples/biorbd_viz.py b/examples/biorbd_viz.py index e068e36..2207aa3 100644 --- a/examples/biorbd_viz.py +++ b/examples/biorbd_viz.py @@ -7,9 +7,9 @@ from pyoviz.BiorbdViz import BiorbdViz b = BiorbdViz(model_path="pyomecaman.s2mMod") -animate_by_hand = False +animate_by_hand = 1 -if animate_by_hand: +if animate_by_hand == 0: n_frames = 200 Q = np.zeros((n_frames, b.nQ)) Q[:, 4] = np.linspace(0, np.pi/2, n_frames) @@ -17,5 +17,11 @@ while b.vtk_window.is_active: b.set_q(Q[i, :]) i = (i+1) % n_frames +elif animate_by_hand == 1: + n_frames = 200 + all_q = np.zeros((n_frames, b.nQ)) + all_q[:, 4] = np.linspace(0, np.pi / 2, n_frames) + b.load_movement(all_q) + b.exec() else: b.exec() diff --git a/pyoviz/BiorbdViz.py b/pyoviz/BiorbdViz.py index 7f7a04f..4e1656a 100644 --- a/pyoviz/BiorbdViz.py +++ b/pyoviz/BiorbdViz.py @@ -243,7 +243,7 @@ def add_options_panel(self): animation_slider_layout = QHBoxLayout() load_push_button = QPushButton("Load movement") load_push_button.setPalette(pal) - load_push_button.released.connect(self.__load_movement) + load_push_button.released.connect(self.__load_movement_from_button) animation_slider_layout.addWidget(load_push_button) self.play_stop_push_button = QPushButton() @@ -305,7 +305,7 @@ def __start_stop_animation(self): self.is_animating = True self.play_stop_push_button.setIcon(self.stop_icon) - def __load_movement(self): + def __load_movement_from_button(self): # Load the actual movement options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog @@ -314,11 +314,17 @@ def __load_movement(self): if not file_name[0]: return self.animated_Q = np.load(file_name[0]) - # Example file was produced using the following lines - # n_frames = 200 - # self.animated_Q = np.zeros((n_frames, self.nQ)) - # self.animated_Q[:, 4] = np.linspace(0, np.pi / 2, n_frames) + self.__load_movement() + + def load_movement(self, all_q, auto_start=True, ignore_animation_warning=True): + self.animated_Q = all_q + self.__load_movement() + if ignore_animation_warning: + self.animation_warning_already_shown = True + if auto_start: + self.__start_stop_animation() + def __load_movement(self): # Activate the start button self.is_animating = False self.play_stop_push_button.setEnabled(True)