#ifndef _GtpVisibilityHierarchyInterface_H__ #define _GtpVisibilityHierarchyInterface_H__ #include "DistanceQueue.h" #include namespace GtpVisibility { enum CullingType {QUERY_CULLED, FRUSTUM_CULLED}; typedef std::vector NodeVector; //typedef std::vector GeometryVector; //typedef std::vector PatchVector; typedef std::pair QueryPair; typedef std::pair PendingQuery; typedef std::queue QueryQueue; typedef std::queue PendingQueue; typedef std::vector HierarchyNodeContainer; class MultiQuery { OcclusionQuery *mQuery; HierarchyNodeContainer *mNodes; }; /** Class which implements an interface for the operations on a hierarchy of a scene. It has to be implemented for any rendering engine to use the CHC algorithm. */ class HierarchyInterface { public: /** Default constructor. */ HierarchyInterface(); virtual ~HierarchyInterface(); /** Returns true if current node is leaf of the hierarchy. @param node hierarchy node @returns true if node is leaf */ virtual bool IsLeaf(HierarchyNode *node) const = 0; /** Traverses and renders the hierarchy from the given node. @param node the hierarchy node */ virtual void TraverseNode(HierarchyNode *node) = 0; /** Renders the given hierarchy node. @param node current hierarchy node to be rendered */ virtual void RenderNode(HierarchyNode *node) = 0; /** Pulls up the visibility from the current node recursively to the parent nodes. @param node the current node */ virtual void PullUpVisibility(HierarchyNode *node) const = 0; /** Issue a occlusion query for this node. @param node the current hierarchy node @param testGeometry (if geometry should be tested instead of the bb). @returns occlusion query for this node */ virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node, const bool testGeometry = false) = 0; /** Returns distance of the node to the view plane. @param node the hierarchy node */ virtual float GetSquaredDistance(HierarchyNode *node) const = 0; /** Checks if the node is visible from the current view frustum. @param node the current node @param intersects returns true if the current node intersects the near plane */ virtual bool CheckFrustumVisible(HierarchyNode *node, bool &intersects) = 0; /** Returns true if there is renderable geometry attached to this node @param node the current node @returns if the node has renderable geometry */ virtual bool HasGeometry(HierarchyNode *node) const = 0; /** Sets the visible flag for this node. @param node the current node @param visible the visible flag */ virtual void SetNodeVisible(HierarchyNode *node, const bool visible) const = 0; /** Returns true if node has the visible flag set. See set */ virtual bool IsNodeVisible(HierarchyNode *node) const = 0; /** Sets the last visited frame id for this node. @param node the current node @param frameId the current frame id */ virtual void SetLastVisited(HierarchyNode *node, const unsigned int frameId) const = 0; virtual void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const = 0; virtual HierarchyNode *GetRandomLeaf(HierarchyNode *root) = 0; virtual bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const = 0; virtual void CollectLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0; /** Collects only leaves that are found visible by view frustum culling. */ //virtual void CollectVisibleLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0; virtual void RenderNodeRecursive(HierarchyNode *node) = 0; /** Returns frame id when this node was last visited by the traverser. See set */ virtual unsigned int LastVisited(HierarchyNode *node) const = 0; /** Visualization of a culled node, dependent on the culling type. @param node the hierarchy node to be visualized @param type can be one of FRUSTUM_CULLED, QUERY_CULLED */ virtual void VisualizeCulledNode(HierarchyNode *node, CullingType type) const = 0; /** Sets the root of the scene hierarchy. @param root the hierarchy root */ void SetHierarchyRoot(HierarchyNode *root); /** Get the root of the scene hierarchy. @return the hierarchy root */ HierarchyNode *GetHierarchyRoot() const; /** Sets the scene root and initialises this hierarchy interface for a traversal. @remark also resets the statistics evaluated in the last traversal */ void InitTraversal(); /** Returns current frame id. @returns frame id */ unsigned int GetFrameId() const; /** Returns a pointer to the distance queue. @returns current distance queue. @remark the distance queue stores hierarchy nodes in a front-to-back order */ DistanceQueue *GetQueue(); /** Checks if the node is visible from the current view frustum. @param node the current node */ bool CheckFrustumVisible(HierarchyNode *node); /** Returns number of traversed nodes. */ unsigned int GetNumTraversedNodes(); /** Returns number of rendered nodes. */ unsigned int GetNumRenderedNodes(); /** Returns vector of visible hierarchy nodes from previous render. */ std::vector *GetVisibleNodes(); /** Pulls up the last visited information of this node. */ virtual void PullUpLastVisited(HierarchyNode *node, const int frameId) const = 0; /** Returns parent node. */ virtual HierarchyNode *GetParent(HierarchyNode *node) = 0; /** Returns #frames this node is assumed to be visible. */ virtual int GetNodeAssumedVisible(HierarchyNode *node) = 0; /** Sets #frames this node is assumed to be visible. */ virtual void SetNodeAssumedVisible(HierarchyNode *node, int assumedVisible) = 0; /** Decreases #frames this node is assumed to be visible. */ virtual void DecNodeAssumedVisible(HierarchyNode *node) = 0; virtual void AddToQueue(GtpVisibility::HierarchyNode *node) = 0; virtual void RenderQueue() = 0; virtual void TraverseNode2(GtpVisibility::HierarchyNode *node) = 0; protected: /// the current frame number unsigned int mFrameId; /// index of the lcurrent occlusion query in the array of queries /// NOTE: should rather be iterator int mCurrentTestIdx; /// number of traversed nodes unsigned int mNumTraversedNodes; /// The queue is useful for rendering hierarchy nodes in front to back order. DistanceQueue *mDistanceQueue; /// the root of the hierarchy HierarchyNode *mHierarchyRoot; /// buffer for a node pointer HierarchyNode *mOldNode; /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries) std::vector mVisibleNodes; }; } // namespace GtpVisibility #endif // GtpVisisibilityHierarchyInterface_H