]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/QuadTreeBuilder.hxx
Random trees from Stuart Buchanan
[simgear.git] / simgear / scene / util / QuadTreeBuilder.hxx
1 // Copyright (C) 2008  Tim Moore
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16 #ifndef SIMGEAR_QUADTREEBUILDER_HXX
17 #define SIMGEAR_QUADTREEBUILDER_HXX 1
18
19 #include <vector>
20 #include <osg/ref_ptr>
21 #include <osg/Node>
22 #include <osg/Group>
23 #include <osg/Matrix>
24 #include <osg/Vec2>
25 #include <osg/LOD>
26
27 #define QUAD_TREE_LEAVES 4
28
29 namespace simgear
30 {
31 typedef std::map<osg::ref_ptr<osg::Node>,int> LodMap;
32
33 // Create a quad tree based on x, y extents
34 class QuadTreeBuilder {
35 public:
36     QuadTreeBuilder(const osg::Vec2& min, const osg::Vec2& max);
37     ~QuadTreeBuilder() {}
38     osg::Group* getRoot() { return _root.get(); }
39     // Add node to the quadtree using its x, y and LoD
40     void addNode(osg::Node* node, int lod, const osg::Matrix& transform);
41     // Make a quadtree of nodes from a map of nodes and LOD values
42     static osg::Group* makeQuadTree(LodMap& nodes,
43                                     const osg::Matrix& transform);
44 protected:
45     osg::ref_ptr<osg::Group> _root;
46     osg::LOD* _leaves[QUAD_TREE_LEAVES][QUAD_TREE_LEAVES];
47     osg::Vec2 _min;
48     osg::Vec2 _max;
49 };
50 }
51 #endif