Added support for compute average stats attributes in inverse space to improve

the quality of frame rate reporting.
This commit is contained in:
Robert Osfield 2007-01-30 13:48:04 +00:00
parent 6acd0e89a1
commit b8d98a2cfe
3 changed files with 19 additions and 16 deletions

View File

@ -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;

View File

@ -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 (endFrameNumber<startFrameNumber)
{
@ -99,13 +99,15 @@ bool Stats::getAveragedAttribute(int startFrameNumber, int endFrameNumber, const
double v = 0.0;
if (getAttribute(i,attributeName,v))
{
total += v;
if (averageInInverseSpace) total += 1.0/v;
else total += v;
numValidSamples += 1.0;
}
}
if (numValidSamples>0.0)
{
value = total/numValidSamples;
if (averageInInverseSpace) value = numValidSamples/total;
else value = total/numValidSamples;
return true;
}
else return false;

View File

@ -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);