Page 1 of 2

Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 7:28 am
by cpyles11
Hi all,

I'm new to OpenSim, and am looking for a solution to export bone geometry for each frame of my OpenSim model to .STL or other common CAD format. End goal is to import into a Microsoft Hololens for AR visualization of skeleton kinematics. I saw some posts on converting .vtp files to .obj files, and am assuming I could follow a similar process, but I'm not even clear on how to write .vtp files for each frame.

Any pointers on where to get started would be greatly appreciated, I'm open to software or script based solutions.

Best,
Connor Pyles
Johns Hopkins University Applied Physics Lab

Re: Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 8:45 am
by cpyles11
Alternatively, if could also be possible to export geometry once, and then define coordinate transforms for each geometry. I would just need to know where to look to parse that information.

-Connor

Re: Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 8:46 am
by jimmy
I don't really understand the rationale of your proposed method. Having individual .stl files for every frame of a simulation is nonsensical. There is only a single geometry file (.vtp, .obj, .stl). Any visualizer (including Hololens) would take that one geometry file and draw it given its orientation information. So you would just want frame orientations so that you can tell the visualizer where to draw the geometry.

Re: Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 8:52 am
by cpyles11
James,

Agreed, thus my second post :) Any tips on how to pull frame orientations? I'm assuming the MATLAB API has some tools to do this?

-Connor

Re: Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 10:07 am
by jimmy
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;

Re: Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 10:31 am
by cpyles11
Thanks James, I'll give that a shot and let you know how it goes. I'm assuming the 3.x API's won't convert to Global frame, or something along those lines?

Re: Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 10:38 am
by jimmy
The convenience calls I used (getPositionInGround, getTransformInGround) didn't exist in 3.x. We only exposed the concept of frames in the latest version, in direct response to needs like yours.

The Github repo for the 4.0 beta API is here. The build instructions are pretty straight forward.

Re: Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 11:24 am
by cpyles11
Ok, following build instructions now. Thanks for assisstance.

Re: Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 1:00 pm
by cpyles11
Hi James,

I'm following the "For the impatient (Windows)" build at the link you sent, and when I run ">ctest -C RelWithDebInfo --parallel 8", everything passes except for the Matlab tests (see below). I installed the latest JDK, and a MATLAB "ver" command is showing that it is using Java 1.7.0_60-b19. Any thoughts? Do I need to run configureOpenSim() from within C:\opensim_build\Bindings\Java\Matlab, like I did for previous APIs, and if so, do I do that before or after installing the build?

PowerShell Output:

93% tests passed, 8 tests failed out of 107

Total Test time (real) = 505.91 sec

The following tests FAILED:
100 - Matlab_TugOfWar_RelWithDebInfo (Failed)
101 - Matlab_wiringInputsAndOutputsWithTableReporter_RelWithDebInfo (Failed)
102 - Matlab_RunHopper_answers_RelWithDebInfo (Failed)
103 - Matlab_RunHopperWithDevice_answers_RelWithDebInfo (Failed)
104 - Matlab_ConnectorsInputsOutputs_RelWithDebInfo (Failed)
105 - Matlab_AccessSubcomponents_RelWithDebInfo (Failed)
106 - Matlab_Simbody_RelWithDebInfo (Failed)
107 - Matlab_osimTableStruct_RelWithDebInfo (Failed)
Errors while running CTest

Thanks,
Connor Pyles

Re: Export Bone Geometry to .STL For Each Frame

Posted: Mon Jul 24, 2017 1:24 pm
by cpyles11
Apologies for all the questions, but one more thing, in addition to my above comment on the MATLAB API.

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')" ? If we need to read older models, I'm guessing we could use the 3.x API and write our own functions to convert to the global frame?

-Connor