source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OpenGL/HierarchyNode.h @ 629

Revision 629, 4.5 KB checked in by mattausch, 18 years ago (diff)
Line 
1#ifndef NO_PRAGMA_ONCE
2#pragma once
3#endif
4
5#ifndef HIERARCHYNODE_H
6#define HIERARCHYNODE_H
7
8#include "Geometry.h"
9extern "C"
10{
11        #include "DataTypes.h"
12}
13#include <vector>
14#include <stack>
15
16using namespace std;
17
18class HierarchyNode;
19
20/**
21        This class implements the compare operator for the priority queue.
22        a lower distance has a higher value in the queue
23*/
24template <typename T> class myless
25{
26public:
27       
28        //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const
29        bool operator() (T v1, T v2) const
30    {
31                return (v1->mDistance > v2->mDistance);
32    }
33};
34
35/** This class represents a node in a k-d tree hierarchy. A
36        node has two children. The node can be either an interior node (i.e., left and right child
37        NULL) or a leaf node, which holds the actual geometry.
38*/
39
40class HierarchyNode
41{
42        friend class myless;
43
44public:
45        typedef stack<HierarchyNode *> TraversalStack;
46    typedef vector<Geometry *> GeometryList;
47
48        HierarchyNode();
49        HierarchyNode(const Vector3 boundLower, const Vector3 boundUpper,
50                                 HierarchyNode *parent, int depth);
51        ~HierarchyNode();
52        //! was this node visible the last time it was visited?
53        bool Visible();
54        //! last time this node was visited (in framenumber)
55        unsigned int LastVisited();
56        //! sets visible flag
57        void SetVisible(bool visible);
58        //! sets timestamp (current framenumber)
59        void SetLastVisited(unsigned int lastVisited);
60        //! is this node a leaf node (i.e., geometry)
61        bool IsLeaf();
62        //! renders the geometry in this node. returns number of rendered geometry
63        int Render();
64        //! returns occlusion query id
65        int GetOcclusionQuery();
66        //! sets occlusion query id
67        void SetOcclusionQuery(int occlusionQuery);
68        //! renders the bounding volume  (i.e., a axis aligned bounding box) of the node
69        void RenderBoundingVolume();
70        //! adds geometry to this node (rendered if this node is a leaf)
71        void AddGeometry(Geometry *geometry);
72
73        void SetLeftChild(HierarchyNode *child);
74        void SetRightChild(HierarchyNode *child);
75
76        HierarchyNode *GetParent();
77    HierarchyNode *GetLeftChild();
78        HierarchyNode *GetRightChild();
79
80        //! compute bounding volume (i.e., a axis aligned bounding box) for this geometry.
81        //void CalcBoundingVolume();
82        const AABox& GetBoundingVolume();
83       
84        //! generates the kd-tree from this root-node, returns number of nodes in hierarchy.
85        int     GenerateKdTree();
86
87        //! returns number of nodes in hierarchy with this node.
88        int GetNumHierarchyNodes();
89
90        //! add children of this node ordered to a traversal stack with respect to the view point
91        void PushChildrenOrdered(const Vector3 viewpoint, TraversalStack &traversalStack);
92
93        //! if this node was culled, set the type of culling (frustum, query)
94        void SetCulledType(int culledtype);
95        //! returns type of culling
96        int GetCulledType();
97        //! set gl state to visible render bounding volume
98        void RenderBoundingVolumeForVisualization();
99        //! returns geometry list
100        GeometryList &GetGeometry();
101
102        //! visibly renders also bounding volume of this node
103        static void SetRenderBoundingVolume(bool renderBoundingVolume);
104       
105        /**
106                initialises the static termination criteria.
107                shall be called after all geometry has been added to the root node.
108        */
109        static void InitKdTree(HierarchyNode *root);
110
111        float GetSquaredDistance();
112        void SetDistance(float distance);
113
114        float mDistance;
115
116protected:
117       
118        enum {X_AXIS, Y_AXIS, Z_AXIS};
119
120        //! criteria to stop the splitting of this kd-tree node
121        bool SimpleEnough();
122        //! split plane of the kd-tree (according to mSplitAxis, it is the x, y, or z axis)
123        float ComputeSplitPlane();
124
125        /** calculates a value that expresses if it's reasonable to split the
126           node at the specified position (the smaller the value the better the split)
127           */
128        float ComputeHeuristics(float pos);
129
130        GeometryList mGeometry;
131        //! id of this occlusion query of this node
132        int mOcclusionQuery;
133
134        HierarchyNode *mLeftChild;     
135        HierarchyNode *mRightChild;
136        HierarchyNode *mParent;
137       
138        bool  mVisible;
139        int mLastVisited;
140        bool mAABValid;
141        bool mEnclosedSpaceValid;
142        int mNumHierarchyNodes;
143       
144        AABox mBoundingBox;
145        // the enclosed space of the pure kd-treenode (without considering the geometry)
146        AABox mEnclosedSpace;
147       
148        int mSplitAxis;
149        int mLastRendered;
150        float mSplitValue;
151        int mDepth;
152
153        static bool sRenderBoundingVolume;
154        static float sSplitBandwith;
155
156        // --termination criteria
157
158        static int sGeometryThreshold;
159        // the maximum bounding box surface
160        static float HierarchyNode::sSurfaceThreshold;
161        // the maximum tree depth
162        static int HierarchyNode::sMaxDepth;
163        // the default bounding box drawing color
164        float mBoxColor[3];
165        // distance to the view point
166};
167
168#endif // HIERARCHYNODE_H
Note: See TracBrowser for help on using the repository browser.