I am unable to access the items of a group within marker sets programatically via the Matlab API.
I have been able to access the marker set and the groups within the marker set and the member list within a specific group. However the problem arises when I try to access a specific item within the member list. This as far as I can tell is due to the group being empty as when I query the size it returns 0. However I have checked the osim file and the group is not empty (snipt of the code specifying the group is below).
I thought this may have been due to constructing the model incorrectly (I am using a custom model that I built), so I tested accessing a group of markers I manually added to the leg6dof9muscv43 model and it still returned the group as empty although it could find the group. The matlab code to access the items and the code of the model xml file specifying the group are below.
To check that the matlab code I was using was correct I tested it to access an item in a group of muscles within the force set and this worked without a problem (provided I initialised the system otherwise the group was empty). The code matlab and xml file for this are also below.
I have a work around for accessing the markers I want however it would have been more straight forward if I had been able to do it using the groups, but more than anything I was wondering why it would work for the muscles but not the markers. Any suggestions would be appriciated.
Thanks,
Samuele
Code: Select all
%% MATLAB CODE USED TO ACCESS GROUPS
% Test accessing marker group mannualy added to the leg6dof9muscv43 model
clc, clear, close all
import org.opensim.modeling.*
% Load the model
modelWithMarkerGroups = Model('C:\Users\samue\currentWork\leg6dof9muscv43MarkerGroupAdded.osim');
% Initialise the system otherwise the group is empty in the case of muscles
modelWithMarkerGroups.initSystem;
% Access the marker set
markerSet = modelWithMarkerGroups.get_MarkerSet;
% Access the first group within the marker set
markerGroups = markerSet.getGroup(0);
% Check this has worked by getting the name of the group
markerGroups.getName
% Access the members of the group
markerGroupMembers = markerGroups.getMembers();
% Access a specific item in the group
markerGroupMembers.getSize % This returns 0
% Access the first item in the group
markerGroupMembers.getitem(0);
markerGroupMembers.get(0);
% ---------------------------------------------------------- %
% Test accessing muscle from muscle group in gait2354 model
clc, clear, close all
import org.opensim.modeling.*
% Load the model
modelWithMuscleGroups = Model('C:\OpenSim 4.3\Resources\Models\Gait2354_Simbody\gait2354_simbody.osim');
% Initialise the system otherwise the group is empty
modelWithMuscleGroups.initSystem;
% Access the force set
muscleSet = modelWithMuscleGroups.getForceSet;
% Access the first group within the force set
muscleGroup = muscleSet.getGroup(0);
% Check this has worked by getting the name of the group
muscleGroup.getName
% Access the members of the group
muscleGroupMembers = muscleGroup.getMembers();
% Access a specific item in the group
muscleGroupMembers.getSize; % This returns 0 if the system is not initialised
% Access the first item in the group
muscleGroupMembers.getitem(0);
muscleGroupMembers.get(0);
Code: Select all
% Example of code of osim file specifying marker groups
<MarkerSet name="markerset">
<objects>
<Marker name="R.ASIS">
</Marker>
<Marker name="L.ASIS">
</Marker>
<Marker name="V.Sacral">
</Marker>
<Marker name="R.Thigh.Upper">
</Marker>
<Marker name="R.Thigh.Front">
</Marker>
<Marker name="R.Thigh.Rear">
</Marker>
<Marker name="R.Shank.Upper">
</Marker>
<Marker name="R.Shank.Front">
</Marker>
<Marker name="R.Shank.Rear">
</Marker>
<Marker name="R.Heel">
</Marker>
<Marker name="R.Midfoot.Lat">
</Marker>
<Marker name="R.Toe.Tip">
</Marker>
</objects>
<groups>
<ObjectGroup name="L1Markers">
<members> R.ASIS L.ASIS V.Sacral</members>
</ObjectGroup>
</groups>
</MarkerSet>
% Example of code of osim file specifying muscle groups
<ForceSet>
<objects>
<Thelen2003Muscle name="glut_med1_r">
<Thelen2003Muscle name="glut_med2_r">
<Thelen2003Muscle name="glut_med3_r">
<Thelen2003Muscle name="bifemlh_r">
<Thelen2003Muscle name="bifemsh_r">
<Thelen2003Muscle name="sar_r">
<Thelen2003Muscle name="add_mag2_r">
<Thelen2003Muscle name="tfl_r">
</objects>
<groups>
<ObjectGroup name="R_hip_abd">
<members> glut_max1_r glut_med1_r glut_med2_r glut_med3_r peri_r sar_r tfl_r</members>
</ObjectGroup>
</groups>
</ForceSet>