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

Revision 925, 6.5 KB checked in by mattausch, 19 years ago (diff)

update for ogre 1.2
OcclusionCullingSceneManager? is the only scenemanager in the solution now

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