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

Revision 2280, 6.5 KB checked in by mattausch, 18 years ago (diff)

removed dependency on ogre in gtpvisibility

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