1 // Copyright (C) 2008 Tim Moore
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.
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.
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
20 #include <osg/ref_ptr>
27 #define QUAD_TREE_LEAVES 4
31 typedef std::map<osg::ref_ptr<osg::Node>,int> LodMap;
33 // Create a quad tree based on x, y extents
34 class QuadTreeBuilder {
36 QuadTreeBuilder(const osg::Vec2& min, const osg::Vec2& max);
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);
45 osg::ref_ptr<osg::Group> _root;
46 osg::LOD* _leaves[QUAD_TREE_LEAVES][QUAD_TREE_LEAVES];