Page 1 of 1

build/modify osim file using OpenSim SDK

Posted: Wed Oct 13, 2010 11:39 am
by ajaysonar
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

RE: build/modify osim file using OpenSim SDK

Posted: Wed Oct 13, 2010 2:26 pm
by aymanh
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

RE: build/modify osim file using OpenSim SDK

Posted: Fri Oct 15, 2010 7:12 pm
by ajaysonar
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

RE: build/modify osim file using OpenSim SDK

Posted: Sun Oct 17, 2010 12:51 am
by aymanh
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

RE: build/modify osim file using OpenSim SDK

Posted: Mon Oct 18, 2010 8:00 pm
by ajaysonar
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

RE: build/modify osim file using OpenSim SDK

Posted: Tue Oct 19, 2010 9:37 am
by aymanh
Ajay,

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

Cheers,
-Ayman

RE: build/modify osim file using OpenSim SDK

Posted: Tue Oct 19, 2010 7:18 pm
by ajaysonar
Ayman,

Thanks, that works.

Cheers,
Ajay