source: GTP/trunk/App/Demos/Vis/CHC_revisited/HierarchyNode.h @ 2642

Revision 2642, 4.6 KB checked in by mattausch, 17 years ago (diff)

new demo

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