Added optional control of whether to use KdTrees for intersections
This commit is contained in:
parent
134c86c2d5
commit
2851429333
@ -46,11 +46,12 @@ class Intersector : public osg::Referenced
|
||||
_coordinateFrame(cf),
|
||||
_disabledCount(0) {}
|
||||
|
||||
|
||||
void setCoordinateFrame(CoordinateFrame cf) { _coordinateFrame = cf; }
|
||||
|
||||
CoordinateFrame getCoordinateFrame() const { return _coordinateFrame; }
|
||||
|
||||
|
||||
|
||||
|
||||
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv) = 0;
|
||||
|
||||
virtual bool enter(const osg::Node& node) = 0;
|
||||
@ -72,7 +73,7 @@ class Intersector : public osg::Referenced
|
||||
protected:
|
||||
|
||||
CoordinateFrame _coordinateFrame;
|
||||
unsigned int _disabledCount;
|
||||
unsigned int _disabledCount;
|
||||
|
||||
};
|
||||
|
||||
@ -138,6 +139,7 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
|
||||
virtual void reset();
|
||||
|
||||
|
||||
/** Set the intersector that will be used to intersect with the scene, and to store any hits that occur.*/
|
||||
void setIntersector(Intersector* intersector);
|
||||
|
||||
@ -148,6 +150,13 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
const Intersector* getIntersector() const { return _intersectorStack.empty() ? 0 : _intersectorStack.front().get(); }
|
||||
|
||||
|
||||
/** Set whether the intersectors should use KdTrees when they are found on the scene graph.*/
|
||||
void setUseKdTreeWhenAvailable(bool useKdTrees) { _useKdTreesWhenAvailable; }
|
||||
|
||||
/** Set whether the intersectors should use KdTrees.*/
|
||||
bool getUseKdTreeWhenAvailable() const { return _useKdTreesWhenAvailable; }
|
||||
|
||||
|
||||
/** Set the read callback.*/
|
||||
void setReadCallback(ReadCallback* rc) { _readCallback = rc; }
|
||||
|
||||
@ -201,6 +210,8 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
|
||||
typedef std::list< osg::ref_ptr<Intersector> > IntersectorStack;
|
||||
IntersectorStack _intersectorStack;
|
||||
|
||||
bool _useKdTreesWhenAvailable;
|
||||
|
||||
osg::ref_ptr<ReadCallback> _readCallback;
|
||||
|
||||
|
@ -155,6 +155,8 @@ IntersectionVisitor::IntersectionVisitor(Intersector* intersector, ReadCallback*
|
||||
// override the default node visitor mode.
|
||||
setTraversalMode(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
|
||||
|
||||
_useKdTreesWhenAvailable = true;
|
||||
|
||||
setIntersector(intersector);
|
||||
|
||||
setReadCallback(readCallback);
|
||||
|
@ -299,8 +299,8 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
||||
unsigned int numKdTreeHits = 0;
|
||||
unsigned int numConventionalHits = 0;
|
||||
|
||||
osg::KdTree* kdTree = dynamic_cast<osg::KdTree*>(drawable->getShape());
|
||||
osg::Vec3d kdTreeHit;
|
||||
osg::KdTree* kdTree = iv.getUseKdTreeWhenAvailable() ? dynamic_cast<osg::KdTree*>(drawable->getShape()) : 0;
|
||||
if (kdTree)
|
||||
{
|
||||
osg::KdTree::LineSegmentIntersections intersections;
|
||||
@ -343,11 +343,7 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
||||
}
|
||||
}
|
||||
|
||||
// return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"Not KdTree available"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
osg::Timer_t after_kdTree = osg::Timer::instance()->tick();
|
||||
@ -423,7 +419,7 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
||||
double timeKdTree = osg::Timer::instance()->delta_m(before_kdTree, after_kdTree);
|
||||
double timeConventional = osg::Timer::instance()->delta_m(after_kdTree, after_conventional);
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
if (kdTree)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"KdTree ("<<kdTreeHit<<") intersections = "<<numKdTreeHits<< " time = "<<timeKdTree<<std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user