Skip to main content

adjustBodyScaling.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function scales the body then moves the markers back to their
% original location. This is useful for scaling the body without moving
% the markers.
%
% (Model, string, number) -> ()
% Adjust the scaling of the body without moving the attached markers


function adjustBodyScaling(model, bodyName, value)

markers = getMarkersFromBody(model, bodyName);
markerLocations = {};
for i = 1:length(markers)
markerLocations{i} = org.opensim.modeling.Vec3(model.getMarkerSet().get(markers{i}).get_location());
end

state = initializeState(model);

scaleSet = org.opensim.modeling.ScaleSet();
scale = org.opensim.modeling.Scale();
scale.setSegmentName(bodyName);
scale.setScaleFactors(org.opensim.modeling.Vec3(value / ...
getScalingParameterValue(model, bodyName)));
scale.setApply(true);
scaleSet.cloneAndAppend(scale);
model.scale(state, scaleSet, true, -1.0);

for i = 1:length(markers)
model.getMarkerSet().get(markers{i}).set_location(markerLocations{i});
end
end