2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
35 #include "MT_Point3.h"
45 * Holds a binary tree of SG_Nodes.
55 SG_Node* m_client_object;
58 SG_Tree(SG_Tree* left, SG_Tree* right);
60 SG_Tree(SG_Node* client);
64 * Computes the volume of the bounding box.
66 MT_Scalar volume() const;
69 * Prints the tree (for debugging.)
74 * Returns the left node.
76 SG_Tree *Left() const;
77 SG_Tree *Right() const;
78 SG_Node *Client() const;
80 SG_Tree* Find(SG_Node *node);
82 * Gets the eight corners of this treenode's bounding box,
83 * in world coordinates.
84 * \param box: an array of 8 MT_Point3
85 * \example MT_Point3 box[8];
88 void get(MT_Point3 *box) const;
90 * Get the tree node's bounding box.
92 const SG_BBox& BBox() const;
95 * Test if the given bounding box is inside this bounding box.
97 bool inside(const MT_Point3 &point) const;
99 void SetLeft(SG_Tree *left);
100 void SetRight(SG_Tree *right);
102 MT_Point3 Center() const { return m_center; }
103 MT_Scalar Radius() { return m_radius; }
105 //friend class SG_TreeFactory;
109 bool operator()(const SG_Tree *a, const SG_Tree *b)
111 return a->volume() > b->volume();
117 #ifdef WITH_CXX_GUARDEDALLOC
118 MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_Tree")
124 * SG_TreeFactory generates an SG_Tree from a list of SG_Nodes.
125 * It joins pairs of SG_Nodes to minimise the size of the resultant
127 * cf building an optimized Huffman tree.
132 typedef std::multiset<SG_Tree*, SG_Tree::greater> TreeSet;
139 * Add a node to be added to the tree.
141 void Add(SG_Node* client);
142 void Add(SG_Tree* tree);
145 * Build the tree from the set of nodes added by
148 SG_Tree* MakeTreeUp();
151 * Build the tree from the set of nodes top down.
153 SG_Tree* MakeTreeDown(SG_BBox &bbox);
158 #ifdef WITH_CXX_GUARDEDALLOC
159 MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_TreeFactory")
163 #endif /* __SG_BBOX_H__ */