Ignore:
Timestamp:
01/25/06 01:44:46 (18 years ago)
Author:
mattausch
Message:

finished function for view cell construction
removed bsp rays from vspbspmanager

File:
1 edited

Legend:

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

    r573 r574  
    178178const BspTreeStatistics &VspBspTree::GetStatistics() const 
    179179{ 
    180         return mStat; 
     180        return mBspStats; 
    181181} 
    182182 
     
    273273                                                   AxisAlignedBox3 *forcedBoundingBox) 
    274274{ 
    275         mStat.nodes = 1; 
     275        mBspStats.nodes = 1; 
    276276        mBox.Initialize();      // initialise BSP tree bounding box 
    277277 
     
    353353                mTermMinProbability *= mBox.GetVolume(); 
    354354 
    355         mStat.polys = (int)polys.size(); 
     355        mBspStats.polys = (int)polys.size(); 
    356356 
    357357        cout << "finished" << endl; 
     
    373373        return 
    374374                (sizeof(VspBspTree) + 
    375                  mStat.Leaves() * sizeof(BspLeaf) + 
    376                  mStat.Interior() * sizeof(BspInterior) + 
    377                  mStat.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); 
     375                 mBspStats.Leaves() * sizeof(BspLeaf) + 
     376                 mBspStats.Interior() * sizeof(BspInterior) + 
     377                 mBspStats.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); 
    378378} 
    379379 
     
    405405        tStack.push(tData); 
    406406 
    407         mStat.Start(); 
     407        mBspStats.Start(); 
    408408        cout << "Contructing vsp bsp tree ... \n"; 
    409409 
     
    439439                                  << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    440440 
    441                 if (mStat.Leaves() >= nleaves) 
     441                if (mBspStats.Leaves() >= nleaves) 
    442442                { 
    443443                        nleaves += 500; 
    444444                                 
    445                         cout << "leaves=" << mStat.Leaves() << endl; 
     445                        cout << "leaves=" << mBspStats.Leaves() << endl; 
    446446                        Debug << "needed " 
    447447                          << TimeDiff(interTime, GetTime())*1e-3 << " secs to create 500 leaves" << endl; 
     
    453453        cout << "finished\n"; 
    454454 
    455         mStat.Stop(); 
     455        mBspStats.Stop(); 
    456456} 
    457457 
     
    463463                 (data.mPvs <= mTermMinPvs)   || 
    464464                 (data.mProbability <= mTermMinProbability) || 
    465                  (mStat.Leaves() >= mMaxViewCells) || 
     465                 (mBspStats.Leaves() >= mMaxViewCells) || 
    466466                 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 
    467467                 (data.mDepth >= mTermMaxDepth)); 
     
    509509                AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 
    510510 
    511                 mStat.contributingSamples += conSamp; 
    512                 mStat.sampleContributions +=(int) sampCon; 
     511                mBspStats.contributingSamples += conSamp; 
     512                mBspStats.sampleContributions +=(int) sampCon; 
    513513 
    514514                //-- store additional info 
     
    526526                        PropagateUpValidity(leaf); 
    527527 
    528                         ++ mStat.invalidLeaves; 
     528                        ++ mBspStats.invalidLeaves; 
    529529                } 
    530530                 
     
    572572                { 
    573573                        // terminate branch because of max cost 
    574                         ++ mStat.maxCostNodes; 
     574                        ++ mBspStats.maxCostNodes; 
    575575            return leaf; 
    576576                } 
    577577        } 
    578578 
    579         mStat.nodes += 2; 
     579        mBspStats.nodes += 2; 
    580580 
    581581        //-- subdivide further 
     
    11601160                 
    11611161                //! error also computed if cost ratio is missed 
    1162                 ++ mStat.splits[axis]; 
     1162                ++ mBspStats.splits[axis]; 
    11631163                isAxisAlignedSplit = true; 
    11641164        } 
     
    15091509 
    15101510        // store maximal and minimal depth 
    1511         if (data.mDepth > mStat.maxDepth) 
    1512                 mStat.maxDepth = data.mDepth; 
    1513  
    1514         if (data.mPvs > mStat.maxPvs) 
    1515                 mStat.maxPvs = data.mPvs; 
    1516          
    1517         if (data.mDepth < mStat.minDepth) 
    1518                 mStat.minDepth = data.mDepth; 
     1511        if (data.mDepth > mBspStats.maxDepth) 
     1512                mBspStats.maxDepth = data.mDepth; 
     1513 
     1514        if (data.mPvs > mBspStats.maxPvs) 
     1515                mBspStats.maxPvs = data.mPvs; 
     1516         
     1517        if (data.mDepth < mBspStats.minDepth) 
     1518                mBspStats.minDepth = data.mDepth; 
    15191519 
    15201520        if (data.mDepth >= mTermMaxDepth) 
    1521                 ++ mStat.maxDepthNodes; 
     1521                ++ mBspStats.maxDepthNodes; 
    15221522        // accumulate rays to compute rays /  leaf 
    1523         mStat.accumRays += (int)data.mRays->size(); 
     1523        mBspStats.accumRays += (int)data.mRays->size(); 
    15241524 
    15251525        if (data.mPvs < mTermMinPvs) 
    1526                 ++ mStat.minPvsNodes; 
     1526                ++ mBspStats.minPvsNodes; 
    15271527 
    15281528        if ((int)data.mRays->size() < mTermMinRays) 
    1529                 ++ mStat.minRaysNodes; 
     1529                ++ mBspStats.minRaysNodes; 
    15301530 
    15311531        if (data.GetAvgRayContribution() > mTermMaxRayContribution) 
    1532                 ++ mStat.maxRayContribNodes; 
     1532                ++ mBspStats.maxRayContribNodes; 
    15331533 
    15341534        if (data.mProbability <= mTermMinProbability) 
    1535                 ++ mStat.minProbabilityNodes; 
     1535                ++ mBspStats.minProbabilityNodes; 
    15361536         
    15371537        // accumulate depth to compute average depth 
    1538         mStat.accumDepth += data.mDepth; 
     1538        mBspStats.accumDepth += data.mDepth; 
    15391539 
    15401540#ifdef _DEBUG 
     
    16551655 
    16561656 
    1657 void VspBspTree::ValidateTree() 
     1657void VspBspTree::CollapseViewCells() 
    16581658{ 
    16591659        stack<BspNode *> nodeStack; 
     
    16641664        nodeStack.push(mRoot); 
    16651665         
    1666         const bool addToUnbounded = false; 
    1667  
    16681666        while (!nodeStack.empty())  
    16691667        { 
     
    16721670                 
    16731671                if (node->IsLeaf()) 
    1674                 { 
    1675                         BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
    1676  
    1677                         if (!addToUnbounded && node->TreeValid()) 
     1672        { 
     1673                        BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
     1674 
     1675                        if (!viewCell->GetValid()) 
    16781676                        { 
    16791677                                BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
    16801678                         
    1681                                 if (!mViewCellsManager->CheckValidity(viewCell, 
    1682                                                                                                           mViewCellsManager->GetMinPvsSize(),  
    1683                                                                                                           mViewCellsManager->GetMaxPvsSize())) 
     1679                                vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end(); 
     1680                                for (it = viewCell->mLeaves.begin();it != it_end; ++ it) 
    16841681                                { 
    1685                                         vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end(); 
    1686                                         for (it = viewCell->mLeaves.begin();it != it_end; ++ it) 
    1687                                         { 
    1688                                                 BspLeaf *l = *it; 
    1689                                                  
    1690                                                 l->SetTreeValid(false); 
    1691                                                 PropagateUpValidity(l); 
    1692                                                  
    1693                                                 if (addToUnbounded) 
    1694                                                         l->SetViewCell(GetOrCreateOutOfBoundsCell()); 
    1695  
    1696                                                 ++ mStat.invalidLeaves; 
    1697                                         } 
    1698  
    1699                                         // add to unbounded view cell or set to invalid 
    1700                                         if (addToUnbounded) 
    1701                                         { 
    1702                                                 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 
    1703                                                 DEL_PTR(viewCell); 
    1704                                         } 
    1705                                         else 
    1706                                         { 
    1707                                                 viewCell->SetValid(false); 
    1708                                         } 
     1682                                        BspLeaf *l = *it; 
     1683                                        l->SetViewCell(GetOrCreateOutOfBoundsCell()); 
     1684                                        ++ mBspStats.invalidLeaves; 
    17091685                                } 
     1686 
     1687                                // add to unbounded view cell 
     1688                                GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 
     1689                                DEL_PTR(viewCell); 
    17101690                        } 
    17111691                } 
     
    17191699        } 
    17201700 
    1721         Debug << "invalid leaves: " << mStat.invalidLeaves << endl; 
    1722 } 
     1701        Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 
     1702} 
     1703 
     1704 
     1705void VspBspTree::ValidateTree() 
     1706{ 
     1707        stack<BspNode *> nodeStack; 
     1708 
     1709        if (!mRoot) 
     1710                return; 
     1711 
     1712        nodeStack.push(mRoot); 
     1713         
     1714        mBspStats.invalidLeaves = 0; 
     1715        while (!nodeStack.empty())  
     1716        { 
     1717                BspNode *node = nodeStack.top(); 
     1718                nodeStack.pop(); 
     1719                 
     1720                if (node->IsLeaf()) 
     1721                { 
     1722                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     1723 
     1724                        if (!leaf->GetViewCell()->GetValid()) 
     1725                                ++ mBspStats.invalidLeaves; 
     1726 
     1727                        // validity flags don't match => repair 
     1728                        if (leaf->GetViewCell()->GetValid() != leaf->TreeValid()) 
     1729                        { 
     1730                                leaf->SetTreeValid(leaf->GetViewCell()->GetValid()); 
     1731                                PropagateUpValidity(leaf); 
     1732                        } 
     1733                } 
     1734                else 
     1735                { 
     1736                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1737                 
     1738                        nodeStack.push(interior->GetFront()); 
     1739                        nodeStack.push(interior->GetBack()); 
     1740                } 
     1741        } 
     1742 
     1743        Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 
     1744} 
     1745 
    17231746 
    17241747 
     
    17841807        int splits = 0; 
    17851808 
    1786         while (!rays.empty()) 
    1787         { 
    1788                 RayInfo bRay = rays.back(); 
    1789                 rays.pop_back(); 
    1790  
     1809        RayInfoContainer::const_iterator it, it_end = rays.end(); 
     1810 
     1811        for (it = rays.begin(); it != it_end; ++ it) 
     1812        { 
     1813                RayInfo bRay = *it; 
     1814                 
    17911815                VssRay *ray = bRay.mRay; 
    17921816                float t; 
     
    22132237        int splits = 0; 
    22142238 
    2215         while (!polys.empty()) 
    2216         { 
    2217                 Polygon3 *poly = polys.back(); 
    2218                 polys.pop_back(); 
     2239        PolygonContainer::const_iterator it, it_end = polys.end(); 
     2240 
     2241        for (it = polys.begin(); it != polys.end(); ++ it)       
     2242        { 
     2243                Polygon3 *poly = *it; 
    22192244 
    22202245                // classify polygon 
     
    26322657                BspLeaf *leaf = *it; 
    26332658                 
    2634                 /// create leaf pvs (needed for post processing 
     2659                /// create leaf pvs (needed for post processing) 
    26352660                leaf->mPvs = new ObjectPvs(leaf->GetViewCell()->GetPvs()); 
    26362661 
     
    26742699int VspBspTree::CollectMergeCandidates(const VssRayContainer &rays) 
    26752700{ 
    2676         vector<BspRay *> bspRays; 
    2677  
    26782701        ViewCell::NewMail(); 
    26792702        long startTime = GetTime(); 
    2680         ConstructBspRays(bspRays, rays); 
    2681         Debug << (int)bspRays.size() << " bsp rays constructed in "  
    2682                   << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
    2683  
     2703         
    26842704        map<BspLeaf *, vector<BspLeaf*> > neighborMap; 
    2685         vector<BspIntersection>::const_iterator iit; 
     2705        ViewCellContainer::const_iterator iit; 
    26862706 
    26872707        int numLeaves = 0; 
     
    26892709        BspLeaf::NewMail(); 
    26902710 
    2691         for (int i = 0; i < (int)bspRays.size(); ++ i) 
     2711        for (int i = 0; i < (int)rays.size(); ++ i) 
    26922712        {   
    2693                 BspRay *ray = bspRays[i]; 
     2713                VssRay *ray = rays[i]; 
    26942714         
    26952715                // traverse leaves stored in the rays and compare and  
    26962716                // merge consecutive leaves (i.e., the neighbors in the tree) 
    2697                 if (ray->intersections.size() < 2) 
     2717                if (ray->mViewCells.size() < 2) 
    26982718                        continue; 
    26992719           
    2700                 iit = ray->intersections.begin(); 
    2701                 BspLeaf *leaf = (*(iit ++)).mLeaf; 
     2720                iit = ray->mViewCells.begin(); 
     2721                BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++)); 
     2722                BspLeaf *leaf = bspVc->mLeaves[0]; 
    27022723                 
    27032724                // create leaf pvs (needed for post processing) 
     
    27152736                // traverse intersections  
    27162737                // consecutive leaves are neighbors => add them to queue 
    2717                 for (; iit != ray->intersections.end(); ++ iit) 
     2738                for (; iit != ray->mViewCells.end(); ++ iit) 
    27182739                { 
    27192740                        // next pair 
    27202741                        BspLeaf *prevLeaf = leaf; 
    2721             leaf = (*iit).mLeaf; 
     2742                        bspVc = dynamic_cast<BspViewCell *>(*iit); 
     2743            leaf = bspVc->mLeaves[0]; 
    27222744 
    27232745                        // view space not valid or same view cell 
     
    27812803        Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 
    27822804 
    2783         CLEAR_CONTAINER(bspRays); 
    2784  
    27852805        //-- collect the leaves which haven't been found by ray casting 
    27862806        if (0) 
     
    28572877        mergeStats.Start(); 
    28582878         
    2859         //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mStat.maxPvs; 
     2879        //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mBspStats.maxPvs; 
    28602880        long startTime = GetTime(); 
    28612881 
    2862         cout << "collecting merge candidates ... "; 
     2882        cout << "collecting merge candidates ... " << endl; 
    28632883         
    28642884        if (mUseRaysForMerge) 
     
    28802900 
    28812901        // number of view cells withouth the invalid ones 
    2882         int nViewCells = mStat.Leaves() - mStat.invalidLeaves; 
     2902        int nViewCells = mBspStats.Leaves() - mBspStats.invalidLeaves; 
    28832903         
    28842904         
     
    33703390void VspBspTree::PropagateUpValidity(BspNode *node) 
    33713391{ 
    3372         while (!node->IsRoot() && node->GetParent()->TreeValid()) 
    3373         { 
    3374                 node = node->GetParent(); 
    3375                 node->SetTreeValid(false); 
     3392        const bool isValid = node->TreeValid(); 
     3393 
     3394        // propagative up invalid flag until only invalid nodes exist over this node 
     3395        if (!isValid) 
     3396        { 
     3397                while (!node->IsRoot() && node->GetParent()->TreeValid()) 
     3398                { 
     3399                        node = node->GetParent(); 
     3400                        node->SetTreeValid(false); 
     3401                } 
     3402        } 
     3403        else 
     3404        { 
     3405                // propagative up valid flag until one of the subtrees is invalid 
     3406                while (!node->IsRoot() && !node->TreeValid()) 
     3407                { 
     3408            node = node->GetParent(); 
     3409                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     3410                         
     3411                        // the parent is valid iff both leaves are valid 
     3412                        node->SetTreeValid(interior->GetBack()->TreeValid() &&  
     3413                                                           interior->GetFront()->TreeValid()); 
     3414                } 
    33763415        } 
    33773416} 
Note: See TracChangeset for help on using the changeset viewer.