Accessing objectgroup of markers

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Samuele Gould
Posts: 16
Joined: Tue Nov 19, 2019 5:53 am

Accessing objectgroup of markers

Post by Samuele Gould » Fri Nov 04, 2022 7:05 am

Dear OpenSim community,

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>

Tags:

User avatar
Carmichael Ong
Posts: 401
Joined: Fri Feb 24, 2012 11:50 am

Re: Accessing objectgroup of markers

Post by Carmichael Ong » Fri Nov 18, 2022 1:06 pm

I was able to reproduce the same issue with a different model. I haven't taken a deep dive into the code yet, but my guess is that there might be a slight difference in how muscle groups are loaded from an XML file compared to marker groups. This is also seen if you load the model into the GUI (i.e., you'll see the muscle group in the GUI but not the marker group). Good to hear that you have a workaround, as there might need to be code changes in OpenSim to support this.

POST REPLY