Hi Alexander,
This is a limitation of the implementation of multidispatch used for
traversing the scene graph. If you want to have an apply function that
handles a new type, that apply function needs to be added to the
NodeVisitor base class because NodeVisitor* is the type used when apply
is called during a traversal. Your solution of using a dynamic cast is
the usual workaround when one desires to avoid modifying the base class
object.
Regards,
Mark
Pecoraro, Alexander N wrote:
> I am trying to write a NodeVisitor class that does something to
> osgTerrain::TerrainTile nodes, but for some reason it never enters my
> apply(TerrainTile& tile) function. It just seems to fall back into the
> apply(Group& group) of the base NodeVisitor class. Finally I just gave
> up and overrided the apply(Group& group) and attempted to dynamic cast
> each group to a TerrainTile and then called my apply(TerrainTile&)
> function and that worked, but it doesn't seem like the proper way to do
> it.
>
> What am I doing wrong? Here is my code (in short):
>
> class TerrainTileVisitor : public osg::NodeVisitor
> {
> public:
> TerrainTileVisitor() :
> osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
> {
> }
>
> virtual void apply(osgTerrain::TerrainTile& tile)
> {
> std::cout << "TerrainTile Found!" << std::endl;
> traverse(tile);
> }
>
> //Added this function to make it work
> virtual void apply(osg::Group& group)
> {
> osgTerrain::TerrainTile* tile =
> dynamic_cast<osgTerrain::TerrainTile*>(&group);
> if(tile)
> apply(*tile);
> else
> traverse(group);
> }
> };
>
> Thanks.
>
> Alex
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org