]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/QuadTreeBuilder.hxx
Memory leak fixes from Till Busch
[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
26 namespace simgear
27 {
28 // Create a quad tree based on x, y extents
29 class QuadTreeBuilder {
30 public:
31     QuadTreeBuilder(const osg::Vec2& min, const osg::Vec2& max);
32     ~QuadTreeBuilder() {}
33     osg::Group* getRoot() { return _root.get(); }
34     // Add node to the quadtree using its x, y
35     void addNode(osg::Node* node, const osg::Matrix& transform);
36     // Make a quadtree of nodes from a vector of nodes
37     static osg::Group* makeQuadTree(std::vector<osg::ref_ptr<osg::Node> >& nodes,
38                                     const osg::Matrix& transform);
39 protected:
40     osg::ref_ptr<osg::Group> _root;
41     osg::Group* _leaves[4][4];
42     osg::Vec2 _min;
43     osg::Vec2 _max;
44 };
45 }
46 #endif