Commit 51c5d7bd authored by Sreekanth Arikatla's avatar Sreekanth Arikatla

ENH: Display fps on the screen along with the render fps

parent fa7d2f16
......@@ -166,6 +166,12 @@ public:
///
void reset();
///
/// \brief Set/Get the FPS
///
void setFPS(const size_t fps) { m_fps = fps; }
size_t getFPS() { return m_fps; }
protected:
std::string m_name; ///> Name of the scene
......@@ -178,6 +184,8 @@ protected:
std::vector<std::shared_ptr<SolverBase>> m_solvers; ///> List of non-linear solvers
std::vector<std::shared_ptr<SceneObjectControllerBase>> m_objectControllers; ///> List of controllers
size_t m_fps = 0;
bool m_isInitialized = false;
};
} // imstk
......
......@@ -83,18 +83,29 @@ VTKInteractorStyle::OnTimer()
// Update framerate value display
auto now = std::chrono::high_resolution_clock::now();
double fps = 1e6/(double)std::chrono::duration_cast<std::chrono::microseconds>(now - m_pre).count();
double fps = 1e6 / (double)std::chrono::duration_cast<std::chrono::microseconds>(now - m_pre).count();
fps = 0.1 * fps + 0.9 * m_lastFps;
m_lastFps = fps;
int t = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_lastFpsUpdate).count();
if (t > 100) //wait 100ms before updating displayed value
if (t > 250) //wait 250ms before updating displayed value
{
std::string fpsStr = std::to_string((int)fps) + " fps";
m_fpsActor->SetInput(fpsStr.c_str());
std::string fpsVisualStr = "V: " + std::to_string((int)fps);
std::string fpsPhysicalStr;
if (m_simManager->getStatus() != SimulationStatus::PAUSED)
{
fpsPhysicalStr = "P: " + std::to_string((int)m_simManager->getActiveScene()->getFPS());
}
else
{
fpsPhysicalStr = "P: PAUSED";
}
m_fpsActor->SetInput((fpsVisualStr + std::string(" | ") + fpsPhysicalStr).c_str());
m_lastFpsUpdate = now;
}
m_pre = now;
// Render
this->Interactor->Render();
m_post = std::chrono::high_resolution_clock::now();
......
......@@ -180,6 +180,8 @@ SceneManager::runModule()
}
}
}
m_scene->setFPS((size_t)(1./wwt.getTimeElapsed(StopWatch::TimeUnitType::seconds)));
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment