From b8d98a2cfe030d1a955a51cb4b0db74a63913229 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 30 Jan 2007 13:48:04 +0000 Subject: [PATCH] Added support for compute average stats attributes in inverse space to improve the quality of frame rate reporting. --- include/osg/Stats | 4 ++-- src/osg/Stats.cpp | 12 +++++++----- src/osgViewer/StatsHandler.cpp | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/osg/Stats b/include/osg/Stats index f0e75f4b5..b99b1f903 100644 --- a/include/osg/Stats +++ b/include/osg/Stats @@ -43,8 +43,8 @@ class OSG_EXPORT Stats : public osg::Referenced bool setAttribute(int frameNumber, const std::string& attributeName, double value); bool getAttribute(int frameNumber, const std::string& attributeName, double& value) const; - bool getAveragedAttribute(const std::string& attributeName, double& value) const; - bool getAveragedAttribute(int startFrameNumber, int endFrameNumber, const std::string& attributeName, double& value) const; + bool getAveragedAttribute(const std::string& attributeName, double& value, bool averageInInverseSpace=false) const; + bool getAveragedAttribute(int startFrameNumber, int endFrameNumber, const std::string& attributeName, double& value, bool averageInInverseSpace=false) const; AttributeMap& getAttributeMap(int frameNumber); const AttributeMap& getAttributeMap(int frameNumber) const; diff --git a/src/osg/Stats.cpp b/src/osg/Stats.cpp index f047176a7..3626093ed 100644 --- a/src/osg/Stats.cpp +++ b/src/osg/Stats.cpp @@ -80,12 +80,12 @@ bool Stats::getAttribute(int frameNumber, const std::string& attributeName, doub return true; } -bool Stats::getAveragedAttribute(const std::string& attributeName, double& value) const +bool Stats::getAveragedAttribute(const std::string& attributeName, double& value, bool averageInInverseSpace) const { - return getAveragedAttribute(getEarliestFrameNumber(), getLatestFrameNumber(), attributeName, value); + return getAveragedAttribute(getEarliestFrameNumber(), getLatestFrameNumber(), attributeName, value, averageInInverseSpace); } -bool Stats::getAveragedAttribute(int startFrameNumber, int endFrameNumber, const std::string& attributeName, double& value) const +bool Stats::getAveragedAttribute(int startFrameNumber, int endFrameNumber, const std::string& attributeName, double& value, bool averageInInverseSpace) const { if (endFrameNumber0.0) { - value = total/numValidSamples; + if (averageInInverseSpace) value = numValidSamples/total; + else value = total/numValidSamples; return true; } else return false; diff --git a/src/osgViewer/StatsHandler.cpp b/src/osgViewer/StatsHandler.cpp index 13a7f44ba..554cd0ffa 100644 --- a/src/osgViewer/StatsHandler.cpp +++ b/src/osgViewer/StatsHandler.cpp @@ -190,14 +190,14 @@ void StatsHandler::setUpHUDCamera(osgViewer::Viewer* viewer) struct TextDrawCallback : public virtual osg::Drawable::DrawCallback { - TextDrawCallback(osg::Stats* stats, const std::string& name, int frameDelta, double multiplier = 1.0): + TextDrawCallback(osg::Stats* stats, const std::string& name, int frameDelta, bool averageInInverseSpace, double multiplier): _stats(stats), _attributeName(name), _frameDelta(frameDelta), + _averageInInverseSpace(averageInInverseSpace), _multiplier(multiplier), _tickLastUpdated(0) { - _tickLastUpdated = osg::Timer::instance()->tick(); } /** do customized draw code.*/ @@ -212,7 +212,7 @@ struct TextDrawCallback : public virtual osg::Drawable::DrawCallback { _tickLastUpdated = tick; double value; - if (_stats->getAveragedAttribute( _attributeName, value)) + if (_stats->getAveragedAttribute( _attributeName, value, _averageInInverseSpace)) { sprintf(_tmpText,"%4.2f",value * _multiplier); text->setText(_tmpText); @@ -229,6 +229,7 @@ struct TextDrawCallback : public virtual osg::Drawable::DrawCallback osg::Stats* _stats; std::string _attributeName; int _frameDelta; + bool _averageInInverseSpace; double _multiplier; mutable char _tmpText[128]; mutable osg::Timer_t _tickLastUpdated; @@ -502,7 +503,7 @@ void StatsHandler::setUpScene(osgViewer::Viewer* viewer) frameRateValue->setPosition(pos); frameRateValue->setText("0.0"); - frameRateValue->setDrawCallback(new TextDrawCallback(viewer->getStats(),"Frame rate",-1)); + frameRateValue->setDrawCallback(new TextDrawCallback(viewer->getStats(),"Frame rate",-1, true, 1.0)); pos.y() -= characterSize*1.5f; @@ -543,7 +544,7 @@ void StatsHandler::setUpScene(osgViewer::Viewer* viewer) eventValue->setPosition(pos); eventValue->setText("0.0"); - eventValue->setDrawCallback(new TextDrawCallback(viewer->getStats(),"Event traversal time taken",-1, 1000.0)); + eventValue->setDrawCallback(new TextDrawCallback(viewer->getStats(),"Event traversal time taken",-1, false, 1000.0)); pos.x() = startBlocks; osg::Geometry* geometry = createGeometry(pos, characterSize *0.8, colorUpdateAlpha, _numBlocks); @@ -576,7 +577,7 @@ void StatsHandler::setUpScene(osgViewer::Viewer* viewer) updateValue->setPosition(pos); updateValue->setText("0.0"); - updateValue->setDrawCallback(new TextDrawCallback(viewer->getStats(),"Update traversal time taken",-1, 1000.0)); + updateValue->setDrawCallback(new TextDrawCallback(viewer->getStats(),"Update traversal time taken",-1, false, 1000.0)); pos.x() = startBlocks; osg::Geometry* geometry = createGeometry(pos, characterSize *0.8, colorUpdateAlpha, _numBlocks); @@ -684,7 +685,7 @@ osg::Node* StatsHandler::createCameraStats(const std::string& font, osg::Vec3& p cullValue->setPosition(pos); cullValue->setText("0.0"); - cullValue->setDrawCallback(new TextDrawCallback(stats,"Cull traversal time taken",-1, 1000.0)); + cullValue->setDrawCallback(new TextDrawCallback(stats,"Cull traversal time taken",-1, false, 1000.0)); pos.x() = startBlocks; osg::Geometry* geometry = createGeometry(pos, characterSize *0.8, colorCullAlpha, _numBlocks); @@ -717,7 +718,7 @@ osg::Node* StatsHandler::createCameraStats(const std::string& font, osg::Vec3& p drawValue->setPosition(pos); drawValue->setText("0.0"); - drawValue->setDrawCallback(new TextDrawCallback(stats,"Draw traversal time taken",-1, 1000.0)); + drawValue->setDrawCallback(new TextDrawCallback(stats,"Draw traversal time taken",-1, false, 1000.0)); pos.x() = startBlocks; @@ -752,7 +753,7 @@ osg::Node* StatsHandler::createCameraStats(const std::string& font, osg::Vec3& p gpuValue->setPosition(pos); gpuValue->setText("0.0"); - gpuValue->setDrawCallback(new TextDrawCallback(stats,"GPU draw time taken",-1, 1000.0)); + gpuValue->setDrawCallback(new TextDrawCallback(stats,"GPU draw time taken",-1, false, 1000.0)); pos.x() = startBlocks; osg::Geometry* geometry = createGeometry(pos, characterSize *0.8, colorGPUAlpha, _numBlocks);