root/OpenSceneGraph/trunk/examples/osgkdtree/osgkdtree.cpp @ 8405

Revision 8405, 3.1 kB (checked in by robert, 7 years ago)

Fleshed out some basic kd-tree data structures.

Line 
1/* OpenSceneGraph example, osgintersection.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
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
37class KDNode
38{
39    public:
40   
41        typedef short value_type;
42
43        value_type _leftChild;
44        value_type _rightChild;
45};
46
47class 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
63class 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
78class 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
105int main(int argc, char **argv)
106{
107    // use an ArgumentParser object to manage the program arguments.
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}
Note: See TracBrowser for help on using the browser.