Blender  V2.59
SG_Tree.h
Go to the documentation of this file.
00001 /*
00002  * $Id: SG_Tree.h 35082 2011-02-22 19:30:37Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029  
00034 #ifndef __SG_TREE_H__
00035 #define __SG_TREE_H__
00036  
00037 #include "MT_Point3.h"
00038 #include "SG_BBox.h"
00039 
00040 #include <set> 
00041 
00042 class SG_Node;
00043 
00044 
00049 class SG_Tree 
00050 {
00051         SG_Tree* m_left;
00052         SG_Tree* m_right;
00053         SG_Tree* m_parent;
00054         SG_BBox  m_bbox;
00055         MT_Point3 m_center;
00056         MT_Scalar m_radius;
00057         SG_Node* m_client_object;
00058 public:
00059         SG_Tree();
00060         SG_Tree(SG_Tree* left, SG_Tree* right);
00061         
00062         SG_Tree(SG_Node* client);
00063         ~SG_Tree();
00064         
00068         MT_Scalar volume() const;
00069         
00073         void dump() const;
00074         
00078         SG_Tree *Left() const;
00079         SG_Tree *Right() const;
00080         SG_Node *Client() const;
00081         
00082         SG_Tree* Find(SG_Node *node);
00090         void get(MT_Point3 *box) const;
00094         const SG_BBox& BBox() const;
00095         
00099         bool inside(const MT_Point3 &point) const;
00100         
00101         void SetLeft(SG_Tree *left);
00102         void SetRight(SG_Tree *right);
00103 
00104         MT_Point3 Center() const { return m_center; }
00105         MT_Scalar Radius() { return m_radius; }
00106         
00107         //friend class SG_TreeFactory;
00108         
00109         struct greater
00110         {
00111                 bool operator()(const SG_Tree *a, const SG_Tree *b)
00112                 {
00113                         return a->volume() > b->volume();
00114                 }
00115         };
00116         
00117         
00118         
00119 #ifdef WITH_CXX_GUARDEDALLOC
00120 public:
00121         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_Tree"); }
00122         void operator delete( void *mem ) { MEM_freeN(mem); }
00123 #endif
00124 };
00125 
00126 
00134 class SG_TreeFactory 
00135 {
00136         typedef std::multiset<SG_Tree*, SG_Tree::greater> TreeSet;
00137         TreeSet m_objects;
00138 public:
00139         SG_TreeFactory();
00140         ~SG_TreeFactory();
00141         
00145         void Add(SG_Node* client);
00146         void Add(SG_Tree* tree);
00147 
00152         SG_Tree* MakeTreeUp();
00153         
00157         SG_Tree* MakeTreeDown(SG_BBox &bbox);
00158         
00159         SG_Tree* MakeTree();
00160         
00161         
00162 #ifdef WITH_CXX_GUARDEDALLOC
00163 public:
00164         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_TreeFactory"); }
00165         void operator delete( void *mem ) { MEM_freeN(mem); }
00166 #endif
00167 };
00168 
00169 #endif /* __SG_BBOX_H__ */