OpenSceneGraph 3.6.5
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
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
std::vector< ref_ptr< Node > > NodeList
Definition Group:22
BoundingSphered BoundingSphere
Definition BoundingSphere:308
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
virtual BoundingSphere computeBound() const
Compute the bounding sphere around Node's geometry or children.
virtual void childInserted(unsigned int)
Definition Group:168
Node * getChild(unsigned int i)
Return child node at position i.
Definition Group:117
virtual void childRemoved(unsigned int, unsigned int)
Definition Group:167
virtual void traverse(NodeVisitor &nv)
Traverse downwards : calls children's accept method with NodeVisitor.
virtual const Group * asGroup() const
convert 'const this' into a const Group pointer if Node is a Group, otherwise return 0.
Definition Group:41
virtual bool removeChildren(unsigned int pos, unsigned int numChildrenToRemove)
Remove children from Group.
bool removeChild(const ref_ptr< T > &child)
Definition Group:74
virtual bool setChild(unsigned int i, Node *node)
Set child node at position i.
virtual bool replaceChild(Node *origChild, Node *newChild)
Replace specified child Node with another Node.
META_Node(osg, Group)
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
virtual unsigned int getNumChildren() const
Return the number of children nodes.
bool insertChild(unsigned int index, const ref_ptr< T > &child)
Definition Group:62
const Node * getChild(unsigned int i) const
Return child node at position i.
Definition Group:120
Group(const Group &, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
virtual void setThreadSafeRefUnref(bool threadSafe)
Set whether to use a mutex to ensure ref() and unref() are thread safe.
virtual ~Group()
virtual bool insertChild(unsigned int index, Node *child)
Insert Node to Group at specific location.
bool replaceChild(const ref_ptr< T > &origChild, const ref_ptr< R > &newChild)
Definition Group:100
virtual bool addChild(Node *child)
Add Node to Group.
bool removeChild(unsigned int pos, unsigned int numChildrenToRemove=1)
Remove Node from Group.
Definition Group:84
virtual Group * asGroup()
convert 'this' into a Group pointer if Node is a Group, otherwise return 0.
Definition Group:40
unsigned int getChildIndex(const Node *node) const
Get the index number of child, return a value between 0 and _children.size()-1 if found,...
Definition Group:141
bool containsNode(const ref_ptr< T > &node) const
Definition Group:135
NodeList _children
Definition Group:170
virtual bool removeChild(Node *child)
Remove Node from Group.
virtual void releaseGLObjects(osg::State *=0) const
If State is non-zero, this function releases any associated OpenGL objects for the specified graphics...
bool containsNode(const Node *node) const
Return true if node is contained within Group.
Definition Group:123
bool addChild(const ref_ptr< T > &child)
Definition Group:53
Node()
Construct a node.
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.