| 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 <osgViewer/Viewer> |
|---|
| 41 | |
|---|
| 42 | #include "fixeddivision.h" |
|---|
| 43 | #include "variabledivision.h" |
|---|
| 44 | |
|---|
| 45 | #include <osg/KdTree> |
|---|
| 46 | |
|---|
| 47 | int main(int argc, char **argv) |
|---|
| 48 | { |
|---|
| 49 | |
|---|
| 50 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 51 | |
|---|
| 52 | int maxNumLevels = 16; |
|---|
| 53 | int targetNumIndicesPerLeaf = 16; |
|---|
| 54 | bool processTriangles = true; |
|---|
| 55 | |
|---|
| 56 | while (arguments.read("--max", maxNumLevels)) {} |
|---|
| 57 | while (arguments.read("--leaf", targetNumIndicesPerLeaf)) {} |
|---|
| 58 | while (arguments.read("--points")) processTriangles = false; |
|---|
| 59 | while (arguments.read("--triangles")) processTriangles = true; |
|---|
| 60 | |
|---|
| 61 | osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES); |
|---|
| 62 | |
|---|
| 63 | osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments); |
|---|
| 64 | |
|---|
| 65 | if (!scene) |
|---|
| 66 | { |
|---|
| 67 | std::cout<<"No model loaded, please specify a valid model on the command line."<<std::endl; |
|---|
| 68 | return 0; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | osgUtil::UpdateVisitor updateVisitor; |
|---|
| 73 | updateVisitor.setFrameStamp(new osg::FrameStamp); |
|---|
| 74 | scene->accept(updateVisitor); |
|---|
| 75 | scene->getBound(); |
|---|
| 76 | |
|---|
| 77 | if (arguments.read("--fd")) |
|---|
| 78 | { |
|---|
| 79 | fixeddivision::KDTreeBuilder builder; |
|---|
| 80 | |
|---|
| 81 | builder._maxNumLevels = maxNumLevels; |
|---|
| 82 | builder._targetNumIndicesPerLeaf = targetNumIndicesPerLeaf; |
|---|
| 83 | builder._processTriangles = processTriangles; |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | osg::Timer_t start = osg::Timer::instance()->tick(); |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | scene->accept(builder); |
|---|
| 90 | |
|---|
| 91 | osg::Timer_t end = osg::Timer::instance()->tick(); |
|---|
| 92 | double time = osg::Timer::instance()->delta_s(start,end); |
|---|
| 93 | osg::notify(osg::NOTICE)<<"Time to build "<<time*1000.0<<"ms "<<builder._numVerticesProcessed<<std::endl; |
|---|
| 94 | osg::notify(osg::NOTICE)<<"build speed "<<(double(builder._numVerticesProcessed)/time)/1000000.0<<"M vertices per second"<<std::endl; |
|---|
| 95 | } |
|---|
| 96 | else if (arguments.read("--vd")) |
|---|
| 97 | { |
|---|
| 98 | variabledivision::KDTreeBuilder builder; |
|---|
| 99 | |
|---|
| 100 | builder._maxNumLevels = maxNumLevels; |
|---|
| 101 | builder._targetNumTrianglesPerLeaf = targetNumIndicesPerLeaf; |
|---|
| 102 | builder._processTriangles = processTriangles; |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | osg::Timer_t start = osg::Timer::instance()->tick(); |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | scene->accept(builder); |
|---|
| 109 | |
|---|
| 110 | osg::Timer_t end = osg::Timer::instance()->tick(); |
|---|
| 111 | double time = osg::Timer::instance()->delta_s(start,end); |
|---|
| 112 | osg::notify(osg::NOTICE)<<"Time to build "<<time*1000.0<<"ms "<<builder._numVerticesProcessed<<std::endl; |
|---|
| 113 | osg::notify(osg::NOTICE)<<"build speed "<<(double(builder._numVerticesProcessed)/time)/1000000.0<<"M vertices per second"<<std::endl; |
|---|
| 114 | } |
|---|
| 115 | else |
|---|
| 116 | { |
|---|
| 117 | osgViewer::Viewer viewer; |
|---|
| 118 | viewer.setSceneData(scene.get()); |
|---|
| 119 | return viewer.run(); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | return 0; |
|---|
| 123 | } |
|---|