57 | | osgUtil::IntersectionVisitor intersectVisitor( intersector.get(), new MyReadCallback ); |
58 | | |
59 | | root->accept(intersectVisitor); |
60 | | |
61 | | osg::Timer_t endTick = osg::Timer::instance()->tick(); |
| 53 | osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0); |
| 54 | osg::Vec3d end = bs.center();// - osg::Vec3d(0.0, bs.radius(),0.0); |
| 55 | osg::Vec3d deltaRow( 0.0, 0.0, bs.radius()*0.01); |
| 56 | osg::Vec3d deltaColumn( bs.radius()*0.01, 0.0, 0.0); |
| 57 | unsigned int numRows = 20; |
| 58 | unsigned int numColumns = 20; |
65 | | if ( intersector->containsIntersections() ) |
| 62 | for(unsigned int r=0; r<numRows; ++r) |
| 63 | { |
| 64 | for(unsigned int c=0; c<numColumns; ++c) |
| 65 | { |
| 66 | osg::Vec3d s = start + deltaColumn * double(c) + deltaRow * double(r); |
| 67 | osg::Vec3d e = end + deltaColumn * double(c) + deltaRow * double(r); |
| 68 | osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(s, e); |
| 69 | intersectorGroup->addIntersector( intersector.get() ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | |
| 74 | osgUtil::IntersectionVisitor intersectVisitor( intersectorGroup.get(), new MyReadCallback ); |
| 75 | root->accept(intersectVisitor); |
| 76 | |
| 77 | osg::Timer_t endTick = osg::Timer::instance()->tick(); |
| 78 | |
| 79 | std::cout<<"Completed in "<<osg::Timer::instance()->delta_s(startTick,endTick)<<std::endl; |
| 80 | |
| 81 | if ( intersectorGroup->containsIntersections() ) |
| 82 | { |
| 83 | std::cout<<"Found intersections "<<std::endl; |
| 84 | |
| 85 | osgUtil::IntersectorGroup::Intersectors& intersectors = intersectorGroup->getIntersectors(); |
| 86 | for(osgUtil::IntersectorGroup::Intersectors::iterator intersector_itr = intersectors.begin(); |
| 87 | intersector_itr != intersectors.end(); |
| 88 | ++intersector_itr) |
| 89 | { |
| 90 | osgUtil::LineSegmentIntersector* lsi = dynamic_cast<osgUtil::LineSegmentIntersector*>(intersector_itr->get()); |
| 91 | if (lsi) |
| 92 | { |
| 93 | osgUtil::LineSegmentIntersector::Intersections& intersections = lsi->getIntersections(); |
| 94 | for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = intersections.begin(); |
| 95 | itr != intersections.end(); |
| 96 | ++itr) |
| 97 | { |
| 98 | const osgUtil::LineSegmentIntersector::Intersection& intersection = *itr; |
| 99 | std::cout<<" ratio "<<intersection.ratio<<std::endl; |
| 100 | std::cout<<" point "<<intersection.localIntersectionPoint<<std::endl; |
| 101 | std::cout<<" normal "<<intersection.localIntersectionNormal<<std::endl; |
| 102 | std::cout<<" indices "<<intersection.indexList.size()<<std::endl; |
| 103 | std::cout<<" primitiveIndex "<<intersection.primitiveIndex<<std::endl; |
| 104 | std::cout<<std::endl; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | } |
| 110 | |
| 111 | } |
| 112 | else |
67 | | osgUtil::LineSegmentIntersector::Intersections& intersections = intersector->getIntersections(); |
68 | | for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = intersections.begin(); |
69 | | itr != intersections.end(); |
70 | | ++itr) |
| 114 | osg::Timer_t startTick = osg::Timer::instance()->tick(); |
| 115 | |
| 116 | #if 1 |
| 117 | osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0); |
| 118 | osg::Vec3d end = bs.center() - osg::Vec3d(0.0, bs.radius(),0.0); |
| 119 | #else |
| 120 | osg::Vec3d start = bs.center() + osg::Vec3d(0.0,0.0, bs.radius()); |
| 121 | osg::Vec3d end = bs.center() - osg::Vec3d(0.0, 0.0, bs.radius()); |
| 122 | #endif |
| 123 | |
| 124 | osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(start, end); |
| 125 | |
| 126 | osgUtil::IntersectionVisitor intersectVisitor( intersector.get(), new MyReadCallback ); |
| 127 | |
| 128 | root->accept(intersectVisitor); |
| 129 | |
| 130 | osg::Timer_t endTick = osg::Timer::instance()->tick(); |
| 131 | |
| 132 | std::cout<<"Completed in "<<osg::Timer::instance()->delta_s(startTick,endTick)<<std::endl; |
| 133 | |
| 134 | if ( intersector->containsIntersections() ) |
72 | | const osgUtil::LineSegmentIntersector::Intersection& intersection = *itr; |
73 | | std::cout<<" ratio "<<intersection.ratio<<std::endl; |
74 | | std::cout<<" point "<<intersection.localIntersectionPoint<<std::endl; |
75 | | std::cout<<" normal "<<intersection.localIntersectionNormal<<std::endl; |
76 | | std::cout<<" indices "<<intersection.indexList.size()<<std::endl; |
77 | | std::cout<<" primitiveIndex "<<intersection.primitiveIndex<<std::endl; |
78 | | std::cout<<std::endl; |
| 136 | osgUtil::LineSegmentIntersector::Intersections& intersections = intersector->getIntersections(); |
| 137 | for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = intersections.begin(); |
| 138 | itr != intersections.end(); |
| 139 | ++itr) |
| 140 | { |
| 141 | const osgUtil::LineSegmentIntersector::Intersection& intersection = *itr; |
| 142 | std::cout<<" ratio "<<intersection.ratio<<std::endl; |
| 143 | std::cout<<" point "<<intersection.localIntersectionPoint<<std::endl; |
| 144 | std::cout<<" normal "<<intersection.localIntersectionNormal<<std::endl; |
| 145 | std::cout<<" indices "<<intersection.indexList.size()<<std::endl; |
| 146 | std::cout<<" primitiveIndex "<<intersection.primitiveIndex<<std::endl; |
| 147 | std::cout<<std::endl; |
| 148 | } |