Edit xml Scale File via MatLab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Edit xml Scale File via MatLab

Post by Axel Koussou » 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 :

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');
I mainly have a bug when I tempt to add the MarkerPairSet or the BodyScaleSet to Measurement. This error appears :

Code: Select all

Check for missing argument or incorrect argument data type in call to function 'cloneAndAppend'.
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
Attachments
Measurement_Test.PNG
Measurement_Test.PNG (15.7 KiB) Viewed 1232 times
Measurement.PNG
Measurement.PNG (46.54 KiB) Viewed 1232 times

Tags:

User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Re: Edit xml Scale File via MatLab

Post by Axel Koussou » Fri Sep 18, 2020 4:29 am

Otherwise, to deal with this problem, I have tried to use a different approach.

Briefly, I have created a .xml file corresponding to all the MeasurementSet I would like, and I have tried to add this .xml file to the whole Scale .xml file. For that, I have used :

Code: Select all

ScaleTool.getModelScaler().setScaleSetFile('MeasurementSet.xml')
Doing that, I obtain this error that I am not sure to fully understand :

Code: Select all

Java exception occurred:
java.lang.RuntimeException: PropertyObjArray:
ERR- Attempting to append invalid object of type Measurement 
	
	at 
	org.opensim.modeling.opensimActuatorsAnalysesToolsJNI.ModelScaler_setScaleSetFile(Native Method)

	at
    org.opensim.modeling.ModelScaler.setScaleSetFile(ModelScaler.java:127)
Do you think that it is possible to proceed like that? If yes, do you know what causes this error ?

Thank you

Regards

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

Re: Edit xml Scale File via MatLab

Post by Ayman Habib » Sat Sep 19, 2020 9:55 am

Hi Axel,

The error message correctly suggests that you're trying to set a "ScaleSet" from a "MeasurementSet" which is not supported since these are two different, unrelated object types.

Glad to see the informative error reporting at work, but please let us know why believed this would work so we can clarify the documentation.

Best regards,
-Ayman

User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Re: Edit xml Scale File via MatLab

Post by Axel Koussou » Sun Sep 20, 2020 2:33 am

Hi,

Thanks for your help.
As explained, I'm trying to complete a .xml file directly via MatLab but I have trouble concerning the MeasurementSet.

I thought that, after setting the MarkerPair and add them to the MarkerPairSet :

Code: Select all

MP=MarkerPair();
MP.setMarkerName(0,'MidPSIS');
MP.setMarkerName(1,'MidASIS');
MPS.cloneAndAppend(MP); %Add MP to MPS
It would be possible to add the MarkerPairSet to the Measurement named PevisX, but maybe I'm not completly understanding this well :

Code: Select all

M=Measurement();
M.setName('PelvisX');
M.setApply(true);
M.cloneAndAppend(MPS) % Add MPS to M. Here is the bug. 
(The same process is made for the BodyScaleSet.)

So, do you know how could I do such a step?

Thanks

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

Re: Edit xml Scale File via MatLab

Post by Ayman Habib » Mon Sep 21, 2020 9:41 am

Hi Axel,

The cloneAndAppend interface is used exclusively for Sets, if you have a "MeasurementSet" you can use cloneAndAppend to add a new "Measurement" to the set. It doesn't apply to arbitrary properties.
If you need access to MarkerPairSet from a Measurement, then call getMarkerPairSet to get a reference to the set and thenapply the operation (e.g. cloneAndAppend) to the result.

It is generally a good idea to check the API documentation (doxygen) https://simtk.org/api_docs/opensim/api_docs/ for class methods/signatures when using the API.

Hope this helps,
-Ayman

User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Re: Edit xml Scale File via MatLab

Post by Axel Koussou » Mon Sep 21, 2020 11:18 pm

Hi Ayman,

Thanks for your reply.
I'm aware that one can use cloneAndAppend to add a new "Measurement" to the "MeasurementSet". That's already what I do (you can see it if you go back to my first message with my entire code).
I also define my "MarkerPairSet".

I thought that it would be enough. But if you check my resulting .xml file (still in the first message), my "MeasurementSet" stay empty.
That's why, I thought that I had to add my "MarkerPairSet" to my "Measurement", and then the "Measurement" to the "MeasurementSet", but, as said, I obtain a message error.

So, I just want to know what I'm doing wrong. As explained, I'm just looking to create my "MeasurementSet", with several "Measurement", based on different "MarkerPairs".

Thanks

User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Re: Edit xml Scale File via MatLab

Post by Axel Koussou » Fri Sep 25, 2020 1:11 am

Solution :

I finally came to a solution. I misunderstood the "objects" class. In fact, you can cloneAndAppend only an object to an other one.

So, the correct code lines are :

M.getMarkerPairSet().cloneAndAppend(MP)

and then, with the same logic, you can add your Measurement to you MeasurementSet :

ST.getModelScaler().getMeasurementSet().cloneAndAppend(M);

Thanks,

Regards

User avatar
Axel Koussou
Posts: 56
Joined: Mon Aug 10, 2020 12:07 am

Re: Edit xml Scale File via MatLab

Post by Axel Koussou » Thu Apr 29, 2021 2:15 am

Hi all,

Sorry to reopen this channel.

I have succeeded in creating a MatLab function to scale my model. Everything works perfectly.
Nevertheless, everytime I run the code I got this message in my MatLab Command Window :

Couldn't find file 'r_pelvis.vtp'.
Couldn't find file 'l_pelvis.vtp'.

and so on... for all the geometries.

I know that Geometries are just for visualization purpose but I do not understand why this message is appearing.
My GeometryPath is correctly set. Moreover, when I open my scaled model in the GUI, all the bones appear correctly. So I do not understand why this message keeps appearing.

Do you have any idea why I got this message?

Thanks in advance,

Regards

POST REPLY