Ignore:
Timestamp:
11/18/06 23:15:55 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1764 r1765  
    4040 
    4141// pvs penalty can be different from pvs size 
    42 inline static float EvalPvsPenalty(const int pvs,  
    43                                                                    const int lower, 
    44                                                                    const int upper) 
     42inline static float EvalPvsPenalty(const float pvs,  
     43                                                                   const float lower, 
     44                                                                   const float upper) 
    4545{ 
    4646        // clamp to minmax values 
     
    734734                         
    735735                mTotalCost -= sc->GetRenderCostDecrease(); 
    736                 mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 
     736                mTotalPvsSize += (int)(tFrontData.mPvs + tBackData.mPvs - tData.mPvs); 
    737737                mPvsEntries += sc->GetPvsEntriesIncr(); 
    738738 
     
    932932 
    933933        //-- compute pvs 
    934         frontData.mPvs = EvalPvsSize(*frontData.mRays); 
    935         backData.mPvs = EvalPvsSize(*backData.mRays); 
     934        frontData.mPvs = EvalPvsCost(*frontData.mRays); 
     935        backData.mPvs = EvalPvsCost(*backData.mRays); 
    936936                 
    937937        //-- split front and back node geometry and compute area 
     
    11201120 
    11211121 
    1122 int VspTree::PrepareHeuristics(KdLeaf *leaf) 
     1122float VspTree::PrepareHeuristics(KdLeaf *leaf) 
    11231123{        
    1124         int pvsSize = 0; 
     1124        float pvsSize = 0; 
    11251125         
    11261126        if (!leaf->Mailed()) 
     
    11601160 
    11611161 
    1162 int VspTree::PrepareHeuristics(const RayInfoContainer &rays) 
     1162float VspTree::PrepareHeuristics(const RayInfoContainer &rays) 
    11631163{        
    11641164        Intersectable::NewMail(); 
     
    11661166        BvhLeaf::NewMail(); 
    11671167 
    1168         int pvsSize = 0; 
     1168        float pvsSize = 0; 
    11691169 
    11701170        RayInfoContainer::const_iterator ri, ri_end = rays.end(); 
     
    12431243 
    12441244void VspTree::EvalHeuristics(const SortableEntry &ci, 
    1245                                                          int &pvsLeft, 
    1246                                                          int &pvsRight) const 
     1245                                                         float &pvsLeft, 
     1246                                                         float &pvsRight) const 
    12471247{ 
    12481248        VssRay *ray = ci.ray; 
     
    12511251        if (ci.type == SortableEntry::ERayMin) 
    12521252        { 
     1253                pvsLeft += EvalMinEventContribution(*ray, true); 
    12531254#if COUNT_ORIGIN_OBJECTS 
    1254                 pvsLeft += EvalMinEventContribution(*ray, true); 
    1255 #else 
    12561255                pvsLeft += EvalMinEventContribution(*ray, false); 
    12571256#endif 
     
    12591258        else // eval changes in pvs causes by max event  
    12601259        { 
     1260                pvsRight -= EvalMaxEventContribution(*ray, true); 
    12611261#if COUNT_ORIGIN_OBJECTS 
    1262                 pvsRight -= EvalMaxEventContribution(*ray, true); 
    1263 #else 
    12641262                pvsRight -= EvalMaxEventContribution(*ray, false); 
    12651263#endif 
     
    12711269                                                                           const AxisAlignedBox3 &box, 
    12721270                                                                           const int axis, 
    1273                                                                            float &position) 
    1274 { 
    1275         // get subset of rays 
    1276         RayInfoContainer randomRays; 
    1277         randomRays.reserve(mMaxTests); 
    1278  
    1279         RayInfoContainer *usedRays; 
    1280  
    1281         if (mMaxTests < (int)tData.mRays->size()) 
    1282         { 
    1283                 GetRayInfoSets(*tData.mRays, mMaxTests, randomRays); 
    1284                 usedRays = &randomRays; 
    1285         } 
    1286         else 
    1287         { 
    1288                 usedRays = tData.mRays; 
    1289         } 
    1290  
     1271                                                                           float &position, 
     1272                                                                           const RayInfoContainer &usedRays) 
     1273{ 
    12911274        const float minBox = box.Min(axis); 
    12921275        const float maxBox = box.Max(axis); 
     
    12971280        const float maxBand = minBox + mMaxBand * sizeBox; 
    12981281 
    1299         SortSubdivisionCandidates(*usedRays, axis, minBand, maxBand); 
     1282        SortSubdivisionCandidates(usedRays, axis, minBand, maxBand); 
    13001283 
    13011284        // prepare the sweep 
    13021285        // note: returns pvs size => no need t give pvs size as function parameter 
    1303         const int pvsSize = PrepareHeuristics(*usedRays); 
     1286        const float pvsCost = PrepareHeuristics(usedRays); 
    13041287 
    13051288        // go through the lists, count the number of objects left and right 
     
    13071290        // C = ct_div_ci  + (ql*rl + qr*rr)/queries 
    13081291 
    1309         int pvsl = 0; 
    1310         int pvsr = pvsSize; 
    1311  
    1312         int pvsBack = pvsl; 
    1313         int pvsFront = pvsr; 
    1314  
    1315         float sum = (float)pvsSize * sizeBox; 
     1292        float pvsl = 0; 
     1293        float pvsr = pvsCost; 
     1294 
     1295        float pvsBack = pvsl; 
     1296        float pvsFront = pvsr; 
     1297 
     1298        float sum = pvsCost * sizeBox; 
    13161299        float minSum = 1e20f; 
    13171300 
     
    13271310        BvhLeaf::NewMail(); 
    13281311 
    1329         //-- traverse through visibility events 
    1330         vector<SortableEntry>::const_iterator ci, ci_end = mLocalSubdivisionCandidates->end(); 
    1331  
    1332 #ifdef GTPGTP_DEBUG 
    1333         const float volRatio = tData.mBoundingBox.GetVolume() / (sizeBox * mBoundingBox.GetVolume()); 
     1312        const float volRatio =  
     1313                tData.mBoundingBox.GetVolume() / (sizeBox * mBoundingBox.GetVolume()); 
     1314 
     1315        //////// 
     1316        //-- iterate through visibility events 
     1317 
     1318        vector<SortableEntry>::const_iterator ci,  
     1319                ci_end = mLocalSubdivisionCandidates->end(); 
     1320 
     1321#ifdef GTP_DEBUG 
    13341322        const int leaves = mVspStats.Leaves(); 
    13351323        const bool printStats = ((axis == 0) && (leaves > 0) && (leaves < 90)); 
     
    13701358                        sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value); 
    13711359                         
    1372 #ifdef GTPGTP_DEBUG 
     1360#ifdef GTP_DEBUG 
    13731361                        if (printStats) 
    13741362                        { 
     
    14041392        //-- compute cost 
    14051393 
    1406         const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 
    1407         const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 
     1394        const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize(); 
     1395        const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize(); 
    14081396 
    14091397        const float pOverall = sizeBox; 
     
    14111399        const float pFront = maxBox - position; 
    14121400 
    1413         const float penaltyOld = EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit); 
     1401        const float penaltyOld = EvalPvsPenalty(pvsCost, lowerPvsLimit, upperPvsLimit); 
    14141402    const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 
    14151403        const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 
     
    14231411        } 
    14241412         
    1425 #ifdef GTPGTP_DEBUG 
    1426         Debug << "\n§§§§ eval local cost §§§§" << endl 
     1413//#ifdef GTP_DEBUG 
     1414        cout << "\n((((( eval local cost )))))" << endl 
    14271415                  << "back pvs: " << penaltyBack << " front pvs: " << penaltyFront << " total pvs: " << penaltyOld << endl  
    14281416                  << "back p: " << pBack * volRatio << " front p " << pFront * volRatio << " p: " << pOverall * volRatio << endl 
    14291417                  << "old rc: " << oldRenderCost * volRatio << " new rc: " << newRenderCost * volRatio << endl 
    14301418                  << "render cost decrease: " << oldRenderCost * volRatio - newRenderCost * volRatio << endl; 
    1431 #endif 
     1419//#endif 
    14321420        return ratio; 
    14331421} 
     
    14541442                mOnlyDrivingAxis || mCirculatingAxis; 
    14551443         
     1444        // get subset of rays 
     1445        RayInfoContainer randomRays; 
     1446        randomRays.reserve(mMaxTests); 
     1447 
     1448        RayInfoContainer *usedRays; 
     1449 
     1450        if (mMaxTests < (int)tData.mRays->size()) 
     1451        { 
     1452                GetRayInfoSets(*tData.mRays, mMaxTests, randomRays); 
     1453                usedRays = &randomRays; 
     1454        } 
     1455        else 
     1456        { 
     1457                usedRays = tData.mRays; 
     1458        } 
     1459 
    14561460        if (mCirculatingAxis) 
    14571461        { 
     
    14601464 
    14611465                if (parent) 
     1466                { 
    14621467                        parentAxis = dynamic_cast<VspInterior *>(parent)->GetAxis(); 
     1468                } 
    14631469 
    14641470                sAxis = (parentAxis + 1) % 3; 
     
    14761482                        { 
    14771483                                //-- place split plane using heuristics 
     1484 
    14781485                                nCostRatio[axis] = 
    14791486                                        EvalLocalCostHeuristics(tData, 
    14801487                                                                                        box, 
    14811488                                                                                        axis, 
    1482                                                                                         nPosition[axis]);                        
     1489                                                                                        nPosition[axis], 
     1490                                                                                        *usedRays);                      
    14831491                        } 
    14841492                        else 
    14851493                        { 
    14861494                                //-- split plane position is spatial median                              
     1495                                 
    14871496                                nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 
    14881497                                nCostRatio[axis] = EvalLocalSplitCost(tData, 
     
    15051514        } 
    15061515 
    1507         //////////////////////////////// 
     1516        ///////////////////////// 
    15081517        //-- assign values of best split 
    15091518 
     
    15711580 
    15721581 
    1573         //////////////////////////////////// 
     1582        /////////////////// 
    15741583        //-- evaluate render cost heuristics 
    15751584 
    1576         const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 
    1577         const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 
    1578  
    1579         const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit); 
    1580     const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit); 
    1581         const float penaltyBack = EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit); 
     1585        const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize(); 
     1586        const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize(); 
     1587 
     1588        const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit); 
     1589    const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 
     1590        const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 
    15821591                         
    15831592        const float oldRenderCost = pOverall * penaltyOld; 
     
    15901599        const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 
    15911600 
    1592 #ifdef GTPGTP_DEBUG 
     1601#ifdef GTP_DEBUG 
    15931602        Debug << "\nvsp render cost decrease" << endl 
    15941603                  << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl  
     
    16191628        KdLeaf::NewMail(3); 
    16201629 
    1621         const int pvsSize = data.mPvs; 
     1630        const float pvsSize = data.mPvs; 
    16221631        RayInfoContainer::const_iterator rit, rit_end = data.mRays->end(); 
    16231632 
     
    18631872        if (data.mPvs > mVspStats.maxPvs) 
    18641873        { 
    1865                 mVspStats.maxPvs = data.mPvs; 
    1866         } 
    1867  
    1868         mVspStats.pvs += data.mPvs; 
     1874                mVspStats.maxPvs = (int)data.mPvs; 
     1875        } 
     1876 
     1877        mVspStats.pvs += (int)data.mPvs; 
    18691878 
    18701879        if (data.mDepth < mVspStats.minDepth) 
     
    22152224 
    22162225 
    2217 int VspTree::EvalPvsSize(const RayInfoContainer &rays) const 
    2218 { 
    2219         int pvsSize = 0; 
     2226float VspTree::EvalPvsCost(const RayInfoContainer &rays) const 
     2227{ 
     2228        float pvsCost = 0; 
    22202229         
    22212230        Intersectable::NewMail(); 
     
    22282237        { 
    22292238                VssRay *ray = (*rit).mRay; 
     2239                 
     2240                pvsCost += EvalContributionToPvs(*ray, true); 
     2241 
    22302242#if COUNT_ORIGIN_OBJECTS 
    2231                 pvsSize += EvalContributionToPvs(*ray, true); 
    2232 #else 
    2233                 pvsSize += EvalContributionToPvs(*ray, false); 
     2243                pvsCost += EvalContributionToPvs(*ray, false); 
    22342244#endif 
    22352245        } 
    22362246         
    2237         return pvsSize; 
     2247        return pvsCost; 
    22382248} 
    22392249 
     
    23072317        { 
    23082318                VssRay *ray = (*rit).mRay; 
     2319 
     2320                pvsSize += EvalPvsEntriesContribution(*ray, true); 
     2321 
    23092322#if COUNT_ORIGIN_OBJECTS 
    2310                 pvsSize += EvalPvsEntriesContribution(*ray, true); 
    2311 #else 
    23122323                pvsSize += EvalPvsEntriesContribution(*ray, false); 
    23132324#endif 
     
    28902901 
    28912902        /// collect pvs from rays 
    2892         const int pvsSize = EvalPvsSize(rays); 
     2903        const float pvsCost = EvalPvsCost(rays); 
    28932904         
    28942905        // root and bounding box were already constructed 
     
    29012912         
    29022913        // first vsp traversal data 
    2903         VspTraversalData vData(leaf, 0, &rays, pvsSize, prop, mBoundingBox); 
     2914        VspTraversalData vData(leaf, 0, &rays, pvsCost, prop, mBoundingBox); 
    29042915 
    29052916 
     
    29232934        leaf->SetSubdivisionCandidate(splitCandidate); 
    29242935 
    2925         mTotalCost = (float)pvsSize; 
     2936        mTotalCost = pvsCost; 
    29262937        mPvsEntries = EvalPvsEntriesSize(rays); 
    29272938 
     
    30573068 
    30583069 
    3059 int VspTree::PrepareHeuristics(const VssRay &ray, const bool isTermination) 
    3060 { 
    3061         int pvsSize = 0; 
     3070float VspTree::PrepareHeuristics(const VssRay &ray, const bool isTermination) 
     3071{ 
     3072        float pvsSize = 0; 
    30623073         
    30633074        Intersectable *obj; 
Note: See TracChangeset for help on using the changeset viewer.