Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_TREENODEKD_H__
00009 #define __SP_TREENODEKD_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spTreeNode.hpp"
00014
00015
00016 namespace sp
00017 {
00018 namespace scene
00019 {
00020
00021
00022 static const u8 DEF_KDTREE_LEVEL = 12;
00023
00024
00026 enum EKDTreeAxles
00027 {
00028 KDTREE_XAXIS = 0,
00029 KDTREE_YAXIS,
00030 KDTREE_ZAXIS,
00031 };
00032
00033
00035 class SP_EXPORT KDTreeNode : public TreeNode
00036 {
00037
00038 public:
00039
00040 KDTreeNode(TreeNode* Parent = 0, const dim::aabbox3df &Box = dim::aabbox3df());
00041 ~KDTreeNode();
00042
00043
00044
00045 bool isLeaf() const;
00046
00047 void addChildren();
00048 void removeChildren();
00049
00050 const TreeNode* findLeaf(const dim::vector3df &Point) const;
00051 void findLeafList(std::list<const TreeNode*> &TreeNodeList, const dim::vector3df &Point, f32 Radius) const;
00052 void findLeafList(std::list<const TreeNode*> &TreeNodeList, const dim::line3df &Line) const;
00053 void findLeafList(std::list<const TreeNode*> &TreeNodeList, const dim::line3df &Line, f32 Radius) const;
00054
00055 const TreeNode* findLeafSub(const dim::vector3df &Point) const;
00056 void findLeafListSub(std::list<const TreeNode*> &TreeNodeList, const dim::vector3df &Point, f32 Radius) const;
00057
00058
00059
00060 template <class A, class B> void addChildren()
00061 {
00062 removeChildren();
00063
00064 dim::aabbox3df NearBox, FarBox;
00065 getBoxes(NearBox, FarBox);
00066
00067 ChildNear_ = createChild<A>(NearBox);
00068 ChildFar_ = createChild<B>(FarBox);
00069 }
00070
00071 template <class A, class B> void addChildren(const EKDTreeAxles Axis, f32 Distance)
00072 {
00073 Axis_ = Axis;
00074 Distance_ = Distance;
00075 addChildren<A, B>();
00076 }
00077
00078 template <class T> void addChildren()
00079 {
00080 addChildren<T, T>();
00081 }
00082 template <class T> void addChildren(const EKDTreeAxles Axis, f32 Distance)
00083 {
00084 addChildren<T, T>(Axis, Distance);
00085 }
00086
00087
00088
00089 inline TreeNode* getChildNear() const
00090 {
00091 return ChildNear_;
00092 }
00093 inline TreeNode* getChildFar() const
00094 {
00095 return ChildFar_;
00096 }
00097
00098 inline void setAxis(const EKDTreeAxles Axis)
00099 {
00100 Axis_ = Axis;
00101 }
00102 inline EKDTreeAxles getAxis() const
00103 {
00104 return Axis_;
00105 }
00106
00107 inline void setDistance(f32 Distance)
00108 {
00109 Distance_ = Distance;
00110 }
00111 inline f32 getDistance() const
00112 {
00113 return Distance_;
00114 }
00115
00116 inline void setBox(const dim::aabbox3df &Box)
00117 {
00118 Box_ = Box;
00119 }
00120 inline dim::aabbox3df getBox() const
00121 {
00122 return Box_;
00123 }
00124
00125 private:
00126
00127
00128
00129 void getBoxes(dim::aabbox3df &NearBox, dim::aabbox3df &FarBox) const;
00130
00131
00132
00133 TreeNode* ChildNear_;
00134 TreeNode* ChildFar_;
00135
00136 EKDTreeAxles Axis_;
00137 f32 Distance_;
00138
00139 dim::aabbox3df Box_;
00140
00141 };
00142
00143
00144 }
00145
00146 }
00147
00148
00149 #endif
00150
00151
00152
00153