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

Revision 174, 6.4 KB checked in by mattausch, 19 years ago (diff)
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 *IssueOcclusionQuery(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 previously rendered hierarchy nodes.
127        */
128        std::vector<HierarchyNode *> *GetVisibleNodes();
129        /** Returns vector of previoulsy rendered geometry.
130        */
131       
132        /** Issue a occlusion query for this mesh.
133                @param node the current mesh
134                @returns occlusion query for this node
135        */
136        virtual GtpVisibility::OcclusionQuery *IssueOcclusionQuery(GtpVisibility::Mesh *mesh) = 0;
137
138        /** Returns the geometry of a given hierarchy node.
139                @param node the hierarchy node containing the geometry
140                @param geometryList geometry is returned in this list
141                @param includeChildren if the geometry of the children should be taken into account
142        */
143        virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,   
144                                                         GeometryList *geometryList,
145                                                         bool includeChildren) = 0;
146
147
148        /** Renders the given geometry.
149        */
150        virtual void RenderGeometry(GtpVisibility::Mesh *geom) = 0;
151
152       
153        /** This is an optimization when issuing the occlusion test.
154                The test is done with actual geometry rather than the bounding
155                box of leave nodes previously marked as visible.
156
157                @param testGeometry if this optimization should be used
158                @remark this option is only useful for the coherent hierarchical culling algorithm
159        */
160        void TestGeometryForVisibleLeaves(bool testGeometry);
161
162
163
164protected:
165        /// chc optimization for testing geometry of leaves instead of bounding box
166        bool mTestGeometryForVisibleLeaves;
167        /// the current frame number
168        unsigned int mFrameId;
169        /// points to the last occlusion query in the query list
170        int mCurrentTestIdx;
171       
172        /// number of traversed nodes
173        unsigned int mNumTraversedNodes;
174
175        /// The queue is useful for rendering hierarchy nodes in front to back order.
176        DistanceQueue *mDistanceQueue;
177
178        /// the root of the hierarchy
179        HierarchyNode *mHierarchyRoot;
180       
181        /// buffer for a node pointer
182        HierarchyNode *mSavedNode;
183        /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
184        std::vector<HierarchyNode *> mVisibleNodes;
185};
186} // namespace GtpVisibility
187
188#endif // GtpVisisibilityHierarchyInterface_H
Note: See TracBrowser for help on using the repository browser.