| 53 | | { |
| 54 | | osg::Timer_t startTick = osg::Timer::instance()->tick(); |
| 55 | | |
| 56 | | osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0); |
| 57 | | osg::Vec3d end = bs.center();// - osg::Vec3d(0.0, bs.radius(),0.0); |
| 58 | | osg::Vec3d deltaRow( 0.0, 0.0, bs.radius()*0.01); |
| 59 | | osg::Vec3d deltaColumn( bs.radius()*0.01, 0.0, 0.0); |
| 60 | | unsigned int numRows = 50; |
| 61 | | unsigned int numColumns = 50; |
| 62 | | |
| 63 | | osgSim::LineOfSight los; |
| 64 | | |
| 65 | | for(unsigned int r=0; r<numRows; ++r) |
| 66 | | { |
| 67 | | for(unsigned int c=0; c<numColumns; ++c) |
| 68 | | { |
| 69 | | osg::Vec3d s = start + deltaColumn * double(c) + deltaRow * double(r); |
| 70 | | osg::Vec3d e = end + deltaColumn * double(c) + deltaRow * double(r); |
| 71 | | los.addLOS(s,e); |
| 72 | | } |
| 73 | | } |
| 74 | | |
| 75 | | |
| 76 | | los.computeIntersections(root.get()); |
| 77 | | |
| 78 | | osg::Timer_t endTick = osg::Timer::instance()->tick(); |
| 79 | | |
| 80 | | std::cout<<"Completed in "<<osg::Timer::instance()->delta_s(startTick,endTick)<<std::endl; |
| 81 | | |
| 82 | | #if 0 |
| 83 | | for(unsigned int i=0; i<los.getNumLOS(); i++) |
| 84 | | { |
| 85 | | const osgSim::LineOfSight::Intersections& intersections = los.getIntersections(i); |
| 86 | | for(osgSim::LineOfSight::Intersections::const_iterator itr = intersections.begin(); |
| 87 | | itr != intersections.end(); |
| 88 | | ++itr) |
| 89 | | { |
| 90 | | std::cout<<" point "<<*itr<<std::endl; |
| 91 | | } |
| 92 | | } |
| 93 | | #endif |
| 94 | | |
| 95 | | // now do a second traversal to test performance of cache. |
| 96 | | startTick = osg::Timer::instance()->tick(); |
| 97 | | |
| 98 | | los.computeIntersections(root.get()); |
| 99 | | |
| 100 | | endTick = osg::Timer::instance()->tick(); |
| 101 | | |
| 102 | | std::cout<<"Completed in "<<osg::Timer::instance()->delta_s(startTick,endTick)<<std::endl; |
| 103 | | |
| 104 | | } |
| 105 | | else if (useIntersectorGroup) |
| | 67 | osgSim::LineOfSight los; |
| | 68 | |
| | 69 | osgSim::HeightAboveTerrain hat; |
| | 70 | hat.setDatabaseCacheReadCallback(los.getDatabaseCacheReadCallback()); |
| | 71 | |
| | 72 | for(unsigned int r=0; r<numRows; ++r) |
| | 73 | { |
| | 74 | for(unsigned int c=0; c<numColumns; ++c) |
| | 75 | { |
| | 76 | osg::Vec3d s = start + deltaColumn * double(c) + deltaRow * double(r); |
| | 77 | osg::Vec3d e = end + deltaColumn * double(c) + deltaRow * double(r); |
| | 78 | los.addLOS(s,e); |
| | 79 | hat.addPoint(s); |
| | 80 | } |
| | 81 | } |
| | 82 | |
| | 83 | |
| | 84 | std::cout<<"Computing LineOfSight"<<std::endl; |
| | 85 | |
| | 86 | los.computeIntersections(scene.get()); |
| | 87 | |
| | 88 | osg::Timer_t endTick = osg::Timer::instance()->tick(); |
| | 89 | |
| | 90 | std::cout<<"Completed in "<<osg::Timer::instance()->delta_s(startTick,endTick)<<std::endl; |
| | 91 | |
| | 92 | #if 1 |
| | 93 | for(unsigned int i=0; i<los.getNumLOS(); i++) |
| | 94 | { |
| | 95 | const osgSim::LineOfSight::Intersections& intersections = los.getIntersections(i); |
| | 96 | for(osgSim::LineOfSight::Intersections::const_iterator itr = intersections.begin(); |
| | 97 | itr != intersections.end(); |
| | 98 | ++itr) |
| | 99 | { |
| | 100 | std::cout<<" point "<<*itr<<std::endl; |
| | 101 | } |
| | 102 | } |
| | 103 | #endif |
| | 104 | |
| | 105 | // now do a second traversal to test performance of cache. |
| | 106 | startTick = osg::Timer::instance()->tick(); |
| | 107 | |
| | 108 | std::cout<<"Computing HeightAboveTerrain"<<std::endl; |
| | 109 | |
| | 110 | hat.computeIntersections(scene.get()); |
| | 111 | |
| | 112 | for(unsigned int i=0; i<hat.getNumPoints(); i++) |
| | 113 | { |
| | 114 | std::cout<<" point = "<<hat.getPoint(i)<<" hat = "<<hat.getHeightAboveTerrain(i)<<std::endl; |
| | 115 | } |
| | 116 | |
| | 117 | endTick = osg::Timer::instance()->tick(); |
| | 118 | |
| | 119 | std::cout<<"Completed in "<<osg::Timer::instance()->delta_s(startTick,endTick)<<std::endl; |
| | 120 | |
| | 121 | } |
| | 122 | else if (useIntersectorGroup) |
| | 123 | { |
| | 124 | osg::Timer_t startTick = osg::Timer::instance()->tick(); |
| | 125 | |
| | 126 | osg::Vec3d start = bs.center() + osg::Vec3d(0.0,bs.radius(),0.0); |
| | 127 | osg::Vec3d end = bs.center();// - osg::Vec3d(0.0, bs.radius(),0.0); |
| | 128 | osg::Vec3d deltaRow( 0.0, 0.0, bs.radius()*0.01); |
| | 129 | osg::Vec3d deltaColumn( bs.radius()*0.01, 0.0, 0.0); |
| | 130 | unsigned int numRows = 20; |
| | 131 | unsigned int numColumns = 20; |
| | 132 | |