1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version.  The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * OpenSceneGraph Public License for more details.
12 */
13 #include <osgUtil/StateGraph>
14 
15 #include <osg/Notify>
16 
17 using namespace osg;
18 using namespace osgUtil;
19 
reset()20 void StateGraph::reset()
21 {
22     _parent = NULL;
23     _stateset = NULL;
24 
25     _depth = 0;
26 
27     _children.clear();
28     _leaves.clear();
29 }
30 
31 /** recursively clean the StateGraph of all its drawables, lights and depths.
32   * Leaves children intact, and ready to be populated again.*/
clean()33 void StateGraph::clean()
34 {
35 
36     // clean local drawables etc.
37     _leaves.clear();
38 
39     // call clean on all children.
40     for(ChildList::iterator itr=_children.begin();
41         itr!=_children.end();
42         ++itr)
43     {
44         itr->second->clean();
45     }
46 
47 }
48 
49 /** recursively prune the StateGraph of empty children.*/
prune()50 void StateGraph::prune()
51 {
52     // call prune on all children.
53     ChildList::iterator citr=_children.begin();
54     while(citr!=_children.end())
55     {
56         citr->second->prune();
57 
58         if (citr->second->empty())
59         {
60             ChildList::iterator ditr= citr++;
61             _children.erase(ditr);
62         }
63         else ++citr;
64     }
65 }
66