% This function is part of the NMSM Pipeline, see file for full license.
%
% This function prints out the optimized muscle tendon parameters from
% Neural Control Personalization in an osimx file
%
% (string, 2D matrix, string) -> (None)
% Prints Neural Control Personalization results in osimx file
function writeNeuralControlPersonalizationOsimxFile(inputs, ...
resultsDirectory, precalInputs)
modelFileName = inputs.model;
model = Model(modelFileName);
buildFromExisting = false;
if isfield(inputs, 'osimxFileName')
if isfile(inputs.osimxFileName)
osimx = parseOsimxFile(inputs.osimxFileName);
[~, name, ~] = fileparts(inputs.osimxFileName);
outfile = fullfile(resultsDirectory, strcat(name, "_ncp.xml"));
buildFromExisting = true;
end
end
if ~buildFromExisting
% As only muscle parameters are included, the MtpOsimxTemplate can be
% reused
osimx = buildMtpOsimxTemplate(...
replace(model.getName().toCharArray',".","_dot_"), ...
modelFileName);
[~, name, ~] = fileparts(modelFileName);
outfile = fullfile(resultsDirectory, strcat(name, "_ncp.xml"));
end
osimx.modelName = name;
osimx.model = modelFileName;
if ~isfield(osimx, 'muscles')
osimx.muscles = [];
end
for i = 1:length(inputs.muscleTendonColumnNames)
if ~isfield(osimx.muscles, inputs.muscleTendonColumnNames(i))
osimx.muscles.(inputs.muscleTendonColumnNames(i)) = struct();
end
if ~isfield(osimx.muscles.(inputs.muscleTendonColumnNames(i)), "optimalFiberLength")
osimx.muscles.(inputs.muscleTendonColumnNames(i)) ...
.optimalFiberLength = inputs.optimalFiberLength(i);
end
if ~isfield(osimx.muscles.(inputs.muscleTendonColumnNames(i)), "tendonSlackLength")
osimx.muscles.(inputs.muscleTendonColumnNames(i)) ...
.tendonSlackLength = inputs.tendonSlackLength(i);
end
if precalInputs.optimizeIsometricMaxForce && ...
~isfield(osimx.muscles.(inputs.muscleTendonColumnNames(i)), "maxIsometricForce")
osimx.muscles.(inputs.muscleTendonColumnNames(i)) ...
.maxIsometricForce = inputs.maxIsometricForce(i);
end
end
writeOsimxFile(buildOsimxFromOsimxStruct(osimx), outfile)
end