Muscle Origin and Insertion Coordinate Transformation
- Michael Asmussen
- Posts: 67
- Joined: Mon Jul 11, 2016 7:46 am
Muscle Origin and Insertion Coordinate Transformation
I am fairly new to OpenSim. I would like to extract a muscle's origin and insertion in relation to a different reference frame rather than what is provided in the GeometryPath within the Properties window. For example, the tibialis anterior in the gait2392_simbody model has three attachment points -two with respect to the tibia reference frame and one with respect to the calcaneus reference frame. I was wondering how to extract these coordinates of the tibialis anterior with respect to, for example, the right ankle joint reference frame (talus, I believe).
Also, is there a quick method within OpenSim to extract the muscle length from the origin to a wrapping point and a wrapping point to the insertion or does this length have to be calculated with a script?
Thank you,
Mike
Also, is there a quick method within OpenSim to extract the muscle length from the origin to a wrapping point and a wrapping point to the insertion or does this length have to be calculated with a script?
Thank you,
Mike
- Thomas Uchida
- Posts: 1804
- Joined: Wed May 16, 2012 11:40 am
Re: Muscle Origin and Insertion Coordinate Transformation
There's an easy way to do this:the tibialis anterior in the gait2392_simbody model has three attachment points -two with respect to the tibia reference frame and one with respect to the calcaneus reference frame. I was wondering how to extract these coordinates of the tibialis anterior with respect to, for example, the right ankle joint reference frame (talus, I believe).
- Open the model.
- In the Navigator panel, select the tib_ant_r muscle.
- In the Properties panel, click the "..." button beside GeometryPath.
- In the dialog box that appears, select talus_r from the Body drop-down boxes. The coordinates shown in the X, Y, and Z textboxes will be updated (the point will now be expressed in the new reference frame).
Not that I know of. It would be nice if MuscleAnalysis reported this information, but currently it does not.is there a quick method within OpenSim to extract the muscle length from the origin to a wrapping point and a wrapping point to the insertion
- Michael Asmussen
- Posts: 67
- Joined: Mon Jul 11, 2016 7:46 am
Re: Muscle Origin and Insertion Coordinate Transformation
Hi Tom,
Thanks for your response! Is there a method within OpenSim to extract the coordinates of the attachments point of a muscle with respect to a joint, as you described, as a function of a joint angle change? For example, the coordinates of the three attachments of the tibialis anterior with respect to the talus as a function of the joint angle of the ankle?
Thanks,
Mike
Thanks for your response! Is there a method within OpenSim to extract the coordinates of the attachments point of a muscle with respect to a joint, as you described, as a function of a joint angle change? For example, the coordinates of the three attachments of the tibialis anterior with respect to the talus as a function of the joint angle of the ankle?
Thanks,
Mike
- Thomas Uchida
- Posts: 1804
- Joined: Wed May 16, 2012 11:40 am
Re: Muscle Origin and Insertion Coordinate Transformation
I think you could do that with a script that sets the pose, extracts the locations of the PathPoints associated with each muscle (see GeometryPath::getPathPointSet()), and repeats for each pose. The method I described in my first post would answer the question you asked in your original post, but it would change the bodies to which the points are attached. Instead of changing the model, you would want the script to extract the location of each PathPoint in the local frame and then re-express the point in the desired frame using SimbodyEngine::transformPosition() (https://simtk.org/api_docs/opensim/api_ ... 36ab374330).Is there a method within OpenSim to extract the coordinates of the attachments point of a muscle with respect to a joint, as you described, as a function of a joint angle change?
- Michael Asmussen
- Posts: 67
- Joined: Mon Jul 11, 2016 7:46 am
Re: Muscle Origin and Insertion Coordinate Transformation
Is there an example script to work from that loads a model and sets the pose of the model for certain joints or does this have to be done from scratch?tkuchida wrote:I think you could do that with a script that sets the pose, extracts the locations of the PathPoints associated with each muscle (see GeometryPath::getPathPointSet()), and repeats for each pose.
Thank you,
Mike
- Thomas Uchida
- Posts: 1804
- Joined: Wed May 16, 2012 11:40 am
Re: Muscle Origin and Insertion Coordinate Transformation
Here's a rough (untested) MATLAB script to get you started:
Code: Select all
import org.opensim.modeling.*
% Load model and create underlying computational system.
model = Model('arm26.osim');
state = model.initSystem();
% References to coordinates.
shoulder = model.getCoordinateSet().get('r_shoulder_elev');
elbow = model.getCoordinateSet().get('r_elbow_flex');
% Set an arbitrary pose.
shoulder.setValue(state, 0.1);
elbow.setValue(state, 0.1);
% Reference to set of points defining muscle path.
BIClong = model.getMuscles().get('BIClong');
pathPointSet = BIClong.getGeometryPath().getPathPointSet();
% Loop through points in muscle path.
for i = 0:pathPointSet.getSize()-1
pathPoint = pathPointSet.get(i);
% Location of point and body in which it's expressed.
locInBody = pathPoint.getLocation();
fromBodyName = pathPoint.getBodyName();
if (strcmp(fromBodyName, 'ground'))
fromBody = model.getGround();
else
fromBody = model.getBodySet().get(fromBodyName);
end
% Re-express in desired body.
toBodyName = 'r_humerus';
toBody = model.getBodySet().get(toBodyName);
newLoc = fromBody.findLocationInAnotherFrame(state, locInBody, toBody);
fprintf('point %d expressed in %s: %s\n', i, toBodyName, char(newLoc));
end
- Michael Asmussen
- Posts: 67
- Joined: Mon Jul 11, 2016 7:46 am
Re: Muscle Origin and Insertion Coordinate Transformation
Thanks for the rough Matlab script!
I have tried to run the script on its own before modifying. I am currently having trouble with one of the scripting commands. Below is the error I am receiving. Any ideas of how to fix the issue?
No appropriate method, property, or field 'findLocationInAnotherFrame' for class 'org.opensim.modeling.Body'.
Error in CoordinatesMuscleRespecttoJoint (line 40)
newLoc = fromBody.findLocationInAnotherFrame(state, locInBody, toBody);
Thank you,
Mike
I have tried to run the script on its own before modifying. I am currently having trouble with one of the scripting commands. Below is the error I am receiving. Any ideas of how to fix the issue?
No appropriate method, property, or field 'findLocationInAnotherFrame' for class 'org.opensim.modeling.Body'.
Error in CoordinatesMuscleRespecttoJoint (line 40)
newLoc = fromBody.findLocationInAnotherFrame(state, locInBody, toBody);
Thank you,
Mike
- Thomas Uchida
- Posts: 1804
- Joined: Wed May 16, 2012 11:40 am
Re: Muscle Origin and Insertion Coordinate Transformation
What version of OpenSim are you using?
- Michael Asmussen
- Posts: 67
- Joined: Mon Jul 11, 2016 7:46 am
- Thomas Uchida
- Posts: 1804
- Joined: Wed May 16, 2012 11:40 am
Re: Muscle Origin and Insertion Coordinate Transformation
Apologies; the script was written in 4.0. Here's a 3.3 version:
The following output is displayed in the MATLAB Command Window:
Please test to make sure it's providing the data you seek.
Code: Select all
import org.opensim.modeling.*
% Load model and create underlying computational system.
model = Model('arm26.osim');
state = model.initSystem();
% References to coordinates.
shoulder = model.getCoordinateSet().get('r_shoulder_elev');
elbow = model.getCoordinateSet().get('r_elbow_flex');
% Set an arbitrary pose.
shoulder.setValue(state, 0.1);
elbow.setValue(state, 0.1);
% Reference to set of points defining muscle path.
BIClong = model.getMuscles().get('BIClong');
pathPointSet = BIClong.getGeometryPath().getPathPointSet();
% Loop through points in muscle path.
for i = 0:pathPointSet.getSize()-1
pathPoint = pathPointSet.get(i);
% Location of point and body in which it's expressed.
locInBody = pathPoint.getLocation();
fromBodyName = pathPoint.getBodyName();
if (strcmp(fromBodyName, 'ground'))
fromBody = model.getGroundBody();
else
fromBody = model.getBodySet().get(fromBodyName);
end
% Re-express in desired body.
toBodyName = 'r_humerus';
toBody = model.getBodySet().get(toBodyName);
newLoc = Vec3(0);
model.getSimbodyEngine().transformPosition(state, fromBody, locInBody, toBody, newLoc);
fprintf('point %d expressed in %s: %s\n', i, toBodyName, char(newLoc));
end
Code: Select all
point 0 expressed in r_humerus: ~[-0.020527,0.0127087,-0.0219865]
point 1 expressed in r_humerus: ~[-0.00925225,0.0220215,-0.0134858]
point 2 expressed in r_humerus: ~[0.02131,0.01793,0.01028]
point 3 expressed in r_humerus: ~[0.02378,-0.00511,0.01201]
point 4 expressed in r_humerus: ~[0.01345,-0.02827,0.00136]
point 5 expressed in r_humerus: ~[0.01068,-0.07736,-0.00165]
point 6 expressed in r_humerus: ~[0.01703,-0.12125,0.00024]
point 7 expressed in r_humerus: ~[0.0228,-0.1754,-0.0063]
point 8 expressed in r_humerus: ~[0.0184789,-0.337904,0.00921652]