source: trunk/VUT/GtpVisibility/include/HierarchyInterface.h @ 175

Revision 175, 6.1 KB checked in by mattausch, 19 years ago (diff)

added trees

Line 
1#ifndef _GtpVisibilityHierarchyInterface_H__
2#define _GtpVisibilityHierarchyInterface_H__
3
4#include "DistanceQueue.h"
5#include "VisibilityMesh.h"
6#include <stack>
7
8namespace GtpVisibility {
9
10enum  CullingType {QUERY_CULLED, FRUSTUM_CULLED};
11
12typedef std::vector<HierarchyNode *> HierarchyNodeList;
13typedef std::vector<GtpVisibility::Mesh *> GeometryList;
14typedef std::vector<GtpVisibility::Patch *> PatchList;
15typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
16typedef std::queue<QueryPair> QueryQueue;
17
18
19/**     Class which implements a hierarchy interface for a scene hierarchy.
20*/
21class HierarchyInterface
22{
23public:
24        /** Default constructor.
25        */
26        HierarchyInterface();
27        virtual ~HierarchyInterface();
28        /** Returns true if current node is leaf of the hierarchy.
29                @param node hierarchy node
30                @returns true if node is leaf
31        */
32    virtual bool IsLeaf(HierarchyNode *node) const = 0;
33        /** Traverses and renders the given node.
34                @param node the hierarchy node
35        */
36        virtual void TraverseNode(HierarchyNode *node) = 0;
37        /** Renders current hierarchy node.
38                @param node current hierarchy node to be rendered
39        */
40        virtual void RenderNode(HierarchyNode *node) = 0;
41        /** Pulls up the visibility from the current node recursively to the parent nodes.
42                @param node the current node
43        */
44        virtual void PullUpVisibility(HierarchyNode *node) = 0;
45        /** Issue a occlusion query for this node.
46                @param node the current hierarchy node
47                @returns occlusion query for this node
48        */
49        virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node,
50                const bool wasVisible = false) = 0;
51        /** Sets the root of the scene hierarchy.
52                @param root the hierarchy root
53        */
54        void SetHierarchyRoot(HierarchyNode *root);
55    /** Get the root of the scene hierarchy.
56                @return the hierarchy root
57        */
58        HierarchyNode *GetHierarchyRoot() const;
59        /** Sets the scene root and initialises this hierarchy interface for a traversal.               
60                @remark also resets the statistics evaluated in the last traversal
61        */
62        void InitTraversal();
63        /** Returns current frame id.
64                @returns frame id
65        */
66        unsigned int GetFrameId() const;
67        /** Returns a pointer to the distance queue.
68                @returns current distance queue.
69                @remark the distance queue stores hierarchy nodes in a front-to-back order
70        */
71        DistanceQueue *GetQueue();
72        /** Returns distance of the node to the view plane.
73                @param node1 the hierarchy node
74        */                     
75        virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
76        /** Checks if the node is visible from the current view frustum.
77                @param node the current node
78                @param intersects returns true if the current node intersects the near plane
79        */
80        virtual bool CheckFrustumVisible(HierarchyNode *node, bool &intersects) = 0;
81        /** Checks if the node is visible from the current view frustum.
82                @param node the current node
83        */
84        bool CheckFrustumVisible(HierarchyNode *node);
85        /** Returns next available occlusion query or creates new one.
86                @return the next occlusion query
87        */
88        virtual OcclusionQuery *GetNextOcclusionQuery() = 0;
89        /** Returns true if there is renderable geometry attached to this node
90                @param node the current node
91                @returns if the node has renderable geometry
92        */
93    virtual bool HasGeometry(HierarchyNode *node) const = 0;
94        /** Sets the visible flag for this node.
95                @param node the current node
96                @param visible the visible flag
97        */
98        virtual void SetNodeVisible(HierarchyNode *node, const bool visible) = 0;
99        /** Returns true if node has the visible flag set. See set
100        */
101        virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
102        /** Sets the last visited frame id for this node.
103                @param node the current node
104                @param frameId the current frame id
105        */
106        virtual void SetLastVisited(HierarchyNode *node,
107                                                                const unsigned int frameId) = 0;
108        /** Returns frame id when this node was last visited by the traverser. See set
109        */
110        virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
111        /** Returns number of traversed nodes.
112        */
113        unsigned int GetNumTraversedNodes();
114        /** Returns number of rendered nodes.
115        */
116        unsigned int GetNumRenderedNodes();
117               
118        //bool mIsShadowPass;
119
120        /** Visualization of a culled node, dependent on the culling type.
121                @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
122        */
123        virtual void VisualizeCulledNode(HierarchyNode *node,
124                CullingType type) = NULL;
125
126        /** Returns vector of visible hierarchy nodes from previous render.
127        */
128        std::vector<HierarchyNode *> *GetVisibleNodes();
129        /** Returns vector of previoulsy rendered geometry.
130        */
131       
132        /** Returns the geometry of a given hierarchy node.
133                @param node the hierarchy node containing the geometry
134                @param geometryList geometry is returned in this list
135                @param includeChildren if the geometry of the children should be taken into account
136        */
137        virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,   
138                                                         GeometryList *geometryList,
139                                                         bool includeChildren) = 0;
140
141       
142        /** This is an optimization when issuing the occlusion test.
143                The test is done with actual geometry rather than the bounding
144                box of leave nodes previously marked as visible.
145
146                @param testGeometry if this optimization should be used
147                @remark this option is only useful for the coherent hierarchical culling algorithm
148        */
149        void TestGeometryForVisibleLeaves(bool testGeometry);
150
151
152protected:
153        /// chc optimization for testing geometry of leaves instead of bounding box
154        bool mTestGeometryForVisibleLeaves;
155        /// the current frame number
156        unsigned int mFrameId;
157        /// points to the last occlusion query in the query list
158        int mCurrentTestIdx;
159       
160        /// number of traversed nodes
161        unsigned int mNumTraversedNodes;
162
163        /// The queue is useful for rendering hierarchy nodes in front to back order.
164        DistanceQueue *mDistanceQueue;
165
166        /// the root of the hierarchy
167        HierarchyNode *mHierarchyRoot;
168       
169        /// buffer for a node pointer
170        HierarchyNode *mSavedNode;
171        /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
172        std::vector<HierarchyNode *> mVisibleNodes;
173};
174} // namespace GtpVisibility
175
176#endif // GtpVisisibilityHierarchyInterface_H
Note: See TracBrowser for help on using the repository browser.