Page 1 of 1

C++ API Visualizer

Posted: Tue Mar 20, 2018 3:03 am
by dimitra
Hello,

I was wondering if you could help me with the API visualizer. I have used it through the Matlab API before, but I now need it in C++ and I can't get it to work...

Here are the relevant steps in Matlab:

Code: Select all

osimModel = Model('my_model.osim');
osimModel.setUseVisualizer(true);

state = osimModel.initSystem;
osim_viz = osimModel.updVisualizer;
osim_viz.show(state);
Then I have a loop where I update the coordinate values and muscle activations in the state (based on an external device), and I call
osim_viz.show(state);
at every iteration to display the new model position + colour of muscles. It works fine.

In C++, I've done:

Code: Select all

Model osimModel("my_model.osim");
osimModel.setUseVisualizer(true);
osimModel.buildSystem();

SimTK::State& state = osimModel.initializeState();
OpenSim::ModelVisualizer& osim_viz = osimModel.updVisualizer();
osim_viz.show(state);
If I run that, a visualizer window opens and closes very quickly, and I get a very polite message (not an error message) that says: "simbody-visualizer: received Shutdown message. Goodbye."

Any help would be greatly appreciated!

Best wishes,
Dimitra

Re: C++ API Visualizer

Posted: Tue Mar 20, 2018 8:27 am
by chrisdembia
Add the following to the end of your code:

Code: Select all

std::cin.get()

Re: C++ API Visualizer

Posted: Thu Mar 22, 2018 7:42 am
by dimitra
Thank you very much Chris! :D