a b/MATLAB/private/isKinMatchingModelCoords.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
function [out, missing_coords_list] = isKinMatchingModelCoords(osimModel, headers_in_struct)
19
20
% OpenSim suggested settings
21
import org.opensim.modeling.*
22
OpenSimObject.setDebugLevel(3);
23
24
% getting model coordinates and their number
25
coordsModel = osimModel.updCoordinateSet();
26
N_coordsModel = coordsModel.getSize();
27
28
% check if coordinates are the same (sometimes time is also here)
29
if any(strcmp('time', headers_in_struct))
30
    coordsNames_in_struct = headers_in_struct(~strcmp('time', headers_in_struct));
31
else
32
    coordsNames_in_struct = headers_in_struct;
33
end
34
n_miss = 1;
35
n_matched = 1;
36
coordNames = {};
37
missing_coords_list = {};
38
39
for n = 0:N_coordsModel-1
40
    %extracting the column for the state variable of interest
41
    cur_coordName =  char(coordsModel.get(n).getName());
42
    if find(strcmp(cur_coordName, coordsNames_in_struct)) == n+1
43
        coordNames{n_matched} = cur_coordName;
44
        n_matched = n_matched+1;
45
    else
46
        missing_coords_list{n_miss} = cur_coordName;
47
        n_miss = n_miss+1;
48
    end
49
end
50
51
if length(coordNames) == length(coordsNames_in_struct)
52
    out = 1;
53
    return
54
else
55
    warning('Coordinate structure and model are NOT properly matched (coordinates and their order).');
56
    out = 0;
57
    
58
end
59
60
end