Scale Factors not reflecting- Matlab Scaling

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mritula Chandrasekaran
Posts: 94
Joined: Tue Dec 19, 2017 5:36 am

Scale Factors not reflecting- Matlab Scaling

Post by Mritula Chandrasekaran » Mon Jun 08, 2020 5:02 pm

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>

Tags:

User avatar
Ayman Habib
Posts: 2252
Joined: Fri Apr 01, 2005 12:24 pm

Re: Scale Factors not reflecting- Matlab Scaling

Post by Ayman Habib » Mon Jun 08, 2020 7:42 pm

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

User avatar
Mritula Chandrasekaran
Posts: 94
Joined: Tue Dec 19, 2017 5:36 am

Re: Scale Factors not reflecting- Matlab Scaling

Post by Mritula Chandrasekaran » Mon Jun 08, 2020 11:40 pm

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
Attachments
Models_Osim.zip
(25.93 KiB) Downloaded 109 times

User avatar
Maud Hendriksen
Posts: 20
Joined: Thu May 14, 2020 12:00 am

Re: Scale Factors not reflecting- Matlab Scaling

Post by Maud Hendriksen » Wed Jul 15, 2020 3:34 am

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

User avatar
Mritula Chandrasekaran
Posts: 94
Joined: Tue Dec 19, 2017 5:36 am

Re: Scale Factors not reflecting- Matlab Scaling

Post by Mritula Chandrasekaran » Tue Jul 21, 2020 3:32 pm

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

User avatar
Jordan Sturdy
Posts: 9
Joined: Fri Sep 22, 2017 8:56 am

Re: Scale Factors not reflecting- Matlab Scaling

Post by Jordan Sturdy » Thu Jul 23, 2020 10:19 am

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

User avatar
Mritula Chandrasekaran
Posts: 94
Joined: Tue Dec 19, 2017 5:36 am

Re: Scale Factors not reflecting- Matlab Scaling

Post by Mritula Chandrasekaran » Thu Jul 23, 2020 1:02 pm

Thanks Jordan. Will try and update you.

Thanks
Mritula

POST REPLY