VSG Logo   OpenInventor Forum

Go Back   Open Inventor Forum > Open Inventor Main Forum

Open Inventor Main Forum General discussions about Open Inventor from VSG

Reply
 
Thread Tools Display Modes
  #1  
Old 05-02-2012, 03:39 AM
aman.sonu aman.sonu is offline
Active Member
 
Join Date: Nov 2008
Posts: 42
Default Node in Accumulated Element

Hi Mike,

I have created a new accumulated element for my own node e.g. SoMyNode. I have one renderer, which will be using this element.

I want to add the information to element during SoMyNode traversal.

i have the following queries:

1. can I add the instance of SoMyNode to Element directly. if i create a new variable in my element e.g. sbPList.
2. Will it create some issues?

I am providing some code
Code:
class MyElement : public SoAccumulatedElement
{
     static void add(SoState *state, SoNode *node, SoNode *node)
     {
           ..........
           nodes.append(node);
     }
private:
     SbPList nodes;

};

class SoMyNode : public SoNode
{
    void GLRender(SoGLRenderAction *ac) {

      MyElement::add(ac->getState(),this,this);

    }
}

class MyRenderer 
{
    void GLRender(SoGLRenderAction *ac) {

        MyElement *element = MyElement::getInstance(ac->getState());


     }

}
__________________
Thanks and Best Regards,
Aman
Reply With Quote
  #2  
Old 07-10-2012, 09:24 AM
ndaguise ndaguise is offline
VSG Staff
 
Join Date: Apr 2009
Location: Mérignac (FRANCE)
Posts: 7
Default

Hello,

You can store some nodes in elements only if you are sure that these nodes will not be destroyed before the Open Inventor state. In fact, is a node is destroyed or removed from the scene, the Open Inventor is not necessarily rebuilt, thus, at the next traversal, application will crash because of bad node access.

A solution can be implemented to manage this problem, but we clearly not recommend it (but possible since OIV 9.0.1. It consists in adding an auditor to the stored nodes so that nodes deletion is tracked throught the dyingReference() virtual method call.

As an example:

Code:
class MyElement : public SoAccumulatedElement
{
     static void add(SoState *state, SoNode *node, SoNode *node)
     {
           ..........
           nodes.append(node);
           node->addAuditor(this, SoNotRec::ELEMENT);
     }
     MyElement::~MyElement()
     {
          for (int i=0;i<nodes.size();++i)
          {
               if ( nodes[i] != NULL )
                    nodes[i]->removeAuditor(this,SoNotRec::ELEMENT);
          }
      }

     virtual void MyElement::dyingReference()
     {
          // A node as been destroyed... cleanup the list...
          for (int i=0;i<nodes.size();++i)
          {
               if ( nodes[i] != NULL )
                    nodes[i]->removeAuditor(this,SoNotRec::ELEMENT);
          }
          nodes.clear();
     }

     private:
          SbPList nodes;
};
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:14 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Copyright VSG, SAS, 2008.