Page 1 of 1

Scale Factors not reflecting- Matlab Scaling

Posted: Mon Jun 08, 2020 5:02 pm
by mritula
Hi,
I am trying to add scale factors to ScaleSetup.xml file through Matlab scripting as below for scaled.osim file.
1. The program executes without error but the scale factors doesn't appear to be utilized. Kindly let me know what could be the error.
2, Kindly confirm me if Im looking at the appropriate value for ScaleFactors

Thanks,
Mritula

Code: Select all

%Scaling in Matlab without write xml
import org.opensim.modeling.*;

%% Include all geometry files
path='C:\OpenSim4pt1\Geometry';
ModelVisualizer.addDirToGeometrySearchPaths(path);
 
%% 
subjectMass=100;
model = Model('D:\Gait_Recognition_Mritula\Public_Dataset\WIP\Scaling\ExecuteMatlabBatchScaling\Models\LOWER_EXTRE_MODIFIED_MRITULA2705.osim');

%% add markers to model
% set = MarkerSet(model,'D:\Gait_Recognition_Mritula\Public_Dataset\WIP\Scaling\ExecuteMatlabBatchScaling\ScaleSetup\gait2392_MarkerSet_forscalingOpensim4.xml');
% model.updMarkerSet().assign(set);

%%adding Scale Factors for segments
segNames = {'pelvis','femur_r','tibia_r','talus_r','calcn_r','toes_r',...
        'femur_l','tibia_l','talus_l','calcn_l','toes_l'};
    
newScaleSet = ScaleSet();
s=[2,2,2];
vec = osimVec3FromArray(s)

for i = 1:length(segNames)
    segScale(i) = Scale();
    segScale(i).setSegmentName(segNames{i});
    segScale(i).getScaleFactors(vec);         %scaleFactor as input- eg[1.1 1.1 1.1]  
    segScale(i).setScaleFactors(vec); 
    segScale(i).setApply(true);
    newScaleSet.cloneAndAppend(segScale(i));
end

% scale the model
state = model.initSystem;
model.scale(state,newScaleSet, subjectMass, true);

model.setName('Scaled_Model2');
model.initSystem();
model.print(['ScaledModel2.osim']);

No change in the below section before and after Scale execution
<FrameGeometry name="frame_geometry">
<!--Path to a Component that satisfies the Socket 'frame' of type Frame.-->
<socket_frame>..</socket_frame>
<!--Scale factors in X, Y, Z directions respectively.-->
-------->> <scale_factors>0.20000000000000001 0.20000000000000001 0.20000000000000001</scale_factors>
</FrameGeometry>

Re: Scale Factors not reflecting- Matlab Scaling

Posted: Mon Jun 08, 2020 7:42 pm
by aymanh
Hello,

The scale factors you pointed to are just for the visualization of FrameGeometry and accordingly are fixed so are unrelated to actual scale of model/bodies. Scale factors should be applied to meshes, attachment points, and inertial properties etc.

Hope this helps,
-Ayman

Re: Scale Factors not reflecting- Matlab Scaling

Posted: Mon Jun 08, 2020 11:40 pm
by mritula
Hi Ayman,
How to programmatically supply the Body Applied Scale Factor (from Scale Factors tab) in Scale Tool. Can you kindly help me out with the syntax to do it.

Thanks
Mritula

Re: Scale Factors not reflecting- Matlab Scaling

Posted: Wed Jul 15, 2020 3:34 am
by mchendriksen
Hi Mritula,

Did you find out how to programatically include the scale factors during scaling the model?
I am trying this right now and hope you have found the way to do it.

Regards,

Maud

Re: Scale Factors not reflecting- Matlab Scaling

Posted: Tue Jul 21, 2020 3:32 pm
by mritula
Hi Maud,
Not yet, I am still trying. I am using XML write to modify scalefactors accordingly in the scalesetup file as of now.

Thanks,
Mritula

Re: Scale Factors not reflecting- Matlab Scaling

Posted: Thu Jul 23, 2020 10:19 am
by j_sturdy
Hi Mritula,
I've done something like you are trying using 3.3 through Matlab. Comparing to the code you posted, I believe you have one extra line in the for loop causing your problem.

Code: Select all

segScale(i).getScaleFactors(vec);         %scaleFactor as input- eg[1.1 1.1 1.1]  
This line is reading the default values in the scale factor and inserting them into "vec", thus overwriting any value you have set previously. If you remove this line, I think your scaling should work properly. You can write the scale set to an xml file to check that it is updating similar to the following.

Code: Select all

newScaleSet.print("testScaleSet.xml")

Best,
Jordan

Re: Scale Factors not reflecting- Matlab Scaling

Posted: Thu Jul 23, 2020 1:02 pm
by mritula
Thanks Jordan. Will try and update you.

Thanks
Mritula