Re: [osg-users] basic traversal problem

2009-12-07 Thread Trajce Nikolov
please ignore this one. I figured that out
Nick

http://www.linkedin.com/in/tnikolov


On Mon, Dec 7, 2009 at 5:15 AM, Trajce Nikolov nikolov.tra...@gmail.comwrote:

 The attachment was too big . Now should be ok

 Nick

 http://www.linkedin.com/in/tnikolov
 Sent from Gümüşsuyu, İstanbul, Turkey

 On Mon, Dec 7, 2009 at 4:55 AM, Trajce Nikolov 
 nikolov.tra...@gmail.comwrote:

 Hi community,

 I have osg file and I am doing traversal to get nodes with given name. In
 the osg file, I see the Geode with the name, however the visitor never gets
 there

 Here is my Visitor and the file is attached

 class FindMirrorGeometryNodeVisitor : public osg::NodeVisitor
 {
 public:
 FindMirrorGeometryNodeVisitor()
  : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
 {
 }

 virtual void apply(osg::Group node)
 {
 for (unsigned int i=0; inode.getNumChildren(); ++i)
  {
 traverse(*node.getChild(i));
 }
  }

 virtual void apply(osg::Geode node)
 {
  osg::Node::DescriptionList dl = node.getDescriptions();
 osg::Node::DescriptionList::iterator itr = dl.begin();
  for (; itr != dl.end(); ++itr)
 {
 if (itr-find_first_of(#MIRROR) != std::string::npos)
  {
 std::cout  Never gets here !  std::endl;
  }
 }
 traverse(node);
  }
 };


 Any ideas? Can you give it a shot. I should be up to date with the svn

 Nick

 http://www.linkedin.com/in/tnikolov
 Sent from Gümüşsuyu, İstanbul, Turkey



___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] basic traversal problem

2009-12-07 Thread Trajce Nikolov
Hi JSG,


Nick

http://www.linkedin.com/in/tnikolov
Sent from Gümüşsuyu, İstanbul, Turkey

On Mon, Dec 7, 2009 at 6:02 AM, Jean-Sébastien Guay 
jean-sebastien.g...@cm-labs.com wrote:

 Hello Trajce,


 I have osg file and I am doing traversal to get nodes with given
name. In the osg file, I see the Geode with the name, however the
visitor never gets there


 [...]


 virtual void apply(osg::Group node)
{
for (unsigned int i=0; inode.getNumChildren(); ++i)
{
traverse(*node.getChild(i));
}
}


 Well first of all, you don't need this, the osg::NodeVisitor base class
 version of apply(osg::Group) will traverse all children of a group already.



yea ... I was doing couple of testings so I put the other sample




 virtual void apply(osg::Geode node)
{
  osg::Node::DescriptionList dl = node.getDescriptions();
  osg::Node::DescriptionList::iterator itr = dl.begin();
  for (; itr != dl.end(); ++itr)
  {
if (itr-find_first_of(#MIRROR) != std::string::npos)
{
  std::cout  Never gets here !  std::endl;
}
  }
  traverse(node);
}


 Here, you're not checking the node's name, you're checking its description
 list... In addition, find_first_of doesn't do what you think it does. It
 finds the first occurence of *any* of the characters in the string you pass
 (so the first occurence of either '#' 'M' 'I'...). Try this instead:


 virtual void apply(osg::Geode node)
 {
   if (node.getName().find(#MIRROR) != std::string::npos)
   {
 std::cout  Should get here if one of the Geodes' name has
 #MIRROR in it  std::endl;
   }
   traverse(node);
 }

 std::string::find returns the first occurrence of the argument within the
 string object you call it on, or std::string::npos if not found.


good hint ... Thanks !


 Also note that you're only checking Geodes here... If you want to find any
 node that has #MIRROR in its name, you might want to override the
 apply(osg::Node node), which will be called for all types of nodes (as long
 as you don't override other versions of apply() ).

 And a little tip I imagine you know, but just in case: you can write your
 scene graph to a .osg file (either with osgDB::writeNodeFile() in code or
 with osgconv on the command line) and then inspect it with a text editor to
 make sure one of the nodes really has #MIRROR in its name.


That is what I am doing to check the scenegraph.


Its been quite a while since I used OSG and just need time to get a hand of
it again. Forgot many things ... But I learn fast ;-)

Thanks a gain for the support




 Hope this helps,

 J-S
 --
 __
 Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] basic traversal problem

2009-12-07 Thread Jean-Sébastien Guay

Hi Nick,


Thanks again for the support


My pleasure.

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org