1 #ifndef SIMGEAR_SPLICINGVISITOR_HXX
2 #define SIMGEAR_SPLICINGVISITOR_HXX 1
7 #include <osg/NodeVisitor>
12 class SplicingVisitor : public osg::NodeVisitor
15 META_NodeVisitor(simgear,SplicingVisitor);
17 virtual ~SplicingVisitor() {}
19 osg::NodeList traverse(osg::Node& node);
20 using osg::NodeVisitor::apply;
21 virtual void apply(osg::Node& node);
22 virtual void apply(osg::Group& node);
24 static T* copyIfNeeded(T& node, const osg::NodeList& children);
26 static T* copy(T& node, const osg::NodeList& children);
28 * Push the result of processing this node.
30 * If the child list is not equal to the node's current children,
31 * make a copy of the node. Record the (possibly new) node which
32 * should be the returned result if the node is visited again.
34 osg::Group* pushResultNode(osg::Group* node, osg::Group* newNode,
35 const osg::NodeList& children);
37 * Push the result of processing this node.
39 * Record the (possibly new) node which should be the returned
40 * result if the node is visited again.
42 osg::Node* pushResultNode(osg::Node* node, osg::Node* newNode);
44 * Push some node onto the list of result nodes.
46 osg::Node* pushNode(osg::Node* node);
47 osg::Node* getResult();
48 osg::Node* getNewNode(osg::Node& node)
50 return getNewNode(&node);
52 osg::Node* getNewNode(osg::Node* node);
53 bool recordNewNode(osg::Node* oldNode, osg::Node* newNode);
54 osg::NodeList& getResults() { return _childStack.back(); }
56 std::vector<osg::NodeList> _childStack;
57 typedef std::map<osg::ref_ptr<osg::Node>, osg::ref_ptr<osg::Node> > NodeMap;
62 T* SplicingVisitor::copyIfNeeded(T& node, const osg::NodeList& children)
64 bool copyNeeded = false;
65 if (node.getNumChildren() == children.size()) {
66 for (std::size_t i = 0; i < children.size(); ++i)
67 if (node.getChild(i) != children[i].get()) {
75 return copy(node, children);
81 T* SplicingVisitor::copy(T& node, const osg::NodeList& children)
83 T* result = osg::clone(&node, osg::CopyOp::SHALLOW_COPY);
84 result->removeChildren(0, result->getNumChildren());
85 for (osg::NodeList::const_iterator itr = children.begin(),
89 result->addChild(itr->get());