diff --git a/bionc/vizualization/pyorerun_interface.py b/bionc/vizualization/pyorerun_interface.py index 09f461bd..dd49f323 100644 --- a/bionc/vizualization/pyorerun_interface.py +++ b/bionc/vizualization/pyorerun_interface.py @@ -1,7 +1,7 @@ import numpy as np from pyorerun.biorbd_components.model_display_options import DisplayModelOptions -from ..bionc_numpy import NaturalVector +from ..bionc_numpy import NaturalVector, NaturalCoordinates from ..bionc_numpy.joints import Joint from ..protocols.biomechanical_model import GenericBiomechanicalModel @@ -51,6 +51,10 @@ def nb_segments(self) -> int: def segments(self) -> tuple["BioncSegment", ...]: return tuple(BioncSegment(s, i) for i, s in enumerate(self.model.segments.values())) + @property + def segment_names_with_mass(self) -> tuple[str, ...]: + return tuple([segment.name for segment in self.model.segments.values() if segment.mass > 0]) + def segment_homogeneous_matrices_in_global(self, q: np.ndarray, segment_index: int) -> np.ndarray: """ Returns a biorbd object containing the roto-translation matrix of the segment in the global reference frame. @@ -63,11 +67,12 @@ def segment_homogeneous_matrices_in_global(self, q: np.ndarray, segment_index: i return transform - def center_of_mass(self, q: np.ndarray) -> np.ndarray: + def centers_of_mass(self, q: np.ndarray) -> np.ndarray: """ Returns the position of the center of mass in the global reference frame """ - pass + Q = NaturalCoordinates(q[:, None]) + return self.model.center_of_mass_position(Q).squeeze().T @property def nb_ligaments(self) -> int: diff --git a/examples/play_with_joints/two_constant_length.py b/examples/play_with_joints/two_constant_length.py index 89a7218c..1b452d2f 100644 --- a/examples/play_with_joints/two_constant_length.py +++ b/examples/play_with_joints/two_constant_length.py @@ -173,6 +173,16 @@ def main(initial_pose: str = "hanged", show_results: bool = True): all_states=all_states, dynamics=dynamics, ) + + # animation + from pyorerun import PhaseRerun + from bionc.vizualization.pyorerun_interface import BioncModelNoMesh + + prr = PhaseRerun(t_span=time_steps) + model_interface = BioncModelNoMesh(model) + prr.add_animated_model(model_interface, NaturalCoordinates(all_states[: (12 * model.nb_segments), :])) + prr.rerun() + # plot results import matplotlib.pyplot as plt @@ -196,15 +206,6 @@ def main(initial_pose: str = "hanged", show_results: bool = True): plt.legend() plt.show() - # animation - from pyorerun import PhaseRerun - from bionc.vizualization.pyorerun_interface import BioncModelNoMesh - - prr = PhaseRerun(t_span=time_steps) - model_interface = BioncModelNoMesh(model) - prr.add_animated_model(model_interface, NaturalCoordinates(all_states[: (12 * model.nb_segments), :])) - prr.rerun() - if __name__ == "__main__": # main("hanged", show_results=True) diff --git a/pyproject.toml b/pyproject.toml index 0709e30e..f008ac53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,20 +20,31 @@ classifiers = [ "Operating System :: OS Independent", ] dependencies = [ - - numpy - - packaging + "numpy", + "packaging", # "ezc3d", # Not yet available on pypi, use `conda install -c conda-forge ezc3d` - - plotly - - pyorerun - - python >=3.9 - - casadi - - dill - - mesa-libgl-devel-cos7-x86_64 - - pyomeca - - numba + "plotly", + "pyorerun", + "python >=3.9", + "casadi", + "dill", + "mesa-libgl-devel-cos7-x86_64", + "pyomeca", + "numba", # "biorbd" # Not yet available on pypi, use `conda install -c conda-forge biorbd` - ] -keywords = ["inverse-kinematics", "biomechanics", "multibody-dynamics", "mechanics motion-analysis", "kinesiology", "inverse-dynamics, "cartesian-coordinates", "forward-dynamics", "holonomic-constraints", "natural-coordinates"] - +] +keywords = [ + "inverse-kinematics", + "biomechanics", + "multibody-dynamics", + "mechanics", + "motion-analysis", + "kinesiology", + "inverse-dynamics", + "cartesian-coordinates", + "forward-dynamics", + "holonomic-constraints", + "natural-coordinates" +] [project.urls] homepage = "http://github.com/Ipuch/bionc"