Changeset 610


Ignore:
Timestamp:
02/09/06 12:14:11 (18 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
9 edited

Legend:

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

    r581 r610  
    5959  void NormalizeMaximum(); 
    6060   
    61   /** Merges pvs of a and pvs of b into this pvs. 
     61  /** Merges pvs of a into this pvs. 
    6262   */ 
    63   void Merge(const Pvs<T> &a, const Pvs<T> &b); 
     63  void Merge(const Pvs<T> &a); 
    6464   
    6565  /** Difference of pvs to pvs b. 
     
    130130 
    131131template <typename T> 
    132 void Pvs<T>::Merge(const Pvs<T> &a, const Pvs<T> &b) 
     132void Pvs<T>::Merge(const Pvs<T> &a) 
    133133{ 
    134134        std::map<T, PvsData<T>, LtSample<T> >::const_iterator it; 
    135135 
    136         mEntries = a.mEntries; 
    137          
    138         for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
     136        for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
    139137        { 
    140138                PvsData<T> *data = Find((*it).first); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r608 r610  
    12861286 
    12871287                // compress root node 
    1288                 PropagateUpVisibility(interior); 
     1288                PullUpVisibility(interior); 
    12891289        } 
    12901290} 
     
    13281328         
    13291329 
    1330 void ViewCellsTree::PropagateUpVisibility(ViewCellInterior *interior) 
     1330void ViewCellsTree::PullUpVisibility(ViewCellInterior *interior) 
    13311331{ 
    13321332        Intersectable::NewMail((int)interior->mChildren.size()); 
     
    15361536} 
    15371537 
     1538 
     1539void ViewCellsTree::PropagateUpPvs(ViewCell *vc) 
     1540{ 
     1541        while (vc->GetParent()) 
     1542        { 
     1543                vc->GetParent()->GetPvs().Merge(vc->GetPvs()); 
     1544                vc = vc->GetParent(); 
     1545        } 
     1546} 
    15381547 
    15391548 
     
    16241633 
    16251634 
     1635bool ViewCellsTree::Export(ofstream &stream) 
     1636{ 
     1637        ExportViewCell(mRoot, stream); 
     1638 
     1639        return true; 
     1640} 
     1641 
     1642 
     1643void ViewCellsTree::ExportViewCell(ViewCell *viewCell, ofstream &stream) 
     1644{ 
     1645        ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end(); 
     1646 
     1647        if (0) // test with empty pvs 
     1648        for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
     1649        { 
     1650                stream << (*it).first->GetId() << " "; 
     1651        } 
     1652 
     1653        stream << "\" />" << endl; 
     1654 
     1655        if (viewCell->IsLeaf()) 
     1656        { 
     1657                stream << "<Leaf "; 
     1658                stream << "id=\"" << viewCell->GetId() << "\" "; 
     1659                stream << "active=\"" << viewCell->mIsActive << "\" "; 
     1660                stream << "mergecost=\"" << viewCell->GetMergeCost() << "\" "; 
     1661                stream << "pvs=\""; 
     1662                stream << "</Leaf>" << endl; 
     1663        } 
     1664        else 
     1665        { 
     1666                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(viewCell); 
     1667         
     1668                stream << "<Interior "; 
     1669                stream << "id=\"" << viewCell->GetId() << "\" "; 
     1670                stream << "active=\"" << viewCell->mIsActive << "\" "; 
     1671                stream << "mergecost=\"" << viewCell->GetMergeCost() << "\" "; 
     1672                stream << "pvs=\""; 
     1673 
     1674                ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1675 
     1676                for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1677                { 
     1678                        ExportViewCell(*it, stream); 
     1679                } 
     1680 
     1681                stream << "</Interior>" << endl; 
     1682        } 
     1683} 
     1684 
     1685 
    16261686 
    16271687/**************************************************************************/ 
     
    17041764 
    17051765 
     1766 
     1767 
     1768 
    17061769/************************************************************************/ 
    17071770/*                    MergeStatistics implementation                    */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r609 r610  
    351351        ViewCell *GetActiveViewCell(ViewCell *vc) const; 
    352352 
     353        /** Propagates pvs up the tree to the root. 
     354        */ 
     355        void PropagateUpPvs(ViewCell *vc); 
     356 
     357        bool Export(ofstream &stream); 
     358 
     359 
    353360protected: 
    354361 
     
    421428        int UpdateActiveViewCells(ViewCellContainer &viewCells); 
    422429 
    423         void PropagateUpVisibility(ViewCellInterior *interior); 
     430        void PullUpVisibility(ViewCellInterior *interior); 
    424431 
    425432        void CompressViewCellsPvs(ViewCell *root); 
     
    428435        */ 
    429436        float GetMemUsage() const; 
     437         
     438        /** 
     439                Exports single view cell. 
     440                NOTE: should be in exporter!! 
     441        */ 
     442        void ExportViewCell(ViewCell *viewCell, ofstream &stream); 
     443 
    430444 
    431445 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r605 r610  
    5050 
    5151BspNode::BspNode():  
    52 mParent(NULL), mTreeValid(true) 
     52mParent(NULL), mTreeValid(true), mTimeStamp(0) 
    5353{} 
    5454 
     
    216216mRoot(NULL),  
    217217mUseAreaForPvs(false), 
    218 mGenerateViewCells(true) 
     218mGenerateViewCells(true), 
     219mTimeStamp(0) 
    219220{ 
    220221        Randomize(); // initialise random generator for heuristics 
     
    10981099        backData.mNode = interior->GetBack(); 
    10991100         
     1101        frontData.mNode->mTimeStamp = mTimeStamp; 
     1102        backData.mNode->mTimeStamp = mTimeStamp ++; 
     1103 
    11001104        //DEL_PTR(leaf); 
    11011105        return interior; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r590 r610  
    261261        int mMailbox; 
    262262 
     263        int mTimeStamp; 
     264 
    263265protected: 
    264266 
     
    955957        ViewCellsManager *mViewCellsManager; 
    956958 
     959        int mTimeStamp; 
    957960 
    958961private: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r609 r610  
    334334float ViewCellsManager::GetViewSpaceVolume() 
    335335{ 
    336         return mViewSpaceBox.GetVolume()*(2.0f*sqr((float)M_PI)); 
     336        return mViewSpaceBox.GetVolume() * (2.0f * sqr((float)M_PI)); 
    337337} 
    338338 
     
    544544        ViewCellInterior *vc = new ViewCellInterior();//GenerateViewCell(); 
    545545 
     546        vc->GetPvs() = left->GetPvs(); 
    546547        // merge pvs 
    547         vc->GetPvs().Merge(left->GetPvs(), right->GetPvs()); 
     548        vc->GetPvs().Merge(right->GetPvs()); 
    548549 
    549550        //-- merge ray sets 
     
    576577        { 
    577578                // merge pvs 
    578                 vc->GetPvs().Merge(vc->GetPvs(), (*it)->GetPvs()); 
     579                vc->GetPvs().Merge((*it)->GetPvs()); 
    579580 
    580581                vc->SetupChildLink(*it); 
     
    940941 
    941942 
    942 void ViewCellsManager::ExportViewCell(ViewCell *viewCell, ofstream &stream) 
    943 { 
    944         stream << "<ViewCell id=\"" << viewCell->GetId() << "\" "; 
    945         stream << "pvs=\""; 
    946  
    947         ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end(); 
    948         if(0) // test with empty pvs 
    949         for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    950         { 
    951                 stream << (*it).first->GetId() << " "; 
    952         } 
    953  
    954         stream << "\" />" << endl; 
    955 } 
     943void ViewCellsManager::CollectViewCells(const int n)  
     944{ 
     945        mNumActiveViewCells = n; 
     946        mViewCells.clear(); 
     947        CollectViewCells(); 
     948} 
     949 
    956950 
    957951 
     
    16251619        //-- load the view cells itself, i.e., the ids and the pvs 
    16261620        stream << "<ViewCells>" << endl; 
     1621 
     1622#if 0 
     1623         
    16271624        ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 
     1625                 
    16281626        for (it = mViewCells.begin(); it != it_end; ++ it) 
    16291627                ExportViewCell(*it, stream); 
     1628#else 
     1629        mViewCellsTree->Export(stream); 
     1630#endif 
    16301631 
    16311632        stream << "</ViewCells>" << endl; 
     
    16601661                        BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*lit); 
    16611662                        bspVc->mLeaf->SetViewCell(vc); 
     1663                } 
     1664        } 
     1665} 
     1666 
     1667 
     1668void BspViewCellsManager::CreateMergeHierarchy() 
     1669{ 
     1670        TraversalQueue tQueue; 
     1671 
     1672        tQueue.push(TraversalData(mBspTree->GetRoot(), NULL)); 
     1673 
     1674        while (!tQueue.empty()) 
     1675        { 
     1676                TraversalData tData = tQueue.top(); 
     1677                tQueue.pop(); 
     1678 
     1679                if (tData.mNode->IsLeaf()) 
     1680                { 
     1681                        ViewCell *viewCell = dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell(); 
     1682                        viewCell->SetMergeCost((float)tData.mNode->mTimeStamp); 
     1683 
     1684                        if (tData.mParentViewCell) 
     1685                        { 
     1686                                tData.mParentViewCell->SetupChildLink(viewCell); 
     1687                                // probagate up pvs 
     1688                                mViewCellsTree->PropagateUpPvs(viewCell); 
     1689                        } 
     1690                } 
     1691                else 
     1692                { 
     1693                        BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
     1694                        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
     1695                        viewCellInterior->SetMergeCost((float)tData.mNode->mTimeStamp); 
     1696 
     1697 
     1698                        tQueue.push(TraversalData(interior->GetBack(), viewCellInterior)); 
     1699                        tQueue.push(TraversalData(interior->GetFront(), viewCellInterior)); 
     1700 
     1701                        if (tData.mParentViewCell) 
     1702                                tData.mParentViewCell->SetupChildLink(viewCellInterior); 
    16621703                } 
    16631704        } 
     
    27912832void VspBspViewCellsManager::CreateMergeHierarchy() 
    27922833{ 
    2793          
     2834        TraversalQueue tQueue; 
     2835 
     2836        tQueue.push(TraversalData(mVspBspTree->GetRoot(), NULL)); 
     2837 
     2838        while (!tQueue.empty()) 
     2839        { 
     2840                TraversalData tData = tQueue.top(); 
     2841                tQueue.pop(); 
     2842 
     2843                if (tData.mNode->IsLeaf()) 
     2844                { 
     2845                        ViewCell *viewCell = dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell(); 
     2846 
     2847                        if (tData.mParentViewCell) 
     2848                        { 
     2849                                tData.mParentViewCell->SetupChildLink(viewCell); 
     2850                                // probagate up pvs 
     2851                                mViewCellsTree->PropagateUpPvs(viewCell); 
     2852                        } 
     2853                } 
     2854                else 
     2855                { 
     2856                        BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
     2857                        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
     2858                         
     2859                        tQueue.push(TraversalData(interior->GetBack(), viewCellInterior)); 
     2860                        tQueue.push(TraversalData(interior->GetFront(), viewCellInterior)); 
     2861 
     2862                        if (tData.mParentViewCell) 
     2863                                tData.mParentViewCell->SetupChildLink(viewCellInterior); 
     2864                } 
     2865        } 
    27942866} 
    27952867 
     
    33423414        //-- load the view cells itself, i.e., the ids and the pvs 
    33433415        stream << "<ViewCells>" << endl; 
     3416         
     3417#if 0 
     3418         
    33443419        ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 
     3420                 
    33453421        for (it = mViewCells.begin(); it != it_end; ++ it) 
    33463422                ExportViewCell(*it, stream); 
     3423#else 
     3424        mViewCellsTree->Export(stream); 
     3425#endif 
    33473426 
    33483427        stream << "</ViewCells>" << endl; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r609 r610  
    66#include "Containers.h" 
    77#include "ViewCell.h" 
     8#include "ViewCellBsp.h" 
    89 
    910class ViewCell; 
     
    349350                                                                                vector<MergeCandidate> &candidates) = 0; 
    350351 
    351          
    352    
    353   void CollectViewCells(const int n) { 
    354         mNumActiveViewCells = n; 
    355         mViewCells.clear(); 
    356         CollectViewCells(); 
    357   } 
    358  
    359  
    360   virtual bool EqualToSpatialNode(ViewCell *viewCell) const { return false;} 
     352        void CollectViewCells(const int n); 
     353 
     354 
     355        virtual void CreateMergeHierarchy() {}; 
     356         
     357        virtual bool EqualToSpatialNode(ViewCell *viewCell) const { return false;} 
     358 
     359 
    361360protected: 
    362361 
     
    411410        void CreateViewCellMeshes(); 
    412411 
    413         /** 
    414                 Exports single view cell. 
    415                 NOTE: should be in exporter!! 
    416         */ 
    417         void ExportViewCell(ViewCell *viewCell, ofstream &stream); 
    418  
    419  
    420         /**  
    421                 Takes different measures to prepares the view cells after loading them from disc. 
     412 
     413        /** Takes different measures to prepares the view cells after loading them from disc. 
    422414        */ 
    423415        virtual void PrepareLoadedViewCells() {}; 
     
    537529        bool ExportViewCells(const string filename); 
    538530 
     531        void CreateMergeHierarchy(); 
     532 
     533 
    539534protected: 
     535 
     536        struct TraversalData 
     537        {   
     538                ViewCellInterior *mParentViewCell; 
     539                BspNode *mNode; 
     540                 
     541 
     542                TraversalData() {} 
     543                TraversalData(BspNode *node, ViewCellInterior *vc): 
     544                         mNode(node), mParentViewCell(vc) 
     545                {} 
     546    
     547                bool operator<(const TraversalData &b) const  
     548                { 
     549                        return mNode->mTimeStamp < b.mNode->mTimeStamp; 
     550                } 
     551        }; 
     552 
     553        typedef priority_queue<TraversalData> TraversalQueue; 
    540554 
    541555        /** HACK 
     
    754768protected: 
    755769 
     770        struct TraversalData 
     771        {   
     772                ViewCellInterior *mParentViewCell; 
     773                BspNode *mNode; 
     774                 
     775 
     776                TraversalData() {} 
     777                TraversalData(BspNode *node, ViewCellInterior *vc): 
     778                         mNode(node), mParentViewCell(vc) 
     779                {} 
     780    
     781                bool operator<(const TraversalData &b) const  
     782                { 
     783                        return mNode->mTimeStamp < b.mNode->mTimeStamp; 
     784                } 
     785        }; 
     786 
     787        typedef priority_queue<TraversalData> TraversalQueue; 
     788 
     789        /** Returns node of the spatial hierarchy corresponding to the view cell 
     790                if such a node exists. 
     791        */ 
    756792        BspNode *GetSpatialNode(ViewCell *viewCell) const; 
     793 
    757794        /** HACK 
    758795        */ 
     
    778815        void PrepareLoadedViewCells(); 
    779816 
    780          
     817        void CreateMergeHierarchy(); 
    781818        /// the view space partition BSP tree. 
    782819        VspBspTree *mVspBspTree; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r609 r610  
    6868mStoreRays(false), 
    6969mRenderCostWeight(0.5), 
    70 mUseRandomAxis(false) 
     70mUseRandomAxis(false), 
     71mTimeStamp(0) 
    7172{ 
    7273        bool randomize = false; 
     
    8788        //-- max cost ratio for early tree termination 
    8889        environment->GetFloatValue("VspBspTree.Termination.maxCostRatio", mTermMaxCostRatio); 
    89 mTermMinPolygons = 25; 
     90 
     91        // HACK 
     92        mTermMinPolygons = 25; 
     93 
    9094        //-- factors for bsp tree split plane heuristics 
    9195        environment->GetFloatValue("VspBspTree.Factor.balancedRays", mBalancedRaysFactor); 
     
    729733        frontData.mNode = interior->GetFront(); 
    730734        backData.mNode = interior->GetBack(); 
     735 
     736        frontData.mNode->mTimeStamp = mTimeStamp; 
     737        backData.mNode->mTimeStamp = mTimeStamp ++; 
    731738 
    732739        //DEL_PTR(leaf); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r607 r610  
    716716        bool mUsePolygonSplitIfAvailable; 
    717717 
     718        int mTimeStamp; 
     719 
    718720private: 
    719721 
Note: See TracChangeset for help on using the changeset viewer.