| 812 | } |
| 813 | |
| 814 | void Optimizer::RemoveEmptyNodesVisitor::removeEmptyNodes() |
| 815 | { |
| 816 | |
| 817 | NodeList newEmptyGroups; |
| 818 | |
| 819 | // keep iterator through until scene graph is cleaned of empty nodes. |
| 820 | while (!_redundantNodeList.empty()) |
| 821 | { |
| 822 | for(NodeList::iterator itr=_redundantNodeList.begin(); |
| 823 | itr!=_redundantNodeList.end(); |
| 824 | ++itr) |
| 825 | { |
| 826 | |
| 827 | osg::ref_ptr<osg::Node> nodeToRemove = (*itr); |
| 828 | |
| 829 | // take a copy of parents list since subsequent removes will modify the original one. |
| 830 | osg::Node::ParentList parents = nodeToRemove->getParents(); |
| 831 | |
| 832 | for(osg::Node::ParentList::iterator pitr=parents.begin(); |
| 833 | pitr!=parents.end(); |
| 834 | ++pitr) |
| 835 | { |
| 836 | osg::Group* parent = *pitr; |
| 837 | if (!parent->asSwitch() && !dynamic_cast<osg::LOD*>(parent) && !dynamic_cast<osg::Sequence*>(parent)) |
| 838 | { |
| 839 | parent->removeChild(nodeToRemove.get()); |
| 840 | if (parent->getNumChildren()==0 && isOperationPermissibleForObject(parent)) newEmptyGroups.insert(parent); |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | _redundantNodeList.clear(); |
| 846 | _redundantNodeList.swap(newEmptyGroups); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | |
| 851 | //////////////////////////////////////////////////////////////////////////// |
no test coverage detected