source: GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h @ 2558

Revision 2558, 6.9 KB checked in by mattausch, 17 years ago (diff)
Line 
1#ifndef _GtpVisibilityHierarchyInterface_H__
2#define _GtpVisibilityHierarchyInterface_H__
3
4
5#include "DistanceQueue.h"
6#include <stack>
7
8
9namespace GtpVisibility {
10
11enum  CullingType {QUERY_CULLED, FRUSTUM_CULLED};
12
13typedef std::vector<HierarchyNode *> NodeVector;
14//typedef std::vector<GtpVisibility::Mesh *> GeometryVector;
15//typedef std::vector<GtpVisibility::Patch *> PatchVector;
16
17typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
18typedef std::pair<HierarchyNode *, bool> PendingQuery;
19typedef std::queue<QueryPair> QueryQueue;
20typedef std::queue<PendingQuery> PendingQueue;
21
22typedef std::vector<HierarchyNode *> HierarchyNodeContainer;
23
24
25class MultiQuery
26{
27        OcclusionQuery *mQuery;
28        HierarchyNodeContainer *mNodes;
29};
30
31
32
33/**     Class which implements an interface for the operations on a hierarchy
34        of a scene.
35        It has to be implemented for any rendering engine to use the CHC algorithm.
36*/
37class HierarchyInterface
38{
39public:
40        /** Default constructor.
41        */
42        HierarchyInterface();
43        virtual ~HierarchyInterface();
44        /** Returns true if current node is leaf of the hierarchy.
45                @param node hierarchy node
46                @returns true if node is leaf
47        */
48    virtual bool IsLeaf(HierarchyNode *node) const = 0;
49        /** Traverses and renders the hierarchy from the given node.
50                @param node the hierarchy node
51        */
52        virtual void TraverseNode(HierarchyNode *node) = 0;
53        /** Renders the given hierarchy node.
54                @param node current hierarchy node to be rendered
55        */
56        virtual void RenderNode(HierarchyNode *node) = 0;
57        /** Pulls up the visibility from the current node recursively to the parent nodes.
58                @param node the current node
59        */
60        virtual void PullUpVisibility(HierarchyNode *node) const = 0;
61        /** Issue a occlusion query for this node.
62                @param node the current hierarchy node
63                @param testGeometry (if geometry should be tested instead of the bb).
64                @returns occlusion query for this node
65        */
66        virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node,
67                                                                                                        const bool testGeometry = false) = 0;
68        /** Returns distance of the node to the view plane.
69                @param node the hierarchy node
70        */                     
71        virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
72        /** Checks if the node is visible from the current view frustum.
73                @param node the current node
74                @param intersects returns true if the current node intersects the near plane
75        */
76        virtual bool CheckFrustumVisible(HierarchyNode *node,
77                                                                         bool &intersects) = 0;
78       
79        /** Returns true if there is renderable geometry attached to this node
80                @param node the current node
81                @returns if the node has renderable geometry
82        */
83    virtual bool HasGeometry(HierarchyNode *node) const = 0;
84        /** Sets the visible flag for this node.
85                @param node the current node
86                @param visible the visible flag
87        */
88        virtual void SetNodeVisible(HierarchyNode *node,
89                                                                const bool visible) const = 0;
90        /** Returns true if node has the visible flag set. See set
91        */
92        virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
93        /** Sets the last visited frame id for this node.
94                @param node the current node
95                @param frameId the current frame id
96        */
97        virtual void SetLastVisited(HierarchyNode *node,
98                                                                const unsigned int frameId) const = 0;
99       
100
101        virtual void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const = 0;
102
103        virtual HierarchyNode *GetRandomLeaf(HierarchyNode *root) = 0;
104        virtual bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const = 0;
105
106        virtual void CollectLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0;
107
108        /** Collects only leaves that are found visible by view frustum culling.
109        */
110        //virtual void CollectVisibleLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0;
111
112        virtual void RenderNodeRecursive(HierarchyNode *node) = 0;
113
114        /** Returns frame id when this node was last visited by the traverser. See set
115        */
116        virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
117               
118        /** Visualization of a culled node, dependent on the culling type.
119                @param node the hierarchy node to be visualized
120                @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
121        */
122        virtual void VisualizeCulledNode(HierarchyNode *node,
123                                                                         CullingType type) const = 0;
124
125        /** Sets the root of the scene hierarchy.
126                @param root the hierarchy root
127        */
128        void SetHierarchyRoot(HierarchyNode *root);
129    /** Get the root of the scene hierarchy.
130                @return the hierarchy root
131        */
132        HierarchyNode *GetHierarchyRoot() const;
133        /** Sets the scene root and initialises this hierarchy interface for a traversal.               
134                @remark also resets the statistics evaluated in the last traversal
135        */
136        void InitTraversal();
137        /** Returns current frame id.
138                @returns frame id
139        */
140        unsigned int GetFrameId() const;
141        /** Returns a pointer to the distance queue.
142                @returns current distance queue.
143                @remark the distance queue stores hierarchy nodes in a front-to-back order
144        */
145        DistanceQueue *GetQueue();
146        /** Checks if the node is visible from the current view frustum.
147                @param node the current node
148        */
149        bool CheckFrustumVisible(HierarchyNode *node);
150        /** Returns number of traversed nodes.
151        */
152        unsigned int GetNumTraversedNodes();
153        /** Returns number of rendered nodes.
154        */
155        unsigned int GetNumRenderedNodes();
156        /** Returns vector of visible hierarchy nodes from previous render.
157        */
158        std::vector<HierarchyNode *> *GetVisibleNodes();
159        /** Pulls up the last visited information of this node.
160        */
161        virtual void PullUpLastVisited(HierarchyNode *node, const int frameId) const = 0;
162        /** Returns parent node.
163        */
164        virtual HierarchyNode *GetParent(HierarchyNode *node) = 0;
165        /** Returns #frames this node is assumed to be visible.
166        */
167        virtual int GetNodeAssumedVisible(HierarchyNode *node) = 0;
168        /** Sets #frames this node is assumed to be visible.
169        */
170        virtual void SetNodeAssumedVisible(HierarchyNode *node, int assumedVisible) = 0;
171        /** Decreases #frames this node is assumed to be visible.
172        */
173        virtual void DecNodeAssumedVisible(HierarchyNode *node) = 0;
174       
175        virtual void AddToQueue(GtpVisibility::HierarchyNode *node) = 0;
176
177        virtual void RenderQueue() = 0;
178
179        virtual void TraverseNode2(GtpVisibility::HierarchyNode *node) = 0;
180
181protected:
182
183        /// the current frame number
184        unsigned int mFrameId;
185       
186        /// index of the lcurrent occlusion query in the array of queries
187        /// NOTE: should rather be iterator
188        int mCurrentTestIdx;
189       
190        /// number of traversed nodes
191        unsigned int mNumTraversedNodes;
192
193        /// The queue is useful for rendering hierarchy nodes in front to back order.
194        DistanceQueue *mDistanceQueue;
195
196        /// the root of the hierarchy
197        HierarchyNode *mHierarchyRoot;
198       
199        /// buffer for a node pointer
200        HierarchyNode *mOldNode;
201
202        /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
203        std::vector<HierarchyNode *> mVisibleNodes;
204};
205
206} // namespace GtpVisibility
207
208#endif // GtpVisisibilityHierarchyInterface_H
Note: See TracBrowser for help on using the repository browser.