Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapted to Pyomeca 2020.0.1 #33

Merged
merged 3 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions BiorbdViz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
if biorbd.currentLinearAlgebraBackend() == 1:
import casadi

from pyomeca import Markers3d
from .biorbd_vtk import VtkModel, VtkWindow, Mesh, MeshCollection, RotoTrans, RotoTransCollection
from pyomeca import Markers
from .biorbd_vtk import VtkModel, VtkWindow, Mesh, Rototrans
from PyQt5.QtWidgets import (
QSlider,
QVBoxLayout,
Expand Down Expand Up @@ -83,7 +83,7 @@ def _get_data_from_casadi(self, Q=None, compute_kin=True):
class CoM(BiorbdFunc):
def __init__(self, model):
super().__init__(model)
self.data = np.ndarray((3, 1, 1))
self.data = np.ones((4, 1, 1))

def _prepare_function_for_casadi(self):
Qsym = casadi.MX.sym("Q", self.m.nbQ(), 1)
Expand All @@ -95,10 +95,10 @@ def _get_data_from_eigen(self, Q=None, compute_kin=True):
else:
CoM = self.m.CoM(Q, False)
for i in range(self.m.nbSegment()):
self.data[:, 0, 0] = CoM.to_array()
self.data[:3, 0, 0] = CoM.to_array()

def _get_data_from_casadi(self, Q=None, compute_kin=True):
self.data[:, :, 0] = self.CoM(Q)
self.data[:3, :, 0] = self.CoM(Q)

class CoMbySegment(BiorbdFunc):
def __init__(self, model):
Expand All @@ -116,12 +116,12 @@ def _get_data_from_eigen(self, Q=None, compute_kin=True):
else:
allCoM = self.m.CoMbySegment(Q, False)
for com in allCoM:
self.data.append(com.to_array())
self.data.append(np.append(com.to_array(), 1))

def _get_data_from_casadi(self, Q=None, compute_kin=True):
self.data = []
for i in range(self.m.nbSegment()):
self.data.append(np.array(self.CoMs(Q)[:, i]))
self.data.append(np.append(self.CoMs(Q)[:, i], 1))

class MusclesPointsInGlobal(BiorbdFunc):
def __init__(self, model):
Expand Down Expand Up @@ -276,35 +276,35 @@ def __init__(
# 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.nbMarkers(), 1)))
self.markers = Markers(np.ndarray((3, self.model.nbMarkers(), 1)))
if self.show_markers:
self.Markers = InterfacesCollections.Markers(self.model)
self.global_center_of_mass = Markers3d(np.ndarray((3, 1, 1)))
self.global_center_of_mass = Markers(np.ndarray((3, 1, 1)))
if self.show_global_center_of_mass:
self.CoM = InterfacesCollections.CoM(self.model)
self.segments_center_of_mass = Markers3d(np.ndarray((3, self.model.nbSegment(), 1)))
self.segments_center_of_mass = Markers(np.ndarray((3, self.model.nbSegment(), 1)))
if self.show_segments_center_of_mass:
self.CoMbySegment = InterfacesCollections.CoMbySegment(self.model)
if self.show_meshes:
self.mesh = MeshCollection()
self.mesh = []
self.meshPointsInMatrix = InterfacesCollections.MeshPointsInMatrix(self.model)
for i, vertices in enumerate(self.meshPointsInMatrix.get_data(Q=self.Q, compute_kin=False)):
triangles = np.ndarray((len(self.model.meshFaces()[i]), 3), dtype="int32")
for k, patch in enumerate(self.model.meshFaces()[i]):
triangles[k, :] = patch.face()
self.mesh.append(Mesh(vertex=vertices, triangles=triangles.T))
self.model.updateMuscles(self.Q, True)
self.muscles = MeshCollection()
self.muscles = []
for group_idx in range(self.model.nbMuscleGroups()):
for muscle_idx in range(self.model.muscleGroup(group_idx).nbMuscles()):
musc = self.model.muscleGroup(group_idx).muscle(muscle_idx)
tp = np.zeros((3, len(musc.position().musclesPointsInGlobal()), 1))
self.muscles.append(Mesh(vertex=tp))
self.musclesPointsInGlobal = InterfacesCollections.MusclesPointsInGlobal(self.model)
self.rt = RotoTransCollection()
self.rt = []
self.allGlobalJCS = InterfacesCollections.AllGlobalJCS(self.model)
for rt in self.allGlobalJCS.get_data(Q=self.Q, compute_kin=False):
self.rt.append(RotoTrans(rt))
self.rt.append(Rototrans(rt))

if self.show_global_ref_frame:
self.vtk_model.create_global_ref_frame()
Expand Down Expand Up @@ -757,18 +757,18 @@ def __load_movement(self):

def __set_markers_from_q(self):
self.markers[0:3, :, :] = self.Markers.get_data(Q=self.Q, compute_kin=False)
self.vtk_model.update_markers(self.markers.get_frame(0))
self.vtk_model.update_markers(self.markers.isel(time=[0]))

def __set_global_center_of_mass_from_q(self):
com = self.CoM.get_data(Q=self.Q, compute_kin=False)
self.global_center_of_mass[0:3, 0, 0] = com.reshape(-1, 1)
self.vtk_model.update_global_center_of_mass(self.global_center_of_mass.get_frame(0))
self.global_center_of_mass.loc[{"channel": 0, "time": 0}] = com.squeeze()
self.vtk_model.update_global_center_of_mass(self.global_center_of_mass.isel(time=[0]))

def __set_segments_center_of_mass_from_q(self):
coms = self.CoMbySegment.get_data(Q=self.Q, compute_kin=False)
for k, com in enumerate(coms):
self.segments_center_of_mass[0:3, k, 0] = com.reshape(-1, 1)
self.vtk_model.update_segments_center_of_mass(self.segments_center_of_mass.get_frame(0))
self.segments_center_of_mass.loc[{"channel": k, "time": 0}] = com.squeeze()
self.vtk_model.update_segments_center_of_mass(self.segments_center_of_mass.isel(time=[0]))

def __set_meshes_from_q(self):
for m, meshes in enumerate(self.meshPointsInMatrix.get_data(Q=self.Q, compute_kin=False)):
Expand All @@ -784,12 +784,12 @@ def __set_muscles_from_q(self):
for muscle_idx in range(self.model.muscleGroup(group_idx).nbMuscles()):
musc = self.model.muscleGroup(group_idx).muscle(muscle_idx)
for k, pts in enumerate(musc.position().musclesPointsInGlobal()):
self.muscles.get_frame(0)[idx][0:3, k, 0] = muscles[cmp]
self.muscles[idx].loc[{"channel": k, "time": 0}] = np.append(muscles[cmp], 1)
cmp += 1
idx += 1
self.vtk_model.update_muscle(self.muscles)

def __set_rt_from_q(self):
for k, rt in enumerate(self.allGlobalJCS.get_data(Q=self.Q, compute_kin=False)):
self.rt[k] = RotoTrans(rt)
self.rt[k] = Rototrans(rt)
self.vtk_model.update_rt(self.rt)
Loading