forked from pyomeca/pyorerun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavailable_interfaces.py
More file actions
76 lines (63 loc) · 2.83 KB
/
available_interfaces.py
File metadata and controls
76 lines (63 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from .abstract_model_interface import AbstractModel, AbstractModelNoMesh
from ..model_components.model_display_options import DisplayModelOptions
AVAILABLE_INTERFACES = {}
# Biorbd
try:
from .biorbd_model_interface import BiorbdModelNoMesh, BiorbdModel
AVAILABLE_INTERFACES["biorbd"] = (BiorbdModel, BiorbdModelNoMesh)
except ImportError:
# biorbd is not installed, these classes will not be available
pass
try:
from .osim_model_interface import OsimModelNoMesh, OsimModel
AVAILABLE_INTERFACES["opensim"] = (OsimModel, OsimModelNoMesh)
except ImportError:
# OpenSim n'est pas installé, ces classes ne seront pas disponibles
pass
try:
from .pinocchio_model_interface import PinocchioModelNoMesh, PinocchioModel
AVAILABLE_INTERFACES["pinocchio"] = (PinocchioModel, PinocchioModelNoMesh)
except ImportError:
# Pinocchio is not installed, these classes will not be available
pass
def model_from_file(model_path: str, options: DisplayModelOptions = None) -> tuple[AbstractModel, AbstractModelNoMesh]:
"""
Create a model interface based on the provided model path.
Parameters
----------
model_path : str
Path to the model file (either .osim or .bioMod).
options : dict, optional
Options for the model interface.
Returns
-------
tuple[AbstractModel, AbstractModelNoMesh]
A tuple containing the model interface and a no-mesh instance of the model.
"""
if model_path.endswith(".osim"):
if "opensim" not in AVAILABLE_INTERFACES:
raise ImportError(
f"OpenSim is not installed. Please install it to use OpenSim models."
f"Use: conda install opensim-org::opensim"
)
model = AVAILABLE_INTERFACES["opensim"][0](model_path, options=options)
no_instance_mesh = AVAILABLE_INTERFACES["opensim"][1]
elif model_path.endswith(".bioMod"):
if "biorbd" not in AVAILABLE_INTERFACES:
raise ImportError(
f"biorbd is not installed. Please install it to use biorbd models."
f"Use: conda install -c conda-forge biorbd"
)
model = AVAILABLE_INTERFACES["biorbd"][0](model_path, options=options)
no_instance_mesh = AVAILABLE_INTERFACES["biorbd"][1]
elif model_path.endswith(".urdf"):
if "pinocchio" not in AVAILABLE_INTERFACES:
raise ImportError(
f"Pinocchio is not installed. Please install it to use URDF models."
f"Use: pip install pin (or conda install pinocchio)"
)
model = AVAILABLE_INTERFACES["pinocchio"][0](model_path, options=options)
no_instance_mesh = AVAILABLE_INTERFACES["pinocchio"][1]
else:
raise ValueError("The model must be in biorbd (.bioMod), opensim (.osim), or pinocchio (.urdf) format.")
return model, no_instance_mesh