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

Revision 158, 6.3 KB checked in by mattausch, 19 years ago (diff)

removed node visibility for item buffer

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;
16
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 TraverseNode(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                @remark also resets the statistics evaluated in the last traversal
60        */
61        void InitTraversal();
62        /** Returns current frame id.
63                @returns frame id
64        */
65        unsigned int GetFrameId() const;
66        /** Returns a pointer to the distance queue.
67                @returns current distance queue.
68                @remark the distance queue stores hierarchy nodes in a front-to-back order
69        */
70        DistanceQueue *GetQueue();
71        /** Returns distance of the node to the view plane.
72                @param node1 the hierarchy node
73        */                     
74        virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
75        /** Checks if the node is visible from the current view frustum.
76                @param node the current node
77                @param intersects returns true if the current node intersects the near plane
78        */
79        virtual bool CheckFrustumVisible(HierarchyNode *node, bool &intersects) = 0;
80        /** Checks if the node is visible from the current view frustum.
81                @param node the current node
82        */
83        bool CheckFrustumVisible(HierarchyNode *node);
84        /** Returns next available occlusion query or creates new one.
85                @return the next occlusion query
86        */
87        virtual OcclusionQuery *GetNextOcclusionQuery() = 0;
88        /** Returns true if there is renderable geometry attached to this node
89                @param node the current node
90                @returns if the node has renderable geometry
91        */
92    virtual bool HasGeometry(HierarchyNode *node) const = 0;
93        /** Sets the visible flag for this node.
94                @param node the current node
95                @param visible the visible flag
96        */
97        virtual void SetNodeVisible(HierarchyNode *node, const bool visible) = 0;
98        /** Returns true if node has the visible flag set. See set
99        */
100        virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
101        /** Sets the last visited frame id for this node.
102                @param node the current node
103                @param frameId the current frame id
104        */
105        virtual void SetLastVisited(HierarchyNode *node,
106                                                                const unsigned int frameId) = 0;
107        /** Returns frame id when this node was last visited by the traverser. See set
108        */
109        virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
110        /** Returns number of traversed nodes.
111        */
112        unsigned int GetNumTraversedNodes();
113        /** Returns number of rendered nodes.
114        */
115        unsigned int GetNumRenderedNodes();
116               
117        //bool mIsShadowPass;
118
119        /** Visualization of a culled node, dependent on the culling type.
120                @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
121        */
122        virtual void VisualizeCulledNode(HierarchyNode *node,
123                CullingType type) = NULL;
124
125        /** Returns vector of previously rendered hierarchy nodes.
126        */
127        std::vector<HierarchyNode *> *GetRenderedNodes();
128        /** Returns vector of previoulsy rendered geometry.
129        */
130       
131        /** Issue a occlusion query for this mesh.
132                @param node the current mesh
133                @returns occlusion query for this node
134        */
135        virtual GtpVisibility::OcclusionQuery *IssueOcclusionQuery(GtpVisibility::Mesh *mesh) = 0;
136
137        /** Returns the geometry of a given hierarchy node.
138                @param node the hierarchy node containing the geometry
139                @param geometryList geometry is returned in this list
140                @param includeChildren if the geometry of the children should be taken into account
141        */
142        virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,   
143                                                         GeometryList *geometryList,
144                                                         bool includeChildren) = 0;
145
146
147        /** Renders the given geometry.
148        */
149        virtual void RenderGeometry(GtpVisibility::Mesh *geom) = 0;
150
151       
152        /** This is an optimization when issuing the occlusion test.
153                The test is done with actual geometry rather than the bounding
154                box of leave nodes previously marked as visible.
155
156                @param testGeometry if this optimization should be used
157                @remark this option is only useful for the coherent hierarchical culling algorithm
158        */
159        void TestGeometryForVisibleLeaves(bool testGeometry);
160
161
162
163protected:
164        /// chc optimization for testing geometry of leaves instead of bounding box
165        bool mTestGeometryForVisibleLeaves;
166        /// the current frame number
167        unsigned int mFrameId;
168        /// points to the last occlusion query in the query list
169        int mCurrentTestIdx;
170       
171        /// number of traversed nodes
172        unsigned int mNumTraversedNodes;
173
174        /// The queue is useful for rendering hierarchy nodes in front to back order.
175        DistanceQueue *mDistanceQueue;
176
177        /// the root of the hierarchy
178        HierarchyNode *mHierarchyRoot;
179       
180        /// buffer for a node pointer
181        HierarchyNode *mSavedNode;
182        /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
183        std::vector<HierarchyNode *> mRenderedNodes;
184};
185} // namespace GtpVisibility
186
187#endif // GtpVisisibilityHierarchyInterface_H
Note: See TracBrowser for help on using the repository browser.