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

Revision 2558, 6.9 KB checked in by mattausch, 17 years ago (diff)
RevLine 
[59]1#ifndef _GtpVisibilityHierarchyInterface_H__
2#define _GtpVisibilityHierarchyInterface_H__
3
[2455]4
[59]5#include "DistanceQueue.h"
[155]6#include <stack>
[59]7
[2455]8
[59]9namespace GtpVisibility {
10
[112]11enum  CullingType {QUERY_CULLED, FRUSTUM_CULLED};
12
[370]13typedef std::vector<HierarchyNode *> NodeVector;
[2280]14//typedef std::vector<GtpVisibility::Mesh *> GeometryVector;
15//typedef std::vector<GtpVisibility::Patch *> PatchVector;
16
[130]17typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
[370]18typedef std::pair<HierarchyNode *, bool> PendingQuery;
[130]19typedef std::queue<QueryPair> QueryQueue;
[370]20typedef std::queue<PendingQuery> PendingQueue;
[130]21
[2292]22typedef std::vector<HierarchyNode *> HierarchyNodeContainer;
[158]23
[2292]24
[2558]25class MultiQuery
26{
27        OcclusionQuery *mQuery;
28        HierarchyNodeContainer *mNodes;
29};
30
31
32
[2292]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.
[59]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        */
[74]48    virtual bool IsLeaf(HierarchyNode *node) const = 0;
[897]49        /** Traverses and renders the hierarchy from the given node.
[59]50                @param node the hierarchy node
51        */
[158]52        virtual void TraverseNode(HierarchyNode *node) = 0;
[897]53        /** Renders the given hierarchy node.
[130]54                @param node current hierarchy node to be rendered
[59]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        */
[345]60        virtual void PullUpVisibility(HierarchyNode *node) const = 0;
[59]61        /** Issue a occlusion query for this node.
62                @param node the current hierarchy node
[2455]63                @param testGeometry (if geometry should be tested instead of the bb).
[59]64                @returns occlusion query for this node
65        */
[175]66        virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node,
[2455]67                                                                                                        const bool testGeometry = false) = 0;
[87]68        /** Returns distance of the node to the view plane.
[726]69                @param node the hierarchy node
[59]70        */                     
[87]71        virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
[59]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        */
[2258]76        virtual bool CheckFrustumVisible(HierarchyNode *node,
77                                                                         bool &intersects) = 0;
[2306]78       
[59]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        */
[74]83    virtual bool HasGeometry(HierarchyNode *node) const = 0;
[59]84        /** Sets the visible flag for this node.
85                @param node the current node
86                @param visible the visible flag
87        */
[2258]88        virtual void SetNodeVisible(HierarchyNode *node,
89                                                                const bool visible) const = 0;
[59]90        /** Returns true if node has the visible flag set. See set
91        */
[74]92        virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
[59]93        /** Sets the last visited frame id for this node.
94                @param node the current node
95                @param frameId the current frame id
96        */
[74]97        virtual void SetLastVisited(HierarchyNode *node,
[345]98                                                                const unsigned int frameId) const = 0;
[2306]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
[2543]108        /** Collects only leaves that are found visible by view frustum culling.
[2538]109        */
[2543]110        //virtual void CollectVisibleLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0;
[2538]111
[2306]112        virtual void RenderNodeRecursive(HierarchyNode *node) = 0;
113
[59]114        /** Returns frame id when this node was last visited by the traverser. See set
115        */
[74]116        virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
[155]117               
[112]118        /** Visualization of a culled node, dependent on the culling type.
[897]119                @param node the hierarchy node to be visualized
[112]120                @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
121        */
122        virtual void VisualizeCulledNode(HierarchyNode *node,
[897]123                                                                         CullingType type) const = 0;
[111]124
[2306]125        /** Sets the root of the scene hierarchy.
126                @param root the hierarchy root
[130]127        */
[2306]128        void SetHierarchyRoot(HierarchyNode *root);
129    /** Get the root of the scene hierarchy.
130                @return the hierarchy root
[130]131        */
[2306]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();
[2455]159        /** Pulls up the last visited information of this node.
160        */
[2332]161        virtual void PullUpLastVisited(HierarchyNode *node, const int frameId) const = 0;
[2455]162        /** Returns parent node.
163        */
[2332]164        virtual HierarchyNode *GetParent(HierarchyNode *node) = 0;
[2455]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;
[2555]174       
175        virtual void AddToQueue(GtpVisibility::HierarchyNode *node) = 0;
[2332]176
[2555]177        virtual void RenderQueue() = 0;
178
179        virtual void TraverseNode2(GtpVisibility::HierarchyNode *node) = 0;
180
[59]181protected:
[606]182
[158]183        /// the current frame number
[59]184        unsigned int mFrameId;
[2455]185       
[925]186        /// index of the lcurrent occlusion query in the array of queries
187        /// NOTE: should rather be iterator
[59]188        int mCurrentTestIdx;
189       
[155]190        /// number of traversed nodes
[59]191        unsigned int mNumTraversedNodes;
[158]192
193        /// The queue is useful for rendering hierarchy nodes in front to back order.
[59]194        DistanceQueue *mDistanceQueue;
[111]195
[155]196        /// the root of the hierarchy
197        HierarchyNode *mHierarchyRoot;
198       
[158]199        /// buffer for a node pointer
[2455]200        HierarchyNode *mOldNode;
[2306]201
[158]202        /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
[174]203        std::vector<HierarchyNode *> mVisibleNodes;
[59]204};
[2455]205
[59]206} // namespace GtpVisibility
[155]207
[112]208#endif // GtpVisisibilityHierarchyInterface_H
Note: See TracBrowser for help on using the repository browser.