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.