Visualizer frame rate capped at 90fps
Posted: Thu Jun 26, 2014 12:33 am
Hello forum!
I've been playing around with the visualizer in the latest days. For testing purposes I'm trying to achieve the highest fps possible on the visualizer. I've created a little script that generates a single sphere which motion is prescribed through some simple equations. No dynamics, integration or other fancy things.
This is the code I've been using, tested on different machines, and on both linux and win7.
As you can see there's a while cycle that tries to generate as more frame as possible. Since the geometry is simple I would expect to have really high fps, however I get limited at 90. I've already disabled the vsync on my graphic card, and in this way I've managed to move from 60 to 90 fps. I've also tested the three different modes (Visualizer::Mode), and tried both drawFrameNow() and report().
I looked at the visualizer code, but I couldn't find any hardcoded frame rate limiter. Does anyone have any idea of what could be the cause? Am I doing something in the wrong way?
I've been playing around with the visualizer in the latest days. For testing purposes I'm trying to achieve the highest fps possible on the visualizer. I've created a little script that generates a single sphere which motion is prescribed through some simple equations. No dynamics, integration or other fancy things.
This is the code I've been using, tested on different machines, and on both linux and win7.
Code: Select all
#include "Simbody.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <chrono>
#include <thread>
#include <fstream>
int main() {
SimTK::MultibodySystem system;
SimTK::SimbodyMatterSubsystem matter(system);
SimTK::Body::Rigid sphereBody;
sphereBody.addDecoration(SimTK::Transform(), SimTK::DecorativeSphere(SimTK::Real(0.1)).setColor(SimTK::Red));
SimTK::MobilizedBody::Free freeSphere(matter.updGround(), sphereBody);
SimTK::Visualizer viz(system);
viz.setShowFrameRate(true);
viz.setBackgroundType(SimTK::Visualizer::BackgroundType::SolidColor);
viz.setBackgroundColor(SimTK::Black);
viz.setMode(SimTK::Visualizer::Mode::RealTime);
viz.setShutdownWhenDestructed(true);
viz.setDesiredBufferLengthInSec(0);
system.realizeTopology();
SimTK::State state = system.getDefaultState();
freeSphere.setQ(state, SimTK::Vec7(0, 0, 0, 1, 1, 1, 0));
system.realize(state);
viz.report(state);
std::ofstream outF("dumpStats.txt");
viz.setDesiredFrameRate(200);
unsigned nFrames(0), frameCounter(0);
unsigned timeStepMilliseconds = 5;
auto start = std::chrono::system_clock::now();
while (1) {
double x(sin(nFrames*timeStepMilliseconds*1e-3));
double y(cos(nFrames*timeStepMilliseconds*1e-3));
double z((x + y) / 2);
freeSphere.setQToFitTranslation(state, SimTK::Vec3(x, y, z));
// viz.report(state);
viz.drawFrameNow(state);
viz.dumpStats(outF);
++frameCounter;
++nFrames;
// std::this_thread::sleep_for(std::chrono::milliseconds(timeStepMilliseconds));
if ((std::chrono::duration_cast<std::chrono::milliseconds >(std::chrono::system_clock::now() - start)) > std::chrono::milliseconds(1000)) {
std::cout << "\n" << frameCounter << "\n";
start = std::chrono::system_clock::now();
frameCounter = 0;
}
}
return 0;
}
I looked at the visualizer code, but I couldn't find any hardcoded frame rate limiter. Does anyone have any idea of what could be the cause? Am I doing something in the wrong way?