Edit xml Scale File via MatLab
Posted: Fri Sep 18, 2020 4:06 am
Hi guys,
I am able to scale a Model by using the GUI of OpenSim. But, I would like to automate this process to implement it in a larger Matlab data processing pipeline.
Thus, if I understand clearly, the whole thing is about to create an .xml file like the one loaded when you perform scaling directly in the GUI.
So far, I have been able to create some of the items present in this .xml file (subject data, model and marker files, time range etc...). But I have trouble to express my MeasurementSet on which my scaling process will be based.
From the attached file Measurement.png, you can see an example of what I would like (for one Measurement) .
From the attached file Measurement_Test.png, you can see an example of what I get so far.
As you can see, I am not able to create my MeasurementSet.
Here is my entire code :
I mainly have a bug when I tempt to add the MarkerPairSet or the BodyScaleSet to Measurement. This error appears :
I do not know what is wrong, why the function works when I add MP to MPS, but does not work when I add MPS to M.
Moreover, I do not find any clearly function that could achieve what I want to do. For exemple, a function like : Measurement().setMarkerPairSet() in order to add some MarkerPairSet to Measurement.
Does anybody know how to solve this problem? Or how to obtain a complete .xml file for Scaling with MatLab.
Thank you,
Regards
I am able to scale a Model by using the GUI of OpenSim. But, I would like to automate this process to implement it in a larger Matlab data processing pipeline.
Thus, if I understand clearly, the whole thing is about to create an .xml file like the one loaded when you perform scaling directly in the GUI.
So far, I have been able to create some of the items present in this .xml file (subject data, model and marker files, time range etc...). But I have trouble to express my MeasurementSet on which my scaling process will be based.
From the attached file Measurement.png, you can see an example of what I would like (for one Measurement) .
From the attached file Measurement_Test.png, you can see an example of what I get so far.
As you can see, I am not able to create my MeasurementSet.
Here is my entire code :
Code: Select all
% Pull in the modeling classes straight from the OpenSim distribution
import org.opensim.modeling.*
% Load the model and initialize
model = Model(fullfile(modelFilePath, modelFile));
state=model.initSystem();
%% Setup Subjects Data, Scaling order, Marker and Static Files and Mass Distribution Preservation
SCT=ScaleTool();
SCT.setSubjectMass(data.Mass);
SCT.setSubjectHeight(data.Height);
SCT.setSubjectAge(data.Age);
SCT.setName(Name);
ScalingOrderArray=ArrayStr();
ScalingOrderArray.setSize(1);
ScalingOrderArray.setitem(0,'measurements');
SCT.getModelScaler().setScalingOrder(ScalingOrderArray);
SCT.getModelScaler().setMarkerFileName(fullfile(trcFilePath,trcFile)) %trc file for measurements
SCT.getMarkerPlacer().setStaticPoseFileName(fullfile(trcFilePath,trcFile)) %trc file for static pose
SCT.getModelScaler().setPreserveMassDist(true);
%% Setup MeasurementSet
MS=MeasurementSet();
M=Measurement();
M.setName('PelvisX');
M.setApply(true);
MS.cloneAndAppend(M);
%MarkerPairSet
MPS=MarkerPairSet();
MP=MarkerPair();
MP.setMarkerName(0,'MidPSIS');
MP.setMarkerName(1,'MidASIS');
MPS.cloneAndAppend(MP); %Add MP to MPS
M.cloneAndAppend(MPS) % Add MPS to M. Here is the bug.
%BodyScaleSet
BSS=BodyScaleSet();
BS=BodyScale();
BS.setName('pelvis');
AxisNameArray=ArrayStr();
AxisNameArray.setSize(1);
AxisNameArray.setitem(0,'X');
BS.setAxisNames(AxisNameArray);
BSS.cloneAndAppend(BS); %Add BS to BSS
M.cloneAndAppend(BSS) % Add BSS to M. Here is the bug
%%
Some code lines about Output files and Time processing
.
.
.
%% Print xml
SCT.print('setup_scale.xml');
Code: Select all
Check for missing argument or incorrect argument data type in call to function 'cloneAndAppend'.
Moreover, I do not find any clearly function that could achieve what I want to do. For exemple, a function like : Measurement().setMarkerPairSet() in order to add some MarkerPairSet to Measurement.
Does anybody know how to solve this problem? Or how to obtain a complete .xml file for Scaling with MatLab.
Thank you,
Regards