diff --git a/include/osg/Group b/include/osg/Group index 9434d724a..f0b1617bf 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -65,12 +65,7 @@ class OSG_EXPORT Group : public Node * and do not change the reference count of the Node. * Note, do not override, only override removeChildren(,) is required. */ - inline bool removeChild( Node *child ) - { - unsigned int pos = getChildIndex(child); - if (pos<_children.size()) return removeChildren(pos,1); - else return false; - } + virtual bool removeChild( Node *child ); /** Remove Node from Group. * If Node is contained in Group then remove it from the child @@ -90,14 +85,14 @@ class OSG_EXPORT Group : public Node * Note, must be override by subclasses of Group which add per child attributes.*/ virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove); - /** Replace specified Node with another Node. + /** Replace specified child Node with another Node. * Equivalent to setChild(getChildIndex(orignChild),node) * See docs for setChild for further details on implementation. */ virtual bool replaceChild( Node *origChild, Node* newChild ); /** Return the number of children nodes. */ - inline unsigned int getNumChildren() const { return static_cast(_children.size()); } + virtual unsigned int getNumChildren() const; /** Set child node at position i. * Return true if set correctly, false on failure (if node==NULL || i is out of range). diff --git a/include/osg/Node b/include/osg/Node index b5eb8d930..1b410a0ba 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -148,7 +148,7 @@ class OSG_EXPORT Node : public Object virtual void traverse(NodeVisitor& /*nv*/) {} /** A vector of osg::Group pointers which is used to store the parent(s) of node.*/ - typedef std::vector ParentList; + typedef std::vector ParentList; /** Get the parent list of node. */ inline const ParentList& getParents() const { return _parents; } @@ -157,14 +157,14 @@ class OSG_EXPORT Node : public Object * prevent modification of the parent list.*/ inline ParentList getParents() { return _parents; } - inline Group* getParent(unsigned int i) { return _parents[i]; } + inline Node* getParent(unsigned int i) { return _parents[i]; } /** * Get a single const parent of node. * @param i index of the parent to get. * @return the parent i. */ - inline const Group* getParent(unsigned int i) const { return _parents[i]; } + inline const Node* getParent(unsigned int i) const { return _parents[i]; } /** * Get the number of parents of node. @@ -172,6 +172,22 @@ class OSG_EXPORT Node : public Object */ inline unsigned int getNumParents() const { return static_cast(_parents.size()); } + + + /** Provide interface for Composite like Group nodes to implement.*/ + virtual unsigned int getNumChildren() const { return 0; } + + /** Provide interface for Composite like Group nodes to implement.*/ + virtual bool addChild( Node* /*child*/ ) { return false; } + + /** Provide interface for Composite like Group nodes to implement.*/ + virtual bool removeChild( Node* /*child*/ ) { return false; } + + /** Provide interface for Composite like Group nodes to implement.*/ + virtual bool replaceChild( Node* /*origChild*/, Node* /*newChild*/ ) { return false; } + + + /** Get the list of node paths parent paths. * The optional Node* haltTraversalAtNode allows the user to prevent traversal beyond a specifed node. */ NodePathList getParentalNodePaths(osg::Node* haltTraversalAtNode=0) const; @@ -451,8 +467,8 @@ class OSG_EXPORT Node : public Object mutable BoundingSphere _boundingSphere; mutable bool _boundingSphereComputed; - void addParent(osg::Group* node); - void removeParent(osg::Group* node); + void addParent(osg::Node* node); + void removeParent(osg::Node* node); ParentList _parents; friend class osg::Group; diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index 0bc91bd2b..5074ebcbd 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -145,6 +145,20 @@ bool Group::insertChild( unsigned int index, Node *child ) else return false; } +unsigned int Group::getNumChildren() const +{ + return static_cast(_children.size()); +} + + +bool Group::removeChild( Node *child ) +{ + unsigned int pos = getChildIndex(child); + if (pos<_children.size()) return removeChildren(pos,1); + else return false; +} + + bool Group::removeChildren(unsigned int pos,unsigned int numChildrenToRemove) { if (pos<_children.size() && numChildrenToRemove>0) diff --git a/src/osg/Node.cpp b/src/osg/Node.cpp index bf0637338..f0cfd8b7a 100644 --- a/src/osg/Node.cpp +++ b/src/osg/Node.cpp @@ -93,14 +93,14 @@ Node::~Node() setStateSet(0); } -void Node::addParent(osg::Group* node) +void Node::addParent(osg::Node* node) { OpenThreads::ScopedPointerLock lock(getRefMutex()); _parents.push_back(node); } -void Node::removeParent(osg::Group* node) +void Node::removeParent(osg::Node* node) { OpenThreads::ScopedPointerLock lock(getRefMutex()); diff --git a/src/osgPlugins/txp/TXPParser.cpp b/src/osgPlugins/txp/TXPParser.cpp index 8201a5da9..485b1c98c 100644 --- a/src/osgPlugins/txp/TXPParser.cpp +++ b/src/osgPlugins/txp/TXPParser.cpp @@ -316,7 +316,7 @@ void TXPParser::removeEmptyGroups() osg::Node::ParentList parents = node->getParents(); for (unsigned int j = 0; j < parents.size(); j++) { - osg::Group* parent = parents[j]; + osg::Node* parent = parents[j]; if (parent) parent->removeChild(node); } } diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 149ac5a04..61f2d76a8 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -1387,7 +1387,7 @@ void Optimizer::RemoveEmptyNodesVisitor::removeEmptyNodes() pitr!=parents.end(); ++pitr) { - osg::Group* parent = *pitr; + osg::Node* parent = *pitr; if (!dynamic_cast(parent) && !dynamic_cast(parent) && strcmp(parent->className(),"MultiSwitch")!=0) @@ -1580,7 +1580,7 @@ void Optimizer::CombineLODsVisitor::apply(osg::LOD& lod) { if (isOperationPermissibleForObject(&lod)) { - _groupList.insert(lod.getParent(i)); + _groupList.insert(lod.getParent(i)->asGroup()); } } }