[68] | 1 | #ifndef _KdTree_H__ |
---|
| 2 | #define _KdTree_H__ |
---|
| 3 | |
---|
| 4 | #include "Containers.h" |
---|
| 5 | #include "AxisAlignedBox3.h" |
---|
| 6 | |
---|
| 7 | namespace GtpVisibilityPreprocessor { |
---|
| 8 | |
---|
| 9 | class KdNode; |
---|
| 10 | /** KdTree for indexing scene entities - occluders/occludees/viewcells */ |
---|
| 11 | class KdTree { |
---|
| 12 | public: |
---|
| 13 | |
---|
| 14 | /** Insert occluder into the tree */ |
---|
| 15 | virtual void InsertOccluder(Mesh *occluder) { |
---|
| 16 | // mRoot->mOccluders.push_back(occluder); |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | /** Insert occludee into the tree */ |
---|
| 20 | virtual void InsertOccludee(Mesh *occludee) { |
---|
| 21 | // mRoot->mOccludees.push_back(occludee); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | /** Insert view cell into the tree */ |
---|
| 25 | virtual void InsertViewCell(ViewCell *viewCell) { |
---|
| 26 | // mRoot->mViewcells.push_back(viewCell); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | /** Check whether subdivision criteria are met for the given subtree. |
---|
| 30 | If not subdivide the leafs of the subtree. The criteria are specified in |
---|
| 31 | the environment as well as the subdivision method. By default surface area |
---|
| 32 | heuristics is used. |
---|
| 33 | |
---|
| 34 | @param subtree root of the subtree |
---|
| 35 | |
---|
| 36 | @return true if subdivision was performed, false if subdivision criteria |
---|
| 37 | were already met |
---|
| 38 | */ |
---|
| 39 | virtual bool Subdivide(KdNode *subtree); |
---|
| 40 | |
---|
| 41 | /** Get the root of the tree */ |
---|
| 42 | KdNode *GetRoot() const { |
---|
| 43 | return mRoot; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | protected: |
---|
| 47 | /// root of the tree |
---|
| 48 | KdNode *mRoot; |
---|
| 49 | /// bounding box of the tree root |
---|
| 50 | AxisAlignedBox3 mBox; |
---|
| 51 | }; |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | class KdInterior; |
---|
| 55 | /** Abstract class for kd-tree node */ |
---|
| 56 | class KdNode { |
---|
| 57 | |
---|
| 58 | /** Determines whether this node is a leaf or interior node |
---|
| 59 | @return true if leaf |
---|
| 60 | */ |
---|
| 61 | virtual bool IsLeaf() const = 0; |
---|
| 62 | |
---|
| 63 | /** Determines whether this node is the root of the tree |
---|
| 64 | @return true if root |
---|
| 65 | */ |
---|
| 66 | virtual bool IsRoot() const { |
---|
| 67 | return mParent == NULL; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | protected: |
---|
| 71 | /** Parent of the node - the parent is a little overhead for maintanance of the tree, |
---|
| 72 | but allows various optimizations of tree traversal algorithms */ |
---|
| 73 | KdInterior *mParent; |
---|
| 74 | }; |
---|
| 75 | |
---|
| 76 | /** Implementation of the kd-tree interior node */ |
---|
| 77 | class KdInterior : public KdNode { |
---|
| 78 | |
---|
| 79 | public: |
---|
| 80 | /** \sa KdNode::IsLeaf() */ |
---|
| 81 | virtual bool IsLeaf() const { return false; } |
---|
| 82 | |
---|
| 83 | protected: |
---|
| 84 | /** splitting axis */ |
---|
| 85 | int axis; |
---|
| 86 | /** splitting position, absolute position within the bounding box of this node */ |
---|
| 87 | float mPosition; |
---|
| 88 | |
---|
| 89 | /** back node */ |
---|
| 90 | KdNode *mBack; |
---|
| 91 | /** front node */ |
---|
| 92 | KdNode *mFront; |
---|
| 93 | |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | /** Implementation of the kd-tree leaf node */ |
---|
| 98 | class KdLeaf : public KdNode { |
---|
| 99 | public: |
---|
| 100 | /** \sa KdNode::IsLeaf() */ |
---|
| 101 | virtual bool IsLeaf() const { return true; } |
---|
| 102 | |
---|
| 103 | protected: |
---|
| 104 | /** pointers to occluders contained in this node */ |
---|
| 105 | MeshContainer mOccluders; |
---|
| 106 | /** pointers to occludees contained in this node */ |
---|
| 107 | MeshContainer mOccludees; |
---|
| 108 | /** pointers to viewcells contained in this node */ |
---|
| 109 | ViewCellContainer mViewCells; |
---|
| 110 | }; |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | }; |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | #endif |
---|