a b/MATLAB/private/isMuscleConnectedToBody.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                                              %
16
%    email:    l.modenese@imperial.ac.uk                                  %
17
% ----------------------------------------------------------------------- %
18
% Script checking if an OpenSim muscle and a given body in an MSK model
19
% are connected, i.e. if the muscle path has at least one point attached 
20
% to that body.
21
% Note that:
22
% 1) osimMuscle is used to avoid passing in the model. That is the reason 
23
%    why function isBodyInModel was not used (requires model).
24
% 2) if a BodyName not belonging to the model if specified, flag will be 0.
25
%
26
% INPUTS:
27
%       -osimMuscle: a muscle from an OpenSim model (API object).
28
%       -osimBodyName: name of a body included in the OpenSim model.
29
%
30
% OUTPUT:
31
%       -flag: variable of value 1 or 0, depending if the muscle is
32
%       attached to the body (1) or not (0).
33
%
34
%
35
% written: 2014 (Griffith University)
36
% last modified: 
37
% 26 Jun 2017: comments (LM)
38
% 29 Nov 2018: renamed, recommented, added to MFD Matlab tool (LM).
39
% ----------------------------------------------------------------------- %
40
function flag = isMuscleConnectedToBody(osimMuscle, osimBodyName)
41
42
% initialise answ
43
flag = 0;
44
45
% check name
46
if isjava(osimBodyName)
47
    osimBodyName = char(osimBodyName);
48
end
49
50
% extract muscle pathpointset
51
muspathpointset = osimMuscle.getGeometryPath.getPathPointSet();
52
53
% looping through the pathpoints of a muscle to check if any of those is
54
% attached to the body of interest
55
for n_p = 0:muspathpointset.getSize-1
56
    % current attachment body of the muscle point
57
    curr_attach_body = char(muspathpointset.get(n_p).getBodyName);
58
    % check if this is the specified body
59
    if strcmp(curr_attach_body, osimBodyName)
60
        flag = 1;
61
        display(['Muscle ', char(osimMuscle.getName),' is attached to body ', osimBodyName]);
62
        return
63
    end
64
end
65
66
% give feedback also if muscle does not attached to specified body
67
if flag == 0
68
    display(['Muscle ', char(osimMuscle.getName),' does NOT attach to body ', char(osimBodyName)]);
69
end
70
71
end