API Visualizer doesn't render output for the "Performing a Simulation" example [OpenSim 3.3]

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Lucas Wolf
Posts: 3
Joined: Sun Sep 03, 2017 12:25 am

API Visualizer doesn't render output for the "Performing a Simulation" example [OpenSim 3.3]

Post by Lucas Wolf » Mon Sep 11, 2017 6:08 am

Hi all,

I am new to OpenSim and recently compiled version 3.3 on Linux (Ubuntu Xenial 16.04) with Simbody 3.5.4. Now I am trying to reproduce the "Performing a Simulation" example (https://simtk-confluence.stanford.edu/d ... Simulation). I followed the tutorial until including the "Get the Model's Ground Body" section (see code below) and copied the .vtp-files into the project directory.

As I understand it, the Windows GUI is not available on Linux, thus I tried to use the API Visualizer (as outlined in https://simtk-confluence.stanford.edu/d ... Visualizer). Now, when I compile and execute the code, the visualizer window opens, but not geometry is rendered. I merely get a blank screen with the "View" and "Show" menus.

Here is the code:

Code: Select all

#include <OpenSim/OpenSim.h>
 
using namespace OpenSim;
 
int main() {
 
    try {
        // Create an OpenSim model and set its name
        Model osimModel;
        osimModel.setUseVisualizer(true);
 
        ModelDisplayHints &displayHints = osimModel.updDisplayHints();
        displayHints.setShowWrapGeometry(true)
                    .setShowContactGeometry(true)
                    .setShowMusclePaths(true)
                    .setShowPathPoints(true)
                    .setShowMarkers(true)
                    .setShowForces(true)
                    .setShowFrames(true)
                    .setShowLabels(true)
                    .setShowDebugGeometry(true);
 
        osimModel.setName("tugOfWar");
 
        // Get a reference to the model's ground body
        OpenSim::Body& ground = osimModel.getGroundBody();
 
        // Add display geometry to the ground to visualize
        ground.addDisplayGeometry("ground.vtp");
        ground.addDisplayGeometry("anchor1.vtp");
        ground.addDisplayGeometry("anchor2.vtp");
 
        osimModel.print("tugOfWar_model.osim");
 
        osimModel.initSystem();
 
 
        std::cin.get();
    } catch (OpenSim::Exception ex) {
        std::cout << ex.getMessage() << std::endl;
        return 1;
    }
   
    std::cout << "OpenSim example completed successfully.\n";
    return 0;
}
Where did I go wrong? Or is this behaviour expected?

Thanks in advance. Any help is appreciated.

Lucas

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

Re: API Visualizer doesn't render output for the "Performing a Simulation" example [OpenSim 3.3]

Post by Thomas Uchida » Mon Sep 11, 2017 10:50 am

I think you need to send a State to the visualizer:
SimTK::State& state = osimModel.initSystem();
osimModel.getVisualizer().show(state);
See VisualizeModel.cpp (https://github.com/opensim-org/opensim- ... eModel.cpp).

User avatar
Lucas Wolf
Posts: 3
Joined: Sun Sep 03, 2017 12:25 am

Re: API Visualizer doesn't render output for the "Performing a Simulation" example [OpenSim 3.3]

Post by Lucas Wolf » Mon Sep 11, 2017 10:54 am

Perfect, that solved it.

Thank you very much!

POST REPLY