osgUtil.IntersectorGroup 类用于组合多个互不干扰的 Intersectors。它提供了一种简单的方式来管理一组交点测试器,并使其一起工作,以查找一组场景图节点与测试器之间的交点。

IntersectorGroup()构造函数。
IntersectorGroup(const IntersectorGroup& ig, const CopyOp& copyop = CopyOp::SHALLOW_COPY)用于进行深层复制的构造函数。
virtual ~IntersectorGroup()析构函数。
void setCoordinateFrame(CoordinateFrame cf)设置交点测试器的坐标系。默认为 LOCAL。
CoordinateFrame getCoordinateFrame() const获取交点测试器的坐标系。
void setIntersectionLimit(unsigned int limit)设置交点的最大数量。默认为 UINT_MAX。
unsigned int getIntersectionLimit() const获取交点的最大数量。
void addIntersector(IntersectFunctor* intersector)将一个交点测试器添加到组中。
unsigned int getNumIntersectors() const获取组中的交点测试器数量。
IntersectFunctor* getIntersector(unsigned int i)获取组中指定索引的交点测试器。
const IntersectFunctor* getIntersector(unsigned int i) const获取组中指定索引的交点测试器。
void setIntersectMask(unsigned int mask)设置测试器的截止面遮罩。
unsigned int getIntersectMask() const获取测试器的截止面遮罩值。
void operator () (IntersectionVisitor& iv, osg::Drawable* drawable) const迭代每个交点测试器,并在场景图中查找相交的对象。
void operator () (std::vector<Intersection>& intersections, const osg::Drawable::DrawCallback* dc) const在场景图中查找所有相交的对象,并返回相交列表。
void operator () (std::vector<Intersection>& intersections, osg::Node* node) const在场景图中查找所有相交的对象,并返回相交列表。
osg::Drawable、osg::Node、osgUtil.IntersectVisitor。
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osgUtil/IntersectorGroup>
#include <osgDB/ReadFile>
#include <iostream>
int main()
{
    // 加载场景图
    osg::ref_ptr<osg::Node> model = osgDB::readNodeFile("cow.osg");
    // 创建交点测试器 group
    osg::ref_ptr<osgUtil::IntersectorGroup> group = new osgUtil::IntersectorGroup;
    group->addIntersector(new osgUtil::LineSegmentIntersector(osg::Vec3(0, 0, 0), osg::Vec3(0, 0, -1)));
    // 创建 IntersectionVisitor 并使用交点测试器进行测试
    osgUtil::IntersectionVisitor iv(group.get());
    model->accept(iv);
    // 输出测试结果
    osgUtil::IntersectorGroup::IntersectVisitor::HitList hits;
    group->fillIntersectionList(iv.getHitList(hits));
    for (osgUtil::IntersectorGroup::IntersectVisitor::HitList::iterator hit_itr = hits.begin(); hit_itr != hits.end(); ++hit_itr)
    {
        const osgUtil::IntersectorGroup::Intersection& intersection = *hit_itr;
        std::cout << "Intersection at " << intersection.getWorldIntersectPoint() << std::endl;
    }
    return 0;
}