Blender V2.61 - r43446

SG_Tree.h

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