Added osgUtil::IntersectorGroup to handle groups of osgUtil::Intersectors
This commit is contained in:
@@ -39,45 +39,115 @@ int main(int argc, char **argv)
|
||||
|
||||
std::cout<<"Intersection "<<std::endl;
|
||||
|
||||
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
||||
|
||||
|
||||
osg::BoundingSphere bs = root->getBound();
|
||||
#if 1
|
||||
osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0);
|
||||
osg::Vec3d end = bs.center() - osg::Vec3d(0.0, bs.radius(),0.0);
|
||||
#else
|
||||
osg::Vec3d start = bs.center() + osg::Vec3d(0.0,0.0, bs.radius());
|
||||
osg::Vec3d end = bs.center() - osg::Vec3d(0.0, 0.0, bs.radius());
|
||||
#endif
|
||||
|
||||
|
||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(start, end);
|
||||
|
||||
osgUtil::IntersectionVisitor intersectVisitor( intersector.get(), new MyReadCallback );
|
||||
|
||||
root->accept(intersectVisitor);
|
||||
|
||||
osg::Timer_t endTick = osg::Timer::instance()->tick();
|
||||
|
||||
std::cout<<"Completed in "<<osg::Timer::instance()->delta_s(startTick,endTick)<<std::endl;
|
||||
|
||||
if ( intersector->containsIntersections() )
|
||||
bool useIntersectorGroup = true;
|
||||
|
||||
if (useIntersectorGroup)
|
||||
{
|
||||
osgUtil::LineSegmentIntersector::Intersections& intersections = intersector->getIntersections();
|
||||
for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = intersections.begin();
|
||||
itr != intersections.end();
|
||||
++itr)
|
||||
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
||||
|
||||
osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0);
|
||||
osg::Vec3d end = bs.center();// - osg::Vec3d(0.0, bs.radius(),0.0);
|
||||
osg::Vec3d deltaRow( 0.0, 0.0, bs.radius()*0.01);
|
||||
osg::Vec3d deltaColumn( bs.radius()*0.01, 0.0, 0.0);
|
||||
unsigned int numRows = 20;
|
||||
unsigned int numColumns = 20;
|
||||
|
||||
osg::ref_ptr<osgUtil::IntersectorGroup> intersectorGroup = new osgUtil::IntersectorGroup();
|
||||
|
||||
for(unsigned int r=0; r<numRows; ++r)
|
||||
{
|
||||
const osgUtil::LineSegmentIntersector::Intersection& intersection = *itr;
|
||||
std::cout<<" ratio "<<intersection.ratio<<std::endl;
|
||||
std::cout<<" point "<<intersection.localIntersectionPoint<<std::endl;
|
||||
std::cout<<" normal "<<intersection.localIntersectionNormal<<std::endl;
|
||||
std::cout<<" indices "<<intersection.indexList.size()<<std::endl;
|
||||
std::cout<<" primitiveIndex "<<intersection.primitiveIndex<<std::endl;
|
||||
std::cout<<std::endl;
|
||||
for(unsigned int c=0; c<numColumns; ++c)
|
||||
{
|
||||
osg::Vec3d s = start + deltaColumn * double(c) + deltaRow * double(r);
|
||||
osg::Vec3d e = end + deltaColumn * double(c) + deltaRow * double(r);
|
||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(s, e);
|
||||
intersectorGroup->addIntersector( intersector.get() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
osgUtil::IntersectionVisitor intersectVisitor( intersectorGroup.get(), new MyReadCallback );
|
||||
root->accept(intersectVisitor);
|
||||
|
||||
osg::Timer_t endTick = osg::Timer::instance()->tick();
|
||||
|
||||
std::cout<<"Completed in "<<osg::Timer::instance()->delta_s(startTick,endTick)<<std::endl;
|
||||
|
||||
if ( intersectorGroup->containsIntersections() )
|
||||
{
|
||||
std::cout<<"Found intersections "<<std::endl;
|
||||
|
||||
osgUtil::IntersectorGroup::Intersectors& intersectors = intersectorGroup->getIntersectors();
|
||||
for(osgUtil::IntersectorGroup::Intersectors::iterator intersector_itr = intersectors.begin();
|
||||
intersector_itr != intersectors.end();
|
||||
++intersector_itr)
|
||||
{
|
||||
osgUtil::LineSegmentIntersector* lsi = dynamic_cast<osgUtil::LineSegmentIntersector*>(intersector_itr->get());
|
||||
if (lsi)
|
||||
{
|
||||
osgUtil::LineSegmentIntersector::Intersections& intersections = lsi->getIntersections();
|
||||
for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = intersections.begin();
|
||||
itr != intersections.end();
|
||||
++itr)
|
||||
{
|
||||
const osgUtil::LineSegmentIntersector::Intersection& intersection = *itr;
|
||||
std::cout<<" ratio "<<intersection.ratio<<std::endl;
|
||||
std::cout<<" point "<<intersection.localIntersectionPoint<<std::endl;
|
||||
std::cout<<" normal "<<intersection.localIntersectionNormal<<std::endl;
|
||||
std::cout<<" indices "<<intersection.indexList.size()<<std::endl;
|
||||
std::cout<<" primitiveIndex "<<intersection.primitiveIndex<<std::endl;
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::Timer_t startTick = osg::Timer::instance()->tick();
|
||||
|
||||
#if 1
|
||||
osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0);
|
||||
osg::Vec3d end = bs.center() - osg::Vec3d(0.0, bs.radius(),0.0);
|
||||
#else
|
||||
osg::Vec3d start = bs.center() + osg::Vec3d(0.0,0.0, bs.radius());
|
||||
osg::Vec3d end = bs.center() - osg::Vec3d(0.0, 0.0, bs.radius());
|
||||
#endif
|
||||
|
||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(start, end);
|
||||
|
||||
osgUtil::IntersectionVisitor intersectVisitor( intersector.get(), new MyReadCallback );
|
||||
|
||||
root->accept(intersectVisitor);
|
||||
|
||||
osg::Timer_t endTick = osg::Timer::instance()->tick();
|
||||
|
||||
std::cout<<"Completed in "<<osg::Timer::instance()->delta_s(startTick,endTick)<<std::endl;
|
||||
|
||||
if ( intersector->containsIntersections() )
|
||||
{
|
||||
osgUtil::LineSegmentIntersector::Intersections& intersections = intersector->getIntersections();
|
||||
for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = intersections.begin();
|
||||
itr != intersections.end();
|
||||
++itr)
|
||||
{
|
||||
const osgUtil::LineSegmentIntersector::Intersection& intersection = *itr;
|
||||
std::cout<<" ratio "<<intersection.ratio<<std::endl;
|
||||
std::cout<<" point "<<intersection.localIntersectionPoint<<std::endl;
|
||||
std::cout<<" normal "<<intersection.localIntersectionNormal<<std::endl;
|
||||
std::cout<<" indices "<<intersection.indexList.size()<<std::endl;
|
||||
std::cout<<" primitiveIndex "<<intersection.primitiveIndex<<std::endl;
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user