Visualization using OpenSim API
Visualization using OpenSim API
Dear All:
I want to use OpenSim API to visualize the result of the simulation states, while when I use the following code:
osimModel.setUseVisualizer(true);
State stat=osimModel.initSystem();
No visualization happens.
If I add the code "osimModel.getVisualizer().show(stat);", unhandled exception error of VC++ happens.
Thanks for anyone who can help!
I want to use OpenSim API to visualize the result of the simulation states, while when I use the following code:
osimModel.setUseVisualizer(true);
State stat=osimModel.initSystem();
No visualization happens.
If I add the code "osimModel.getVisualizer().show(stat);", unhandled exception error of VC++ happens.
Thanks for anyone who can help!
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Visualization using OpenSim API
That is the expected behavior; initSystem() does not generate visualization.No visualization happens.
Have you tried replacing State with State& on line 2? The show() method takes a const SimTK::State& as an argument (https://simtk.org/api_docs/opensim/api_ ... d647ab0120) and I'm not sure that your State stat will be implicitly cast to a const reference.If I add the code "osimModel.getVisualizer().show(stat);", unhandled exception error of VC++ happens.
Re: Visualization using OpenSim API
tkuchida wrote:That is the expected behavior; initSystem() does not generate visualization.No visualization happens.
Have you tried replacing State with State& on line 2? The show() method takes a const SimTK::State& as an argument (https://simtk.org/api_docs/opensim/api_ ... d647ab0120) and I'm not sure that your State stat will be implicitly cast to a const reference.If I add the code "osimModel.getVisualizer().show(stat);", unhandled exception error of VC++ happens.
Dear Dr Uchida:
Thank you so much for your reply!
I replaced with State&, but the problem is still the same.
![Shocked :shock:](./images/smilies/icon_eek.gif)
Access Violation,unhandled exception.
The constructed model object's member "_fileName" is "whether or not this task will be used during inverse kinematic slove"!
I also see the OpenSim::Object's name of the constructed model is "GaitModel2392" when debugging.
Thanks & Regards.
Jack
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Visualization using OpenSim API
It sounds like there is a parsing error when reading your model file. The phrase "Whether or not this task will be used during inverse kinematics solve" is a comment associated with the apply property of IKMarkerTask. You might try removing the IKMarkerTask elements and looking for typos in the model file. I also notice non-English characters in your attached image, which may cause problems as well (e.g., see viewtopicPhpbb.php?f=91&t=2937).The constructed model object's member "_fileName" is "whether or not this task will be used during inverse kinematic slove"!
It would also be useful to know whether this model has ever been opened successfully, what version of OpenSim it has been used in, and the version of OpenSim you are using. In short, under what conditions was the model last opened successfully and what changes have been made since then?
Re: Visualization using OpenSim API
tkuchida wrote:It sounds like there is a parsing error when reading your model file. The phrase "Whether or not this task will be used during inverse kinematics solve" is a comment associated with the apply property of IKMarkerTask. You might try removing the IKMarkerTask elements and looking for typos in the model file. I also notice non-English characters in your attached image, which may cause problems as well (e.g., see viewtopicPhpbb.php?f=91&t=2937).The constructed model object's member "_fileName" is "whether or not this task will be used during inverse kinematic slove"!
It would also be useful to know whether this model has ever been opened successfully, what version of OpenSim it has been used in, and the version of OpenSim you are using. In short, under what conditions was the model last opened successfully and what changes have been made since then?
Dear Dr Uchida:
Thanks for your reply!
The model gaitModel2392 can be opened successfully with OpenSim 3.2 GUI, I just now tried this.The version of OpenSim is 3.2.
No change has been made since then. I haven't modified the osim model file.
You mentioned "IKMarkerTask", I cannot find the element in the osim model file.
The osim model file is with "OpenSimDocument Version="20303", but when executing, the program shows "updating 20303 to lastest format". But if I use a "30000" version osim file, the problem is still the same.
I used "try catch", the program shows "no visualizer present".
Thanks and hope for your help!
Thanks & Regards,
Jack
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Visualization using OpenSim API
Please upload the files necessary to reproduce the error and I will try to investigate.
Re: Visualization using OpenSim API
Dear Uchida:tkuchida wrote:Please upload the files necessary to reproduce the error and I will try to investigate.
In the attachment please find the files concerned.
Another problem is the ScaleTool object, also with unhandled exception issues. The code is inside the file containing "main()";
Thanks & Best Regards,
Jack
- Attachments
-
- The relevant files.zip
- (521.17 KiB) Downloaded 20 times
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Visualization using OpenSim API
The following works in MATLAB using OpenSim 3.3:
I also confirmed that the model opens successfully in the OpenSim 3.2 GUI, so I doubt the issue is with the model file. Why the debugger indicates that _filename is "Whether or not this task will be used during inverse kinematics solve" isn't clear, as that text doesn't appear in the model file.
I have two hypotheses at this point:
1. There is some issue due to the locale settings (e.g., see viewtopicPhpbb.php?f=91&t=2937).
2. You are building against incompatible libraries (32- vs. 64-bit) or an incompatible version of Visual Studio.
Before proceeding further, I suggest trying some of the API examples (e.g., http://simtk-confluence.stanford.edu:80 ... Simulation) to ensure they build correctly. You may want to upgrade to OpenSim 3.3 as well, unless you have a particular reason for sticking with 3.2.
Code: Select all
import org.opensim.modeling.*;
model = Model('London Lower Limb Model.osim');
model.setUseVisualizer(1);
state = model.initSystem();
model.getVisualizer().show(state);
I have two hypotheses at this point:
1. There is some issue due to the locale settings (e.g., see viewtopicPhpbb.php?f=91&t=2937).
2. You are building against incompatible libraries (32- vs. 64-bit) or an incompatible version of Visual Studio.
Before proceeding further, I suggest trying some of the API examples (e.g., http://simtk-confluence.stanford.edu:80 ... Simulation) to ensure they build correctly. You may want to upgrade to OpenSim 3.3 as well, unless you have a particular reason for sticking with 3.2.
Re: Visualization using OpenSim API
tkuchida wrote:The following works in MATLAB using OpenSim 3.3:I also confirmed that the model opens successfully in the OpenSim 3.2 GUI, so I doubt the issue is with the model file. Why the debugger indicates that _filename is "Whether or not this task will be used during inverse kinematics solve" isn't clear, as that text doesn't appear in the model file.Code: Select all
import org.opensim.modeling.*; model = Model('London Lower Limb Model.osim'); model.setUseVisualizer(1); state = model.initSystem(); model.getVisualizer().show(state);
I have two hypotheses at this point:
1. There is some issue due to the locale settings (e.g., see viewtopicPhpbb.php?f=91&t=2937).
2. You are building against incompatible libraries (32- vs. 64-bit) or an incompatible version of Visual Studio.
Before proceeding further, I suggest trying some of the API examples (e.g., http://simtk-confluence.stanford.edu:80 ... Simulation) to ensure they build correctly. You may want to upgrade to OpenSim 3.3 as well, unless you have a particular reason for sticking with 3.2.
Dear Uchida:
I changed the locale setting but the problem is still the same. My opensim 3.2 is 64bit version and Visual Studio 2010 is with compile x64 setting.
These are both checked ok and none of them is relevant to the problem.
According to your instructions, I tested the API example you provided of "perform a simulation". Importantly, I found the blocks are not visualized while in the example webpage, they are visualized.
What's more, problem emerges in "modelCoordinateSet[3].setValue(si, blockSideLength);" when unhandled exception happens.
Most importantly, when breaking off the program for debugging, I found the osimModel object has errors (red exclamation marks, cannot calculate their values) in the gravity, bodyset member variables, although the following codes have been performed:
"osimModel.addBody(block);
osimModel.setGravity(Vec3(0,-9.80665,0));"
It means that the bodies and gravity values are not successfully set in the osimModel object at all !
Maybe the problem happens at the construction of osimModel object. But I cannot locate where to solve it?
Thanks & Regards,
Jack
- Thomas Uchida
- Posts: 1789
- Joined: Wed May 16, 2012 11:40 am
Re: Visualization using OpenSim API
Another thought: I don't think the packaged installers include Debug libraries. Have you been building in Debug mode or are these issues present when building in Release mode as well?