Added --kdtree command line option and associated invocation of KdTreeBuilder to enable benchmarking.

Added timing stats code.
This commit is contained in:
Robert Osfield
2017-04-19 10:20:01 +01:00
parent 728a7f2225
commit b77301350b

View File

@@ -20,6 +20,7 @@
// example that provides the user with control over view position with basic picking.
#include <osg/Timer>
#include <osg/KdTree>
#include <osg/io_utils>
#include <osg/observer_ptr>
@@ -205,6 +206,7 @@ public:
osg::Node* node = 0;
osg::Group* parent = 0;
if (_usePolytopeIntersector)
{
osgUtil::PolytopeIntersector* picker;
@@ -229,8 +231,12 @@ public:
}
osgUtil::IntersectionVisitor iv(picker);
osg::ElapsedTime elapsedTime;
viewer->getCamera()->accept(iv);
OSG_NOTICE<<"PoltyopeIntersector traversal took "<<elapsedTime.elapsedTime_m()<<"ms"<<std::endl;
if (picker->containsIntersections())
{
osgUtil::PolytopeIntersector::Intersection intersection = picker->getFirstIntersection();
@@ -269,8 +275,12 @@ public:
}
osgUtil::IntersectionVisitor iv(picker);
osg::ElapsedTime elapsedTime;
viewer->getCamera()->accept(iv);
OSG_NOTICE<<"LineSegmentIntersector traversal took "<<elapsedTime.elapsedTime_m()<<"ms"<<std::endl;
if (picker->containsIntersections())
{
osgUtil::LineSegmentIntersector::Intersection intersection = picker->getFirstIntersection();
@@ -338,10 +348,14 @@ protected:
int main( int argc, char **argv )
{
osg::ref_ptr<osg::Node> loadedModel;
osg::ArgumentParser arguments(&argc, argv);
// load the scene.
if (argc>1) loadedModel = osgDB::readRefNodeFile(argv[1]);
bool useKdTree = false;
while (arguments.read("--kdtree")) { useKdTree = true; }
// load model
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
// if not loaded assume no arguments passed in, try use default mode instead.
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("dumptruck.osgt");
@@ -352,6 +366,14 @@ int main( int argc, char **argv )
return 1;
}
if (useKdTree)
{
OSG_NOTICE<<"Buildering KdTrees"<<std::endl;
osg::ref_ptr<osg::KdTreeBuilder> builder = new osg::KdTreeBuilder;
loadedModel->accept(*builder);
}
// create the window to draw to.
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 200;