[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->setUseVertexBufferObjects(true);
geom->setUseDisplayList(false);
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->setVertexArray(vertices);
geom->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0,
DEFAULT_VERTEX_SIZE));
road_mark_geode->addDrawable(geom.get());
...
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 =
static_cast<osg::Geometry*>(road_mark_geode->getDrawable(0));
geo_drawable->setDataVariance(osg::Object::DYNAMIC);
osg::DrawArrays* drawArrays =
static_cast<osg::DrawArrays*>(geo_drawable->getPrimitiveSet(0));
osg::Vec3Array* vertices =
static_cast<osg::Vec3Array*>(geo_drawable->getVertexArray());
int num_vertices = points_save.size();
drawArrays->setCount(num_vertices);
vertices->resize(num_vertices);
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
Yuan
--
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