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 04-15-2012, 03:56 AM
East2010 East2010 is offline
Distinguished Member
 
Join Date: Aug 2011
Location: China
Posts: 117
Default how to get the parent of a SoNode?

Now,I have got an object (its type is SoNode) and the type of its parent is SoSeparator,how to get its parent?

How to get the child number of SoSeparator?

Last edited by East2010; 04-15-2012 at 04:41 AM.
Reply With Quote
  #2  
Old 04-16-2012, 07:26 PM
mikeheck's Avatar
mikeheck mikeheck is offline
Moderator
 
Join Date: Sep 2008
Location: Carlsbad, CA, USA
Posts: 810
Default

Quote:
Originally Posted by East2010 View Post
Now,I have got an object (its type is SoNode) and the type of its parent is SoSeparator,how to get its parent?
How to get the child number of SoSeparator?
- Create an SoSearchAction
- Call setNode() with the address of the node
- Apply the action to the root of the scene graph
- Call getPath() to get an SoPath
- Call getIndexFromTail(0) to get the index (in its parent) of the node.

To get a pointer to the node's parent call getNodeFromTail(1).
Reply With Quote
  #3  
Old 07-10-2012, 09:36 AM
ndaguise ndaguise is offline
VSG Staff
 
Join Date: Apr 2009
Location: Mérignac (FRANCE)
Posts: 7
Default

Hello,

Then to be faster, you also can use this peace of code.

Code:
#include <Inventor/SoLists.h>
#include <Inventor/misc/SoNotification.h>

void buildHeadNodesList(SoNode* node, std::set<SoNode*>& nodelist)
{
  if (node != NULL)
  {
    SoAuditorList* al = (SoAuditorList*)&(node->getAuditors());
    int j;
    int numParent = 0;
    for ( j = 0; j < al->getLength(); j++ )
    {
      if (al->getType(j) == SoNotRec::PARENT)
      {
        SoNode* parentNode = (SoNode*)(al->getObject(j));
        if (parentNode != NULL)
        {
          buildHeadNodesList(parentNode, nodelist);
          numParent++;
        }
      }
    }
    if (numParent == 0)
      nodelist.insert(node);
  }
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 01:40 PM.


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