[osg-users] How to reduce the cache size limit of OSG ?

OpenSceneGraph Users osg-users at lists.openscenegraph.org
Sun May 31 18:28:04 PDT 2020


Hi Robert,

Sorry for the late reply. The codes of CreateGeometryNode looks like this: 
osg::ref_ptr<osg::MatrixTransform> CreateGeometryNode() {
    std::vector<float> xyzs = RandomPoints(); ///< Create ramdon number of 
points 
    osg::Vec3Array vs = new osg::Vec3Array(xyzs.size()/3, (const osg::Vec3 
*)(xyzs.data()));
    osg::ref_ptr<osg::Geometry> geo = new osg::Geometry;
    geo->setVertexArray(vs.get());
    geo->setColorArray(osg::Vec3(0.5,0.5,0.5));
    geo->setColorBinding(osg::Geometry::BIND_OVERALL);
    geo->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, 
numpt));
    geo->getOrCreateStateSet()->setMode(GL_LIGHTING, 
osg::StateAttribute::OFF);
    geo->getOrCreateStateSet()->setAttribute(new osg::Point(size), 
osg::StateAttribute::ON);
    osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    geode->addDrawable(geo.get());
    mt->addChild(geode);
    return mt; 
}

There's an old post from you which said that OSG will cache objects to 
improve performance, I wonder if this is the case and how I could change 
that behavior. 

Thanks! 

On Wednesday, May 27, 2020 at 2:37:27 AM UTC+8, Robert Osfield wrote:
>
> Hi Hui,
>
>
> On Tuesday, 26 May 2020 10:36:18 UTC+1, Hui Li wrote:
>>
>>
>> The codes looks like this: 
>> ```
>> root = GroupOfSwitch(); 
>> viewer->setSceneData(root);
>> while (!viewer->done()) {
>>     root->removeChild(0); // Remove the point cloud 
>>     pc = sensor.Capture();  // Get the point cloud
>>     geo = CreateGeometryNode(pc);
>>     root->addChild(geo); // Add the pointcloud 
>>     viewer->frame();
>> }
>>
>>
> In "principle" this shouldn't cause unbounded memory growth but as you 
> don't provide any details about the CreateGeometryNode() there is no way 
> for use know what is going on there.  It could be that your leak it right 
> there in that function call, or else where somewhere in your application.
>
> While I can't comment about the details of your implementation the 
> approach of removing, creating and adding new nodes and associated data 
> each frame is really, really inefficient.
>
> As much as possible you should try to reuse data.  For a point cloud 
> application where the data is dynamic I would personally allocate a fixed 
> number of Geometry nodes with fixed Vec3Array's within them and single 
> DrawArray primitive set.  I'd allocate the Vec3Array to it's full size 
> right up front and next change it's size.  The DrawArrays has a count value 
> that you can set to specify how many vertices in the array need to be 
> rendered and needn't be the whole length of the Vec3Aray.
>
> With really large datasets I would chunk the data so rather one big 
> osg::Geometry, I'd have say 10,000 vertices in each osg::Geometry.  I would 
> also use VertexBufferObjects and avoid using DisplayLists.
>
> Do this all correctly and you should get a good performance and no memory 
> growth.
>
> Robert.
>  
>

-- 
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/ddac852b-0888-42a4-82d8-23a92f83b571%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200531/1f641795/attachment.html>


More information about the osg-users mailing list