Skip to content

Commit 3c44753

Browse files
authored
Merge pull request #150 from ANaaim/add_full_kin_calculation
2 parents dc7c06e + f25e064 commit 3c44753

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

bionc/bionc_numpy/inverse_kinematics.py

+3
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ def sol(self):
547547
for ind_max in ind_max_joint_constraint_error
548548
]
549549

550+
total_euler_angles = TimeSeriesUtils.total_euler_angles(self.model, self.Qopt)
551+
550552
self.output = dict(
551553
objective_function=self.objective_function,
552554
success=self.success_optim,
@@ -558,6 +560,7 @@ def sol(self):
558560
segment_rigidity_residual_norm=segment_rigidity_residual_norm,
559561
total_rigidity_residuals=total_rigidity_residuals,
560562
max_rigidbody_violation=max_rigidbody_violation,
563+
total_euler_angles=total_euler_angles,
561564
)
562565

563566
if self.experimental_markers is not None:

bionc/bionc_numpy/time_series_utils.py

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ def marker_constraints_xyz(model, Q: np.ndarray, markers: np.ndarray):
6161
return marker_residuals_xyz
6262

6363

64+
def total_euler_angles(model, Q: np.ndarray):
65+
"""Compute Euler angle for all joint"""
66+
Qi_temp = NaturalCoordinates(Q[:, 0])
67+
euler_temp = model.natural_coordinates_to_joint_angles(Qi_temp)
68+
total_euler_angles = np.zeros((euler_temp.shape[0], euler_temp.shape[1], Q.shape[1]))
69+
70+
for ind_frame in range(Q.shape[1]):
71+
Qi = NaturalCoordinates(Q[:, ind_frame])
72+
total_euler_angles[:, :, ind_frame] = model.natural_coordinates_to_joint_angles(Qi)
73+
74+
return total_euler_angles
75+
76+
6477
class TimeSeriesUtils:
6578
"""
6679
This class contains utility functions to compute the constraints of a biomechanical model for
@@ -75,3 +88,4 @@ class TimeSeriesUtils:
7588
joint_constraints = joint_constraints
7689
total_marker_constraints = total_marker_constraints
7790
marker_constraints_xyz = marker_constraints_xyz
91+
total_euler_angles = total_euler_angles

tests/test_ultimate_inverse_kinematics_heatmap.py

+8
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def test_global_heatmap_ik():
240240
"segment_rigidity_residual_norm",
241241
"total_rigidity_residuals",
242242
"max_rigidbody_violation",
243+
"total_euler_angles",
243244
"total_heatmap_confidence",
244245
"heatmap_confidence_3d",
245246
"heatmap_confidence_2d",
@@ -268,6 +269,13 @@ def test_global_heatmap_ik():
268269
)
269270
np.testing.assert_almost_equal(solutions["heatmap_confidence_2d"], expected_heatmap_confidence_2d, decimal=1e-6)
270271

272+
expected_total_euler_angles = [
273+
[[1.25975366e00, 1.24523863e00], [1.49707656e00, 1.47663685e00]],
274+
[[-1.71958799e-01, -1.48109177e-01], [2.25847119e-13, 2.99721359e-12]],
275+
[[-6.95863809e-01, -7.44889927e-01], [-1.42358347e-12, 8.85611862e-11]],
276+
]
277+
np.testing.assert_almost_equal(solutions["total_euler_angles"], expected_total_euler_angles, decimal=1e-6)
278+
271279

272280
def test_error_Qinit_is_none():
273281
bionc = TestUtils.bionc_folder()

0 commit comments

Comments
 (0)