openscenegraph
Group
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
20namespace osg {
21
22typedef std::vector< ref_ptr<Node> > NodeList;
23
28class OSG_EXPORT Group : public Node
29{
30 public :
31
32
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
53 template<class T> bool addChild( const ref_ptr<T>& child ) { return addChild(child.get()); }
54
60 virtual bool insertChild( unsigned int index, Node *child );
61
62 template<class T> bool insertChild( unsigned int index, const ref_ptr<T>& child ) { return insertChild(index, child.get()); }
63
72 virtual bool removeChild( Node *child );
73
74 template<class T> bool removeChild( const ref_ptr<T>& child ) { return removeChild(child.get()); }
75
84 inline bool removeChild( unsigned int pos, unsigned int numChildrenToRemove=1 )
85 {
86 if (pos<_children.size()) return removeChildren(pos,numChildrenToRemove);
87 else return false;
88 }
89
92 virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
93
98 virtual bool replaceChild( Node *origChild, Node* newChild );
99
100 template<class T, class R> bool replaceChild( const ref_ptr<T>& origChild, const ref_ptr<R>& newChild ) { return replaceChild( origChild.get(), newChild.get()); }
101
103 virtual unsigned int getNumChildren() const;
104
114 virtual bool setChild( unsigned int i, Node* node );
115
117 inline Node* getChild( unsigned int i ) { return _children[i].get(); }
118
120 inline const Node* getChild( unsigned int i ) const { return _children[i].get(); }
121
123 inline bool containsNode( const Node* node ) const
124 {
125
126 for (NodeList::const_iterator itr=_children.begin();
127 itr!=_children.end();
128 ++itr)
129 {
130 if (itr->get()==node) return true;
131 }
132 return false;
133 }
134
135 template<class T> bool containsNode(const ref_ptr<T>& node) const { return containsNode(node.get()); }
136
141 inline unsigned int getChildIndex( const Node* node ) const
142 {
143 for (unsigned int childNum=0;childNum<_children.size();++childNum)
144 {
145 if (_children[childNum]==node) return childNum;
146 }
147 return static_cast<unsigned int>(_children.size()); // node not found.
148 }
149
151 virtual void setThreadSafeRefUnref(bool threadSafe);
152
154 virtual void resizeGLObjectBuffers(unsigned int maxSize);
155
159 virtual void releaseGLObjects(osg::State* = 0) const;
160
162
163 protected:
164
165 virtual ~Group();
166
167 virtual void childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) {}
168 virtual void childInserted(unsigned int /*pos*/) {}
169
171
172
173};
174
175}
176
177#endif
Definition BoundingSphere:35
Definition CopyOp:41
Definition Group:29
virtual BoundingSphere computeBound() const
virtual void childInserted(unsigned int)
Definition Group:168
Node * getChild(unsigned int i)
Definition Group:117
virtual void childRemoved(unsigned int, unsigned int)
Definition Group:167
virtual void traverse(NodeVisitor &nv)
virtual const Group * asGroup() const
Definition Group:41
virtual bool removeChildren(unsigned int pos, unsigned int numChildrenToRemove)
bool removeChild(const ref_ptr< T > &child)
Definition Group:74
virtual bool setChild(unsigned int i, Node *node)
virtual bool replaceChild(Node *origChild, Node *newChild)
META_Node(osg, Group)
virtual void resizeGLObjectBuffers(unsigned int maxSize)
virtual unsigned int getNumChildren() const
bool insertChild(unsigned int index, const ref_ptr< T > &child)
Definition Group:62
const Node * getChild(unsigned int i) const
Definition Group:120
Group(const Group &, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
virtual void setThreadSafeRefUnref(bool threadSafe)
virtual ~Group()
virtual bool insertChild(unsigned int index, Node *child)
bool replaceChild(const ref_ptr< T > &origChild, const ref_ptr< R > &newChild)
Definition Group:100
virtual bool addChild(Node *child)
bool removeChild(unsigned int pos, unsigned int numChildrenToRemove=1)
Definition Group:84
virtual Group * asGroup()
Definition Group:40
unsigned int getChildIndex(const Node *node) const
Definition Group:141
bool containsNode(const ref_ptr< T > &node) const
Definition Group:135
NodeList _children
Definition Group:170
virtual bool removeChild(Node *child)
virtual void releaseGLObjects(osg::State *=0) const
bool containsNode(const Node *node) const
Definition Group:123
bool addChild(const ref_ptr< T > &child)
Definition Group:53
Definition NodeVisitor:82
Definition Node:72
Definition State:80
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
std::vector< ref_ptr< Node > > NodeList
Definition Group:22
#define OSG_EXPORT
Definition osg/Export:39