OSG访问者模式

5 篇文章 0 订阅

osg::Node::accept()

void Node::accept(NodeVisitor& nv)
{
    if (nv.validNodeMask(*this))
    {
        nv.pushOntoNodePath(this);
        nv.apply(*this);
        nv.popFromNodePath();
    }
}

osg::NodeVisitor::apply()

virtual void apply(Drawable& drawable);
virtual void apply(Geometry& geometry);
virtual void apply(Node& node);
virtual void apply(Geode& node);
virtual void apply(Billboard& node);
virtual void apply(Group& node); 

osg::NodeVisitor::traverse()

/** Method for handling traversal of a nodes.
    If you intend to use the visitor for actively traversing
    the scene graph then make sure the accept() methods call
    this method unless they handle traversal directly.*/
inline void traverse(Node& node)
{
    if (_traversalMode==TRAVERSE_PARENTS) node.ascend(*this);
    else if (_traversalMode!=TRAVERSE_NONE) node.traverse(*this);
}

osg::Node::traverse()

/** Traverse downwards : calls children's accept method with NodeVisitor.*/
virtual void traverse(NodeVisitor& /*nv*/) {}

osg::Group::traverse()

void Group::traverse(NodeVisitor& nv)
{
    for(NodeList::iterator itr=_children.begin();
        itr!=_children.end();
        ++itr)
    {
        (*itr)->accept(nv);
    }
}

CullVisitor::apply()

void CullVisitor::apply(Node& node)
{
    if (isCulled(node)) return;

    // push the culling mode.
    pushCurrentMask();

    // push the node's state.
    StateSet* node_state = node.getStateSet();
    if (node_state) pushStateSet(node_state);

    handle_cull_callbacks_and_traverse(node);

    // pop the node's state off the geostate stack.
    if (node_state) popStateSet();

    // pop the culling mode.
    popCurrentMask();
}		

inline void handle_cull_callbacks_and_traverse(osg::Node& node)
{
    osg::Callback* callback = node.getCullCallback();
    if (callback) callback->run(&node,this);
    else traverse(node);
}		

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值