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 

Using callbacks for all graph modifications?


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


Joined: 06 Dec 2013
Posts: 70

PostPosted: Fri Aug 18, 2017 5:21 pm    Post subject:
Using callbacks for all graph modifications?
Reply with quote

Hi all,

I have a custom DataModel describing objects, relations between them. The objects of my custom DataModel are rendered using OSG.

Depending on user events in my app, the objects of my DataModel are modified and OSG is being notified of all these modifications. These modifications leads to e.g. osg::PositionAttitudeTransforms being updated, node masks being modified, osg::Geodes being added or removed of the graph (via addChild() / removeChild()). This leads to a live 3D rendering with animations...

I do all the updates of my OSG graph in a raw way, without using callbacks. This gives code such as

Code:

m_worldFrame->setPosition(EigenToOsgVector3(m_node->m_worldFrame->m_pos));
m_worldFrame->setAttitude(EigenToOsgQuat(m_node->m_worldFrame->m_quat));

if (m_worldFrame)
    m_worldFrame->setNodeMask(0xffffffff);
if (m_mesh)
    m_mesh->setNodeMask(0xffffffff);


Now I am currently reading the Beginners' Guide and have read callbacks should be used for animation (chapter 8 ).

Does that mean I should use callbacks for all modifications of the osg graph?

This could be implemented in such a way that when my DataModel is updated a flag is updated which is read by the callbacks and depending on the state of the flag the callback performs the osg graph update of not. This is possible but this looks very heavy to implement...

Am I getting something wrong? Or should I really use update callbacks for all modifications of the OSG graph (objects moving, setting masks...)?

Thanks a lot,

Antoine.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11971

PostPosted: Fri Aug 18, 2017 8:58 pm    Post subject:
Using callbacks for all graph modifications?
Reply with quote

HI Antoine,

Callbacks are just one way of managing updates to the scene graph, whether they are the most appropriate tool for each job depends entirely and usage case, within one application you may well use multiple approaches, using the appropriate tool for each task.


As a general guide I would suggest that one would use a node callback when you want to encapsulate updates to particular subgraphs so that once you add the callback it looks after its subgraph largely by itself.  For instance a subgraph that you want to spin constantly you create/load the subgraph put a transform above it and attach a callback.  Once setup you then can just pass the whole subgraph into the main scene graph and not have worry about the implementation details any more.


If your updates related closely with high level operations then you'd typically push these high level updates into the frame loop - similar to what you seem to be doing right now.


Robert. 


On 18 August 2017 at 18:21, Antoine Rennuit < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi all,

I have a custom DataModel describing objects, relations between them. The objects of my custom DataModel are rendered using OSG.

Depending on user events in my app, the objects of my DataModel are modified and OSG is being notified of all these modifications. These modifications leads to e.g. osg::PositionAttitudeTransforms being updated, node masks being modified, osg::Geodes being added or removed of the graph (via addChild() / removeChild()). This leads to a live 3D rendering with animations...

I do all the updates of my OSG graph in a raw way, without using callbacks. This gives code such as


Code:

m_worldFrame->setPosition(EigenToOsgVector3(m_node->m_worldFrame->m_pos));
m_worldFrame->setAttitude(EigenToOsgQuat(m_node->m_worldFrame->m_quat));

if (m_worldFrame)
    m_worldFrame->setNodeMask(0xffffffff);
if (m_mesh)
    m_mesh->setNodeMask(0xffffffff);




Now I am currently reading the Beginners' Guide and have read callbacks should be used for animation (chapter Cool.

Does that mean I should use callbacks for all modifications of the osg graph?

This could be implemented in such a way that when my DataModel is updated a flag is updated which is read by the callbacks and depending on the state of the flag the callback performs the osg graph update of not. This is possible but this looks very heavy to implement...

Am I getting something wrong? Or should I really use update callbacks for all modifications of the OSG graph (objects moving, setting masks...)?

Thanks a lot,

Antoine.[/code]

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





_______________________________________________
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


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


Joined: 06 Dec 2013
Posts: 70

PostPosted: Fri Aug 18, 2017 9:25 pm    Post subject:
Reply with quote

Robert,

Thanks a lot for your quick answer!

I understand the design difference you mention and it is relevant.

Now from my readings of the beginners' guide, I understood that callbacks were needed to enforce thread safety. Your answer suggests that it is not the case. Can you confirm? i.e. do you confirm I can modify the OSG objects in a direct way (without callbacks) before calling Viewer::frame() and expect a correct rendering behavior?

Kind regards,

Antoine.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11971

PostPosted: Sat Aug 19, 2017 4:01 pm    Post subject:
Using callbacks for all graph modifications?
Reply with quote

Hi Antonie,
On 18 August 2017 at 22:25, Antoine Rennuit < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
I understand the design difference you mentioni and it is relevant.

Now from my readings of the beginners' guide, I understood that callbacks were needed to enforce thread safety. Your answer suggests that it is not the case. Can you confirm? i.e. do you confirm I can modify the OSG objects in a direct way (without callbacks) before calling Viewer::frame() and expect a correct rendering behavior?


Using update callbacks assists with making scene graph updates thread safe but it's not a necessity, not even a guarantee.  It all depends upon the threading model you are using in viewer and when you are modifying what data.


 If you are running the viewer SingleThreaded then the old threads that the OSG will create will be if you are using a paged database, in which case the OSG will automatically start background threads for reading the data.  These don't impact most work on applications as it all happening in background with data local to that paging threads and is only merged during the update traversal, the viewer handles this all safely for you.


If your are using CullDrawThreadPerContext you also don't need to worry about threading in the update phase (outside viewer.renderingTraversals() that's part of viewer.frame()) as all threads that are doing the rendering only run for the duration of the renderingTraversals() so you'll be safe modifying nodes and geometry/state outside of frame as well.


It's only in DrawThreadPerContext and CullThreadPerCameraDrawThreadPerContext threading models that you need to be careful about modifying the geometry/state in the scene graph as these elements of the scene graph may be read from in the draw thread that can still be running when renderingTraversals() finishes.  If you want to modify geometry/state you need to set the DataVariance on the geometry and state you are modifying to DYANMIC.  This applies to using callbacks or modifying the scene graph outwith viewer.frame().


You are free to modify nodes in the scene graph in the main loop/update and event traversals in all threading models.


Robert.

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


Joined: 06 Dec 2013
Posts: 70

PostPosted: Mon Aug 21, 2017 7:10 am    Post subject:
Reply with quote

Robert,

Thanks a lot for taking the time to answer. This is much clearer now.

Kind regards,

Antoine.
Back to top
View user's profile Send private message
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 [A standardized way to mod scene grap... mp3butcher General 2 Wed Feb 07, 2018 6:16 pm View latest post
No new posts How to Save and Load the current scen... blackball General 1 Mon Dec 11, 2017 5:52 pm View latest post
No new posts Correct way to modify scene graph [SE... Thamm, Russell General 5 Thu Nov 09, 2017 3:52 am View latest post
No new posts How to handle cameras in the scene gr... wernerM General 7 Fri Feb 24, 2017 4:47 pm View latest post
No new posts How to render (sub-)graph only into d... hartwigw General 4 Fri Dec 16, 2016 11:20 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