Ignore:
Timestamp:
12/30/05 12:08:15 (19 years ago)
Author:
mattausch
Message:

changed castlinesegment of vspbpstree
changed rayinfo ray classification for bsp tree
implemented shuffling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r483 r485  
    2121class ViewCellsStatistics; 
    2222class ViewCellsManager; 
     23class BspMergeCandidate; 
     24struct BspRay; 
    2325 
    2426 
     
    222224        BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 
    223225 
    224         /** Returns view cell corresponding to unbounded space. 
    225         */ 
    226         BspViewCell *GetRootCell() const; 
    227  
    228226        /** Returns epsilon of this tree. 
    229227        */ 
    230228        float GetEpsilon() const; 
    231229 
    232  
     230        /** Casts line segment into the tree. 
     231                @param origin the origin of the line segment 
     232                @param termination the end point of the line segment 
     233                @returns view cells intersecting the line segment. 
     234        */ 
    233235    int CastLineSegment(const Vector3 &origin, 
    234236                                                const Vector3 &termination, 
    235237                                                ViewCellContainer &viewcells); 
    236238 
    237         /** Merges leaves with similar PVS. 
    238         */ 
    239         int MergeLeaves(); 
    240239                 
    241240        /** Sets pointer to view cells manager. 
     
    243242        void SetViewCellsManager(ViewCellsManager *vcm); 
    244243 
    245         /** Helper function revalidating the view cell leaf list after merge. 
    246         */ 
    247         void RepairVcLeafLists(); 
    248  
    249         /** Collapses the tree with respect to the view cell partition. 
    250                 @returns node of type leaf if the node could be collapsed, this node otherwise 
     244        /** Returns distance from node 1 to node 2. 
     245        */ 
     246        int TreeDistance(BspNode *n1, BspNode *n2) const; 
     247 
     248        /** Merges view cells according to some cost heuristics. 
     249        */ 
     250        int MergeViewCells(const VssRayContainer &rays); 
     251         
     252        /** Refines view cells using shuffling, i.e., border leaves  
     253                of two view cells are exchanged if the resulting view cells 
     254                are tested to be "better" than the old ones. 
     255                @returns number of refined view cells 
     256        */ 
     257        int RefineViewCells(const VssRayContainer &rays); 
     258 
     259        /** Collapses the tree with respect to the view cell partition, 
     260                i.e. leaves having the same view cell are collapsed. 
     261                @returns node of type leaf if the node could be collapsed,  
     262                this node otherwise 
    251263        */ 
    252264        BspNode *CollapseTree(BspNode *node); 
    253          
    254  
    255         /** Returns distance from node 1 to node 2. 
    256         */ 
    257         int TreeDistance(BspNode *n1, BspNode *n2); 
     265 
     266        /** Constructs bsp rays for post processing and visualization. 
     267        */ 
     268        void ConstructBspRays(vector<BspRay *> &bspRays, 
     269                                                  const VssRayContainer &rays); 
     270 
     271         
     272        /** Merge view cells of leaves l1 and l2. 
     273        */ 
     274        bool MergeViewCells(BspLeaf *l1, BspLeaf *l2) const; 
    258275 
    259276protected: 
     
    286303        }; 
    287304 
     305        /** Shuffles the leaves, i.e., tests if exchanging 
     306                the leaves helps in improving the view cells. 
     307        */ 
     308        bool ShuffleLeaves(BspLeaf *leaf1, BspLeaf *leaf2) const; 
     309 
     310        /** Helper function revalidating the view cell leaf list after merge. 
     311        */ 
     312        void RepairVcLeafLists(); 
     313 
    288314        /** Evaluates tree stats in the BSP tree leafs. 
    289315        */ 
     
    478504 
    479505 
     506        /** Collects candidates for the merge in the merge queue. 
     507                @returns number of leaves in queue 
     508        */ 
     509        int CollectMergeCandidates(); 
     510        /** Collects candidates for the merge in the merge queue. 
     511                @returns number of leaves in queue 
     512        */ 
     513        int CollectMergeCandidates(const VssRayContainer &rays); 
     514 
    480515        /** Take 3 ray endpoints, where two are minimum and one a maximum 
    481516                point or the other way round. 
     
    484519 
    485520        /** Take plane normal as plane normal and the midpoint of the ray. 
    486                 PROBLEM: does not resemble any point where visibility is likely to change 
     521                PROBLEM: does not resemble any point where visibility is  
     522                likely to change 
    487523        */ 
    488524        Plane3 ChooseCandidatePlane2(const RayInfoContainer &rays) const; 
    489525 
    490         /** Fit the plane between the two lines so that the plane has equal shortest  
    491                 distance to both lines. 
     526        /** Fit the plane between the two lines so that the plane  
     527                has equal shortest distance to both lines. 
    492528        */ 
    493529        Plane3 ChooseCandidatePlane3(const RayInfoContainer &rays) const; 
    494530   
    495         /** Merge view cells of leaves l1 and l2. 
    496         */ 
    497         bool MergeViewCells(BspLeaf *l1, BspLeaf *l2); 
     531        void ShuffleLeaf(BspLeaf *leaf,  
     532                                         BspViewCell *vc1,  
     533                                         BspViewCell *vc2) const; 
    498534 
    499535        /// Pointer to the root of the tree 
     
    513549        /// box around the whole view domain 
    514550        AxisAlignedBox3 mBox; 
    515  
    516         /// view cell corresponding to unbounded space 
    517         BspViewCell *mRootCell; 
    518551 
    519552        /// minimal number of rays before subdivision termination 
     
    574607        float mMergeMaxCostRatio; 
    575608 
    576         ViewCellsManager *mViewCellsManager; 
    577  
    578609        // if rays should be stored in leaves 
    579610        bool mStoreRays; 
     611         
     612        /// if only driving axis should be used for split 
     613        bool mOnlyDrivingAxis; 
     614 
     615        ViewCellsManager *mViewCellsManager; 
    580616 
    581617        vector<SortableEntry> *mSplitCandidates; 
    582618 
    583         bool mOnlyDrivingAxis; 
    584  
     619        typedef priority_queue<BspMergeCandidate> MergeQueue; 
     620        MergeQueue mMergeQueue; 
     621         
     622        bool mUseRaysForMerge; 
    585623 
    586624private: 
     
    646684 
    647685protected: 
    648          
     686 
     687        /** Cost of a view cell. 
     688        */ 
     689        float GetCost(ViewCell *vc) const; 
    649690        /** Evaluates the merge costs of the leaves. 
    650691        */ 
     
    661702 
    662703 
     704class MergeStatistics: public StatisticsBase 
     705{ 
     706public: 
     707         
     708        int merged; 
     709        int siblings; 
     710        int candidates; 
     711        int nodes; 
     712 
     713        int accTreeDist; 
     714        int maxTreeDist; 
     715         
     716        Real collectTime; 
     717        Real mergeTime; 
     718 
     719        // Constructor 
     720        MergeStatistics()  
     721        { 
     722                Reset(); 
     723        } 
     724         
     725        double AvgTreeDist() const {return (double)accTreeDist / (double)merged;};  
     726 
     727        void Reset()  
     728        { 
     729                nodes = 0; 
     730                merged = 0; 
     731                siblings = 0; 
     732                candidates = 0; 
     733         
     734                accTreeDist = 0; 
     735                maxTreeDist = 0; 
     736 
     737                collectTime = 0; 
     738                mergeTime = 0; 
     739        } 
     740 
     741        void Print(ostream &app) const; 
     742 
     743        friend ostream &operator<<(ostream &s, const MergeStatistics &stat)  
     744        { 
     745                stat.Print(s); 
     746                return s; 
     747        }  
     748}; 
     749 
    663750#endif 
Note: See TracChangeset for help on using the changeset viewer.