-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcreate_a_population_of_models.py
More file actions
168 lines (150 loc) · 5.31 KB
/
Copy pathcreate_a_population_of_models.py
File metadata and controls
168 lines (150 loc) · 5.31 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""
This example shows how to create a batch of De Leva models within a range of anthropometry.
This could be useful if you want for example assess the impact of anthropometry on a movement.
Here, we want to create a population of female gymnasts performing acrobatics on the bars. Thus, the kinematic chain
will also be modified to place the root segment at the hands.
"""
import os
import numpy as np
import itertools
from biobuddy import (
Axis,
BiomechanicalModel,
C3dData,
Marker,
Mesh,
Segment,
SegmentCoordinateSystem,
Translations,
Rotations,
DeLevaTable,
Sex,
SegmentName,
ViewAs,
SegmentCoordinateSystemUtils,
RotoTransMatrix,
MergeSegmentsTool,
SegmentMerge,
ModifyKinematicChainTool,
ChangeFirstSegment,
)
def create_hand_root_model(
this_height,
this_ankle_height,
this_knee_height,
this_hip_height,
this_shoulder_height,
this_finger_span,
this_wrist_span,
this_elbow_span,
this_shoulder_span,
this_hip_width,
this_foot_length,
this_mass,
):
# Create the inertial table for this model
inertia_table = DeLevaTable(this_mass, sex=Sex.FEMALE)
inertia_table.from_measurements(
total_height=this_height,
ankle_height=this_ankle_height,
knee_height=this_knee_height,
hip_height=this_hip_height,
shoulder_height=this_shoulder_height,
finger_span=this_finger_span,
wrist_span=this_wrist_span,
elbow_span=this_elbow_span,
shoulder_span=this_shoulder_span,
hip_width=this_hip_width,
foot_length=this_foot_length,
)
# Create the model
real_model = inertia_table.to_simple_model()
# real_model.animate()
# Modify the model to merge both arms together
merge_tool = MergeSegmentsTool(real_model)
merge_tool.add(SegmentMerge(name="UPPER_ARMS", first_segment_name="L_UPPER_ARM", second_segment_name="R_UPPER_ARM"))
merge_tool.add(SegmentMerge(name="LOWER_ARMS", first_segment_name="L_LOWER_ARM", second_segment_name="R_LOWER_ARM"))
merge_tool.add(SegmentMerge(name="HANDS", first_segment_name="L_HAND", second_segment_name="R_HAND"))
merged_model = merge_tool.merge()
# merged_model.animate()
# Modify the model to place the root segment at the hands
kinematic_chain_modifier = ModifyKinematicChainTool(merged_model)
kinematic_chain_modifier.add(ChangeFirstSegment(first_segment_name="HANDS", new_segment_name="PELVIS"))
hand_root_model = kinematic_chain_modifier.modify()
# hand_root_model.animate()
return hand_root_model
def main():
# Set the range of anthropometry that you want to create
# TODO: set these as -std, -1/2std, mean, +1/2std, +std
total_mass = [50, 60, 70, 80] # Kg
total_height = [1.50, 1.70, 1.90] # m
ankle_height = [0.01] # m
knee_height_coeff = [0.23, 0.25, 0.27]
hip_height_coeff = [0.48, 0.49, 0.51]
shoulder_height_coeff = [0.78, 0.80, 0.82]
shoulder_width_coeff = [0.30, 0.32, 0.34]
elbow_span_coeff = [0.63, 0.65, 0.67]
wrist_span_coeff = [0.80, 0.82, 0.84]
finger_span_coeff = [1.0, 1.02, 1.04]
foot_length_coeff = [0.3, 0.32, 0.34]
hip_width_coeff = [0.30, 0.32, 0.34]
# Create all combinations using itertools.product
model_number = 0
for combination in itertools.product(
total_mass,
total_height,
ankle_height,
knee_height_coeff,
hip_height_coeff,
shoulder_height_coeff,
shoulder_width_coeff,
elbow_span_coeff,
wrist_span_coeff,
finger_span_coeff,
foot_length_coeff,
hip_width_coeff,
):
(
this_mass,
this_height,
this_ankle_height_coeff,
this_knee_height_coeff,
this_hip_height_coeff,
this_shoulder_height_coeff,
this_shoulder_span_coeff,
this_elbow_span_coeff,
this_wrist_span_coeff,
this_finger_span_coeff,
this_foot_length_coeff,
this_hip_width_coeff,
) = combination
# Get the measurements for this model
this_ankle_height = this_ankle_height_coeff * this_height
this_knee_height = this_knee_height_coeff * this_height
this_hip_height = this_hip_height_coeff * this_height
this_shoulder_height = this_shoulder_height_coeff * this_height
this_shoulder_span = this_shoulder_span_coeff * this_height
this_elbow_span = this_elbow_span_coeff * this_height
this_wrist_span = this_wrist_span_coeff * this_height
this_finger_span = this_finger_span_coeff * this_height
this_foot_length = this_foot_length_coeff * this_height
this_hip_width = this_hip_width_coeff * this_height
hand_root_model = create_hand_root_model(
this_height,
this_ankle_height,
this_knee_height,
this_hip_height,
this_shoulder_height,
this_finger_span,
this_wrist_span,
this_elbow_span,
this_shoulder_span,
this_hip_width,
this_foot_length,
this_mass,
)
# Exporting the output model as a biomod file
hand_root_model.to_biomod(f"population_model_{model_number}.bioMod")
model_number += 1
if __name__ == "__main__":
main()