Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
-
hans o
- Posts: 2
- Joined: Mon Apr 20, 2020 2:02 am
Post
by hans o » Mon Apr 20, 2020 2:22 am
Hello. I am trying to extract scale factors from two models using python to compare them. I can see the scale factors in the osim file, but I am currently failing to read them out for each body part. I am aiming for something like this:
Code: Select all
osimModel = osim.Model(scaledModelFilename)
state = osimModel.initSystem()
nBody = osimModel.getBodySet().getSize() # Number of Bodies
bodyNames = []
scaleFactors = []
# Display scale factors
for i in range(0, nBody):
ScaleFactor = osim.Vec3(0, 0, 0)
osimModel.getBodySet().get(i).getScaleFactors(ScaleFactor)
bodyNames.append(osimModel.getBodySet().get(i).getName())
scaleFactors.append([ScaleFactor.get(0), ScaleFactor.get(1), ScaleFactor.get(2)])
As far as I know, the class ModelComponent (from which "Body" inherits) implements "getScaleFactors", but it takes a frame and a ScaleSet. I do not really know how to obtain them from a model and its bodyparts. The code above fails with the message "'Body' object has no attribute 'getScaleFactors'". Can anyone help with this?
Thanks alot!
Tags:
-
Bryce Killen
- Posts: 104
- Joined: Mon Nov 24, 2014 7:12 pm
Post
by Bryce Killen » Mon Apr 20, 2020 7:03 am
Hi Hans,
See the below code snippet where I extract the scale factors
Code: Select all
#_#_#_#_#_ Femur
femScalesOS = femBody.get_attached_geometry(0).get_scale_factors()
femScales=np.ones(3)
for x in range(0,3):
femScales[x]=femScalesOS.get(x)
Where femBody is a opensim body object
Bryce
-
hans o
- Posts: 2
- Joined: Mon Apr 20, 2020 2:02 am
Post
by hans o » Mon Apr 20, 2020 9:11 am
Wonderful, it worked! Thank you very much.