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

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