Workflow and principle of the intersection Test Module in OSG

Source: Internet
Author: User

There are three main categories:

1. osgutil: polytopeintersector // implementation class of different algorithms

2. osgutil: intersectionvisitor // used to traverse each node in the node tree

3. OSG: node * mnode; // The root node for the intersection test.


First look at usage:

 

osg::ref_ptr<osgUtil::PolytopeIntersector> intersector = new osgUtil::PolytopeIntersector(osgUtil::Intersector::WINDOW, xMin, yMin, xMax, yMax); intersector->setIntersectionLimit(osgUtil::Intersector::LIMIT_ONE_PER_DRAWABLE);osgUtil::IntersectionVisitor iv( intersector.get() );mRootNode->accept(iv);

 

Link

Osgutil: intersectionvisitor contains an osgutil: polytopeintersector instantiated object. The function is to traverse each node and transmit the information of each node to osgutil: polytopeintersector.

(Contains a series of apply methods) such:

void IntersectionVisitor::apply(osg::Group& group){    if (!enter(group)) return;    traverse(group);    leave();}void IntersectionVisitor::apply(osg::Geode& geode){    // OSG_NOTICE<<"apply(Geode&)"<<std::endl;    if (!enter(geode)) return;    // OSG_NOTICE<<"inside apply(Geode&)"<<std::endl;    for(unsigned int i=0; i<geode.getNumDrawables(); ++i)    {        intersect( geode.getDrawable(i) );    }    leave();}

The enter, leave, and intersect functions call the corresponding methods in osgutil: polytopeintersector, for example:

 inline bool enter(const osg::Node& node) { return _intersectorStack.empty() ? false : _intersectorStack.back()->enter(node); }        inline void leave() { _intersectorStack.back()->leave(); }        inline void intersect(osg::Drawable* drawable) { _intersectorStack.back()->intersect(*this, drawable); }        inline void push_clone() { _intersectorStack.push_back ( _intersectorStack.front()->clone(*this) ); }        inline void pop_clone() { if (_intersectorStack.size()>=2) _intersectorStack.pop_back(); }


In this way, almost all algorithms are concentrated in the Intersect method in osgutil: polytopeintersector.

void PolytopeIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable)

To write your own intersection test algorithm, you only need to rewrite the Intersect function.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.