[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 |
|
---|
| 8 | namespace GtpVisibility {
|
---|
| 9 |
|
---|
[112] | 10 | enum CullingType {QUERY_CULLED, FRUSTUM_CULLED};
|
---|
| 11 |
|
---|
[370] | 12 | typedef std::vector<HierarchyNode *> NodeVector;
|
---|
[2280] | 13 | //typedef std::vector<GtpVisibility::Mesh *> GeometryVector;
|
---|
| 14 | //typedef std::vector<GtpVisibility::Patch *> PatchVector;
|
---|
| 15 |
|
---|
[130] | 16 | typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
|
---|
[370] | 17 | typedef std::pair<HierarchyNode *, bool> PendingQuery;
|
---|
[130] | 18 | typedef std::queue<QueryPair> QueryQueue;
|
---|
[370] | 19 | typedef std::queue<PendingQuery> PendingQueue;
|
---|
[130] | 20 |
|
---|
[2292] | 21 | typedef 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 | */
|
---|
| 28 | class HierarchyInterface
|
---|
| 29 | {
|
---|
| 30 | public:
|
---|
| 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;
|
---|
[87] | 60 | /** Returns distance of the node to the view plane.
|
---|
[726] | 61 | @param node the hierarchy node
|
---|
[59] | 62 | */
|
---|
[87] | 63 | virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
|
---|
[59] | 64 | /** Checks if the node is visible from the current view frustum.
|
---|
| 65 | @param node the current node
|
---|
| 66 | @param intersects returns true if the current node intersects the near plane
|
---|
| 67 | */
|
---|
[2258] | 68 | virtual bool CheckFrustumVisible(HierarchyNode *node,
|
---|
| 69 | bool &intersects) = 0;
|
---|
[2306] | 70 |
|
---|
[59] | 71 | /** Returns true if there is renderable geometry attached to this node
|
---|
| 72 | @param node the current node
|
---|
| 73 | @returns if the node has renderable geometry
|
---|
| 74 | */
|
---|
[74] | 75 | virtual bool HasGeometry(HierarchyNode *node) const = 0;
|
---|
[59] | 76 | /** Sets the visible flag for this node.
|
---|
| 77 | @param node the current node
|
---|
| 78 | @param visible the visible flag
|
---|
| 79 | */
|
---|
[2258] | 80 | virtual void SetNodeVisible(HierarchyNode *node,
|
---|
| 81 | const bool visible) const = 0;
|
---|
[59] | 82 | /** Returns true if node has the visible flag set. See set
|
---|
| 83 | */
|
---|
[74] | 84 | virtual bool IsNodeVisible(HierarchyNode *node) const = 0;
|
---|
[59] | 85 | /** Sets the last visited frame id for this node.
|
---|
| 86 | @param node the current node
|
---|
| 87 | @param frameId the current frame id
|
---|
| 88 | */
|
---|
[74] | 89 | virtual void SetLastVisited(HierarchyNode *node,
|
---|
[345] | 90 | const unsigned int frameId) const = 0;
|
---|
[2306] | 91 |
|
---|
| 92 |
|
---|
| 93 | virtual void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const = 0;
|
---|
| 94 |
|
---|
| 95 | virtual HierarchyNode *GetRandomLeaf(HierarchyNode *root) = 0;
|
---|
| 96 | virtual bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const = 0;
|
---|
| 97 |
|
---|
| 98 | virtual void CollectLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0;
|
---|
| 99 |
|
---|
| 100 | virtual void RenderNodeRecursive(HierarchyNode *node) = 0;
|
---|
| 101 |
|
---|
[59] | 102 | /** Returns frame id when this node was last visited by the traverser. See set
|
---|
| 103 | */
|
---|
[74] | 104 | virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
|
---|
[155] | 105 |
|
---|
[112] | 106 | /** Visualization of a culled node, dependent on the culling type.
|
---|
[897] | 107 | @param node the hierarchy node to be visualized
|
---|
[112] | 108 | @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
|
---|
| 109 | */
|
---|
| 110 | virtual void VisualizeCulledNode(HierarchyNode *node,
|
---|
[897] | 111 | CullingType type) const = 0;
|
---|
[111] | 112 |
|
---|
[2306] | 113 | /** Sets the root of the scene hierarchy.
|
---|
| 114 | @param root the hierarchy root
|
---|
[130] | 115 | */
|
---|
[2306] | 116 | void SetHierarchyRoot(HierarchyNode *root);
|
---|
| 117 | /** Get the root of the scene hierarchy.
|
---|
| 118 | @return the hierarchy root
|
---|
[130] | 119 | */
|
---|
[2306] | 120 | HierarchyNode *GetHierarchyRoot() const;
|
---|
[130] | 121 |
|
---|
[155] | 122 | /** This is an optimization when issuing the occlusion test.
|
---|
| 123 | The test is done with actual geometry rather than the bounding
|
---|
[158] | 124 | box of leave nodes previously marked as visible.
|
---|
| 125 |
|
---|
[155] | 126 | @param testGeometry if this optimization should be used
|
---|
| 127 | @remark this option is only useful for the coherent hierarchical culling algorithm
|
---|
| 128 | */
|
---|
| 129 | void TestGeometryForVisibleLeaves(bool testGeometry);
|
---|
| 130 |
|
---|
[2306] | 131 | /** Sets the scene root and initialises this hierarchy interface for a traversal.
|
---|
| 132 | @remark also resets the statistics evaluated in the last traversal
|
---|
| 133 | */
|
---|
| 134 | void InitTraversal();
|
---|
| 135 | /** Returns current frame id.
|
---|
| 136 | @returns frame id
|
---|
| 137 | */
|
---|
| 138 | unsigned int GetFrameId() const;
|
---|
| 139 | /** Returns a pointer to the distance queue.
|
---|
| 140 | @returns current distance queue.
|
---|
| 141 | @remark the distance queue stores hierarchy nodes in a front-to-back order
|
---|
| 142 | */
|
---|
| 143 | DistanceQueue *GetQueue();
|
---|
[155] | 144 |
|
---|
[2306] | 145 | /** Checks if the node is visible from the current view frustum.
|
---|
| 146 | @param node the current node
|
---|
| 147 | */
|
---|
| 148 | bool CheckFrustumVisible(HierarchyNode *node);
|
---|
[2258] | 149 |
|
---|
[2306] | 150 | /** Returns number of traversed nodes.
|
---|
| 151 | */
|
---|
| 152 | unsigned int GetNumTraversedNodes();
|
---|
| 153 | /** Returns number of rendered nodes.
|
---|
| 154 | */
|
---|
| 155 | unsigned int GetNumRenderedNodes();
|
---|
[2258] | 156 |
|
---|
[2306] | 157 | /** Returns vector of visible hierarchy nodes from previous render.
|
---|
| 158 | */
|
---|
| 159 | std::vector<HierarchyNode *> *GetVisibleNodes();
|
---|
[2292] | 160 |
|
---|
[2332] | 161 | virtual void PullUpLastVisited(HierarchyNode *node, const int frameId) const = 0;
|
---|
| 162 | virtual void DetermineVisibilityRatio(HierarchyNode *node) const = 0;
|
---|
| 163 | virtual float GetNodeVisibilityRatio(HierarchyNode *node) const = 0;
|
---|
[2292] | 164 |
|
---|
[2332] | 165 | virtual HierarchyNode *GetParent(HierarchyNode *node) = 0;
|
---|
| 166 |
|
---|
[59] | 167 | protected:
|
---|
[606] | 168 |
|
---|
| 169 |
|
---|
[155] | 170 | /// chc optimization for testing geometry of leaves instead of bounding box
|
---|
| 171 | bool mTestGeometryForVisibleLeaves;
|
---|
[158] | 172 | /// the current frame number
|
---|
[59] | 173 | unsigned int mFrameId;
|
---|
[925] | 174 | /// index of the lcurrent occlusion query in the array of queries
|
---|
| 175 | /// NOTE: should rather be iterator
|
---|
[59] | 176 | int mCurrentTestIdx;
|
---|
| 177 |
|
---|
[155] | 178 | /// number of traversed nodes
|
---|
[59] | 179 | unsigned int mNumTraversedNodes;
|
---|
[158] | 180 |
|
---|
| 181 | /// The queue is useful for rendering hierarchy nodes in front to back order.
|
---|
[59] | 182 | DistanceQueue *mDistanceQueue;
|
---|
[111] | 183 |
|
---|
[155] | 184 | /// the root of the hierarchy
|
---|
| 185 | HierarchyNode *mHierarchyRoot;
|
---|
| 186 |
|
---|
[158] | 187 | /// buffer for a node pointer
|
---|
[155] | 188 | HierarchyNode *mSavedNode;
|
---|
[2306] | 189 |
|
---|
[158] | 190 | /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
|
---|
[174] | 191 | std::vector<HierarchyNode *> mVisibleNodes;
|
---|
[59] | 192 | };
|
---|
| 193 | } // namespace GtpVisibility
|
---|
[155] | 194 |
|
---|
[112] | 195 | #endif // GtpVisisibilityHierarchyInterface_H |
---|