OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Group.h
Go to the documentation of this file.
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 
14 #ifndef OSG_GROUP
15 #define OSG_GROUP 1
16 
17 #include <osg/Node>
18 #include <osg/NodeVisitor>
19 
20 namespace osg {
21 
22 typedef std::vector< ref_ptr<Node> > NodeList;
23 
28 class OSG_EXPORT Group : public Node
29 {
30  public :
31 
32 
33  Group();
34 
36  Group(const Group&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
37 
39 
40  virtual Group* asGroup() { return this; }
41  virtual const Group* asGroup() const { return this; }
42 
43  virtual void traverse(NodeVisitor& nv);
44 
51  virtual bool addChild( Node *child );
52 
58  virtual bool insertChild( unsigned int index, Node *child );
59 
68  virtual bool removeChild( Node *child );
69 
78  inline bool removeChild( unsigned int pos, unsigned int numChildrenToRemove=1 )
79  {
80  if (pos<_children.size()) return removeChildren(pos,numChildrenToRemove);
81  else return false;
82  }
83 
86  virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
87 
92  virtual bool replaceChild( Node *origChild, Node* newChild );
93 
95  virtual unsigned int getNumChildren() const;
96 
106  virtual bool setChild( unsigned int i, Node* node );
107 
109  inline Node* getChild( unsigned int i ) { return _children[i].get(); }
110 
112  inline const Node* getChild( unsigned int i ) const { return _children[i].get(); }
113 
115  inline bool containsNode( const Node* node ) const
116  {
117 
118  for (NodeList::const_iterator itr=_children.begin();
119  itr!=_children.end();
120  ++itr)
121  {
122  if (itr->get()==node) return true;
123  }
124  return false;
125  }
126 
131  inline unsigned int getChildIndex( const Node* node ) const
132  {
133  for (unsigned int childNum=0;childNum<_children.size();++childNum)
134  {
135  if (_children[childNum]==node) return childNum;
136  }
137  return static_cast<unsigned int>(_children.size()); // node not found.
138  }
139 
141  virtual void setThreadSafeRefUnref(bool threadSafe);
142 
144  virtual void resizeGLObjectBuffers(unsigned int maxSize);
145 
149  virtual void releaseGLObjects(osg::State* = 0) const;
150 
151  virtual BoundingSphere computeBound() const;
152 
153  protected:
154 
155  virtual ~Group();
156 
157  virtual void childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) {}
158  virtual void childInserted(unsigned int /*pos*/) {}
159 
160  NodeList _children;
161 
162 
163 };
164 
165 }
166 
167 #endif
#define OSG_EXPORT
Definition: Export.h:43
bool removeChild(unsigned int pos, unsigned int numChildrenToRemove=1)
Definition: Group.h:78
#define META_Node(library, name)
Definition: Node.h:59
Node * getChild(unsigned int i)
Definition: Group.h:109
virtual void childInserted(unsigned int)
Definition: Group.h:158
virtual const Group * asGroup() const
Definition: Group.h:41
NodeList _children
Definition: Group.h:160
unsigned int getChildIndex(const Node *node) const
Definition: Group.h:131
virtual Group * asGroup()
Definition: Group.h:40
virtual void childRemoved(unsigned int, unsigned int)
Definition: Group.h:157
const Node * getChild(unsigned int i) const
Definition: Group.h:112
Definition: Node.h:71
Definition: AlphaFunc.h:19
std::vector< ref_ptr< Node > > NodeList
Definition: Group.h:22
bool containsNode(const Node *node) const
Definition: Group.h:115