[osg-users] osgUtil::LineSegmentIntersector performance issues

Andrea Martini martini.andrea at gmail.com
Tue Dec 4 08:10:09 PST 2018


Hello everyone,
i spent my last weeks to find a reasonable cause concerning osgUtil::LineSegmentIntersector on some osgt file.
In detail, i would like to identify objects in the scene, using line isector (ray casting) starting from a certain point with a ray of 3 meter length .
Following the code i used for detecting object in front of camera (i'm using osg 3.5.3 and Oculus Rift device)


Code:


osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(startPoint, endPoint); 		

osgUtil::IntersectionVisitor iv(intersector.get());

//intersector->setIntersectionLimit(osgUtil::Intersector::LIMIT_NEAREST);
//intersector->setPrecisionHint(osgUtil::Intersector::PrecisionHint::USE_FLOAT_CALCULATIONS);

//for debugging: evaluation of visitor processing time
osg::Timer_t timer_tstart = mGlobalHighResTimer->tick();

iv.setTraversalMask(vrGame::INTERACTIVE);

subgraph->accept(iv);


//for debugging: evaluation of visitor processing time
osg::Timer_t timer_tend = mGlobalHighResTimer->tick();
double  timer_tfinal = mGlobalHighResTimer->delta_m(timer_tstart, timer_tend);
std::cout << " Collision Visitor Time Computed :  " << std::to_string(timer_tfinal) << std::endl;
		





This code works correctly in terms of dected object but some times i noticed low performance when camera points in a space region near the object but not on its geometry. I mean, if camera points the geometry of the object, performance is ok. When camera points near the object (on an empty region) but not on its geometry, performance drop down.

Some numbers: When camera points on empty area near the object, Oculus passes from 90Hz to 45Hz framerate and the computation of 

subgraph->accept(iv);

requires from 2.8 to 4 milliseconds for each frame. 
I also investigated on osgUtil::IntersectionVisitor class, and it seems that (in my specific situation), 

IntersectionVisitor::apply(osg::Transform& transform) 

needs from 2.8 to 4 ms computation time when processes the following code lines:

 // now push an new intersector clone transform to the new local oordinates
    push_clone();
    traverse(transform);
    // pop the clone.
    pop_clone();



Another doubt is related to why, even if i set 

iv.setTraversalMask(0x0001001)

for avoiding to process nodes which have that mask (and the investigated object has this mask), visitor continues to process at each frame something that requires a lot computation time.

The object comes from blender (osgt export), and has One group as root, a MatrixTransform as child, a Geode as child and 3 drawables with 64K vertices on the whole. The osgt file has 18 Mbytes size


My question is: Is there some solution I might adopt to improve these performances? Can you give me some suggestions?


Thank you!

Cheers,
Andrea

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75275#75275







More information about the osg-users mailing list