Page 1 of 1
Question in Editing a xml Scale setting file using matlab
Posted: Wed Dec 04, 2013 12:23 pm
by mbebelveras
Hi all,
I'm trying to edit a xml file using a matlab script and I would like to know how to set the IKTaskSet file within the "Marker Set Placer"
In the xml file it is:
Code: Select all
<MarkerPlacer>
<apply>true</apply>
<IKTaskSet file="C:\Users\Documents\Scale_Tasks.xml" />
<marker_file>marker.trc</marker_file>
<time_range> 0 0.5 </time_range>
<output_model_file> .\Scale_Results\scaled.osim</output_model_file>
<output_marker_file> .\Scale_Results\MarkerSet.xml </output_marker_file>
<max_marker_movement>-1</max_marker_movement>
</MarkerPlacer>
I could change the output file with the following script
Code: Select all
analyzeTool = ScaleTool(genericSetupFile);
analyzeTool.getMarkerPlacer().setOutputModelFileName(outputmodelfile_final)
but I could not understand the instructions in the Doxygen for changing the
<IKTaskSet file="C:\Users\Documents\Scale_Tasks.xml" />
Can anyone help ?
Thanks
Bel
Re: Question in Editing a xml Scale setting file using matla
Posted: Mon Jan 06, 2014 10:20 am
by jimmy
Hi Bel,
If you are trying to set the ikTaskSet using the api interface in matlab you will have to create a ikTaskSet object and then attach it.
ikTaskObject = IKTaskSet('C:\OpenSim 3.1\Models\Gait2354_Simbody\gait2354_IK_Tasks.xml') ;
theIKTaskSetRef = scaleTool.getMarkerPlacer().getIKTaskSet()
theIKTaskSetRef = ikTaskObject
I havent had a chance to test that so just see how it goes.
Otherwise you can edit each weight manually using a for loop;
scaleTool.getMarkerPlacer().getIKTaskSet().clearAndDestroy() % empty the set
for i = 1:nMkrs
scaleTool.getMarkerPlacer().getIKTaskSet().cloneAndAppend(ikTaskObject.get(i))
end
hope that helps,
-james
Re: Question in Editing a xml Scale setting file using matla
Posted: Thu Jan 23, 2014 10:22 am
by mbebelveras
Hi James,
My idea is not to use the loop, so I'll try your first suggestion and let you know if it works
thanks
Bel
Re: Question in Editing a xml Scale setting file using matla
Posted: Fri Jan 24, 2014 12:27 pm
by mbebelveras
Hi James,
It didn't work the way I was thinking. Doing the way you suggested, I could copy the IK tasks from one IKTask file to the other, but I could not modify the path name, nor even copy ( set ) the tasks, in the new Scale Setting file.
It seems that I'm missing a 'set' command.
Do you have any other suggestions?
thanks
Bel
Re: Question in Editing a xml Scale setting file using matlab
Posted: Thu Jun 15, 2017 9:49 am
by mariacfox
Hello,
I'm having a similar issue trying to define the IKTaskSet and MeasurementSet files in MATLAB for batch processing. I tried using the suggested method and it did not work. Are there any new ideas about how to fix this? My IKTaskSet and MeasurementSet files get lost during batch processing even if I have them in the generic XML file, so it would be great to find a way to add them in the batch processing code.
Thank you!
Re: Question in Editing a xml Scale setting file using matlab
Posted: Thu Jun 15, 2017 12:11 pm
by jimmy
Hi, Maria-
My IKTaskSet and MeasurementSet files get lost during batch processing even if I have them in the generic XML file
What do you mean by lost? They don't go anywhere
Anyway, below is some code that may help show you how to write a measurement set or IK task set file. If you are doing this for scaling, you don't need separate files (you can store everything in the ScaleTool)
Code: Select all
import org.opensim.modeling.*
% instantiate a scale tool
scale = ScaleTool()
%% get a reference o the model scalar
% get the model scaler
scaler = scale.getModelScaler()
%% define a measurement
% instantiate and measurement object
m = Measurement()
% get a reference to the marker pair set
mps = m.getMarkerPairSet()
% instantiate a markerpair object; inputing a pair of markers
mp = MarkerPair('RHJC','RKJC')
% add the MarkerPair to the marker pair set
mps.adoptAndAppend(mp)
%% add the measurement to the ModelScaler Measuerement Set
sms = scaler.getMeasurementSet()
% add the measurement to the measurement set
sms.adoptAndAppend(m)
% print the measurement to file (if you want)
sms.print(''measurementset.xml')
%% get a reference to the marker placer
placer = Scale.getMarkerPlacer()
ik = placer.getIKTaskSet()
%% define a task and apend it to the ik task set
% instantiate an IK marker task
t = IKMarkerTask()
% set the name and the weight for the task
t.setName('LASI')
t.setWeight(10)
% append the ik marker task to the the IK task set
ik.adoptAndAppend(t)
% print the ik task set to file (if you want)
ik.print('iktaskset.xml')
Re: Question in Editing a xml Scale setting file using matlab
Posted: Thu Jun 15, 2017 12:19 pm
by mariacfox
James,
Thanks, this is helpful! I wanted to call the IKTastSet and MeasurementSet files because I have generic ones defined that I wanted to use for batch processing:
Code: Select all
<MeasurementSet file=".\Scale_MeasurementSet.xml"/>
This is where the file generated during batch processing "loses" the file I defined in the generic XML. Is there any way to include the files in MATLAB? I tried the code included below that was suggested in another post, but it doesn't seem to work:
Code: Select all
% setup marker placer
markerPlace = scaleTool.getMarkerPlacer();
ikTasks = IKTaskSet('.\Scale_Tasks.xml');
ikTaskSet = markerPlace.getIKTaskSet();
ikTaskSet = ikTasks;
Thank you!
Re: Question in Editing a xml Scale setting file using matlab
Posted: Thu Jun 15, 2017 1:10 pm
by jimmy
Code: Select all
% get the marker placer
placer = scale.getMarkerPlacer()
% get the marker placer's IKTaskSet
placer_TaskSet = placer.getIKTaskSet()
% Instantiate a (separate) task set from file
taskSetFromFile = IKTaskSet('KTaskSet_File.xml')
% Take each (individual) task from the file generated task set and
% append them to the marker placer's task set.
for i = 0 : taskSetFromFile.getSize() - 1
placer_TaskSet.adoptAndAppend(taskSetFromFile.get(i));
end
if taskSetFromFile.getSize() ~= placer_TaskSet.getSize()
error('Number of ik tasks from file do not match number in object')
end