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

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