void showNodeNames() { osgViewer::ViewerBase::Scenes viewerScenes; osgViewer::Scene* scene; ShowNodeNamesVisitor snnv( true ); viewer.getScenes(viewerScenes, true); for (osgViewer::ViewerBase::Scenes::iterator it = viewerScenes.begin(); it!=viewerScenes.end(); ++it) { scene = *it; osg::Node* node = scene->getSceneData(); node->accept( snnv ); } }
void dumpSceneToDisk() { std::string filename = "dump"; osgViewer::ViewerBase::Scenes viewerScenes; osgViewer::Scene* scene; viewer.getScenes(viewerScenes, true); for (osgViewer::ViewerBase::Scenes::iterator it = viewerScenes.begin(); it!=viewerScenes.end(); ++it) { scene = *it; osg::Node* node = scene->getSceneData(); bool result = osgDB::writeNodeFile(*node, filename + ".osg" ); if ( !result ) osg::notify(osg::FATAL) << "Failed in osgDB::writeNodeFile()." << std::endl; } }
int Metrics::run(osgViewer::Viewer& viewer) { if (Metrics::enabled()) { if (!viewer.isRealized()) { viewer.realize(); } // If Metrics are enabled, enable stats on the Viewer so that it we can report them for the Metrics if (Metrics::enabled()) { osgViewer::ViewerBase::Scenes scenes; viewer.getScenes(scenes); for (osgViewer::ViewerBase::Scenes::iterator itr = scenes.begin(); itr != scenes.end(); ++itr) { osgViewer::Scene* scene = *itr; osgDB::DatabasePager* dp = scene->getDatabasePager(); if (dp && dp->isRunning()) { dp->resetStats(); } } viewer.getViewerStats()->collectStats("frame_rate", true); viewer.getViewerStats()->collectStats("event", true); viewer.getViewerStats()->collectStats("update", true); viewer.getCamera()->getStats()->collectStats("rendering", true); viewer.getCamera()->getStats()->collectStats("gpu", true); } // Report memory and fps every 10 frames. unsigned int reportEvery = 10; while (!viewer.done()) { { METRIC_SCOPED_EX("frame", 1, "number", toString<int>(viewer.getFrameStamp()->getFrameNumber()).c_str()); { METRIC_SCOPED("advance"); viewer.advance(); } { METRIC_SCOPED("event"); viewer.eventTraversal(); } { METRIC_SCOPED("update"); viewer.updateTraversal(); } { METRIC_SCOPED("render"); viewer.renderingTraversals(); } } // Report memory and fps periodically. periodically. if (viewer.getFrameStamp()->getFrameNumber() % reportEvery == 0) { // Only report the metrics if they are enabled to avoid computing the memory. if (Metrics::enabled()) { Metrics::counter("Memory::WorkingSet", "WorkingSet", Memory::getProcessPhysicalUsage() / 1048576); Metrics::counter("Memory::PrivateBytes", "PrivateBytes", Memory::getProcessPrivateUsage() / 1048576); Metrics::counter("Memory::PeakPrivateBytes", "PeakPrivateBytes", Memory::getProcessPeakPrivateUsage() / 1048576); } } double eventTime = 0.0; if (viewer.getViewerStats()->getAttribute(viewer.getViewerStats()->getLatestFrameNumber(), "Event traversal time taken", eventTime)) { Metrics::counter("Viewer::Event", "Event", eventTime * 1000.0); } double updateTime = 0.0; if (viewer.getViewerStats()->getAttribute(viewer.getViewerStats()->getLatestFrameNumber(), "Update traversal time taken", updateTime)) { Metrics::counter("Viewer::Update", "Update", updateTime * 1000.0); } double cullTime = 0.0; if (viewer.getCamera()->getStats()->getAttribute(viewer.getCamera()->getStats()->getLatestFrameNumber(), "Cull traversal time taken", cullTime)) { Metrics::counter("Viewer::Cull", "Cull", cullTime * 1000.0); } double drawTime = 0.0; if (viewer.getCamera()->getStats()->getAttribute(viewer.getCamera()->getStats()->getLatestFrameNumber(), "Draw traversal time taken", drawTime)) { Metrics::counter("Viewer::Draw", "Draw", drawTime * 1000.0); } double gpuTime = 0.0; if (viewer.getCamera()->getStats()->getAttribute(viewer.getCamera()->getStats()->getLatestFrameNumber()-1, "GPU draw time taken", gpuTime)) { Metrics::counter("Viewer::GPU", "GPU", gpuTime * 1000.0); } double frameRate = 0.0; if (viewer.getViewerStats()->getAttribute(viewer.getViewerStats()->getLatestFrameNumber() - 1, "Frame rate", frameRate)) { Metrics::counter("Viewer::FPS", "FPS", frameRate); } } return 0; } else { return viewer.run(); } }