Skip to content

Commit 7a133ee

Browse files
authored
Merge branch 'master' into v40
2 parents 60d0e39 + 41ebd8c commit 7a133ee

17 files changed

Lines changed: 1311 additions & 72 deletions

MATLAB/matlab_tool_v4.0/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.log
2+
*.asv
Binary file not shown.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
%-------------------------------------------------------------------------%
2+
% Copyright (c) 2019 Modenese L. %
3+
% Author: Luca Modenese %
4+
% email: l.modenese@imperial.ac.uk %
5+
% ----------------------------------------------------------------------- %
6+
% Load Library
7+
import org.opensim.modeling.*;
8+
9+
% verification
10+
osimModel_name = '../_test_data/MFD_tests/testModel.osim';
11+
IK_mot_file = '../_test_data/MFD_tests/testKinematics_file.mot';
12+
results_directory = '../_test_data/MFD_tests';
13+
bodyOfInterest_name = 'MovingBody';
14+
bodyExpressResultsIn_name = [];
15+
effective_attachm = 'false';
16+
print_attachm = 'true';
17+
vis_on = 'true';
18+
N_frame_test = 5;
19+
20+
% validated_results_folder = '../_test_data/MFD_tests/validated_res';
21+
22+
res_anatAttach_local = getMuscleForceDirection(osimModel_name,...
23+
IK_mot_file,...
24+
results_directory,...
25+
bodyOfInterest_name,...
26+
bodyExpressResultsIn_name,...
27+
effective_attachm,...
28+
print_attachm,...
29+
vis_on,...
30+
N_frame_test);
31+
32+
% res_effectAttach_local = getMuscleForceDirection(osimModel_name,...
33+
% IK_mot_file,...
34+
% results_directory,...
35+
% bodyOfInterest_name,...
36+
% bodyExpressResultsIn_name,...
37+
% 'true',...
38+
% print_attachm,...
39+
% vis_on,...
40+
% []);
41+
%
42+
% res_effectAttach_ground = getMuscleForceDirection(osimModel_name,...
43+
% IK_mot_file,...
44+
% results_directory,...
45+
% bodyOfInterest_name,...
46+
% 'ground',...
47+
% 'true',...
48+
% print_attachm,...
49+
% vis_on,...
50+
% []);
51+
%
52+
% res_anatAttach_ground = getMuscleForceDirection(osimModel_name,...
53+
% IK_mot_file,...
54+
% results_directory,...
55+
% bodyOfInterest_name,...
56+
% 'ground',...
57+
% 'false',...
58+
% print_attachm,...
59+
% vis_on,...
60+
% []);
61+
62+
63+
% res_anatAttach_local
64+
% res_anatAttach_ground
65+
% res_effectAttach_ground
66+
% res_effectAttach_local
67+
%
68+
% res_anatAttach_local_val = sto2Mat(fullfile(validated_results_folder,'LOCAL_ANATOM_MuscleForceDirection_vectors.sto'));
69+
%
70+
% res_anatAttach_ground.rowheaders
71+
% res_effectAttach_ground
72+
% res_effectAttach_local
73+
%--------------------------------------------------------------------------
74+
% %% test 1: simple arm26 model
75+
% osimModel_name = '../_test_data/Arm26/arm26.osim';
76+
% IK_mot_file = '../_test_data/Arm26/elbow_flexion.mot';
77+
% results_directory = '../_test_data/Arm26';
78+
% bodyOfInterest_name = 'r_humerus';
79+
% bodyExpressResultsIn_name = [];
80+
% effective_attachm = 'true';
81+
% print_attachm = 'true';
82+
% vis_on = 'true';
83+
% N_frame_test = 5;
84+
%
85+
% muscleLinesOfActionStruct = getMuscleForceDirection(osimModel_name,...
86+
% IK_mot_file,...
87+
% results_directory,...
88+
% bodyOfInterest_name,...
89+
% bodyExpressResultsIn_name,...
90+
% effective_attachm,...
91+
% print_attachm,...
92+
% vis_on,...
93+
% N_frame_test);
94+
%
95+
%
96+
%--------------------------------------------------------------------------
97+
%% test 2: gait2392 model
98+
osimModel_name = '../_test_data/gait2392/subject01.osim';
99+
IK_mot_file = '../_test_data/gait2392/subject01_walk1_ik.mot';
100+
results_directory = '../_test_data/gait2392';
101+
bodyOfInterest_name = 'femur_r';
102+
bodyExpressResultsIn_name = [];
103+
effective_attachm = 'true';
104+
print_attachm = 'true';
105+
vis_on = 'true';
106+
N_frame_test = 5;
107+
108+
muscleLinesOfActionStruct = getMuscleForceDirection(osimModel_name,...
109+
IK_mot_file,...
110+
results_directory,...
111+
bodyOfInterest_name,...
112+
bodyExpressResultsIn_name,...
113+
effective_attachm,...
114+
print_attachm,...
115+
vis_on,...
116+
N_frame_test);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
%-------------------------------------------------------------------------%
2+
% Copyright (c) 2019 Modenese L. %
3+
% Author: Luca Modenese %
4+
% email: l.modenese@imperial.ac.uk %
5+
% ----------------------------------------------------------------------- %
6+
7+
clear;clc
8+
import org.opensim.modeling.*
9+
10+
% TO DO: add the possibility of following states
11+
%%%%%%%%%%%%% SET UP %%%%%%%%%%%%%%%%%%%%%%%%%%%%
12+
% General model
13+
ModelFile = 'arm26.osim';
14+
% read model
15+
osimModel = Model(ModelFile);
16+
muscles = osimModel.getMuscles();
17+
aOsimMuscleNameSet = 'all';%{'BRA'};
18+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19+
20+
21+
% setting which muscles will be followed
22+
muscleNames = ArrayStr;
23+
if strcmp(aOsimMuscleNameSet,'all')
24+
% getmuscles
25+
muscles.getNames(muscleNames);
26+
else
27+
% assign given muscle names to the set to be analyzed
28+
for n_mn = 1:length( aOsimMuscleNameSet )
29+
muscleNames.append(aOsimMuscleNameSet{n_mn})
30+
end
31+
end
32+
33+
for n_mus = 0:muscleNames.getSize()-1
34+
35+
% current muscle
36+
curr_muscle = muscles.get(muscleNames.getitem(n_mus));
37+
38+
% EXTRACTING THE WRAPPING POINTS
39+
si = osimModel.initSystem();
40+
41+
% get the geometry path for the current state
42+
PathpointArray = curr_muscle.getGeometryPath().getCurrentPath(si);
43+
44+
% normal pathpoints attached to bodies
45+
ModelPathpoint = curr_muscle.getGeometryPath().getPathPointSet();
46+
47+
% check if there are wrapping points
48+
NrOfWrappingPoints = PathpointArray.getSize()-ModelPathpoint.getSize();
49+
50+
% header
51+
display(['Muscle ',char(curr_muscle.getName()), ' (',num2str(NrOfWrappingPoints),' wrapping points)']);
52+
53+
for n_p = 0:PathpointArray.getSize()-1
54+
55+
% get the coordinates of the current pathpoint
56+
curr_point_loc_OS = Vec3(PathpointArray.getitem(n_p).getLocation);
57+
curr_point_loc = [curr_point_loc_OS.get(0),curr_point_loc_OS.get(1),curr_point_loc_OS.get(2)];
58+
59+
% body where the body is attached to
60+
display(['Point ',num2str(n_p+1), ' attached to body ',char(PathpointArray.getitem(n_p).getBodyName())]);
61+
display([num2str(curr_point_loc_OS.get(0)),' ',num2str(curr_point_loc_OS.get(1)),' ',num2str(curr_point_loc_OS.get(2))])
62+
63+
end
64+
display('-----------------------------------');
65+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function Body = getBodyorGround(osimModel,BodyName)
2+
%-------------------------------------------------------------------------%
3+
% getBodyorGround gets a Body or Ground by name from an OpenSim model %
4+
% (version 4.0 and up). %
5+
% %
6+
% INPUTS: %
7+
% - osimModel: the OpenSim model object. %
8+
% - BodyName: name pf body to get, a character string. %
9+
% %
10+
% OUTPUTS: %
11+
% - Body: target PhysicalFrame object, either a Body or Ground. %
12+
% %
13+
% code edition log: %
14+
% 18 Sep 2019: created for OpenSim 4.0 model Body/Ground format (KS). %
15+
% ----------------------------------------------------------------------- %
16+
% Author: Ke Song (Washington University in St. Louis) %
17+
% E-mail: ksong23@wustl.edu %
18+
% ----------------------------------------------------------------------- %
19+
20+
% load Library
21+
import org.opensim.modeling.*;
22+
23+
% get name of Ground in model
24+
osimGroundName = char(osimModel.getGround.getName());
25+
26+
% get Ground or Body based on name
27+
if strcmp(BodyName,osimGroundName)
28+
Body = osimModel.getGround(); %Ground
29+
else
30+
Body = osimModel.getBodySet.get(BodyName);
31+
end
32+
33+
end
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
% 18 Sep 2019: using getCurrentPath to recognize wrap points (KS).
40+
% ----------------------------------------------------------------------- %
41+
function [mus_bodyset_list, mus_pointset_mat] = getCurrentMusclePathAsMat(osimMuscle, s)
42+
43+
% load libraries
44+
import org.opensim.modeling.*;
45+
46+
% get geometry path point array (including wrap points) for current state
47+
curr_PathPointSet = osimMuscle.getGeometryPath().getCurrentPath(s);
48+
49+
n_pp = 1;
50+
for n_p = 0:curr_PathPointSet.getSize-1
51+
52+
% point under examination
53+
curr_point = curr_PathPointSet.get(n_p);
54+
attachBody = curr_point.getBodyName();
55+
56+
% if pathpoint is conditional, then check if it is active
57+
if strcmp(char(curr_point.getConcreteClassName), 'ConditionalPathPoint')
58+
cond_viapoint = ConditionalPathPoint.safeDownCast(curr_point);
59+
% is it active?
60+
if cond_viapoint.isActive(s)
61+
% if yes add it to point set
62+
mus_pointset_mat(n_pp, 1:3) = [curr_point.getLocation(s).get(0), curr_point.getLocation(s).get(1), curr_point.getLocation(s).get(2)]; %#ok<*AGROW>
63+
mus_bodyset_list(n_pp) = {char(attachBody)};
64+
n_pp = n_pp+1;
65+
else
66+
continue
67+
end
68+
else
69+
% if not conditional add it
70+
mus_pointset_mat(n_pp, 1:3) = [curr_point.getLocation(s).get(0), curr_point.getLocation(s).get(1), curr_point.getLocation(s).get(2)];
71+
mus_bodyset_list(n_pp) = {char(attachBody)};
72+
n_pp = n_pp+1;
73+
end
74+
end
75+
76+
end
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 %
16+
% email: l.modenese@imperial.ac.uk %
17+
% ----------------------------------------------------------------------- %
18+
%
19+
% Function that allows to retrieve the value of a specified variable whose
20+
% name is specified in var_name.
21+
%
22+
% INPUTS
23+
% struct: is a structure with fields 'colheaders', the headers, and 'data'
24+
% that is a matrix of data.
25+
% var_name: the name of the variable to extract.
26+
%
27+
% OUTPUTS
28+
% var_value: the column of the matrix correspondent to the header specified
29+
% in input as var_name.
30+
%
31+
%
32+
% written: Luca Modenese, July 2014
33+
% last modified:
34+
% Header (February 2018, LM)
35+
% 29 Nov 2018: renamed, recommented, added to MFD Matlab version (LM).
36+
% ----------------------------------------------------------------------- %
37+
function var_value = getMatStructColumn(struct, var_name)
38+
39+
% gets the index of the desired variable name in the colheaders of the
40+
% structure from where it will be extracted
41+
var_index = strncmp(struct.colheaders, var_name, length(var_name));
42+
43+
if sum(var_index) == 0
44+
%error(['getValueColumnForHeader.m','. No header in structure is matching the name ''',var_name,'''.'])
45+
display(['getValueColumnForHeader.m','. No header in structure is matching the name ''',var_name,''''])
46+
var_value = [];
47+
return
48+
end
49+
50+
% uses the index to retrieve the column of values for that variable.
51+
var_value = struct.data(:,var_index);
52+
53+
end

0 commit comments

Comments
 (0)