| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #include <osgDB/ReadFile> |
|---|
| 21 | |
|---|
| 22 | #include <osg/ArgumentParser> |
|---|
| 23 | #include <osg/ApplicationUsage> |
|---|
| 24 | #include <osg/Timer> |
|---|
| 25 | #include <osg/CoordinateSystemNode> |
|---|
| 26 | #include <osg/Notify> |
|---|
| 27 | #include <osg/io_utils> |
|---|
| 28 | #include <osg/Geometry> |
|---|
| 29 | #include <osg/TriangleIndexFunctor> |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | #include <osgUtil/IntersectionVisitor> |
|---|
| 33 | #include <osgUtil/LineSegmentIntersector> |
|---|
| 34 | #include <osgUtil/UpdateVisitor> |
|---|
| 35 | |
|---|
| 36 | #include <osgSim/LineOfSight> |
|---|
| 37 | #include <osgSim/HeightAboveTerrain> |
|---|
| 38 | #include <osgSim/ElevationSlice> |
|---|
| 39 | |
|---|
| 40 | #include "fixeddivision.h" |
|---|
| 41 | #include "variabledivision.h" |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | int main(int argc, char **argv) |
|---|
| 45 | { |
|---|
| 46 | |
|---|
| 47 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 48 | |
|---|
| 49 | int maxNumLevels = 16; |
|---|
| 50 | int targetNumIndicesPerLeaf = 16; |
|---|
| 51 | bool processTriangles = true; |
|---|
| 52 | |
|---|
| 53 | while (arguments.read("--max", maxNumLevels)) {} |
|---|
| 54 | while (arguments.read("--leaf", targetNumIndicesPerLeaf)) {} |
|---|
| 55 | while (arguments.read("--points")) processTriangles = false; |
|---|
| 56 | while (arguments.read("--triangles")) processTriangles = true; |
|---|
| 57 | |
|---|
| 58 | osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments); |
|---|
| 59 | |
|---|
| 60 | if (!scene) |
|---|
| 61 | { |
|---|
| 62 | std::cout<<"No model loaded, please specify a valid model on the command line."<<std::endl; |
|---|
| 63 | return 0; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | osgUtil::UpdateVisitor updateVisitor; |
|---|
| 68 | updateVisitor.setFrameStamp(new osg::FrameStamp); |
|---|
| 69 | scene->accept(updateVisitor); |
|---|
| 70 | scene->getBound(); |
|---|
| 71 | |
|---|
| 72 | if (arguments.read("--fd")) |
|---|
| 73 | { |
|---|
| 74 | fixeddivision::KDTreeBuilder builder; |
|---|
| 75 | |
|---|
| 76 | builder._maxNumLevels = maxNumLevels; |
|---|
| 77 | builder._targetNumIndicesPerLeaf = targetNumIndicesPerLeaf; |
|---|
| 78 | builder._processTriangles = processTriangles; |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | osg::Timer_t start = osg::Timer::instance()->tick(); |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | scene->accept(builder); |
|---|
| 85 | |
|---|
| 86 | osg::Timer_t end = osg::Timer::instance()->tick(); |
|---|
| 87 | double time = osg::Timer::instance()->delta_s(start,end); |
|---|
| 88 | osg::notify(osg::NOTICE)<<"Time to build "<<time*1000.0<<"ms "<<builder._numVerticesProcessed<<std::endl; |
|---|
| 89 | osg::notify(osg::NOTICE)<<"build speed "<<(double(builder._numVerticesProcessed)/time)/1000000.0<<"M vertices per second"<<std::endl; |
|---|
| 90 | } |
|---|
| 91 | else |
|---|
| 92 | { |
|---|
| 93 | variabledivision::KDTreeBuilder builder; |
|---|
| 94 | |
|---|
| 95 | builder._maxNumLevels = maxNumLevels; |
|---|
| 96 | builder._targetNumTrianglesPerLeaf = targetNumIndicesPerLeaf; |
|---|
| 97 | builder._processTriangles = processTriangles; |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | osg::Timer_t start = osg::Timer::instance()->tick(); |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | scene->accept(builder); |
|---|
| 104 | |
|---|
| 105 | osg::Timer_t end = osg::Timer::instance()->tick(); |
|---|
| 106 | double time = osg::Timer::instance()->delta_s(start,end); |
|---|
| 107 | osg::notify(osg::NOTICE)<<"Time to build "<<time*1000.0<<"ms "<<builder._numVerticesProcessed<<std::endl; |
|---|
| 108 | osg::notify(osg::NOTICE)<<"build speed "<<(double(builder._numVerticesProcessed)/time)/1000000.0<<"M vertices per second"<<std::endl; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | return 0; |
|---|
| 112 | } |
|---|