% This function is part of the NMSM Pipeline, see file for full license.
%
% This function converts the muscles portion of a parsed .osimx file
% into a new .osimx struct to be printed with writeOsimxFile(). See
% buildOsimxFromOsimxStruct() for reference.
%
% (struct, struct) -> (struct)
% Adds muscles to .osimxStruct
function osimx = buildRcnlMuscle(osimx, muscleName, muscleParameters)
muscleObjects = osimx.NMSMPipelineDocument.OsimxModel.RCNLMuscleSet;
if(~isstruct(muscleObjects))
i = 1;
muscleObjects.RCNLMuscle = {};
else
i = length(muscleObjects.RCNLMuscle) + 1;
end
muscles = muscleObjects.RCNLMuscle;
muscles{i}.Attributes.name = convertStringsToChars(muscleName);
if isfield(muscleParameters, 'electromechanicalDelay')
muscles{i}.electromechanical_delay.Comment = 'Optimized electromechanical delay';
muscles{i}.electromechanical_delay.Text = convertStringsToChars( ...
num2str(muscleParameters.electromechanicalDelay, 15));
end
if isfield(muscleParameters, 'activationTimeConstant')
muscles{i}.activation_time_constant.Comment = 'Optimized activation time constant';
muscles{i}.activation_time_constant.Text = convertStringsToChars( ...
num2str(muscleParameters.activationTimeConstant, 15));
end
if isfield(muscleParameters, 'activationNonlinearityConstant')
muscles{i}.activation_nonlinearity_constant.Comment = 'Optimized activation nonlinearity constant';
muscles{i}.activation_nonlinearity_constant.Text = convertStringsToChars( ...
num2str(muscleParameters.activationNonlinearityConstant, 15));
end
if isfield(muscleParameters, 'emgScaleFactor')
muscles{i}.emg_scale_factor.Comment = 'Optimized EMG scale factor';
muscles{i}.emg_scale_factor.Text = convertStringsToChars( ...
num2str(muscleParameters.emgScaleFactor, 15));
end
if isfield(muscleParameters, 'optimalFiberLength')
muscles{i}.optimal_fiber_length.Comment = 'Optimized optimal fiber length';
muscles{i}.optimal_fiber_length.Text = convertStringsToChars( ...
num2str(muscleParameters.optimalFiberLength, 15));
end
if isfield(muscleParameters, 'tendonSlackLength')
muscles{i}.tendon_slack_length.Comment = 'Optimized tendon slack length';
muscles{i}.tendon_slack_length.Text = convertStringsToChars( ...
num2str(muscleParameters.tendonSlackLength, 15));
end
if isfield(muscleParameters, 'maxIsometricForce')
muscles{i}.max_isometric_force.Comment = 'Optimized max isometric force';
muscles{i}.max_isometric_force.Text = convertStringsToChars( ...
num2str(muscleParameters.maxIsometricForce, 15));
end
osimx.NMSMPipelineDocument.OsimxModel.RCNLMuscleSet.RCNLMuscle = muscles;
end