|
a |
|
b/MATLAB/private/getCurrentMusclePathAsMat.m |
|
|
1 |
%-------------------------------------------------------------------------% |
|
|
2 |
% Copyright (c) 2019 Modenese L. % |
|
|
3 |
% % |
|
|
4 |
% Licensed under the Apache License, Version 2.0 (the "License"); % |
|
|
5 |
% you may not use this file except in compliance with the License. % |
|
|
6 |
% You may obtain a copy of the License at % |
|
|
7 |
% http://www.apache.org/licenses/LICENSE-2.0. % |
|
|
8 |
% % |
|
|
9 |
% Unless required by applicable law or agreed to in writing, software % |
|
|
10 |
% distributed under the License is distributed on an "AS IS" BASIS, % |
|
|
11 |
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or % |
|
|
12 |
% implied. See the License for the specific language governing % |
|
|
13 |
% permissions and limitations under the License. % |
|
|
14 |
% % |
|
|
15 |
% Author: Luca Modenese, 2017 % |
|
|
16 |
% email: l.modenese@imperial.ac.uk % |
|
|
17 |
% ----------------------------------------------------------------------- % |
|
|
18 |
% Given a state, this script collects info about the path of a muscle. |
|
|
19 |
% Bodies of muscle attachments and point coordinates are made available as |
|
|
20 |
% a list and a matrix respectively. |
|
|
21 |
% |
|
|
22 |
% INPUTS: |
|
|
23 |
% - osimMuscle: an OpenSim model (API object). |
|
|
24 |
% - s: state, used to update the current muscle path and get |
|
|
25 |
% active conditional viapoints. |
|
|
26 |
% |
|
|
27 |
% OUTPUTS: |
|
|
28 |
% - mus_bodyset_list: matrix where each row is a muscle point and |
|
|
29 |
% columns are its [X Y Z] coordinates in the reference system of |
|
|
30 |
% the body they belong to (as in .osim file). |
|
|
31 |
% - mus_pointset_mat: cell array of body names, same length as |
|
|
32 |
% the PathPointSet, with the name of the Body for each point. |
|
|
33 |
% |
|
|
34 |
% |
|
|
35 |
% last modified: |
|
|
36 |
% 2017: created. |
|
|
37 |
% 26 Jun 2018: comments (LM) |
|
|
38 |
% 29 Nov 2018: renamed, recommented, modified, added to MFD Matlab version. |
|
|
39 |
% ----------------------------------------------------------------------- % |
|
|
40 |
function [mus_bodyset_list, mus_pointset_mat] = getCurrentMusclePathAsMat(osimMuscle, s) |
|
|
41 |
|
|
|
42 |
% load libraries |
|
|
43 |
import org.opensim.modeling.*; |
|
|
44 |
|
|
|
45 |
% get pathpointset |
|
|
46 |
curr_PathPointSet = osimMuscle.getGeometryPath.getPathPointSet(); |
|
|
47 |
|
|
|
48 |
n_pp = 1; |
|
|
49 |
for n_p = 0:curr_PathPointSet.getSize-1 |
|
|
50 |
|
|
|
51 |
% point under examination |
|
|
52 |
curr_point = curr_PathPointSet.get(n_p); |
|
|
53 |
attachBody = curr_point.getBodyName(); |
|
|
54 |
|
|
|
55 |
% if pathpoint is conditional, then check if it is active |
|
|
56 |
if strcmp(char(curr_point.getConcreteClassName), 'ConditionalPathPoint') |
|
|
57 |
cond_viapoint = ConditionalPathPoint.safeDownCast(curr_point); |
|
|
58 |
% is it active? |
|
|
59 |
if cond_viapoint.isActive(s) |
|
|
60 |
% if yes add it to point set |
|
|
61 |
mus_pointset_mat(n_pp, 1:3) = [curr_point.getLocation.get(0), curr_point.getLocation.get(1), curr_point.getLocation.get(2)]; %#ok<*AGROW> |
|
|
62 |
mus_bodyset_list(n_pp) = {char(attachBody)}; |
|
|
63 |
n_pp = n_pp+1; |
|
|
64 |
else |
|
|
65 |
continue |
|
|
66 |
end |
|
|
67 |
else |
|
|
68 |
% if not conditional add it |
|
|
69 |
mus_pointset_mat(n_pp, 1:3) = [curr_point.getLocation.get(0), curr_point.getLocation.get(1), curr_point.getLocation.get(2)]; |
|
|
70 |
mus_bodyset_list(n_pp) = {char(attachBody)}; |
|
|
71 |
n_pp = n_pp+1; |
|
|
72 |
end |
|
|
73 |
end |
|
|
74 |
|
|
|
75 |
end |