osgEarth 2.1.1
Public Member Functions | Static Public Member Functions

osgEarth::RemoveEmptyGroupsVisitor Class Reference

List of all members.

Public Member Functions

 RemoveEmptyGroupsVisitor ()
void apply (osg::Group &group)

Static Public Member Functions

static void run (osg::Node *entry)

Detailed Description

Visitor that looks for empty group nodes and removes them from the scene graph. (Note, if the entry node is an empty group, it will not be affected.)

Definition at line 43 of file NodeUtils.


Constructor & Destructor Documentation

RemoveEmptyGroupsVisitor::RemoveEmptyGroupsVisitor ( )

Definition at line 263 of file NodeUtils.cpp.

                                                   :
osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN )
{
    //nop
}

Member Function Documentation

void RemoveEmptyGroupsVisitor::apply ( osg::Group &  group)

Definition at line 270 of file NodeUtils.cpp.

{
    bool removed = true;
    while( removed )
    {
        removed = false;
        for( unsigned i = 0; i < group.getNumChildren(); ++i )
        {
            osg::Group* child = group.getChild(i)->asGroup();
            if ( child )
            {
                if (child->className() == "Group"         &&
                    child->getStateSet() == 0L            &&
                    child->getCullCallback() == 0L        &&
                    child->getUpdateCallback() == 0L      &&
                    child->getUserData() == 0L            &&
                    child->getName().empty()              &&
                    child->getDescriptions().size() == 0 )
                {
                    for( unsigned j = 0; j < child->getNumChildren(); ++j )
                    {
                        group.addChild( child->getChild( j ) );
                    }

                    group.removeChild( i-- );
                    removed = true;
                }                
            }
        }
    }

    traverse(group);
}
static void osgEarth::RemoveEmptyGroupsVisitor::run ( osg::Node *  entry) [inline, static]

Definition at line 46 of file NodeUtils.

                                          {
            if ( entry ) {
                RemoveEmptyGroupsVisitor v;
                entry->accept( v );
            }
        }

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines