[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] | 9 | namespace GtpVisibility {
|
---|
| 10 |
|
---|
[112] | 11 | enum CullingType {QUERY_CULLED, FRUSTUM_CULLED};
|
---|
| 12 |
|
---|
[370] | 13 | typedef std::vector<HierarchyNode *> NodeVector;
|
---|
[2280] | 14 | //typedef std::vector<GtpVisibility::Mesh *> GeometryVector;
|
---|
| 15 | //typedef std::vector<GtpVisibility::Patch *> PatchVector;
|
---|
| 16 |
|
---|
[130] | 17 | typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
|
---|
[370] | 18 | typedef std::pair<HierarchyNode *, bool> PendingQuery;
|
---|
[130] | 19 | typedef std::queue<QueryPair> QueryQueue;
|
---|
[370] | 20 | typedef std::queue<PendingQuery> PendingQueue;
|
---|
[130] | 21 |
|
---|
[2292] | 22 | typedef std::vector<HierarchyNode *> HierarchyNodeContainer;
|
---|
[158] | 23 |
|
---|
[2292] | 24 |
|
---|
| 25 | /** Class which implements an interface for the operations on a hierarchy
|
---|
| 26 | of a scene.
|
---|
| 27 | It has to be implemented for any rendering engine to use the CHC algorithm.
|
---|
[59] | 28 | */
|
---|
| 29 | class HierarchyInterface
|
---|
| 30 | {
|
---|
| 31 | public:
|
---|
| 32 | /** Default constructor.
|
---|
| 33 | */
|
---|
| 34 | HierarchyInterface();
|
---|
| 35 | virtual ~HierarchyInterface();
|
---|
| 36 | /** Returns true if current node is leaf of the hierarchy.
|
---|
| 37 | @param node hierarchy node
|
---|
| 38 | @returns true if node is leaf
|
---|
| 39 | */
|
---|
[74] | 40 | virtual bool IsLeaf(HierarchyNode *node) const = 0;
|
---|
[897] | 41 | /** Traverses and renders the hierarchy from the given node.
|
---|
[59] | 42 | @param node the hierarchy node
|
---|
| 43 | */
|
---|
[158] | 44 | virtual void TraverseNode(HierarchyNode *node) = 0;
|
---|
[897] | 45 | /** Renders the given hierarchy node.
|
---|
[130] | 46 | @param node current hierarchy node to be rendered
|
---|
[59] | 47 | */
|
---|
| 48 | virtual void RenderNode(HierarchyNode *node) = 0;
|
---|
| 49 | /** Pulls up the visibility from the current node recursively to the parent nodes.
|
---|
| 50 | @param node the current node
|
---|
| 51 | */
|
---|
[345] | 52 | virtual void PullUpVisibility(HierarchyNode *node) const = 0;
|
---|
[59] | 53 | /** Issue a occlusion query for this node.
|
---|
| 54 | @param node the current hierarchy node
|
---|
[2455] | 55 | @param testGeometry (if geometry should be tested instead of the bb).
|
---|
[59] | 56 | @returns occlusion query for this node
|
---|
| 57 | */
|
---|
[175] | 58 | virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node,
|
---|
[2455] | 59 | const bool testGeometry = 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 |
|
---|
[2543] | 100 | /** Collects only leaves that are found visible by view frustum culling.
|
---|
[2538] | 101 | */
|
---|
[2543] | 102 | //virtual void CollectVisibleLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0;
|
---|
[2538] | 103 |
|
---|
[2306] | 104 | virtual void RenderNodeRecursive(HierarchyNode *node) = 0;
|
---|
| 105 |
|
---|
[59] | 106 | /** Returns frame id when this node was last visited by the traverser. See set
|
---|
| 107 | */
|
---|
[74] | 108 | virtual unsigned int LastVisited(HierarchyNode *node) const = 0;
|
---|
[155] | 109 |
|
---|
[112] | 110 | /** Visualization of a culled node, dependent on the culling type.
|
---|
[897] | 111 | @param node the hierarchy node to be visualized
|
---|
[112] | 112 | @param type can be one of FRUSTUM_CULLED, QUERY_CULLED
|
---|
| 113 | */
|
---|
| 114 | virtual void VisualizeCulledNode(HierarchyNode *node,
|
---|
[897] | 115 | CullingType type) const = 0;
|
---|
[111] | 116 |
|
---|
[2306] | 117 | /** Sets the root of the scene hierarchy.
|
---|
| 118 | @param root the hierarchy root
|
---|
[130] | 119 | */
|
---|
[2306] | 120 | void SetHierarchyRoot(HierarchyNode *root);
|
---|
| 121 | /** Get the root of the scene hierarchy.
|
---|
| 122 | @return the hierarchy root
|
---|
[130] | 123 | */
|
---|
[2306] | 124 | HierarchyNode *GetHierarchyRoot() const;
|
---|
| 125 | /** Sets the scene root and initialises this hierarchy interface for a traversal.
|
---|
| 126 | @remark also resets the statistics evaluated in the last traversal
|
---|
| 127 | */
|
---|
| 128 | void InitTraversal();
|
---|
| 129 | /** Returns current frame id.
|
---|
| 130 | @returns frame id
|
---|
| 131 | */
|
---|
| 132 | unsigned int GetFrameId() const;
|
---|
| 133 | /** Returns a pointer to the distance queue.
|
---|
| 134 | @returns current distance queue.
|
---|
| 135 | @remark the distance queue stores hierarchy nodes in a front-to-back order
|
---|
| 136 | */
|
---|
| 137 | DistanceQueue *GetQueue();
|
---|
| 138 | /** Checks if the node is visible from the current view frustum.
|
---|
| 139 | @param node the current node
|
---|
| 140 | */
|
---|
| 141 | bool CheckFrustumVisible(HierarchyNode *node);
|
---|
| 142 | /** Returns number of traversed nodes.
|
---|
| 143 | */
|
---|
| 144 | unsigned int GetNumTraversedNodes();
|
---|
| 145 | /** Returns number of rendered nodes.
|
---|
| 146 | */
|
---|
| 147 | unsigned int GetNumRenderedNodes();
|
---|
| 148 | /** Returns vector of visible hierarchy nodes from previous render.
|
---|
| 149 | */
|
---|
| 150 | std::vector<HierarchyNode *> *GetVisibleNodes();
|
---|
[2455] | 151 | /** Pulls up the last visited information of this node.
|
---|
| 152 | */
|
---|
[2332] | 153 | virtual void PullUpLastVisited(HierarchyNode *node, const int frameId) const = 0;
|
---|
[2455] | 154 | /** Returns parent node.
|
---|
| 155 | */
|
---|
[2332] | 156 | virtual HierarchyNode *GetParent(HierarchyNode *node) = 0;
|
---|
[2455] | 157 | /** Returns #frames this node is assumed to be visible.
|
---|
| 158 | */
|
---|
| 159 | virtual int GetNodeAssumedVisible(HierarchyNode *node) = 0;
|
---|
| 160 | /** Sets #frames this node is assumed to be visible.
|
---|
| 161 | */
|
---|
| 162 | virtual void SetNodeAssumedVisible(HierarchyNode *node, int assumedVisible) = 0;
|
---|
| 163 | /** Decreases #frames this node is assumed to be visible.
|
---|
| 164 | */
|
---|
| 165 | virtual void DecNodeAssumedVisible(HierarchyNode *node) = 0;
|
---|
[2555] | 166 |
|
---|
| 167 | virtual void AddToQueue(GtpVisibility::HierarchyNode *node) = 0;
|
---|
[2332] | 168 |
|
---|
[2555] | 169 | virtual void RenderQueue() = 0;
|
---|
| 170 |
|
---|
| 171 | virtual void TraverseNode2(GtpVisibility::HierarchyNode *node) = 0;
|
---|
| 172 |
|
---|
[59] | 173 | protected:
|
---|
[606] | 174 |
|
---|
[158] | 175 | /// the current frame number
|
---|
[59] | 176 | unsigned int mFrameId;
|
---|
[2455] | 177 |
|
---|
[925] | 178 | /// index of the lcurrent occlusion query in the array of queries
|
---|
| 179 | /// NOTE: should rather be iterator
|
---|
[59] | 180 | int mCurrentTestIdx;
|
---|
| 181 |
|
---|
[155] | 182 | /// number of traversed nodes
|
---|
[59] | 183 | unsigned int mNumTraversedNodes;
|
---|
[158] | 184 |
|
---|
| 185 | /// The queue is useful for rendering hierarchy nodes in front to back order.
|
---|
[59] | 186 | DistanceQueue *mDistanceQueue;
|
---|
[111] | 187 |
|
---|
[155] | 188 | /// the root of the hierarchy
|
---|
| 189 | HierarchyNode *mHierarchyRoot;
|
---|
| 190 |
|
---|
[158] | 191 | /// buffer for a node pointer
|
---|
[2455] | 192 | HierarchyNode *mOldNode;
|
---|
[2306] | 193 |
|
---|
[158] | 194 | /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries)
|
---|
[174] | 195 | std::vector<HierarchyNode *> mVisibleNodes;
|
---|
[59] | 196 | };
|
---|
[2455] | 197 |
|
---|
[59] | 198 | } // namespace GtpVisibility
|
---|
[155] | 199 |
|
---|
[112] | 200 | #endif // GtpVisisibilityHierarchyInterface_H |
---|