Ignore:
Timestamp:
03/11/07 02:17:58 (17 years ago)
Author:
mattausch
Message:

added render cost bound for objects, improved undersampling compensation

File:
1 edited

Legend:

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

    r2224 r2227  
    634634 
    635635 
     636static float AvgRaysPerObject(const int pvs, const int nRays) 
     637{ 
     638        return (float)nRays / ((float)pvs + Limits::Small); 
     639} 
     640 
     641 
    636642void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate,  
    637643                                                                                   const bool computeSplitPlane, 
     
    689695        // avg contribution of a ray to a pvs 
    690696        const float pvs = (float)CountViewCells(*tData.mSampledObjects); 
    691         const float avgRayContri = AvgRayContribution((int)pvs, tData.mNumRays); 
     697        //const float avgRayContri = AvgRayContribution((int)pvs, tData.mNumRays); 
     698        const float avgRaysPerObject = AvgRaysPerObject((int)pvs, tData.mNumRays); 
    692699 
    693700        // high avg ray contri, the result is influenced by undersampling 
    694         splitCandidate.SetAvgRayContribution(avgRayContri); 
     701        splitCandidate.SetAvgRaysPerObject(avgRaysPerObject); 
    695702        const float viewSpaceVol = GetViewSpaceVolume(); 
    696703 
     
    699706        const float parentVol = tData.mCorrectedVolume * oldRatio; 
    700707 
     708        //cout << "h " << avgRaysPerObject << " "; 
    701709        // this leaf is a pvs entry in all the view cells 
    702710        // that see one of the objects. 
     
    708716 
    709717        splitCandidate.mCorrectedFrontVolume =  
    710                 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells, parentVol, avgRayContri); 
     718                mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells, parentVol, avgRaysPerObject); 
    711719         
    712720        splitCandidate.mCorrectedBackVolume =  
    713                 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeBackViewCells, parentVol, avgRayContri); 
     721                mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeBackViewCells, parentVol, avgRaysPerObject); 
    714722         
    715723        const float relfrontCost = splitCandidate.mCorrectedFrontVolume *  
     
    727735        // increase in pvs entries 
    728736        const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate,  
    729                                                                                                   avgRayContri,  
     737                                                                                                  avgRaysPerObject,  
    730738                                                                                                  (int)pvs,  
    731739                                                                                                  splitCandidate.mNumFrontViewCells,  
     
    737745        { 
    738746                cout << "bvh volume cost" 
    739                  << " avg ray contri: " << avgRayContri << " ratio: " << oldRatio  
     747                 << " avg rays per object: " << avgRaysPerObject << " ratio: " << oldRatio  
    740748                 << " parent: " << parentVol << " old vol: " << oldVolume  
    741749                 << " frontvol: " << splitCandidate.mVolumeFrontViewCells << " corr. " << splitCandidate.mCorrectedFrontVolume  
     
    766774 
    767775int BvHierarchy::EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate,  
    768                                                                         const float avgRayContri, 
     776                                                                        const float avgRaysPerObjects, 
    769777                                                                        const int numParentViewCells, 
    770778                                                                        const int numFrontViewCells, 
     
    780788         
    781789        splitCandidate.mCorrectedFrontPvs =  
    782                 mHierarchyManager->EvalCorrectedPvs((float)frontViewCells, parentPvs, avgRayContri); 
     790                mHierarchyManager->EvalCorrectedPvs((float)frontViewCells, parentPvs, avgRaysPerObjects); 
    783791        splitCandidate.mCorrectedBackPvs = 
    784                 mHierarchyManager->EvalCorrectedPvs((float)backViewCells, parentPvs, avgRayContri); 
     792                mHierarchyManager->EvalCorrectedPvs((float)backViewCells, parentPvs, avgRaysPerObjects); 
    785793 
    786794        if (0) 
    787795        cout << "bvh pvs" 
    788                  << " avg ray contri: " << avgRayContri << " ratio: " << oldPvsRatio  
     796                 << " avg ray contri: " << avgRaysPerObjects << " ratio: " << oldPvsRatio  
    789797                 << " parent: " << parentPvs << " " << " old vol: " << oldPvsSize 
    790798                 << " frontpvs: " << frontViewCells << " corr. " << splitCandidate.mCorrectedFrontPvs  
     
    10141022#endif 
    10151023 
    1016 #if 1 
    10171024 
    10181025float BvHierarchy::EvalSah(const BvhTraversalData &tData, 
     
    11111118                ar = rbox.SurfaceArea(); 
    11121119 
     1120#if BOUND_RENDERCOST 
    11131121                const float sum = noValidSplit ? 1e25f : objectsLeft * al + objectsRight * ar; 
    1114        
     1122#else 
     1123                const float rcLeft = std::max(objectsLeft, MIN_RENDERCOST); 
     1124                const float rcRight = std::max(objectsRight, MIN_RENDERCOST); 
     1125 
     1126                const float sum = noValidSplit ? 1e25f : objectsLeft * al + objectsRight * ar; 
     1127 
     1128#endif 
    11151129                /*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=("  
    11161130                         << lbox.SurfaceArea() << "," << rbox.SurfaceArea() << ")" << endl; 
     
    11531167} 
    11541168 
    1155 #else 
    1156  
    1157 float BvHierarchy::EvalSah(const BvhTraversalData &tData, 
    1158                                                   const int axis, 
    1159                                                   ObjectContainer &objectsFront, 
    1160                                                   ObjectContainer &objectsBack) 
     1169 
     1170 
     1171float BvHierarchy::EvalSahWithTigherBbox(const BvhTraversalData &tData, 
     1172                                                                                const int axis, 
     1173                                                                                ObjectContainer &objectsFront, 
     1174                                                                                ObjectContainer &objectsBack) 
    11611175{ 
    11621176        // go through the lists, count the number of objects left and right 
     
    12941308} 
    12951309 
    1296 #endif 
    12971310 
    12981311static bool PrepareOutput(const int axis, 
     
    14231436                const bool noValidSplit = (nObjectsRight <= Limits::Small); 
    14241437 
     1438#if BOUND_RENDERCOST 
    14251439                // the heuristics 
    14261440            const float sum = noValidSplit ?  
    14271441                        1e25f : volLeft * (float)nObjectsLeft + volRight * (float)nObjectsRight; 
    1428  
     1442#else 
     1443                const float rcLeft = max(nObjectsLeft, MIN_RENDERCOST); 
     1444                const float rcRight = max(nObjectsRight, MIN_RENDERCOST); 
     1445 
     1446                // the heuristics 
     1447            const float sum = noValidSplit ?  
     1448                        1e25f : volLeft * (float)rcLeft + volRight * (float)rcRight; 
     1449 
     1450#endif 
     1451                 
    14291452#ifdef GTP_DEBUG 
    14301453                if (printStats) 
     
    18421865float BvHierarchy::EvalAbsCost(const ObjectContainer &objects) 
    18431866{ 
     1867        float result; 
    18441868#if USE_BETTER_RENDERCOST_EST 
    18451869        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     
    18471871        for (oit = objects.begin(); oit != oit_end; ++ oit) 
    18481872        { 
    1849                 objRenderCost += ViewCellsManager::GetRendercost(*oit); 
     1873                result += ViewCellsManager::GetRendercost(*oit); 
    18501874        } 
    18511875#else 
    1852         return (float)objects.size(); 
     1876        result = (float)objects.size(); 
    18531877#endif 
     1878 
     1879#if BOUND_RENDERCOST 
     1880        result = max(result, MIN_RENDERCOST); 
     1881#endif 
     1882 
     1883        return result; 
    18541884} 
    18551885 
     
    18751905        /////////////// 
    18761906        //-- render cost heuristics 
     1907 
    18771908        const float objRenderCost = EvalAbsCost(objects); 
    18781909 
Note: See TracChangeset for help on using the changeset viewer.