Skip to content

Commit

Permalink
Merge pull request #8 from pariterre/VizExample
Browse files Browse the repository at this point in the history
Load movement from a file
  • Loading branch information
pariterre authored May 15, 2019
2 parents 62a620d + 6256388 commit 2e6c5a7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ venv.bak/
/.idea

*altair-data*

*.npy
10 changes: 8 additions & 2 deletions examples/biorbd_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
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)
i = 0
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()
18 changes: 12 additions & 6 deletions pyoviz/BiorbdViz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 2e6c5a7

Please sign in to comment.