Ignore:
Timestamp:
10/05/06 18:51:15 (18 years ago)
Author:
mattausch
Message:

added measurement for pvs entries size decrease during subdivision

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1571 r1576  
    616616void VspTree::CreateViewCell(VspTraversalData &tData, const bool updatePvs) 
    617617{ 
     618        /////////////// 
    618619        //-- create new view cell 
    619         VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode); 
     620        VspLeaf *leaf = tData.mNode; 
    620621         
    621622        VspViewCell *viewCell = new VspViewCell(); 
     
    627628        if (updatePvs) 
    628629        { 
    629                 //-- update pvs of view cell 
     630                // update pvs of view cell 
    630631                AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 
    631632 
     
    642643                /////////// 
    643644                //-- store sampling rays 
    644                 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
     645        RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
    645646 
    646647                for (it = tData.mRays->begin(); it != it_end; ++ it) 
    647648                { 
    648649                        (*it).mRay->Ref();                       
     650                        // note: should rather store rays with view cell 
    649651                        leaf->mVssRays.push_back((*it).mRay); 
    650652                } 
     
    689691                // create new interior node and two leaf node 
    690692                const AxisAlignedPlane splitPlane = sc->mSplitPlane; 
    691                 const int maxCostMisses = sc->mMaxCostMisses; 
     693                const int maxCostMisses = sc->GetMaxCostMisses(); 
    692694 
    693695                newNode = SubdivideNode(splitPlane, tData, tFrontData, tBackData); 
     
    788790 
    789791        // max cost threshold violated? 
    790         splitCandidate.mMaxCostMisses = maxCostRatioViolated  ?  
     792        splitCandidate.SetMaxCostMisses(maxCostRatioViolated  ?  
    791793                        splitCandidate.mParentData.mMaxCostMisses + 1: 
    792                         splitCandidate.mParentData.mMaxCostMisses; 
     794                        splitCandidate.mParentData.mMaxCostMisses); 
    793795         
    794796        float oldRenderCost; 
     
    800802 
    801803        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
     804 
     805        // the increase in pvs entries num induced by this split 
     806        const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate); 
     807        splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 
    802808 
    803809#if 0 
     
    814820 
    815821 
     822int VspTree::EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate) const 
     823{ 
     824        float oldPvsSize = 0; 
     825        float fPvsSize = 0; 
     826        float bPvsSize = 0; 
     827         
     828        AxisAlignedPlane candidatePlane = splitCandidate.mSplitPlane; 
     829        RayInfoContainer::const_iterator rit,  
     830                rit_end = splitCandidate.mParentData.mRays->end(); 
     831 
     832        // this is the main ray classification loop! 
     833        for(rit = splitCandidate.mParentData.mRays->begin(); rit != rit_end; ++ rit) 
     834        { 
     835                VssRay *ray = (*rit).mRay; 
     836                RayInfo rayInf = *rit; 
     837                 
     838                float t; 
     839                // classify ray 
     840                const int cf =  
     841                        rayInf.ComputeRayIntersection(candidatePlane.mAxis,  
     842                                                                                  candidatePlane.mPosition, t); 
     843 
     844                UpdatePvsEntriesContribution(*ray, true, cf, fPvsSize, bPvsSize, oldPvsSize); 
     845        } 
     846         
     847        return (int)(fPvsSize + bPvsSize - oldPvsSize); 
     848} 
     849 
     850 
    816851VspInterior *VspTree::SubdivideNode(const AxisAlignedPlane &splitPlane, 
    817852                                                                        VspTraversalData &tData, 
     
    836871                          *backData.mRays); 
    837872 
    838         ///////////// 
    839873        //-- compute pvs 
    840874        frontData.mPvs = EvalPvsSize(*frontData.mRays); 
    841875        backData.mPvs = EvalPvsSize(*backData.mRays); 
    842         //Debug << "f pvs: " << frontData.mPvs << " b pvs: " << backData.mPvs << " pvs " << tData.mPvs << endl; 
    843          
     876                 
    844877        //-- split front and back node geometry and compute area 
    845878        tData.mBoundingBox.Split(splitPlane.mAxis,  
     
    851884        backData.mProbability = tData.mProbability - frontData.mProbability; 
    852885 
    853         // update some stats 
    854         // store maximal depth 
     886 
     887        //////// 
     888        //-- update some stats 
     889         
    855890        if (tData.mDepth > mVspStats.maxDepth) 
    856         { 
    857                 //Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl; 
     891        {       //Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl; 
    858892                mVspStats.maxDepth = tData.mDepth; 
    859893        } 
    860894 
    861         // two more leaves 
     895        // two more leaves per split 
    862896        mVspStats.nodes += 2; 
    863897        /// and a new split 
     
    865899 
    866900 
    867     /////////////////////// 
     901        //////////////// 
    868902        //-- create front and back and subdivide further 
    869903 
     
    902936        CreateViewCell(frontData, false); 
    903937        CreateViewCell(backData, false); 
    904  
    905938 
    906939#if WORK_WITH_VIEWCELL_PVS 
     
    14361469        // mark objects in the front / back / both using mailboxing 
    14371470        // then count pvs sizes 
     1471 
    14381472        Intersectable::NewMail(3); 
    14391473        KdLeaf::NewMail(3); 
     
    14971531                  << "render cost decrease: " << renderCostDecrease << endl; 
    14981532#endif 
     1533 
    14991534        return renderCostDecrease; 
    15001535} 
     
    15191554 
    15201555        const int pvsSize = data.mPvs; 
    1521  
    15221556        RayInfoContainer::const_iterator rit, rit_end = data.mRays->end(); 
    15231557 
     
    15351569        } 
    15361570 
    1537  
     1571        ////////////// 
    15381572        //-- evaluate cost heuristics 
    1539  
    15401573        float pOverall = data.mProbability; 
    15411574 
     
    15551588 
    15561589 
    1557 void VspTree::UpdateContributionsToPvs(Intersectable *obj, 
    1558                                                                            const int cf, 
    1559                                                                            float &frontPvs, 
    1560                                                                            float &backPvs, 
    1561                                                                            float &totalPvs) const 
    1562 { 
    1563         if (!obj) return; 
    1564  
    1565         //const float renderCost = mViewCellsManager->SimpleRay &raynderCost(obj); 
    1566         const int renderCost = 1; 
    1567  
    1568         // object in no pvs => new 
    1569         if (!obj->Mailed() && !obj->Mailed(1) && !obj->Mailed(2)) 
    1570         { 
    1571                 totalPvs += renderCost; 
    1572         } 
    1573  
    1574         // QUESTION matt: is it safe to assume that  
    1575         // the object belongs to no pvs in this case? 
    1576         //if (cf == Ray::COINCIDENT) return; 
    1577  
    1578         if (cf >= 0) // front pvs 
    1579         { 
    1580                 if (!obj->Mailed() && !obj->Mailed(2)) 
    1581                 { 
    1582                         frontPvs += renderCost; 
    1583                  
    1584                         // already in back pvs => in both pvss 
    1585                         if (obj->Mailed(1)) 
    1586                                 obj->Mail(2); 
    1587                         else 
    1588                                 obj->Mail(); 
    1589                 } 
    1590         } 
    1591  
    1592         if (cf <= 0) // back pvs 
    1593         { 
    1594                 if (!obj->Mailed(1) && !obj->Mailed(2)) 
    1595                 { 
    1596                         backPvs += renderCost; 
    1597                  
    1598                         // already in front pvs => in both pvss 
    1599                         if (obj->Mailed()) 
    1600                                 obj->Mail(2); 
    1601                         else 
    1602                                 obj->Mail(1); 
    1603                 } 
    1604         } 
    1605 } 
    1606  
    1607  
    16081590void VspTree::UpdateContributionsToPvs(BvhLeaf *leaf, 
    16091591                                                                           const int cf, 
    16101592                                                                           float &frontPvs, 
    16111593                                                                           float &backPvs, 
    1612                                                                            float &totalPvs) const 
     1594                                                                           float &totalPvs, 
     1595                                                                           const bool countEntries) const 
    16131596{ 
    16141597        if (!leaf) return; 
    1615  
    1616         const int renderCost = (int)leaf->mObjects.size(); 
     1598        const int renderCost = countEntries ? 1 : (int)leaf->mObjects.size(); 
    16171599 
    16181600        // leaf in no pvs => new 
     
    16211603                totalPvs += renderCost; 
    16221604        } 
    1623  
    1624         // QUESTION matt: is it safe to assume that  
    1625         // the leaf belongs to no pvs in this case? 
    1626         //if (cf == Ray::COINCIDENT) return; 
    16271605 
    16281606        if (cf >= 0) // front pvs 
     
    16841662    }    
    16851663         
    1686         // QUESTION matt: is it safe to assume that  
    1687         // the object belongs to no pvs in this case? 
    1688         //if (cf == Ray::COINCIDENT) return; 
    1689  
    16901664        if (cf >= 0) // front pvs 
    16911665        { 
     
    21462120 
    21472121 
     2122int VspTree::EvalPvsEntriesContribution(const VssRay &ray,  
     2123                                                                                const bool isTermination) const 
     2124 
     2125{ 
     2126                Intersectable *obj;  
     2127                Vector3 pt; 
     2128                KdNode *node; 
     2129 
     2130                ray.GetSampleData(isTermination, pt, &obj, &node); 
     2131                if (!obj) return 0; 
     2132 
     2133                switch(mHierarchyManager->GetObjectSpaceSubdivisionType()) 
     2134                { 
     2135                case HierarchyManager::NO_OBJ_SUBDIV: 
     2136                { 
     2137                        if (!obj->Mailed()) 
     2138                        { 
     2139                                obj->Mail(); 
     2140                                return 1; 
     2141                        } 
     2142                         
     2143                        return 0; 
     2144                } 
     2145 
     2146                case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     2147                { 
     2148                        KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 
     2149                        if (!leaf->Mailed()) 
     2150                        { 
     2151                                leaf->Mail(); 
     2152                                return 1; 
     2153                        } 
     2154                         
     2155                        return 0; 
     2156                } 
     2157        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     2158                { 
     2159                        BvhLeaf *bvhleaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     2160 
     2161                        if (!bvhleaf->Mailed()) 
     2162                        { 
     2163                                bvhleaf->Mail(); 
     2164                                return 1; 
     2165                        } 
     2166                         
     2167                        return 0; 
     2168                } 
     2169        default: 
     2170                break; 
     2171        } 
     2172 
     2173        return 0; 
     2174} 
     2175 
     2176 
     2177int VspTree::EvalPvsEntriesSize(const RayInfoContainer &rays) const 
     2178{ 
     2179        int pvsSize = 0; 
     2180 
     2181        Intersectable::NewMail(); 
     2182        KdNode::NewMail(); 
     2183        BvhLeaf::NewMail(); 
     2184 
     2185        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     2186 
     2187        for (rit = rays.begin(); rit != rays.end(); ++ rit) 
     2188        { 
     2189                VssRay *ray = (*rit).mRay; 
     2190 
     2191                pvsSize += EvalPvsEntriesContribution(*ray, true); 
     2192                pvsSize += EvalPvsEntriesContribution(*ray, false); 
     2193        } 
     2194 
     2195        return pvsSize; 
     2196} 
     2197 
     2198 
    21482199float VspTree::GetEpsilon() const 
    21492200{ 
     
    29913042 
    29923043 
    2993 int VspTree::EvalContributionToPvs(const VssRay &ray,  
    2994                                                                    const bool isTermination) const 
     3044void VspTree::UpdatePvsEntriesContribution(const VssRay &ray, 
     3045                                                                                   const bool isTermination, 
     3046                                                                                   const int cf, 
     3047                                                                                   float &frontPvs, 
     3048                                                                                   float &backPvs, 
     3049                                                                                   float &totalPvs) const 
     3050{ 
     3051        /*ray.GetSampleData(isTermination, pt, &obj, &node); 
     3052        if (!obj) return 0; 
     3053 
     3054        switch (mHierarchyManager->GetObjectSpaceSubdivisionType()) 
     3055        { 
     3056        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     3057                // TODO 
     3058                break; 
     3059        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     3060                { 
     3061                        BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     3062                        UpdateContributionsToPvs(leaf, true, cf, pvsFront, pvsBack, totalPvs, true);             
     3063                        break; 
     3064                } 
     3065        default: 
     3066                UpdateContributionsToPvs(obj, true, cf, pvsFront, pvsBack, totalPvs, true);      
     3067                break; 
     3068        }*/ 
     3069} 
     3070 
     3071 
     3072int VspTree::EvalContributionToPvs(const VssRay &ray, const bool isTermination) const 
    29953073{        
    29963074        Intersectable *obj;  
     
    30183096                { 
    30193097                        KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 
    3020  
    30213098                        pvs += EvalContributionToPvs(leaf); 
    30223099                        break; 
     
    30483125        leaf->Mail(); 
    30493126 
     3127        // this is the pvs which is uniquely part of this kd leaf 
    30503128        int pvs = (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
    30513129 
Note: See TracChangeset for help on using the changeset viewer.