source: trunk/VUT/GtpVisibility/include/HierarchyInterface.h @ 174

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