OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

osgUtil::LineSegmentIntersector performance issues


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Andrea74
User


Joined: 24 Aug 2009
Posts: 82

PostPosted: Tue Dec 04, 2018 4:09 pm    Post subject:
osgUtil::LineSegmentIntersector performance issues
Reply with quote

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
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12215

PostPosted: Tue Dec 04, 2018 5:21 pm    Post subject:
osgUtil::LineSegmentIntersector performance issues
Reply with quote

Hi Andrea,


The osg::KdTree is design for the purpose of accelerating intersection testing.  What you need to do is run the KdTreeBuilder visitor on your subgraph to generate KdTree for each osg::Geometry in the subgraph, these then get assigned automaticaly to each osg::Geometry as a Shape.  The intersection traversals then automatically detect the KdTree when available and use it instead of the raw primitive data into the Geometry.


I would also strongly recommend upgrading 3.6.3, it even contains some nice improvement for KdTree building and intersections.



Robert.

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Andrea74
User


Joined: 24 Aug 2009
Posts: 82

PostPosted: Wed Dec 05, 2018 8:17 am    Post subject:
Reply with quote

Hi Robert,
thank you for your suggestion.
After using of :

osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::Options::BUILD_KDTREES);

and

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

intersector visitor performances are good again.

Now, the code:

subgraph->accept(iv);

requires (in the same scenes yesterday described) only 0.01 ms.


Thank you

Cheers,
Andrea
Back to top
View user's profile Send private message
Chris Hanson
Guest





PostPosted: Wed Dec 05, 2018 2:23 pm    Post subject:
osgUtil::LineSegmentIntersector performance issues
Reply with quote

Do you only need drawable-level discrimination? You can spend a lot of effort intersection testing each polygon on the CPU. You can also offload a lot of the work onto the GPU, but OSG doesn't do this for you. If you only need the ray hit closest to the Eye, you can also use a variant of Picking -- set a 1x1 pixel viewport around the ray frustum and shovel the geometry through the rasterizer to record which fragment is closest. With various techniques you can assign fragment IDs on whatever granularity (Drawable, polygon, or something else) you wish. This can be quite quick because the GPU is optimized to do this and you can rasterize to an FBO.

Maybe explain better what you are trying to ACCOMPLISH, rather than just the current technique you are trying to use to accomplish it. Many times people don't even know the right question to ask to get the best solution.


On Wed, Dec 5, 2018 at 9:18 AM Andrea Martini < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi Robert,
thank you for your suggestion.
After using of : 

osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::Options::BUILD_KDTREES);

and

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

intersector visitor performances are good again.

Now, the code:

subgraph->accept(iv);

requires (in the same scenes yesterday described) only 0.01 ms.


Thank you

Cheers,
Andrea

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





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



--
Chris 'Xenon' Hanson, omo sanza lettere. http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 • GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Forensics • Imaging • UAVs • GIS • GPS • osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile • iPhone/iPad/iOS • Android
@alphapixel facebook.com/alphapixel (775) 623-PIXL [7495]

------------------
Post generated by Mail2Forum
Back to top
Chris Hanson
Guest





PostPosted: Wed Dec 05, 2018 2:24 pm    Post subject:
osgUtil::LineSegmentIntersector performance issues
Reply with quote

Here's one take on the matter:

http://ogldev.atspace.co.uk/www/tutorial29/tutorial29.html

------------------
Post generated by Mail2Forum
Back to top
Andrea74
User


Joined: 24 Aug 2009
Posts: 82

PostPosted: Wed Dec 05, 2018 4:47 pm    Post subject:
Reply with quote

Hi Chris Hanson,
thank you for your suggestion and your advanced solution.
However, the Robert Osfield's answer solved completely issues concerning my unclear question.
At the moment i find very hard to improve (using my equipment) performance beyond 0.01 ms.
Anyway, i will take in consideration your useful suggenstions for next challenges.

Cheers,
Andrea
Back to top
View user's profile Send private message
Chris Hanson
Guest





PostPosted: Wed Dec 05, 2018 10:22 pm    Post subject:
osgUtil::LineSegmentIntersector performance issues
Reply with quote

If you are achieving .01ms with your current hardware and model, and you are happy with that, by ALL means, you should not put further effort into it.

I remarked as much for other's benefit and for those who might read the thread in the future and wonder about strategies for working with more complex models where first-hit is sufficient and utilizing the GPU to do the heavy lifting can be a big win.


Glad it works for you.


On Wed, Dec 5, 2018 at 5:47 PM Andrea Martini < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
Hi Chris Hanson,
thank you for your suggestion and your advanced solution.
However, the Robert Osfield's answer solved completely issues concerning my unclear question.
At the moment i find very hard to improve (using my equipment) performance beyond  0.01 ms.
Anyway, i will take in consideration your  useful suggenstions for next challenges.

Cheers,
Andrea

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





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



--
Chris 'Xenon' Hanson, omo sanza lettere. http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 • GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Forensics • Imaging • UAVs • GIS • GPS • osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile • iPhone/iPad/iOS • Android
@alphapixel facebook.com/alphapixel (775) 623-PIXL [7495]

------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Questions concerning Performance issu... Andrea74 General 3 Fri Dec 14, 2018 11:24 am View latest post
No new posts Dynamic VBO Performance Drop ravidavi General 2 Thu Dec 06, 2018 8:36 pm View latest post
No new posts osg3.6.3 plugin issues jaisingla Plugins [osgPlugins] 2 Thu Oct 18, 2018 6:35 am View latest post
No new posts CPU load and performance drop when ru... particleSim General 1 Fri Oct 05, 2018 9:39 am View latest post
No new posts issues compiling 3.0.1 Lonnie.CTR.Souder General 2 Wed Sep 26, 2018 8:59 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP