Introduced code for doing dummy test traversals - used for benchmarking KdTree code.

This commit is contained in:
Robert Osfield 2008-07-09 19:40:10 +00:00
parent 15e5bdbcae
commit c41ca3d6a0
3 changed files with 7 additions and 27 deletions

View File

@ -155,6 +155,9 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
/** Set whether the intersectors should use KdTrees.*/
bool getUseKdTreeWhenAvailable() const { return _useKdTreesWhenAvailable; }
void setDoDummyTraversal(bool dummy) { _dummyTraversal = dummy; }
bool getDoDummyTraversal() const { return _dummyTraversal; }
/** Set the read callback.*/
@ -212,6 +215,7 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
IntersectorStack _intersectorStack;
bool _useKdTreesWhenAvailable;
bool _dummyTraversal;
osg::ref_ptr<ReadCallback> _readCallback;

View File

@ -156,6 +156,7 @@ IntersectionVisitor::IntersectionVisitor(Intersector* intersector, ReadCallback*
setTraversalMode(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
_useKdTreesWhenAvailable = true;
_dummyTraversal = false;
setIntersector(intersector);

View File

@ -285,6 +285,8 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
osg::Vec3d s(_start), e(_end);
if ( !intersectAndClip( s, e, drawable->getBound() ) ) return;
if (iv.getDoDummyTraversal()) return;
double epsilon = 1e-8;
if ((s-e).length()<epsilon)
{
@ -295,11 +297,6 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
e += (delta_e_end * scale);
}
osg::Timer_t before_kdTree = osg::Timer::instance()->tick();
unsigned int numKdTreeHits = 0;
unsigned int numConventionalHits = 0;
osg::Vec3d kdTreeHit;
osg::KdTree* kdTree = iv.getUseKdTreeWhenAvailable() ? dynamic_cast<osg::KdTree*>(drawable->getShape()) : 0;
if (kdTree)
{
@ -328,7 +325,6 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
hit.primitiveIndex = lsi.primitiveIndex;
hit.localIntersectionPoint = _start*(1.0-remap_ratio) + _end*remap_ratio;
kdTreeHit = hit.localIntersectionPoint;
// osg::notify(osg::NOTICE)<<"KdTree: ratio="<<hit.ratio<<" ("<<hit.localIntersectionPoint<<")"<<std::endl;
@ -337,7 +333,6 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
hit.indexList.swap(lsi.indexList);
hit.ratioList.swap(lsi.ratioList);
++numKdTreeHits;
insertIntersection(hit);
}
@ -346,13 +341,10 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
return;
}
osg::Timer_t after_kdTree = osg::Timer::instance()->tick();
osg::TriangleFunctor<LineSegmentIntersectorUtils::TriangleIntersector> ti;
ti.set(s,e);
drawable->accept(ti);
osg::Vec3d conventionalHit;
if (ti._hit)
{
osg::Geometry* geometry = drawable->asGeometry();
@ -378,7 +370,6 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
hit.primitiveIndex = triHit._index;
hit.localIntersectionPoint = _start*(1.0-remap_ratio) + _end*remap_ratio;
conventionalHit = hit.localIntersectionPoint;
// osg::notify(osg::NOTICE)<<"Conventional: ratio="<<hit.ratio<<" ("<<hit.localIntersectionPoint<<")"<<std::endl;
@ -409,25 +400,9 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
}
insertIntersection(hit);
++numConventionalHits;
}
}
osg::Timer_t after_conventional = osg::Timer::instance()->tick();
double timeKdTree = osg::Timer::instance()->delta_m(before_kdTree, after_kdTree);
double timeConventional = osg::Timer::instance()->delta_m(after_kdTree, after_conventional);
#if 0
if (kdTree)
{
osg::notify(osg::NOTICE)<<"KdTree ("<<kdTreeHit<<") intersections = "<<numKdTreeHits<< " time = "<<timeKdTree<<std::endl;
osg::notify(osg::NOTICE)<<"Conventional ("<<conventionalHit<<") intersections = "<<numConventionalHits<< " time = "<<timeConventional<<std::endl;
osg::notify(osg::NOTICE)<<"Ratio = "<<timeConventional/timeKdTree<<std::endl;
osg::notify(osg::NOTICE)<<std::endl;
}
#endif
}
void LineSegmentIntersector::reset()