Ignore:
Timestamp:
06/12/08 01:09:23 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h

    r2753 r2755  
    55 
    66#include "Geometry.h" 
    7 //#include "FlexibleHeap.h" 
    87 
    98 
     
    1413// Forward declarations 
    1514 
    16 class SceneGeometry; 
     15class SceneEntity; 
    1716class Camera; 
    1817 
     
    2322{ 
    2423        friend class Bvh; 
     24        friend class BvhLoader; 
     25        friend class myless; 
    2526 
    2627public: 
     
    5253        */ 
    5354        BvhNode(BvhNode *parent); 
    54          
    5555        /** Returns true if this node is a leaf. 
    5656        */ 
     
    7575        virtual void ResetVisibility(); 
    7676 
    77         virtual int GetType() = 0; //{ return BVH_NODE; } 
    78  
    79  
    80         ///////////////////// 
     77        virtual bool IsLeaf() = 0; //{ return BVH_NODE; } 
     78 
     79 
     80        //////////////// 
    8181        //-- visibility culling related functions 
    8282 
    8383        inline int GetLastVisitedFrame() const; 
    8484 
    85         inline void SetLastVisitedFrame(const int lastVisited); 
     85        inline void SetLastVisitedFrame(int lastVisited); 
    8686        /** If this node is considered visible. 
    8787        */ 
     
    8989        /** Set visibility flag of the node. 
    9090        */ 
    91         inline void SetVisible(const bool visible); 
     91        inline void SetVisible(bool visible); 
    9292        /** The assumed visible time span of this node. 
    9393        */ 
    94         inline void SetAssumedVisibleFrames(const int t); 
     94        inline void SetAssumedVisibleFrames(int t); 
    9595        /** See set. 
    9696        */ 
     
    108108         
    109109        inline int GetTimesInvisible() const; 
    110         inline void SetTimesInvisible(const int t); 
     110        inline void SetTimesInvisible(int t); 
    111111         
    112112        inline int GetTurnedVisibleFrame() const; 
    113         inline void SetTurnedVisibleFrame(const int turnedVisibleFrame); 
     113        inline void SetTurnedVisibleFrame(int turnedVisibleFrame); 
    114114 
    115115        inline int GetLastTestedFrame(); 
    116         inline void SetLastTestedFrame(const int lastTested); 
     116        inline void SetLastTestedFrame(int lastTested); 
    117117         
    118118        inline bool IsViewFrustumCulled() const; 
    119         inline void SetViewFrustumCulled(const bool frustumCulled); 
     119        inline void SetViewFrustumCulled(bool frustumCulled); 
    120120 
    121121        inline bool IsNew() const; 
    122         inline void SetIsNew(const bool isNew); 
     122        inline void SetIsNew(bool isNew); 
     123 
     124 
     125        /** Returns the bounding box of this node. 
     126        */ 
     127        inline const AxisAlignedBox3 &GetBox() { return mBox; } 
     128        /** Return index of this node. 
     129        */ 
     130        inline int GetId() const { return mId; } 
     131        /** See get 
     132        */ 
     133        inline void SetId(int id) { mId = id; } 
    123134 
    124135 
     
    152163        /// the parent node 
    153164        BvhNode *mParent; 
    154         /// stores the visibility related parameters 
     165        /// stores the visibility related info 
    155166        VisibilityInfo mVisibility; 
    156167 
     
    181192        /// these nodes can be tested instead of the current node 
    182193        int mTestNodesIdx; 
     194         
    183195        int mNumTestNodes; 
     196 
    184197        int mIndicesPtr; 
     198 
    185199        /// Area of this node 
    186200        float mArea; 
     201        /// distance to the camera 
     202        float mDistance; 
     203        /// the index of this node 
     204        unsigned int mId; 
     205        /// indices used for draw array rendering 
     206        unsigned int *mIndices; 
     207        /// the bounding box 
     208        AxisAlignedBox3 mBox; 
     209 
    187210}; 
    188211 
     
    302325class BvhInterior: public BvhNode 
    303326{ 
    304 friend class Bvh; 
     327        friend class Bvh; 
     328        friend class BvhLoader; 
    305329 
    306330public: 
     331 
    307332        BvhInterior(BvhNode *parent): mBack(NULL), mFront(NULL), BvhNode(parent) 
    308333        {} 
     
    319344        /** Returns split axis of this interior node. 
    320345        */ 
    321         inline int GetAxis() {return (int)mAxis;} 
     346        inline int GetAxis() { return (int)mAxis; } 
    322347        /** Returns position of the split axis. 
    323348        */ 
     
    337362class BvhLeaf: public BvhNode 
    338363{ 
    339 friend class Bvh; 
     364        friend class Bvh; 
     365        friend class BvhLoader; 
    340366 
    341367public: 
     
    347373 
    348374        virtual bool IsLeaf() { return true; } 
     375}; 
     376 
     377 
     378/**     This class implements the compare operator for the priority queue. 
     379        a lower distance has a higher value in the queue 
     380*/ 
     381class myless 
     382{ 
     383public: 
     384        bool operator() (BvhNode *v1, BvhNode *v2) const 
     385    { 
     386                return (v1->mDistance > v2->mDistance); 
     387    } 
    349388}; 
    350389 
     
    354393class Bvh 
    355394{ 
     395        friend class BvhLoader; 
     396 
    356397        /** Bvh properties 
    357398        */ 
     
    401442        */ 
    402443        inline int GetNumLeaves() const {return mNumNodes / 2 + 1;} 
    403         /** Constructs the bounding volume hierarchy. 
    404         */ 
    405         void Construct(); 
    406444        /** Returns root node of the bvh. 
    407445        */ 
    408         BvhNode *GetRoot() {return mRoot;} 
     446        BvhNode *GetRoot() { return mRoot; } 
    409447        /** Counts the triangle in this leaf. 
    410448        */ 
     
    412450 
    413451 
     452        void CollectNodes(BvhNode *node, BvhNodeContainer &nodes, int depth); 
     453        void CollectNodes(BvhNode *node, BvhNodeContainer &nodes); 
     454        void CollectLeaves(BvhNode *node, BvhLeafContainer &leaves); 
     455 
     456 
    414457        ////////////////////// 
    415458 
    416459        /** Returns geometry by reference (faster). 
    417460        */ 
    418         SceneGeometry **GetGeometry(BvhNode *node, int &size); 
     461        SceneEntity **GetGeometry(BvhNode *node, int &size); 
    419462 
    420463 
     
    442485        */ 
    443486        int     IsWithinViewFrustum(BvhNode *node); 
    444         /** sets frame dependent values. 
    445         */ 
    446         void InitFrame(Camera *camera, const int currentFrameId); 
    447         /** this gives the orthogonal distance from the viewpoint to the nearest bounding box vertex 
     487        /** Sets frame dependent values. 
     488        */ 
     489        void InitFrame(Camera *camera, int currentFrameId); 
     490        /** This gives the orthogonal distance from the viewpoint to the nearest bounding box vertex 
    448491                note that negative values can appear because culling is done only afterwards 
    449492        */ 
    450493        float CalcDistance(BvhNode *node) const; 
    451         /** Sets maximal depth for taking the bounding boxes to test the 
    452                 visibility of a node. The deeper the more the box fits to the geometry. 
    453         */ 
    454         void SetMaxDepthForTestingChildren(const int maxDepth); 
    455         /** Pulls up the fully visible classification in the bvh. 
    456         */ 
    457         void UpdateFullVisibility(BvhNode *node) const; 
    458494        /** Pulls up the last visited classification in the bvh. 
    459495        */ 
    460         void PullUpLastVisited(BvhNode *node, const int frameId) const; 
     496        void PullUpLastVisited(BvhNode *node, int frameId) const; 
    461497        /** Resets the node classifications in the tree. 
    462498        */ 
     
    465501                wireframes for visualization purpose. 
    466502        */ 
    467         void RenderBoundingBoxesForViz(const int mode); 
    468         /** Returns squared min distance to the view point. 
    469         */ 
    470         float GetSquareDistance(BvhNode *node) const; 
     503        //void RenderBoundingBoxesForViz(int mode); 
    471504        /** Count triangles the node contains. 
    472505        */ 
     
    477510 
    478511 
    479         //////////// 
    480         //-- functions that change the boundaries of the nodes 
    481  
    482         void SetUseTighterBoundsForTests(bool tighterBoundsForTests); 
    483  
    484         void SetAreaRatioThresholdForTestingChildren(const float ratio); 
    485  
    486  
     512        //////// 
     513        //-- functions influencing tighter bounds 
     514 
     515 
     516        /** Sets maximal depth for taking the bounding boxes to test the 
     517                visibility of a node.  
     518                Deeper => the bounds adapt more to the geometry. 
     519        */ 
     520        void SetMaxDepthForTestingChildren(int maxDepth); 
     521 
     522        void SetAreaRatioThresholdForTestingChildren(float ratio); 
     523 
     524        /** Returns stats. 
     525        */ 
    487526        const BvhStats &GetBvhStats() const {return mBvhStats;} 
    488  
    489         void SetCollectTighterBoundsWithMaxLevel(bool t); 
    490  
    491  
    492         ////////////// 
    493  
    494         static unsigned int sCurrentVboId; 
    495527         
    496528 
    497529protected: 
    498530 
    499         /** Small struct representing a frustum. 
    500         */ 
    501         struct Frustum 
    502         { 
    503                 /// the 6 clip planes 
    504                 float mClipPlane[6][4]; 
    505         }; 
    506          
    507  
    508  
    509531        //////////////////// 
    510532 
    511         /** Constructor loading the bvh from disc 
    512         */ 
    513         Bvh(const std::string &filename); 
    514533        /** protected constructor: do nothing. 
    515534        */ 
    516         //Bvh(): mCamera(NULL), mFrameId(-1), mVertices(NULL), mRenderer(NULL) {} 
     535        Bvh(); 
    517536        /** Destructor. 
    518537        */ 
     
    534553        void RenderBoundingBoxesWithDrawArrays(int numNodes); 
    535554 
    536         int RenderBoundingBoxesImmediate(const BvhNodeContainer &nodes); 
    537         /** Renders a bounding box in immediate mode using index restart 
    538                 and restarts the strip only if wished. 
    539         */ 
    540         void RenderBoundingBoxImmediate(const AxisAlignedBox3 &box, bool restartStrip); 
    541555        /** Create the indices that each node needs to use vbo rendering. 
    542556        */ 
     
    550564        */ 
    551565        void UpdateInteriors(BvhNode *node); 
    552         /** Recomputes the boundaries of the nodes. This function is always called if 
    553                 some boundary options are changed. 
     566        /** Recomputes the boundaries of the nodes.  
     567            This function is always called if some boundary options are changed. 
    554568        */ 
    555569        void RecomputeBounds(); 
     
    558572        */ 
    559573        int PostProcessLeaves(BvhLeafContainer &leaves); 
    560  
    561  
    562         int     IsWithinViewFrustumLocal(BvhNode *node); 
    563  
    564         int     IsWithinViewFrustum(const AxisAlignedBox3 &box, int planeMask, int preferredPlane); 
    565          
    566         float GetMinSquareDistance(const AxisAlignedBox3 &box) const; 
    567          
     574                 
    568575         
    569576        //////////////////////// 
     
    572579        BvhNode *mRoot; 
    573580        /// pointers to the geometry associated with this node 
    574         SceneGeometry **mGeometry; 
     581        SceneEntity **mGeometry; 
    575582        /// #of entities 
    576583        size_t mGeometrySize; 
     
    579586        //////////////// 
    580587 
    581  
    582         /// these values are valid for all nodes 
    583         char mClipPlaneAABBVertexIndices[6][2]; 
    584         /// the current view frustum 
    585         Frustum mFrustum; 
    586588        /// the current camera 
    587589        Camera *mCamera; 
     
    589591        int mFrameId; 
    590592        /// a vertex array used if working with indexed arrays (without vbo) 
    591         //Point3f *mVertices; 
     593        Vector3 *mVertices; 
    592594        /// indices used for draw array rendering 
    593595        unsigned int *mIndices; 
     
    599601 
    600602        float mAreaRatioThreshold; 
    601         float mVolRatioThreshold; 
     603 
    602604 
    603605        BvhStats mBvhStats; 
    604606 
    605         //HierarchyNodeContainer mTestNodes; 
     607        BvhNodeContainer mTestNodes; 
    606608         
    607609        unsigned int *mTestIndices; 
     
    609611        int mCurrentIndicesPtr; 
    610612 
    611         float mScale; 
    612  
    613         Vector3 mNearPlane; 
    614         float mNearPlaneD; 
    615613        int mNumNodes; 
     614 
     615 
     616        ////////////// 
     617 
     618        static unsigned int sCurrentVboId; 
    616619}; 
    617620 
Note: See TracChangeset for help on using the changeset viewer.