[76e9f4]: / tool_funcs / applyTorsionToMarkers.m

Download this file

71 lines (53 with data), 2.7 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
%-------------------------------------------------------------------------%
% Copyright (c) 2021 Modenese L. %
% Author: Luca Modenese, 2021 %
% email: l.modenese@imperial.ac.uk %
% ----------------------------------------------------------------------- %
function osimModel = applyTorsionToMarkers(osimModel, aSegmentName, aTorsionAxisString, torsion_angle_func_rad)
import org.opensim.modeling.*
% check if segment is included in the model
if osimModel.getBodySet().getIndex(aSegmentName)<0
error('The specified segment is not included in the OpenSim model')
end
disp('-------------------');
disp(' ADJUSTING MARKERS ');
disp('-------------------');
% converting the axis in the index used later
[RotMat, axis_ind] = getAxisRotMat(aTorsionAxisString);
% extracting MarkerSet
markers = osimModel.getMarkerSet();
N_markers = markers.getSize();
% loop through the muscles
for n_marker = 0:N_markers-1
% current muscles
curr_marker = markers.get(n_marker);
% Body attached to each point of the PathPointSet
if getOpenSimVersion()<4.0 %OpenSim 3.3
attachBodyName = char(curr_marker.getBodyName());
else %OpenSim 4.x
attachBodyName = char(curr_marker.getParentFrame().getName());
end
if strcmp(attachBodyName, aSegmentName)
disp(['processing ', char(curr_marker.getName())]);
% point coordinates
if getOpenSimVersion()<4.0 %OpenSim 3.3
markerLocVec3 = curr_marker.getOffset();
else %OpenSim 4.x
markerLocVec3 = curr_marker.get_location();
end
% convert to Matlab var
markerLocCoords = [markerLocVec3.get(0),markerLocVec3.get(1),markerLocVec3.get(2)];
% compute torsion metric for the attachment point
TorsRotMat = RotMat(torsion_angle_func_rad(markerLocCoords(axis_ind)));
% compute new muscle attachment coordinates
new_markerLocCoords = (TorsRotMat*markerLocCoords')';%musCoord * M'
% transform to MATLAB vector
newOffset = Vec3(new_markerLocCoords(1), new_markerLocCoords(2), new_markerLocCoords(3));
% setting the torsioned marker offset
if getOpenSimVersion()<4.0 %OpenSim 3.3
curr_marker.setOffset(newOffset);
else %OpenSim 4.x
curr_marker.set_location(newOffset);
end
end
end