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

feat(factory from biorbd.Model) #14

Merged
merged 3 commits into from
Apr 4, 2024
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
31 changes: 31 additions & 0 deletions examples/biorbd/from_biorbd_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import biorbd
import numpy as np

from pyorerun import BiorbdModel, PhaseRerun


def main():
# building some time components
nb_frames = 50
nb_seconds = 1
t_span = np.linspace(0, nb_seconds, nb_frames)

biorbd_model = biorbd.Model("models/Wu_Shoulder_Model_kinova_scaled_adjusted_2.bioMod")
prr_model = BiorbdModel.from_biorbd_object(biorbd_model)

# building some generalized coordinates
q = np.zeros((biorbd_model.nbQ(), nb_frames))
q[10, :] = np.linspace(0, np.pi / 8, nb_frames)
q[12, :] = np.linspace(0, np.pi / 3, nb_frames)
q[11, :] = np.linspace(0, np.pi / 4, nb_frames)
q[13, :] = np.linspace(0, np.pi / 8, nb_frames)
q[14, :] = np.linspace(0, np.pi / 8, nb_frames)
q[15, :] = np.linspace(0, np.pi / 8, nb_frames)

viz = PhaseRerun(t_span)
viz.add_animated_model(prr_model, q)
viz.rerun("msk_model")


if __name__ == "__main__":
main()
8 changes: 6 additions & 2 deletions pyorerun/biorbd_components/model_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ class BiorbdModelNoMesh:
A class to handle a biorbd model and its transformations
"""

def __init__(self, path, options=None):
def __init__(self, path: str, options=None):
self.path = path
self.model = biorbd.Model(path)
self.options = options if options is not None else DisplayModelOptions()
self.options: DisplayModelOptions = options if options is not None else DisplayModelOptions()

@classmethod
def from_biorbd_object(cls, model: biorbd.Model, options=None):
return cls(model.path().absolutePath().to_string(), options)

@property
def name(self):
Expand Down
4 changes: 2 additions & 2 deletions pyorerun/biorbd_components/model_updapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def create_muscles_updater(self):
self.name,
properties=LineStripProperties(
strip_names=self.model.muscle_names,
color=np.array(self.model.options.muscle_color),
radius=self.model.options.muscle_radius,
color=np.array(self.model.options.muscles_color),
radius=self.model.options.muscles_radius,
),
update_callable=self.model.muscle_strips,
)
Expand Down