Ignore:
Timestamp:
01/18/06 23:35:50 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r548 r551  
    8383        // maximum and minimum number of view cells 
    8484        environment->GetIntValue("VspBspTree.Termination.maxViewCells", mMaxViewCells); 
     85 
     86        environment->GetBoolValue("VspBspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 
     87 
     88        //-- merge options 
    8589        environment->GetIntValue("VspBspTree.PostProcess.minViewCells", mMergeMinViewCells); 
    8690        environment->GetFloatValue("VspBspTree.PostProcess.maxCostRatio", mMergeMaxCostRatio); 
    87  
    88         environment->GetBoolValue("VspBspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 
    8991        environment->GetBoolValue("VspBspTree.PostProcess.useRaysForMerge", mUseRaysForMerge); 
    9092 
     
    116118        Debug << "max plane candidates: " << mMaxRayCandidates << endl; 
    117119        Debug << "randomize: " << randomize << endl; 
    118  
     120        Debug << "minimum view cells: " << mMergeMinViewCells << endl; 
     121        Debug << "using area for pvs: " << mUseAreaForPvs << endl; 
    119122        Debug << "Split plane strategy: "; 
    120123        if (mSplitPlaneStrategy & RANDOM_POLYGON) 
     
    870873         
    871874        //TODO: for kd split geometry already is box 
    872         if (1 && mUseAreaForPvs) 
     875        if (1) 
    873876        { 
    874877                PolygonContainer::const_iterator it, it_end = tData.mGeometry->mPolys.end(); 
     
    10121015        {   // volume 
    10131016                pBack = pFront = pOverall * 0.5f; 
     1017                 
     1018#if 0 
    10141019                // box length substitute for probability 
    1015 #if 0 
    10161020                const float minBox = box.Min(axis); 
    10171021                const float maxBox = box.Max(axis); 
     
    16031607{ 
    16041608        ViewCell::NewMail(); 
    1605         CollectViewCells(mRoot, onlyValid, viewCells); 
     1609         
     1610        CollectViewCells(mRoot, onlyValid, viewCells, true); 
    16061611} 
    16071612 
     
    19011906 
    19021907 
     1908typedef pair<BspNode *, BspNodeGeometry *> bspNodePair; 
     1909 
    19031910int VspBspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 
    19041911                                                   const bool onlyUnmailed) const 
    19051912{ 
    1906         BspNodeGeometry geom; 
    1907         ConstructGeometry(n, geom); 
    1908  
    1909         stack<BspNode *> nodeStack; 
    1910         nodeStack.push(mRoot); 
    1911  
     1913        stack<bspNodePair> nodeStack; 
     1914         
     1915        BspNodeGeometry nodeGeom; 
     1916        ConstructGeometry(n, nodeGeom); 
     1917         
    19121918        // split planes from the root to this node 
    19131919        // needed to verify that we found neighbor leaf 
     
    19151921        ExtractHalfSpaces(n, halfSpaces); 
    19161922 
     1923 
     1924        BspNodeGeometry *rgeom = new BspNodeGeometry(); 
     1925        ConstructGeometry(mRoot, *rgeom); 
     1926 
     1927        nodeStack.push(bspNodePair(mRoot, rgeom)); 
     1928 
     1929 
    19171930        while (!nodeStack.empty()) 
    19181931        { 
    1919                 BspNode *node = nodeStack.top(); 
     1932                BspNode *node = nodeStack.top().first; 
     1933                BspNodeGeometry *geom = nodeStack.top().second; 
     1934 
    19201935                nodeStack.pop(); 
    19211936 
    1922                 if (node->IsLeaf()) 
    1923  
    1924                 {       // test if this leaf is in valid view space 
    1925             if (node->TreeValid() && 
    1926                                 node != n &&  
    1927                                 (!onlyUnmailed || !node->Mailed())) 
     1937                bool isAdjacent = true; 
     1938 
     1939                // test all planes of current node if still adjacent 
     1940                for (int i = 0; (i < halfSpaces.size()) && isAdjacent && (node != n); ++ i) 
     1941                { 
     1942                        const int cf = 
     1943                                Polygon3::ClassifyPlane(geom->mPolys, 
     1944                                                                                halfSpaces[i], 
     1945                                                                                mEpsilon); 
     1946 
     1947                        if (cf == Polygon3::BACK_SIDE) 
    19281948                        { 
    1929                                 // test all planes of current node if candidate really 
    1930                                 // is neighbour 
    1931                                 BspNodeGeometry neighborCandidate; 
    1932                                 ConstructGeometry(node, neighborCandidate); 
    1933  
    1934                                 bool isAdjacent = true; 
    1935                                 for (int i = 0; (i < halfSpaces.size()) && isAdjacent; ++ i) 
     1949                                isAdjacent = false; 
     1950                        } 
     1951                } 
     1952 
     1953                if (isAdjacent) 
     1954                { 
     1955                 
     1956                        if (node->IsLeaf()) 
     1957                        {        
     1958                                // test if this leaf is in valid view space 
     1959                                if (node->TreeValid() && 
     1960                                        node != n &&  
     1961                                        (!onlyUnmailed || !node->Mailed())) 
    19361962                                { 
    1937                                         const int cf = 
    1938                                                 Polygon3::ClassifyPlane(neighborCandidate.mPolys, 
    1939                                                                                                 halfSpaces[i], 
    1940                                                                                                 mEpsilon); 
    1941  
    1942                                         if (cf == Polygon3::BACK_SIDE) 
    1943                                                 isAdjacent = false; 
     1963                                        // neighbor was found 
     1964                                        neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 
    19441965                                } 
    1945                                 // neighbor was found 
    1946                                 if (isAdjacent) 
    1947                                         neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 
    19481966                        } 
    1949                 } 
    1950                 else 
    1951                 { 
    1952                         BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    1953  
    1954                         const int cf = Polygon3::ClassifyPlane(geom.mPolys, 
    1955                                                                                                    interior->GetPlane(), 
    1956                                                                                                    mEpsilon); 
    1957  
    1958                         if (cf == Polygon3::FRONT_SIDE) 
    1959                                 nodeStack.push(interior->GetFront()); 
    19601967                        else 
    1961                                 if (cf == Polygon3::BACK_SIDE) 
    1962                                         nodeStack.push(interior->GetBack()); 
     1968                        { 
     1969                                BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1970 
     1971                                const int cf = Polygon3::ClassifyPlane(nodeGeom.mPolys, 
     1972                                                                                                           interior->GetPlane(), 
     1973                                                                                                           mEpsilon); 
     1974                         
     1975                                BspNode *front = interior->GetFront(); 
     1976                                BspNode *back = interior->GetBack(); 
     1977             
     1978                                BspNodeGeometry *fGeom = new BspNodeGeometry(); 
     1979                                BspNodeGeometry *bGeom = new BspNodeGeometry(); 
     1980 
     1981                                geom->SplitGeometry(*fGeom, 
     1982                                                                        *bGeom, 
     1983                                                                        interior->GetPlane(), 
     1984                                                                        mBox, 
     1985                                                                        mEpsilon); 
     1986                 
     1987                                if (cf == Polygon3::FRONT_SIDE) 
     1988                                { 
     1989                                        nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 
     1990                                        DEL_PTR(bGeom); 
     1991                                } 
    19631992                                else 
    19641993                                { 
    1965                                         // random decision 
    1966                                         nodeStack.push(interior->GetBack()); 
    1967                                         nodeStack.push(interior->GetFront()); 
     1994                                        if (cf == Polygon3::BACK_SIDE) 
     1995                                        { 
     1996                                                nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 
     1997                                                DEL_PTR(fGeom); 
     1998                                        } 
     1999                                        else 
     2000                                        {       // random decision 
     2001                                                nodeStack.push(bspNodePair(front, fGeom)); 
     2002                                                nodeStack.push(bspNodePair(back, bGeom)); 
     2003                                        } 
    19682004                                } 
    1969                 } 
     2005                        } 
     2006                } 
     2007 
     2008                DEL_PTR(geom); 
    19702009        } 
    19712010 
     
    26422681        if (0) 
    26432682        { 
     2683                cout << "finding additional merge candidates using geometry" << endl; 
    26442684                vector<BspLeaf *> leaves; 
    26452685                CollectLeaves(leaves, true); 
     
    27022742        mergeStats.Start(); 
    27032743        // TODO: REMOVE LATER for performance! 
    2704         const bool showMergeStats = true; 
     2744        const bool showMergeStats = false; 
    27052745        //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mStat.maxPvs; 
    27062746        long startTime = GetTime(); 
    27072747 
    27082748        if (mUseRaysForMerge) 
     2749        { 
     2750                cout << "collecting merge candidates (rays) ... "; 
    27092751                mergeStats.nodes = CollectMergeCandidates(rays); 
     2752                cout << "fininshed collecting candidates" << endl; 
     2753        } 
    27102754        else 
    27112755        { 
     
    27142758                mergeStats.nodes = CollectMergeCandidates(leaves); 
    27152759        } 
     2760         
    27162761 
    27172762        mergeStats.collectTime = TimeDiff(startTime, GetTime()); 
     
    27222767        int pass = 0; 
    27232768        const int nextPass = 200; 
     2769 
     2770        cout << "starting merge ... "; 
    27242771 
    27252772        //-- use priority queue to merge leaf pairs 
     
    27442791 
    27452792                        MergeViewCells(mc.GetLeaf1(), mc.GetLeaf2()); 
    2746                         -- nViewCells; 
    2747                          
     2793                                                 
    27482794                         
    27492795                        // increase absolute merge cost 
     
    27742820                                                << "#CurrentPvs\n" << mc.GetLeaf1()->GetViewCell()->GetPvs().GetSize() << endl; 
    27752821 
     2822                                        cout << "exporting view cells ... "; 
    27762823                                        ViewCellContainer viewCells;     
    27772824                                        CollectViewCells(mRoot, false, viewCells); 
    27782825                         
     2826                                         
    27792827                                        char s[64]; 
    27802828                                        sprintf(s, "merged_viewcells%07d.x3d", nViewCells); 
     
    27842832                                        { 
    27852833                                                exporter->ExportGeometry(objects); 
    2786                                                 Debug << "vc size " << viewCells.size() << endl; 
     2834                                                Debug << "vc size " << (int)viewCells.size() << " merge queue size: " << (int)mMergeQueue.size() << endl; 
    27872835                                                ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    27882836                 
     
    27942842                                                delete exporter; 
    27952843                                        } 
     2844                                        cout << "finished " << endl; 
    27962845                                } 
    27972846                        } 
     2847 
     2848                        -- nViewCells; 
    27982849                        ++ mergeStats.merged; 
    2799  
    28002850                } 
    28012851                // merge candidate not valid, because one of the leaves was already 
     
    28072857                } 
    28082858        } 
    2809  
     2859        cout << "finished merge" << endl; 
    28102860        mergeStats.mergeTime = TimeDiff(startTime, GetTime()); 
    28112861        mergeStats.Stop(); 
     
    29112961 
    29122962 
    2913 float GetShuffledVcCost(BspLeaf *leaf, BspViewCell *vc1, BspViewCell *vc2, bool useArea) 
     2963float VspBspTree::GetShuffledVcCost(BspLeaf *leaf, BspViewCell *vc1, BspViewCell *vc2) const 
    29142964{ 
    29152965        //const int pvs1 = SubtractedPvsSize(vc1, leaf, *leaf->mPvs); 
     
    29172967        const int pvs2 = AddedPvsSize(vc2->GetPvs(), *leaf->mPvs); 
    29182968 
     2969        if (pvs1 + pvs2 > mViewCellsManager->GetMaxPvsSize()) 
     2970                return 1e15f; 
     2971 
    29192972        float p1, p2; 
    29202973 
    2921     if (useArea) 
     2974    if (mUseAreaForPvs) 
    29222975        { 
    29232976                p1 = vc1->GetArea() - leaf->mProbability; 
     
    30043057        // the view cell should not be empty after the shuffle 
    30053058        if (vc1->mLeaves.size() > 1) 
    3006                 shuffledCost1 = GetShuffledVcCost(leaf1, vc1, vc2, mUseAreaForPvs); 
     3059                shuffledCost1 = GetShuffledVcCost(leaf1, vc1, vc2); 
    30073060        if (vc2->mLeaves.size() > 1) 
    3008                 shuffledCost2 = GetShuffledVcCost(leaf2, vc2, vc1, mUseAreaForPvs); 
     3061                shuffledCost2 = GetShuffledVcCost(leaf2, vc2, vc1); 
    30093062 
    30103063        // shuffling unsuccessful 
Note: See TracChangeset for help on using the changeset viewer.