Visualizer API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Andrew Stolin
Posts: 12
Joined: Thu Mar 05, 2015 9:41 am

Visualizer API

Post by Andrew Stolin » Tue Jun 30, 2015 2:49 pm

Hi all,

I am trying to get the visualizer to simply show the initial position of a model

The g++ command I am using is the following:

g++ -o testmake -I./ -I/usr/local/sdk/include/ -I/usr/local/lib TugOfWar1_CreateModel.cpp -L/usr/local/sdk/include/ -l osimCommon -l osimSimulation -l osimActuators -l osimAnalyses -l osimTools

And the simple cpp file is:

Code: Select all

//==============================================================================
# include <OpenSim/OpenSim.h>
# include </usr/local/sdk/include/Vendors/lepton/include/Lepton.h>
# include <OpenSim/Simulation/Model/ModelVisualizer.h>

using namespace OpenSim;
using namespace SimTK;

//______________________________________________________________________________

int main()
{


     Model osimModel( "tugOfWar_model_ThelenOnly.osim" );

     osimModel.setUseVisualizer(true);
  
     osimModel.initSystem();


}
The window shows up (blank) and closes immediately. I get the following in the terminal:

Code: Select all

Loaded model osimModel from file tugOfWar_model_ThelenOnly.osim
OpenSim example completed successfully.

VisualizerGUI: received Shutdown message. Goodbye.

I then tried to call the API from python

Code: Select all

from opensim import *
# import the model
osimModel = Model("tugOfWar_model_ThelenOnly.osim")
# Set the Visualizer
osimModel.setUseVisualizer(true);
# Initialize the system
si = osimModel.initSystem()
but get the following error:

Code: Select all

osimModel.setUseVisualizer(true);
NameError: name 'true' is not defined
Any hints?

Thank you in advance

User avatar
Claudio Pizzolato
Posts: 48
Joined: Sat Apr 30, 2011 7:05 am

Re: Visualizer API

Post by Claudio Pizzolato » Tue Jun 30, 2015 6:25 pm

The problem is that your main exits after initSystem.

try something like this, and see how it goes (I haven't tried to compile, but should work).

Code: Select all

int main()
{
     OpenSim::Model osimModel( "tugOfWar_model_ThelenOnly.osim" );
     osimModel.setUseVisualizer(true);
     SimTK::State& s(osimModel.initSystem());
     OpenSim::ModelVisualizer& mV(model_.updVisualizer());
     mV.updSimbodyVisualizer().drawFrameNow(s);
     getchar();
     return 0;
}
Claudio

User avatar
Andrew Stolin
Posts: 12
Joined: Thu Mar 05, 2015 9:41 am

Re: Visualizer API

Post by Andrew Stolin » Wed Jul 01, 2015 1:20 am

Thank you very much for your answer.
I did try to pause the program after initSystem but it left me with the same white window.

I tried to compile your code but I got:

Code: Select all

error: ‘model_’ was not declared in this scope
      OpenSim::ModelVisualizer& mV(model_.updVisualizer());

User avatar
Claudio Pizzolato
Posts: 48
Joined: Sat Apr 30, 2011 7:05 am

Re: Visualizer API

Post by Claudio Pizzolato » Wed Jul 01, 2015 1:29 am

fransim wrote:Thank you very much for your answer.
I did try to pause the program after initSystem but it left me with the same white window.

I tried to compile your code but I got:

Code: Select all

error: ‘model_’ was not declared in this scope
      OpenSim::ModelVisualizer& mV(model_.updVisualizer());

Sorry, I just copy-pasted from some script that is sitting around my pc and I forgot to change a variable name. This works, I've checked.

Code: Select all

int main()
{
    OpenSim::Model osimModel(osimModelFilename);
    osimModel.setUseVisualizer(true);
    SimTK::State& s(osimModel.initSystem());
    OpenSim::ModelVisualizer& mV(osimModel.updVisualizer());
    mV.updSimbodyVisualizer().drawFrameNow(s);
    getchar();
     return 0;
}

User avatar
Andrew Stolin
Posts: 12
Joined: Thu Mar 05, 2015 9:41 am

Re: Visualizer API

Post by Andrew Stolin » Wed Jul 01, 2015 2:51 am

It does seem to work, thank you!

It still doesn't want to compile but I think that's because I am not including some libraries in the compilation. That's an other problem!

Code: Select all

/usr/bin/ld: /tmp/cco9ybJX.o: undefined reference to symbol '_ZNK5SimTK10Visualizer12drawFrameNowERKNS_5StateE'
//usr/local/lib/libSimTKsimbody.so.3.3: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

POST REPLY