[osg-users] [Performance] Update dynamic vertices in drawable by external incoming data

OpenSceneGraph Users osg-users at lists.openscenegraph.org
Tue Feb 18 10:19:45 PST 2020

Hello everyone,

I am not experienced at osg and want to post my question here (please bear 
me if my question is stupid). 

Here is the backround of my question:
I get 400 ~ 800 incoming points of simulated road marks by one programm 
every 20 ~ 30 ms. My Programm is fed by these points continuously on the 
main thread. My goal is to visualise them by connecting them into lines:

After reading many releated posts on this forum, I got some ideas and 
implemented them:

this is basic setup:
    osg::ref_ptr<osg::Geode> road_mark_geode; // hold the vertices inside 
my program
    osg::ref_ptr<osg::Geometry> geom(new osg::Geometry());

    geom->setUpdateCallback(new DynamicRoadMarkCallback); //  I customized 
a osg::Drawable::UpdateCallback to run vertices->dirty(), to update inside 
road mark vertices 
    osg::Vec3Array* vertices(new osg::Vec3Array());
    geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, 

Given that data reception is on main thread, i did this (points_in is 
incoming data from another program):

Loop on main thread:
    receive points and store them -> call function "*update_pos_of_vertices* " 
to set the pos (x, y, z) for vertices by new points.
    Blow is the interested code snippet:
    getdata(points_in, points_save); // save incoming data into "
*points_save"* of my own data type
    update_pos_of_vertices (points_save) {
        osg::Geometry* geo_drawable = 
osg::DrawArrays* drawArrays = 
osg::Vec3Array* vertices = 
int num_vertices = points_save.size();
for (... ) { 
vertices->at(i).set(points_save[i]); // set new pos of each vertex

My program ran and i got visualized lines which are linked by points (see 
pic in attachment). But my program becomes very slow: average time for one 
single loop is 50ms. So my question is:
How can I improve the performance?
Did I do anything wrong regarding the my implementation above?

Look  forward to any help, tips and remarks!
Thank you






You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/5a56fb13-4d17-41dd-a7c5-62ec49a3d421%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200218/9102729d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: visualized_lines.png
Type: image/png
Size: 3770 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200218/9102729d/attachment.png>

More information about the osg-users mailing list