Ignore:
Timestamp:
01/19/06 23:36:01 (18 years ago)
Author:
mattausch
Message:

started implementing merge visualization !not working!!

File:
1 edited

Legend:

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

    r556 r557  
    3838bool BspMergeCandidate::sUseArea = false; 
    3939 
     40 
    4041/********************************************************************/ 
    4142/*                  class VspBspTree implementation                 */ 
    4243/********************************************************************/ 
     44 
    4345 
    4446VspBspTree::VspBspTree(): 
     
    498500 
    499501                mStat.contributingSamples += conSamp; 
    500                 mStat.sampleContributions += sampCon; 
     502                mStat.sampleContributions +=(int) sampCon; 
    501503 
    502504                //-- store additional info 
     
    19151917typedef pair<BspNode *, BspNodeGeometry *> bspNodePair; 
    19161918 
     1919 
    19171920int VspBspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 
    19181921                                                   const bool onlyUnmailed) const 
     
    19251928        // split planes from the root to this node 
    19261929        // needed to verify that we found neighbor leaf 
     1930        // TODO: really needed? 
    19271931        vector<Plane3> halfSpaces; 
    19281932        ExtractHalfSpaces(n, halfSpaces); 
     
    19341938        nodeStack.push(bspNodePair(mRoot, rgeom)); 
    19351939 
     1940        Debug << "here77" << endl; 
    19361941 
    19371942        while (!nodeStack.empty()) 
     
    19421947                nodeStack.pop(); 
    19431948 
    1944                 bool isAdjacent = true; 
    1945  
    1946                  
     1949                if (node->IsLeaf()) 
     1950                {        
     1951                        Debug << "here22" << endl; 
     1952                        // test if this leaf is in valid view space 
     1953                        if (node->TreeValid() && 
     1954                                (node != n) &&  
     1955                                (!onlyUnmailed || !node->Mailed())) 
     1956                        { 
     1957                                Debug << "here" << endl; 
     1958                                bool isAdjacent = true; 
    19471959#if 1 
    1948                 // test all planes of current node if still adjacent 
    1949                 for (int i = 0; (i < halfSpaces.size()) && isAdjacent && (node != n); ++ i) 
    1950                 { 
    1951                         const int cf = 
    1952                                 Polygon3::ClassifyPlane(geom->mPolys, 
    1953                                                                                 halfSpaces[i], 
    1954                                                                                 mEpsilon); 
    1955  
    1956                         if (cf == Polygon3::BACK_SIDE) 
    1957                         { 
    1958                                 isAdjacent = false; 
    1959                         } 
    1960                 } 
    1961 #else 
    1962                 // test all planes of current node if still adjacent 
    1963                 for (int i = 0; i < nodeGeom.size()) && isAdjacent && (node != n); ++ i) 
    1964                 { 
    1965                         Polygon3 *poly = nodeGeom->mPolys[i]; 
    1966  
    1967                         const int cf = 
    1968                                 Polygon3::ClassifyPlane(geom->mPolys, 
    1969                                                                                 poly->GetSupportingPlane(), 
    1970                                                                                 mEpsilon); 
    1971  
    1972                         if (cf == Polygon3::BACK_SIDE) 
    1973                         { 
    1974                                 isAdjacent = false; 
    1975                         } 
    1976                 } 
     1960 
     1961                                // test all planes of current node if still adjacent 
     1962                                for (int i = 0; (i < halfSpaces.size()) && isAdjacent; ++ i) 
     1963                                { 
     1964                                        const int cf = 
     1965                                                Polygon3::ClassifyPlane(geom->mPolys, 
     1966                                                                                                halfSpaces[i], 
     1967                                                                                                mEpsilon); 
     1968 
     1969                                        if (cf == Polygon3::BACK_SIDE) 
     1970                                        { 
     1971                                                isAdjacent = false; 
     1972                                        } 
     1973                                } 
     1974#else // TODO: why is this wrong?? 
     1975                                // test all planes of current node if still adjacent 
     1976                                for (int i = 0; (i < (int)nodeGeom.mPolys.size()) && isAdjacent; ++ i) 
     1977                                { 
     1978                                        Debug << "here33" << endl; 
     1979                                        Polygon3 *poly = nodeGeom.mPolys[i]; 
     1980 
     1981                                        const int cf = 
     1982                                                Polygon3::ClassifyPlane(geom->mPolys, 
     1983                                                                                                poly->GetSupportingPlane(), 
     1984                                                                                                mEpsilon); 
     1985 
     1986                                        if (cf == Polygon3::BACK_SIDE) 
     1987                                        { 
     1988                                                isAdjacent = false; 
     1989                                        } 
     1990                                } 
    19771991#endif 
    1978                 if (isAdjacent) 
    1979                 { 
    1980                  
    1981                         if (node->IsLeaf()) 
    1982                         {        
    1983                                 // test if this leaf is in valid view space 
    1984                                 if (node->TreeValid() && 
    1985                                         node != n &&  
    1986                                         (!onlyUnmailed || !node->Mailed())) 
    1987                                 { 
    1988                                         // neighbor was found 
     1992                                Debug << "here2" << endl; 
     1993                                // neighbor was found 
     1994                                if (isAdjacent) 
    19891995                                        neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 
    1990                                 } 
    19911996                        } 
    19921997                        else 
     
    25052510 
    25062511 
    2507 bool VspBspTree::MergeViewCells(BspLeaf *l1, BspLeaf *l2) const 
     2512bool VspBspTree::MergeViewCells(BspLeaf *l1, BspLeaf *l2) //const 
    25082513{ 
    25092514        //-- change pointer to view cells of all leaves associated 
     
    25452550 
    25462551        // clean up old view cells 
    2547         DEL_PTR(fVc); 
    2548         DEL_PTR(bVc); 
     2552        if (0) 
     2553        { 
     2554                DEL_PTR(fVc); 
     2555                DEL_PTR(bVc); 
     2556        } 
     2557        else // throw them into old view cells container 
     2558        { 
     2559                fVc->mMailbox = -1; 
     2560                bVc->mMailbox = -1; 
     2561 
     2562                mOldViewCells.push_back(fVc); 
     2563                mOldViewCells.push_back(bVc); 
     2564 
     2565                mNewViewCells.push_back(vc); 
     2566        } 
    25492567 
    25502568        return true; 
     
    27642782        BspMergeCandidate::sUseArea = mUseAreaForPvs; 
    27652783 
     2784        // the current view cells are kept in this container 
     2785        ViewCellContainer viewCells; 
     2786        ViewCell::NewMail(); 
     2787        CollectViewCells(mRoot, true, viewCells, true); 
     2788        ViewCell::NewMail(); 
     2789 
    27662790        MergeStatistics mergeStats; 
    27672791        mergeStats.Start(); 
    27682792        // TODO: REMOVE LATER for performance! 
    2769         const bool showMergeStats = false; 
     2793        const bool showMergeStats = true; 
    27702794        //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mStat.maxPvs; 
    27712795        long startTime = GetTime(); 
     
    28462870 
    28472871                                        cout << "exporting view cells ... "; 
    2848                                         ViewCellContainer viewCells;     
    2849                                         CollectViewCells(mRoot, false, viewCells); 
    2850                          
    2851                                          
     2872                                                                 
     2873                                 
     2874                                        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     2875 
     2876                                        Debug << "here2111 " << viewCells.size() << endl; 
     2877                                        for (int i = 0; i < viewCells.size(); ++ i) 
     2878                                        { 
     2879                                                while (!viewCells.empty() && (viewCells.back()->mMailbox == -1)) 
     2880                                                { 
     2881                                                        Debug << "here244" << endl; 
     2882                                                        viewCells.pop_back(); 
     2883                                                } 
     2884 
     2885                                                // already merged view cell, put it to end of vector 
     2886                                                if ((i < viewCells.size()) && (viewCells[i]->mMailbox == -1)) 
     2887                                                { 
     2888                                                        Debug << "here2" << endl; 
     2889                                                        swap(viewCells[i], viewCells.back()); 
     2890                                                } 
     2891                                        } 
     2892                                 
     2893                                        cout << "finished" << endl; 
     2894                                        // not part of any leaf 
     2895                                        CLEAR_CONTAINER(mOldViewCells); 
     2896 
     2897                                        int newVcSize = (int)mNewViewCells.size(); 
     2898                                        // add new view cells to container 
     2899                                        while (!mNewViewCells.empty()) 
     2900                                        { 
     2901                                                viewCells.push_back(mNewViewCells.back()); 
     2902                                                mNewViewCells.pop_back(); 
     2903                                        } 
     2904 
    28522905                                        char s[64]; 
    28532906                                        sprintf(s, "merged_viewcells%07d.x3d", nViewCells); 
     
    28602913                                                ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    28612914                 
     2915                                                int i = (int)viewCells.size(); 
    28622916                                                for (it = viewCells.begin(); it != it_end; ++ it) 
    28632917                                                { 
     2918                                                        Material m = RandomMaterial(); 
     2919                                                        if (i-- == newVcSize) 
     2920                                                        { 
     2921                                                                m.mDiffuseColor.r = 1; 
     2922                                                                m.mDiffuseColor.g = 0; 
     2923                                                                m.mDiffuseColor.b = 0; 
     2924                                                        } 
     2925                                                        exporter->SetForcedMaterial(m); 
    28642926                                                        mViewCellsManager->ExportVcGeometry(exporter, *it); 
    28652927                                                } 
     
    28822944                } 
    28832945        } 
     2946 
     2947 
    28842948        cout << "finished merge" << endl; 
    28852949        mergeStats.mergeTime = TimeDiff(startTime, GetTime()); 
Note: See TracChangeset for help on using the changeset viewer.