4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
37 #include "MT_Point3.h"
47 * Holds a binary tree of SG_Nodes.
57 SG_Node* m_client_object;
60 SG_Tree(SG_Tree* left, SG_Tree* right);
62 SG_Tree(SG_Node* client);
66 * Computes the volume of the bounding box.
68 MT_Scalar volume() const;
71 * Prints the tree (for debugging.)
76 * Returns the left node.
78 SG_Tree *Left() const;
79 SG_Tree *Right() const;
80 SG_Node *Client() const;
82 SG_Tree* Find(SG_Node *node);
84 * Gets the eight corners of this treenode's bounding box,
85 * in world coordinates.
86 * @param box: an array of 8 MT_Point3
87 * @example MT_Point3 box[8];
90 void get(MT_Point3 *box) const;
92 * Get the tree node's bounding box.
94 const SG_BBox& BBox() const;
97 * Test if the given bounding box is inside this bounding box.
99 bool inside(const MT_Point3 &point) const;
101 void SetLeft(SG_Tree *left);
102 void SetRight(SG_Tree *right);
104 MT_Point3 Center() const { return m_center; }
105 MT_Scalar Radius() { return m_radius; }
107 //friend class SG_TreeFactory;
111 bool operator()(const SG_Tree *a, const SG_Tree *b)
113 return a->volume() > b->volume();
119 #ifdef WITH_CXX_GUARDEDALLOC
121 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_Tree"); }
122 void operator delete( void *mem ) { MEM_freeN(mem); }
128 * SG_TreeFactory generates an SG_Tree from a list of SG_Nodes.
129 * It joins pairs of SG_Nodes to minimise the size of the resultant
131 * cf building an optimised Huffman tree.
136 typedef std::multiset<SG_Tree*, SG_Tree::greater> TreeSet;
143 * Add a node to be added to the tree.
145 void Add(SG_Node* client);
146 void Add(SG_Tree* tree);
149 * Build the tree from the set of nodes added by
152 SG_Tree* MakeTreeUp();
155 * Build the tree from the set of nodes top down.
157 SG_Tree* MakeTreeDown(SG_BBox &bbox);
162 #ifdef WITH_CXX_GUARDEDALLOC
164 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_TreeFactory"); }
165 void operator delete( void *mem ) { MEM_freeN(mem); }
169 #endif /* __SG_BBOX_H__ */