Ignore:
Timestamp:
12/21/05 10:53:47 (19 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r473 r474  
    3838mRoot(NULL), 
    3939mPvsUseArea(true), 
    40 mNumCriteria(0) 
     40mCostNormalizer(Limits::Small) 
    4141{ 
    4242        mRootCell = new BspViewCell(); 
     
    9191        Debug << "max polygon candidates: " << mMaxPolyCandidates << endl; 
    9292        Debug << "max plane candidates: " << mMaxRayCandidates << endl; 
    93  
     93         
    9494        Debug << "Split plane strategy: "; 
    9595        if (mSplitPlaneStrategy & RANDOM_POLYGON) 
     96        { 
    9697                Debug << "random polygon "; 
    97  
     98        } 
    9899        if (mSplitPlaneStrategy & AXIS_ALIGNED) 
    99100        { 
    100                 ++ mNumCriteria; 
    101101                Debug << "axis aligned "; 
    102102        } 
    103103        if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 
    104104        { 
    105                 ++ mNumCriteria; 
     105                mCostNormalizer += mLeastRaySplitsFactor; 
    106106                Debug << "least ray splits "; 
    107107        } 
    108108        if (mSplitPlaneStrategy & BALANCED_RAYS) 
    109109        { 
    110                 ++ mNumCriteria; 
     110                mCostNormalizer += mBalancedRaysFactor; 
    111111                Debug << "balanced rays "; 
    112112        } 
    113113        if (mSplitPlaneStrategy & PVS) 
    114114        { 
    115                 ++ mNumCriteria; 
     115                mCostNormalizer += mPvsFactor; 
    116116                Debug << "pvs"; 
    117117        } 
     
    273273        } 
    274274 
     275        mTermMinArea *= mBox.SurfaceArea(); // normalize 
    275276        mStat.polys = (int)polys.size(); 
    276277 
     
    315316 
    316317            tStack.pop(); 
    317  
    318318                // subdivide leaf node 
    319319                BspNode *r = Subdivide(tStack, tData); 
     
    412412                ++ maxCostMisses; 
    413413 
    414                 /*if (maxCostMisses >= mTermMissTolerance) 
     414                if (maxCostMisses >= mTermMissTolerance) 
    415415                { 
    416416                        // terminate branch because of max cost 
    417417                        ++ mStat.maxCostNodes;  
    418418            return leaf; 
    419                 }*/ 
     419                } 
    420420        } 
    421421 
     
    471471                                                                           mEpsilon); 
    472472         
    473                 // area is normalized with view space area 
    474                 frontData.mArea = frontData.mGeometry->GetArea() / mBox.SurfaceArea(); 
    475                 backData.mArea = backData.mGeometry->GetArea() / mBox.SurfaceArea(); 
     473                frontData.mArea = frontData.mGeometry->GetArea(); 
     474                backData.mArea = backData.mGeometry->GetArea(); 
    476475        } 
    477476 
     
    810809                const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx)); 
    811810                //Debug << "current Idx: " << maxIdx << " cand idx " << candidateIdx << endl; 
    812  
     811                 
    813812                Polygon3 *poly = (*data.mPolygons)[candidateIdx]; 
    814                  
     813 
    815814                // swap candidate to the end to avoid testing same plane 
    816815                std::swap((*data.mPolygons)[maxIdx], (*data.mPolygons)[candidateIdx]); 
    817  
     816         
    818817                //Polygon3 *poly = (*data.mPolygons)[(int)RandomValue(0, (int)polys.size() - 1)]; 
    819818 
     
    829828        } 
    830829         
    831         //Debug << "lowest: " << lowestCost << endl; 
    832  
    833830        //-- choose candidate planes extracted from rays 
    834         // we use different methods chosen with 
    835         // equal probability 
     831        //-- different methods are available 
    836832        for (int i = 0; i < mMaxRayCandidates; ++ i) 
    837833        { 
    838834                plane = ChooseCandidatePlane3(*data.mRays); 
    839  
    840835                const float candidateCost = SplitPlaneCost(plane, data); 
    841836 
     
    846841                } 
    847842        } 
     843 
     844#ifdef _DEBUG 
     845        Debug << "plane lowest cost: " << lowestCost << endl; 
     846#endif 
    848847 
    849848        // cost ratio miss 
    850849        if (lowestCost > mTermMaxCostRatio) 
    851850                return false; 
    852  
    853 #ifdef _DEBUG 
    854         Debug << "plane lowest cost: " << lowestCost << endl; 
    855 #endif 
    856851 
    857852        return true; 
     
    10111006        { 
    10121007                const float oldCost = pOverall * (float)data.mPvs + Limits::Small; 
    1013  
    1014                 cost += mPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / oldCost; 
    1015  
    1016                 // give penalty to unbalanced split 
    1017                 if (0) 
    1018                 if (((pFront * 0.2 + Limits::Small) > pBack) ||  
    1019                         (pFront < (pBack * 0.2 + Limits::Small))) 
    1020                         cost += 0.5; 
     1008                cost += mPvsFactor * (frontPvs * pFront + backPvs * pBack) / oldCost; 
     1009 
     1010                //cost += mPvsFactor * 0.5 * (frontPvs * pFront + backPvs * pBack) / oldCost; 
     1011                //Debug << "new cost: " << cost << " over" << frontPvs * pFront + backPvs * pBack << " old cost " << oldCost << endl; 
     1012         
     1013                if (0) // give penalty to unbalanced split 
     1014                        if (((pFront * 0.2 + Limits::Small) > pBack) ||  
     1015                                (pFront < (pBack * 0.2 + Limits::Small))) 
     1016                                        cost += 0.5; 
    10211017        } 
    10221018 
    10231019#ifdef _DEBUG 
    1024 //      Debug << "totalpvs: " << pvs << " ptotal: " << pOverall 
    1025 //                << " frontpvs: " << frontPvs << " pFront: " << pFront  
    1026 //                << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl; 
     1020        Debug << "totalpvs: " << data.mPvs << " ptotal: " << pOverall 
     1021                  << " frontpvs: " << frontPvs << " pFront: " << pFront  
     1022                  << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl; 
    10271023#endif 
    1028  
    1029         // normalize by number of criteria 
    1030         return cost / (float)(mNumCriteria + Limits::Small); 
     1024         
     1025        // normalize cost by sum of linear factors 
     1026        return cost / (float)mCostNormalizer; 
    10311027} 
    10321028 
     
    11181114        if (data.mDepth < mStat.minDepth) 
    11191115                mStat.minDepth = data.mDepth; 
    1120  
     1116         
     1117        if (data.mDepth >= mTermMaxDepth) 
     1118                ++ mStat.maxDepthNodes; 
     1119 
     1120        if (data.mPvs < mTermMinPvs) 
     1121                ++ mStat.minPvsNodes; 
     1122 
     1123        if ((int)data.mRays->size() < mTermMinRays) 
     1124                ++ mStat.minRaysNodes; 
     1125 
     1126        if (data.GetAvgRayContribution() > mTermMaxRayContribution) 
     1127                ++ mStat.maxRayContribNodes; 
     1128         
     1129        if (data.mArea <= mTermMinArea)  
     1130        { 
     1131                //Debug << "area: " << data.mArea / mBox.SurfaceArea() << " min area: " << mTermMinArea / mBox.SurfaceArea() << endl; 
     1132                ++ mStat.minAreaNodes; 
     1133        } 
    11211134        // accumulate depth to compute average depth 
    11221135        mStat.accumDepth += data.mDepth; 
    1123          
    1124  
    1125         if (data.mDepth >= mTermMaxDepth) 
    1126                 ++ mStat.maxDepthNodes; 
    1127  
    1128         if (data.mPvs < mTermMinPvs) 
    1129                 ++ mStat.minPvsNodes; 
    1130  
    1131         if ((int)data.mRays->size() < mTermMinRays) 
    1132                 ++ mStat.minRaysNodes; 
    1133  
    1134         if (data.GetAvgRayContribution() > mTermMaxRayContribution) 
    1135                 ++ mStat.maxRayContribNodes; 
    1136          
    1137         if (data.mGeometry->GetArea() <= mTermMinArea)  
    1138                 ++ mStat.minAreaNodes; 
    11391136 
    11401137#ifdef _DEBUG 
Note: See TracChangeset for help on using the changeset viewer.