| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osg/ArgumentParser> |
|---|
| 20 | #include <osg/ApplicationUsage> |
|---|
| 21 | #include <osg/Timer> |
|---|
| 22 | #include <osg/CoordinateSystemNode> |
|---|
| 23 | #include <osg/Notify> |
|---|
| 24 | #include <osg/io_utils> |
|---|
| 25 | |
|---|
| 26 | #include <osgDB/ReadFile> |
|---|
| 27 | |
|---|
| 28 | #include <osgUtil/IntersectionVisitor> |
|---|
| 29 | #include <osgUtil/LineSegmentIntersector> |
|---|
| 30 | |
|---|
| 31 | #include <osgSim/LineOfSight> |
|---|
| 32 | #include <osgSim/HeightAboveTerrain> |
|---|
| 33 | #include <osgSim/ElevationSlice> |
|---|
| 34 | |
|---|
| 35 | #include <iostream> |
|---|
| 36 | |
|---|
| 37 | class KDNode |
|---|
| 38 | { |
|---|
| 39 | public: |
|---|
| 40 | |
|---|
| 41 | typedef short value_type; |
|---|
| 42 | |
|---|
| 43 | value_type _leftChild; |
|---|
| 44 | value_type _rightChild; |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | class KDLeaf : public osg::Referenced |
|---|
| 48 | { |
|---|
| 49 | public: |
|---|
| 50 | |
|---|
| 51 | KDLeaf(); |
|---|
| 52 | |
|---|
| 53 | typedef unsigned int index_type; |
|---|
| 54 | typedef std::vector< index_type > Indices; |
|---|
| 55 | |
|---|
| 56 | Indices _vertexIndices; |
|---|
| 57 | |
|---|
| 58 | protected: |
|---|
| 59 | |
|---|
| 60 | virtual ~KDLeaf() {} |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | class KDTree : public osg::Referenced |
|---|
| 64 | { |
|---|
| 65 | public: |
|---|
| 66 | |
|---|
| 67 | typedef std::vector< unsigned int > AxisStack; |
|---|
| 68 | typedef std::vector< KDNode > KDNodeList; |
|---|
| 69 | typedef std::vector< osg::ref_ptr<KDLeaf> > KDLeafList; |
|---|
| 70 | |
|---|
| 71 | osg::BoundingBox _bb; |
|---|
| 72 | |
|---|
| 73 | AxisStack _axisStack; |
|---|
| 74 | KDNodeList _kdNodes; |
|---|
| 75 | KDLeafList _kdLeaves; |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | class KDTreeTraverser |
|---|
| 79 | { |
|---|
| 80 | public: |
|---|
| 81 | |
|---|
| 82 | void traverse(KDTree& tree, KDNode::value_type nodeIndex) |
|---|
| 83 | { |
|---|
| 84 | if (nodeIndex>=0) |
|---|
| 85 | { |
|---|
| 86 | KDNode& node = tree._kdNodes[nodeIndex]; |
|---|
| 87 | traverse(tree,node._leftChild); |
|---|
| 88 | traverse(tree,node._rightChild); |
|---|
| 89 | } |
|---|
| 90 | else |
|---|
| 91 | { |
|---|
| 92 | KDNode::value_type leafIndex = -nodeIndex-1; |
|---|
| 93 | KDLeaf& leaf = *(tree._kdLeaves[leafIndex]); |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | void traverse(KDTree& tree) |
|---|
| 99 | { |
|---|
| 100 | if (!tree._kdNodes.empty()) traverse(tree,0); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | }; |
|---|
| 104 | |
|---|
| 105 | int main(int argc, char **argv) |
|---|
| 106 | { |
|---|
| 107 | |
|---|
| 108 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 109 | |
|---|
| 110 | osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments); |
|---|
| 111 | |
|---|
| 112 | if (!scene) |
|---|
| 113 | { |
|---|
| 114 | std::cout<<"No model loaded, please specify a valid model on the command line."<<std::endl; |
|---|
| 115 | return 0; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | return 0; |
|---|
| 120 | } |
|---|