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

Revision 2455, 6.4 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
25/**     Class which implements an interface for the operations on a hierarchy
26        of a scene.
27        It has to be implemented for any rendering engine to use the CHC algorithm.
28*/
29class HierarchyInterface
30{
31public:
32        /** Default constructor.
33        */
34        HierarchyInterface();
35        virtual ~HierarchyInterface();
36        /** Returns true if current node is leaf of the hierarchy.
37                @param node hierarchy node
38                @returns true if node is leaf
39        */
40    virtual bool IsLeaf(HierarchyNode *node) const = 0;
41        /** Traverses and renders the hierarchy from the given node.
42                @param node the hierarchy node
43        */
44        virtual void TraverseNode(HierarchyNode *node) = 0;
45        /** Renders the given hierarchy node.
46                @param node current hierarchy node to be rendered
47        */
48        virtual void RenderNode(HierarchyNode *node) = 0;
49        /** Pulls up the visibility from the current node recursively to the parent nodes.
50                @param node the current node
51        */
52        virtual void PullUpVisibility(HierarchyNode *node) const = 0;
53        /** Issue a occlusion query for this node.
54                @param node the current hierarchy node
55                @param testGeometry (if geometry should be tested instead of the bb).
56                @returns occlusion query for this node
57        */
58        virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node,
59                                                                                                        const bool testGeometry = false) = 0;
60        /** Returns distance of the node to the view plane.
61                @param node the hierarchy node
62        */                     
63        virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
64        /** Checks if the node is visible from the current view frustum.
65                @param node the current node
66                @param intersects returns true if the current node intersects the near plane
67        */
68        virtual bool CheckFrustumVisible(HierarchyNode *node,
69                                                                         bool &intersects) = 0;
70       
71        /** Returns true if there is renderable geometry attached to this node
72                @param node the current node
73                @returns if the node has renderable geometry
74        */
75    virtual bool HasGeometry(HierarchyNode *node) const = 0;
76        /** Sets the visible flag for this node.
77                @param node the current node
78                @param visible the visible flag
79        */
80        virtual void SetNodeVisible(HierarchyNode *node,
81                                                                const bool visible) const = 0;
82        /** Returns true if node has the visible flag set. See set
83        */
84        virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
85        /** Sets the last visited frame id for this node.
86                @param node the current node
87                @param frameId the current frame id
88        */
89        virtual void SetLastVisited(HierarchyNode *node,
90                                                                const unsigned int frameId) const = 0;
91       
92
93        virtual void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const = 0;
94
95        virtual HierarchyNode *GetRandomLeaf(HierarchyNode *root) = 0;
96        virtual bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const = 0;
97
98        virtual void CollectLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0;
99
100        virtual void RenderNodeRecursive(HierarchyNode *node) = 0;
101
102        /** Returns frame id when this node was last visited by the traverser. See set
103        */
104        virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
105               
106        /** Visualization of a culled node, dependent on the culling type.
107                @param node the hierarchy node to be visualized
108                @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
109        */
110        virtual void VisualizeCulledNode(HierarchyNode *node,
111                                                                         CullingType type) const = 0;
112
113        /** Sets the root of the scene hierarchy.
114                @param root the hierarchy root
115        */
116        void SetHierarchyRoot(HierarchyNode *root);
117    /** Get the root of the scene hierarchy.
118                @return the hierarchy root
119        */
120        HierarchyNode *GetHierarchyRoot() const;
121        /** Sets the scene root and initialises this hierarchy interface for a traversal.               
122                @remark also resets the statistics evaluated in the last traversal
123        */
124        void InitTraversal();
125        /** Returns current frame id.
126                @returns frame id
127        */
128        unsigned int GetFrameId() const;
129        /** Returns a pointer to the distance queue.
130                @returns current distance queue.
131                @remark the distance queue stores hierarchy nodes in a front-to-back order
132        */
133        DistanceQueue *GetQueue();
134        /** Checks if the node is visible from the current view frustum.
135                @param node the current node
136        */
137        bool CheckFrustumVisible(HierarchyNode *node);
138        /** Returns number of traversed nodes.
139        */
140        unsigned int GetNumTraversedNodes();
141        /** Returns number of rendered nodes.
142        */
143        unsigned int GetNumRenderedNodes();
144        /** Returns vector of visible hierarchy nodes from previous render.
145        */
146        std::vector<HierarchyNode *> *GetVisibleNodes();
147        /** Pulls up the last visited information of this node.
148        */
149        virtual void PullUpLastVisited(HierarchyNode *node, const int frameId) const = 0;
150        /** Returns parent node.
151        */
152        virtual HierarchyNode *GetParent(HierarchyNode *node) = 0;
153        /** Returns #frames this node is assumed to be visible.
154        */
155        virtual int GetNodeAssumedVisible(HierarchyNode *node) = 0;
156        /** Sets #frames this node is assumed to be visible.
157        */
158        virtual void SetNodeAssumedVisible(HierarchyNode *node, int assumedVisible) = 0;
159        /** Decreases #frames this node is assumed to be visible.
160        */
161        virtual void DecNodeAssumedVisible(HierarchyNode *node) = 0;
162
163protected:
164
165        /// the current frame number
166        unsigned int mFrameId;
167       
168        /// index of the lcurrent occlusion query in the array of queries
169        /// NOTE: should rather be iterator
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 *mOldNode;
183
184        /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
185        std::vector<HierarchyNode *> mVisibleNodes;
186};
187
188} // namespace GtpVisibility
189
190#endif // GtpVisisibilityHierarchyInterface_H
Note: See TracBrowser for help on using the repository browser.