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
build/modify osim file using OpenSim SDK
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
RE: build/modify osim file using OpenSim SDK
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
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
- Ajay Sonar
- Posts: 11
- Joined: Thu Sep 23, 2010 8:54 am
RE: build/modify osim file using OpenSim SDK
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
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
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
RE: build/modify osim file using OpenSim SDK
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
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
- Ajay Sonar
- Posts: 11
- Joined: Thu Sep 23, 2010 8:54 am
RE: build/modify osim file using OpenSim SDK
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
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
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
RE: build/modify osim file using OpenSim SDK
Ajay,
If you'll need to get non const reference, then use osimModel.updBodySet() instead of osimModel.getBodySet()
Cheers,
-Ayman
If you'll need to get non const reference, then use osimModel.updBodySet() instead of osimModel.getBodySet()
Cheers,
-Ayman
- Ajay Sonar
- Posts: 11
- Joined: Thu Sep 23, 2010 8:54 am
RE: build/modify osim file using OpenSim SDK
Ayman,
Thanks, that works.
Cheers,
Ajay
Thanks, that works.
Cheers,
Ajay