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

Revision 370, 6.2 KB checked in by mattausch, 19 years ago (diff)

fixed specular bug in trees
added batched query manager
added t information to ray bsp leaves

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 *> NodeVector;
13typedef std::vector<GtpVisibility::Mesh *> GeometryVector;
14typedef std::vector<GtpVisibility::Patch *> PatchVector;
15typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
16typedef std::pair<HierarchyNode *, bool> PendingQuery;
17typedef std::queue<QueryPair> QueryQueue;
18typedef std::queue<PendingQuery> PendingQueue;
19
20
21/**     Class which implements a hierarchy interface for a scene hierarchy.
22*/
23class HierarchyInterface
24{
25public:
26        /** Default constructor.
27        */
28        HierarchyInterface();
29        virtual ~HierarchyInterface();
30        /** Returns true if current node is leaf of the hierarchy.
31                @param node hierarchy node
32                @returns true if node is leaf
33        */
34    virtual bool IsLeaf(HierarchyNode *node) const = 0;
35        /** Traverses and renders the given node.
36                @param node the hierarchy node
37        */
38        virtual void TraverseNode(HierarchyNode *node) = 0;
39        /** Renders current hierarchy node.
40                @param node current hierarchy node to be rendered
41        */
42        virtual void RenderNode(HierarchyNode *node) = 0;
43        /** Pulls up the visibility from the current node recursively to the parent nodes.
44                @param node the current node
45        */
46        virtual void PullUpVisibility(HierarchyNode *node) const = 0;
47        /** Issue a occlusion query for this node.
48                @param node the current hierarchy node
49                @returns occlusion query for this node
50        */
51        virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node,
52                const bool wasVisible = false) = 0;
53        /** Sets the root of the scene hierarchy.
54                @param root the hierarchy root
55        */
56        void SetHierarchyRoot(HierarchyNode *root);
57    /** Get the root of the scene hierarchy.
58                @return the hierarchy root
59        */
60        HierarchyNode *GetHierarchyRoot() const;
61        /** Sets the scene root and initialises this hierarchy interface for a traversal.               
62                @remark also resets the statistics evaluated in the last traversal
63        */
64        void InitTraversal();
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) const = 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) const = 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) const = 0;
127
128        /** Returns vector of visible hierarchy nodes from previous render.
129        */
130        std::vector<HierarchyNode *> *GetVisibleNodes();
131        /** Returns vector of previoulsy rendered geometry.
132        */
133       
134        /** Returns the geometry of a given hierarchy node.
135                @param node the hierarchy node containing the geometry
136                @param geometryList geometry is returned in this list
137                @param includeChildren if the geometry of the children should be taken into account
138        */
139        virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,   
140                                                         GeometryVector *geometryList,
141                                                         bool includeChildren) = 0;
142
143       
144        /** This is an optimization when issuing the occlusion test.
145                The test is done with actual geometry rather than the bounding
146                box of leave nodes previously marked as visible.
147
148                @param testGeometry if this optimization should be used
149                @remark this option is only useful for the coherent hierarchical culling algorithm
150        */
151        void TestGeometryForVisibleLeaves(bool testGeometry);
152
153
154protected:
155        /// chc optimization for testing geometry of leaves instead of bounding box
156        bool mTestGeometryForVisibleLeaves;
157        /// the current frame number
158        unsigned int mFrameId;
159        /// points to the last occlusion query in the query list
160        int mCurrentTestIdx;
161       
162        /// number of traversed nodes
163        unsigned int mNumTraversedNodes;
164
165        /// The queue is useful for rendering hierarchy nodes in front to back order.
166        DistanceQueue *mDistanceQueue;
167
168        /// the root of the hierarchy
169        HierarchyNode *mHierarchyRoot;
170       
171        /// buffer for a node pointer
172        HierarchyNode *mSavedNode;
173        /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
174        std::vector<HierarchyNode *> mVisibleNodes;
175};
176} // namespace GtpVisibility
177
178#endif // GtpVisisibilityHierarchyInterface_H
Note: See TracBrowser for help on using the repository browser.