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

Revision 726, 6.2 KB checked in by mattausch, 18 years ago (diff)

improved performance of TerrainSceneManager?
revisit octreescenemanager

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       
75        /** Returns distance of the node to the view plane.
76                @param node the hierarchy node
77        */                     
78        virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
79        /** Checks if the node is visible from the current view frustum.
80                @param node the current node
81                @param intersects returns true if the current node intersects the near plane
82        */
83        virtual bool CheckFrustumVisible(HierarchyNode *node, bool &intersects) = 0;
84        /** Checks if the node is visible from the current view frustum.
85                @param node the current node
86        */
87        bool CheckFrustumVisible(HierarchyNode *node);
88        /** Returns next available occlusion query or creates new one.
89                @return the next occlusion query
90        */
91        virtual OcclusionQuery *GetNextOcclusionQuery() = 0;
92        /** Returns true if there is renderable geometry attached to this node
93                @param node the current node
94                @returns if the node has renderable geometry
95        */
96    virtual bool HasGeometry(HierarchyNode *node) const = 0;
97        /** Sets the visible flag for this node.
98                @param node the current node
99                @param visible the visible flag
100        */
101        virtual void SetNodeVisible(HierarchyNode *node, const bool visible) const = 0;
102        /** Returns true if node has the visible flag set. See set
103        */
104        virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
105        /** Sets the last visited frame id for this node.
106                @param node the current node
107                @param frameId the current frame id
108        */
109        virtual void SetLastVisited(HierarchyNode *node,
110                                                                const unsigned int frameId) const = 0;
111        /** Returns frame id when this node was last visited by the traverser. See set
112        */
113        virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
114        /** Returns number of traversed nodes.
115        */
116        unsigned int GetNumTraversedNodes();
117        /** Returns number of rendered nodes.
118        */
119        unsigned int GetNumRenderedNodes();
120               
121        //bool mIsShadowPass;
122
123        /** Visualization of a culled node, dependent on the culling type.
124                @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
125        */
126        virtual void VisualizeCulledNode(HierarchyNode *node,
127                CullingType type) const = 0;
128
129        /** Returns vector of visible hierarchy nodes from previous render.
130        */
131        std::vector<HierarchyNode *> *GetVisibleNodes();
132        /** Returns vector of previoulsy rendered geometry.
133        */
134       
135        /** Returns the geometry of a given hierarchy node.
136                @param node the hierarchy node containing the geometry
137                @param geometryList geometry is returned in this list
138                @param includeChildren if the geometry of the children should be taken into account
139        */
140        virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,   
141                                                         GeometryVector *geometryList,
142                                                         bool includeChildren) = 0;
143
144       
145        /** This is an optimization when issuing the occlusion test.
146                The test is done with actual geometry rather than the bounding
147                box of leave nodes previously marked as visible.
148
149                @param testGeometry if this optimization should be used
150                @remark this option is only useful for the coherent hierarchical culling algorithm
151        */
152        void TestGeometryForVisibleLeaves(bool testGeometry);
153
154
155protected:
156
157
158        /// chc optimization for testing geometry of leaves instead of bounding box
159        bool mTestGeometryForVisibleLeaves;
160        /// the current frame number
161        unsigned int mFrameId;
162        /// points to the last occlusion query in the query list
163        int mCurrentTestIdx;
164       
165        /// number of traversed nodes
166        unsigned int mNumTraversedNodes;
167
168        /// The queue is useful for rendering hierarchy nodes in front to back order.
169        DistanceQueue *mDistanceQueue;
170
171        /// the root of the hierarchy
172        HierarchyNode *mHierarchyRoot;
173       
174        /// buffer for a node pointer
175        HierarchyNode *mSavedNode;
176        /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
177        std::vector<HierarchyNode *> mVisibleNodes;
178};
179} // namespace GtpVisibility
180
181#endif // GtpVisisibilityHierarchyInterface_H
Note: See TracBrowser for help on using the repository browser.