Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_TREENODE_H__
00009 #define __SP_TREENODE_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spBaseObject.hpp"
00014 #include "Base/spMemoryManagement.hpp"
00015 #include "Base/spDimension.hpp"
00016 #include "Base/spMath.hpp"
00017
00018 #include <list>
00019 #include <boost/function.hpp>
00020
00021
00022 namespace sp
00023 {
00024 namespace scene
00025 {
00026
00027
00028 class SceneNode;
00029 class Mesh;
00030 class TreeNode;
00031
00032
00033
00034
00035
00036 static const s32 DEF_TREENODE_FORKSCOUNT = 3;
00037 static const s32 MAX_TREENODE_FORKSCOUNT = 8;
00038
00039 typedef boost::function<void (TreeNode* Node)> TreeNodeDestructorCallback;
00040
00041
00042
00043
00044
00045
00047 enum ETreeNodeTypes
00048 {
00049 TREENODE_QUADTREE,
00050 TREENODE_POINTQUADTREE,
00051 TREENODE_OCTREE,
00052 TREENODE_BSPTREE,
00053 TREENODE_KDTREE,
00054 TREENODE_OBBTREE,
00055 };
00056
00057
00058
00059
00060
00061
00067 struct STreeNodeTriangleData
00068 {
00069 u32 Surface;
00070 u32 Index;
00071 dim::ptriangle3df Triangle;
00072 };
00073
00074
00076 class SP_EXPORT TreeNode : public BaseObject
00077 {
00078
00079 public:
00080
00081 virtual ~TreeNode();
00082
00083
00084
00086 virtual const TreeNode* getRoot() const;
00088 virtual TreeNode* getRoot();
00089
00091 virtual u32 getLevel() const;
00092
00094 virtual bool isLeaf() const = 0;
00095
00097 virtual void addChildren();
00098
00100 virtual void removeChildren();
00101
00107 virtual const TreeNode* findLeaf(const dim::vector3df &Point) const;
00108
00115 virtual void findLeafList(std::list<const TreeNode*> &TreeNodeList, const dim::vector3df &Point, f32 Radius) const;
00116
00123 virtual void findLeafList(std::list<const TreeNode*> &TreeNodeList, const dim::line3df &Line) const;
00124
00131 virtual void findLeafList(std::list<const TreeNode*> &TreeNodeList, const dim::line3df &Line, f32 Radius) const;
00132
00137 virtual const TreeNode* findLeafSub(const dim::vector3df &Point) const;
00142 virtual void findLeafListSub(std::list<const TreeNode*> &TreeNodeList, const dim::vector3df &Point, f32 Radius) const;
00143
00144
00145
00147 inline ETreeNodeTypes getType() const
00148 {
00149 return Type_;
00150 }
00151
00153 inline TreeNode* getParent() const
00154 {
00155 return Parent_;
00156 }
00157
00159 inline bool isRoot() const
00160 {
00161 return Parent_ == 0;
00162 }
00163
00164 inline void setDestructorCallback(const TreeNodeDestructorCallback &Callback)
00165 {
00166 DestructorCallback_ = Callback;
00167 }
00168
00169 protected:
00170
00171
00172
00173 static const f32 EXT_BOUNDBOX_SIZE;
00174
00175
00176
00177 TreeNode(TreeNode* Parent, const ETreeNodeTypes Type);
00178
00179
00180
00181 template <class T> TreeNode* createChild(const dim::aabbox3df &Box)
00182 {
00183 return new T(this, Box);
00184 }
00185
00186
00187
00188 ETreeNodeTypes Type_;
00189 TreeNode* Parent_;
00190
00191 TreeNodeDestructorCallback DestructorCallback_;
00192
00193 };
00194
00195
00196 }
00197
00198 }
00199
00200
00201 #endif
00202
00203
00204
00205