Visualization using OpenSim API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Visualization using OpenSim API

Post by Jack Zhao » Sun Jul 23, 2017 6:56 am

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!

User avatar
Thomas Uchida
Posts: 1789
Joined: Wed May 16, 2012 11:40 am

Re: Visualization using OpenSim API

Post by Thomas Uchida » Sun Jul 23, 2017 1:00 pm

No visualization happens.
That is the expected behavior; initSystem() does not generate visualization.
If I add the code "osimModel.getVisualizer().show(stat);", unhandled exception error of VC++ 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.

User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Re: Visualization using OpenSim API

Post by Jack Zhao » Sun Jul 23, 2017 8:32 pm

tkuchida wrote:
No visualization happens.
That is the expected behavior; initSystem() does not generate visualization.
If I add the code "osimModel.getVisualizer().show(stat);", unhandled exception error of VC++ 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.

Dear Dr Uchida:
Thank you so much for your reply!
I replaced with State&, but the problem is still the same. :shock:
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.
Problem.jpg
Problem.jpg (162.06 KiB) Viewed 714 times

Thanks & Regards.
Jack

User avatar
Thomas Uchida
Posts: 1789
Joined: Wed May 16, 2012 11:40 am

Re: Visualization using OpenSim API

Post by Thomas Uchida » Mon Jul 24, 2017 2:19 am

The constructed model object's member "_fileName" is "whether or not this task will be used during inverse kinematic slove"!
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).

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?

User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Re: Visualization using OpenSim API

Post by Jack Zhao » Mon Jul 24, 2017 4:26 am

tkuchida wrote:
The constructed model object's member "_fileName" is "whether or not this task will be used during inverse kinematic slove"!
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).

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

User avatar
Thomas Uchida
Posts: 1789
Joined: Wed May 16, 2012 11:40 am

Re: Visualization using OpenSim API

Post by Thomas Uchida » Mon Jul 24, 2017 10:51 am

Please upload the files necessary to reproduce the error and I will try to investigate.

User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Re: Visualization using OpenSim API

Post by Jack Zhao » Mon Jul 24, 2017 8:31 pm

tkuchida wrote:Please upload the files necessary to reproduce the error and I will try to investigate.
Dear Uchida:
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

User avatar
Thomas Uchida
Posts: 1789
Joined: Wed May 16, 2012 11:40 am

Re: Visualization using OpenSim API

Post by Thomas Uchida » Mon Jul 24, 2017 10:45 pm

The following works in MATLAB using OpenSim 3.3:

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 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.

User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Re: Visualization using OpenSim API

Post by Jack Zhao » Tue Jul 25, 2017 5:48 am

tkuchida wrote:The following works in MATLAB using OpenSim 3.3:

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 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.




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

User avatar
Thomas Uchida
Posts: 1789
Joined: Wed May 16, 2012 11:40 am

Re: Visualization using OpenSim API

Post by Thomas Uchida » Tue Jul 25, 2017 3:36 pm

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?

POST REPLY