Export Bone Geometry to .STL For Each Frame

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Connor Pyles
Posts: 20
Joined: Wed Jul 19, 2017 1:46 pm

Re: Export Bone Geometry to .STL For Each Frame

Post by Connor Pyles » Mon Jul 24, 2017 1:53 pm

Not sure if this helps, but it looks like the cmake tests are expecting a "C:\opensim-core\Bindings\Java\Matlab\Utilities" folder, which doesn't exist. I figured this out when trying to run configureOpenSim(), which, by the way, I also had to change because it was expecting the OpenSim_buildinfo.txt file in an "sdk" folder, when it was actually in the root openSimFolder.

Thanks,
Connor Pyles

User avatar
Connor Pyles
Posts: 20
Joined: Wed Jul 19, 2017 1:46 pm

Re: Export Bone Geometry to .STL For Each Frame

Post by Connor Pyles » Mon Jul 24, 2017 2:10 pm

Ok, so I did two things, manually removed OpenSim 3.3 API from MATLAB path, including the Java class and library paths, and closed MATLAB before running the ctest again and it worked. Not sure which one was the fix.

Will keep you posted on status, and I'd still appreciate any feedback on loading in 3.x sim results.

Best,
Connor Pyles

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Export Bone Geometry to .STL For Each Frame

Post by Thomas Uchida » Mon Jul 24, 2017 2:49 pm

I understand that the 4.0 API will build models for OpenSim 4.0, but can we initialize models from OpenSim 3.x? I.e., could we run "model = Model('C:\OpenSim 3.3\Models\gait2392_thelen2003muscle.osim')" ?
In general, backwards compatibility is maintained; old models are updated automatically when opened in 4.0. Any known exceptions will be indicated in the upgrade notes as has been done in the past (e.g., see http://simtk-confluence.stanford.edu:80 ... penSim+3.3). A partial list of major changes between 3.3 and 4.0 can be found in CHANGELOG.md on GitHub (https://github.com/opensim-org/opensim- ... ANGELOG.md).

User avatar
Connor Pyles
Posts: 20
Joined: Wed Jul 19, 2017 1:46 pm

Re: Export Bone Geometry to .STL For Each Frame

Post by Connor Pyles » Tue Jul 25, 2017 7:19 am

Ok, thanks for all of you help, I got 4.0 built and the API is working with the code snippet you posted. Now, assuming I have already run an analysis, which commands do I need to iterate through each model state, rather than setting the pelvis tilt/x-location manually?

User avatar
Sina Porsa
Posts: 5
Joined: Sun Jul 15, 2018 4:51 pm

Re: Export Bone Geometry to .STL For Each Frame

Post by Sina Porsa » Tue Oct 16, 2018 9:39 pm

jimmy wrote:
Mon Jul 24, 2017 10:07 am
Depends on what version of OpenSim you want to use. I would recommend using the 4.0 Beta API since there are convenience methods added to do this. The below code would give you the position and orientation of the OpenSim body in the Global.

Code: Select all

import org.opensim.modeling.*

model = Model('gait2392_thelen2003muscle.osim')
% get a reference to the state
s = model.initSystem()

% get a reference to the pelvis body
pelvis = model.getBodySet().get(0)

p0 = pelvis.getPositionInGround(s);
r0 = pelvis.getTransformInGround(s).R;

% Change the pelvis tilt
model.getCoordinateSet().get(0).setValue(s,-10)
% change the pelvis x location
model.getCoordinateSet().get(3).setValue(s,2)

p1 = pelvis.getPositionInGround(s);
r1 = pelvis.getTransformInGround(s).R;
Hi James.
A brief description of what I am trying to solve: In my application, our subjects wear some sort of sensors and perform some daily activities. I have created a model containing our sensors (sensors are fixed to corresponding bodies using WeldJoint). I need to calculate orientation and velocity of sensors as a function of joint angles and joint angular velocities. I can use your proposed method to calculate global orientations, Was wondering if it's any methods available in MATLAB API to calculate velocity of a body in the global frame?

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Export Bone Geometry to .STL For Each Frame

Post by Thomas Uchida » Wed Oct 17, 2018 7:09 am

Was wondering if it's any methods available in MATLAB API to calculate velocity of a body in the global frame?
I think you're looking for the getVelocityInGround() method, which is inherited from the Frame class (https://simtk.org/api_docs/opensim/api_ ... 4526ef9629). You can also type methodsview(pelvis) in MATLAB to see all available methods. You may want to see the following pages in the Confluence documentation:
- "Common Scripting Commands" (https://simtk-confluence.stanford.edu/d ... g+Commands)
- "Scripting with Matlab" (https://simtk-confluence.stanford.edu/d ... ith+Matlab)

User avatar
Sina Porsa
Posts: 5
Joined: Sun Jul 15, 2018 4:51 pm

Re: Export Bone Geometry to .STL For Each Frame

Post by Sina Porsa » Wed Oct 17, 2018 2:09 pm

tkuchida wrote:
Wed Oct 17, 2018 7:09 am
Was wondering if it's any methods available in MATLAB API to calculate velocity of a body in the global frame?
I think you're looking for the getVelocityInGround() method, which is inherited from the Frame class (https://simtk.org/api_docs/opensim/api_ ... 4526ef9629). You can also type methodsview(pelvis) in MATLAB to see all available methods. You may want to see the following pages in the Confluence documentation:
- "Common Scripting Commands" (https://simtk-confluence.stanford.edu/d ... g+Commands)
- "Scripting with Matlab" (https://simtk-confluence.stanford.edu/d ... ith+Matlab)
That's exactly what I was looking for. Thanks!
One more question, is there any thing available to get the gravity vector in a local frame?

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Export Bone Geometry to .STL For Each Frame

Post by Thomas Uchida » Wed Oct 17, 2018 5:29 pm

is there any thing available to get the gravity vector in a local frame?
See the Frame::expressVectorInAnotherFrame() method: https://simtk.org/api_docs/opensim/api_ ... 696dd48b02.

User avatar
Jom Pornthep
Posts: 1
Joined: Tue Jan 03, 2017 7:57 pm

Re: Export Bone Geometry to .STL For Each Frame

Post by Jom Pornthep » Fri Jan 11, 2019 6:38 pm

In case anyone stumbles across this thread from Google.

I made a python script to convert VTP to STL and export the default pose of an OpenSim model. It can't export the animation/frames, but you can either extend the script yourself or keep changing the default pose and running the script.

https://github.com/prnthp/opensim-stl-export

Cheers m8

POST REPLY