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

Revision 155, 6.8 KB checked in by mattausch, 19 years ago (diff)

added node traversal interface

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