build/modify osim file using OpenSim SDK

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ajay Sonar
Posts: 11
Joined: Thu Sep 23, 2010 8:54 am

build/modify osim file using OpenSim SDK

Post by Ajay Sonar » Wed Oct 13, 2010 11:39 am

Ayman,

(from the previous post in 'osim file documentation').

I was able to read in an existing osim file (UpperLowerBody.osim by Delp et al)and add new body to it (l4 and l5 vertebrae). I removed the hat_spine.vtp from the thorax body (in Notepad). I want to split the spine in to upper spine, which I will add back to the thorax body, and the lower spine which contain the lumbar vertebrae (L1-L5). I want to connect each lumbar vertebrae with each other with ball joint and L5 connects to pelvis and L1 connects to the modified thorax. Right now L5 connects to ground and L4 connects to L5. But L4 does not seem to be connected to L5 when I load the model in OpenSim. I am not able to find a way to get the Body objects from the model so that I can use that information to create BallJoints between the new body and the existing body. Can you suggest me how that could be done. Is there a way I can upload the cpp file I have right now for you to take a look?

Thanks,
Ajay

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

RE: build/modify osim file using OpenSim SDK

Post by Ayman Habib » Wed Oct 13, 2010 2:26 pm

Ajay,

The vtp files are used only for visualization, they do not affect the multibody system.
What you want is add a sequence of Joints between the pelvis and thorax (to replace an existing one). The API example in /APIExamples/ExampleMain shows an example of creating a Joint and connecting a body to an existing body using this joint, and adding DisplayGeometry.

There are API calls to construct the model from an osim file: for example

Model m("myModelFile.osim");

then you can get a reference to a Body by name:

OpenSim::Body& p=m.getBodySet().get("pelvis");

Based on the Joint type you want you'll use different constructors.
After you make the modifications to your model you can write it to XML using a call like:
m.print("myModel.osim");


Hope this helps,
-Ayman

User avatar
Ajay Sonar
Posts: 11
Joined: Thu Sep 23, 2010 8:54 am

RE: build/modify osim file using OpenSim SDK

Post by Ajay Sonar » Fri Oct 15, 2010 7:12 pm

Hi Ayman,

I got the links (L1-L5) between thorax and pelvis. I was trying to change the parent body for thorax to L1 from pelvis and did the following,

// Get the thorax body
OpenSim::Body thoraxBody=osimModel.getBodySet().get("thorax");

OpenSim::Joint &thoraxJoint=thoraxBody.getJoint();

the I tried
thoraxJoint.setParentName("lumbar_1");

and
thoraxJoint.setParentBody(*l1Body);

both did not work. Since it was just one parent body I changed it in Notepad++, but otherwise what am I missing here. I also checked the tutorials but could not figure out.

Thanks,
Ajay

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

RE: build/modify osim file using OpenSim SDK

Post by Ayman Habib » Sun Oct 17, 2010 12:51 am

Ajay,

One thing I see is that the line

OpenSim::Body thoraxBody=osimModel...

creates a "fresh Copy" of the thoraxBody. Instead you should use
OpenSim::Body& thoraxBody=osimModel...

Please let me know if that works for you.

Cheers,
-Ayman

User avatar
Ajay Sonar
Posts: 11
Joined: Thu Sep 23, 2010 8:54 am

RE: build/modify osim file using OpenSim SDK

Post by Ajay Sonar » Mon Oct 18, 2010 8:00 pm

Hi Ayman,

If I change the line to

OpenSim::BodySet& thoraxBody=osimModel.getBodySet().get("thorax");

it generates an error,
error C2440: 'initializing' : cannot convert from 'const OpenSim::Body' to 'OpenSim::Body &'

Any suggestions.

Regards,
Ajay

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

RE: build/modify osim file using OpenSim SDK

Post by Ayman Habib » Tue Oct 19, 2010 9:37 am

Ajay,

If you'll need to get non const reference, then use osimModel.updBodySet() instead of osimModel.getBodySet()

Cheers,
-Ayman

User avatar
Ajay Sonar
Posts: 11
Joined: Thu Sep 23, 2010 8:54 am

RE: build/modify osim file using OpenSim SDK

Post by Ajay Sonar » Tue Oct 19, 2010 7:18 pm

Ayman,

Thanks, that works.

Cheers,
Ajay

POST REPLY