Ignore:
Timestamp:
12/20/06 12:18:41 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
5 edited

Legend:

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

    r1912 r1913  
    374374} 
    375375                                                                         
     376float BvHierarchy::GetViewSpaceVolume() const 
     377{ 
     378        return mViewCellsManager->GetViewSpaceBox().GetVolume(); 
     379} 
     380 
    376381 
    377382BvhInterior *BvHierarchy::SubdivideNode(const BvhSubdivisionCandidate &sc, 
     
    444449    
    445450        //-- compute pvs correction to cope with undersampling 
    446         frontData.mPvs = CountViewCells(front->mObjects); 
    447         backData.mPvs = CountViewCells(back->mObjects); 
     451        frontData.mPvs = (float)CountViewCells(front->mObjects); 
     452        backData.mPvs = (float)CountViewCells(back->mObjects); 
    448453 
    449454        frontData.mCorrectedPvs = sc.mCorrectedFrontPvs; 
     
    452457        // compute probability of this node being visible,  
    453458        // i.e., volume of the view cells that can see this node 
    454         frontData.mRenderCost = EvalRenderCost(sc.mFrontObjects); 
    455         backData.mRenderCost = EvalRenderCost(sc.mBackObjects); 
    456  
    457         frontData.mCorrectedRenderCost = sc.mCorrectedFrontCost; 
    458         backData.mCorrectedRenderCost = sc.mCorrectedBackCost; 
     459        frontData.mVolume = EvalViewCellsVolume(sc.mFrontObjects) / GetViewSpaceVolume(); 
     460        backData.mVolume = EvalViewCellsVolume(sc.mBackObjects) / GetViewSpaceVolume(); 
     461 
     462        frontData.mCorrectedVolume = sc.mCorrectedFrontVolume; 
     463        backData.mCorrectedVolume = sc.mCorrectedBackVolume; 
    459464 
    460465    // how often was max cost ratio missed in this branch? 
     
    628633 
    629634        // avg contribution of a ray to a pvs 
    630         const float pvs = CountViewCells(leaf->mObjects); 
    631         const float avgRayContri = AvgRayContribution(pvs, tData.mNumRays); 
     635        const float pvs = (float)CountViewCells(leaf->mObjects); 
     636        const float avgRayContri = AvgRayContribution((int)pvs, tData.mNumRays); 
    632637 
    633638        cout << "bvh avg ray contri: " << avgRayContri << endl; 
     
    635640        splitCandidate.SetAvgRayContribution(avgRayContri); 
    636641 
    637         const float oldRenderCost = EvalRenderCost(leaf->mObjects); 
    638         const float oldRatio = oldRenderCost / tData.mRenderCost; 
    639         const float parentCost = tData.mCorrectedRenderCost * oldRatio; 
    640  
    641         cout << "old ratio: " << oldRatio << endl; 
     642        const float oldVolume = EvalViewCellsVolume(leaf->mObjects) / GetViewSpaceVolume(); 
     643        const float oldRatio = tData.mVolume > 0 ? oldVolume / tData.mVolume : 1; 
     644        const float parentVol = tData.mCorrectedVolume * oldRatio; 
     645 
    642646        // this leaf is a pvs entry in all the view cells 
    643647        // that see one of the objects. 
    644         const int frontCost = EvalRenderCost(splitCandidate.mFrontObjects); 
    645         const int backCost = EvalRenderCost(splitCandidate.mBackObjects); 
    646  
    647         cout <<"here8 ============ "<< parentCost << endl; 
    648         splitCandidate.mCorrectedFrontCost =  
    649                 mHierarchyManager->EvalCorrectedPvs(frontCost, parentCost, avgRayContri); 
    650  
    651         cout << "bvh front cost: " << frontCost << " corrected: " << splitCandidate.mCorrectedFrontCost << endl; 
     648        const float frontVol = EvalViewCellsVolume(splitCandidate.mFrontObjects) / GetViewSpaceVolume(); 
     649        const float backVol = EvalViewCellsVolume(splitCandidate.mBackObjects) / GetViewSpaceVolume(); 
     650 
     651        cout <<"here8 "<< parentVol << " " << " old ratio: " << oldRatio << " frointvol: " << frontVol << endl; 
     652        splitCandidate.mCorrectedFrontVolume =  
     653                mHierarchyManager->EvalCorrectedPvs(frontVol, parentVol, avgRayContri); 
     654 
     655        cout << "bvh front vol: " << frontVol << " corrected: " << splitCandidate.mCorrectedFrontVolume << endl; 
    652656        cout <<"here104 "<< endl; 
    653657 
    654         splitCandidate.mCorrectedBackCost =  
    655                 mHierarchyManager->EvalCorrectedPvs(backCost, parentCost, avgRayContri); 
    656          
    657         cout << "back cost: " << backCost << " corrected: " << splitCandidate.mCorrectedBackCost << endl; 
     658        splitCandidate.mCorrectedBackVolume =  
     659                mHierarchyManager->EvalCorrectedPvs(backVol, parentVol, avgRayContri); 
     660         
     661        cout << "back vol: " << backVol << " corrected: " << splitCandidate.mCorrectedBackVolume << endl; 
     662 
     663        const float relfrontCost = splitCandidate.mCorrectedFrontVolume *  
     664                EvalAbsCost(splitCandidate.mFrontObjects); 
     665        const float relBackCost =  splitCandidate.mCorrectedFrontVolume *  
     666                EvalAbsCost(splitCandidate.mBackObjects); 
     667        const float relParentCost = parentVol *  
     668                EvalAbsCost(leaf->mObjects); 
    658669 
    659670        // compute global decrease in render cost 
    660         const float newRenderCost =  
    661                 splitCandidate.mCorrectedFrontCost + splitCandidate.mCorrectedBackCost; 
    662         const float renderCostDecr = parentCost - newRenderCost; 
     671        const float newRenderCost = relfrontCost + relBackCost; 
     672        const float renderCostDecr = relParentCost - newRenderCost; 
    663673         
    664674        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
     
    676686        float priority = EvalPriority(splitCandidate,  
    677687                                                                  renderCostDecr, 
    678                                                                   oldRenderCost); 
     688                                                                  relParentCost); 
    679689 
    680690        // compute global decrease in render cost 
     
    686696                                                                        const float avgRayContri) const 
    687697{ 
    688         const int oldPvsSize = CountViewCells(splitCandidate.mParentData.mNode->mObjects); 
    689         const float oldPvsRatio = splitCandidate.mParentData.mPvs > 0 ? oldPvsSize / splitCandidate.mParentData.mPvs : 1; 
     698        const float oldPvsSize = (float)CountViewCells(splitCandidate.mParentData.mNode->mObjects); 
     699        const float oldPvsRatio = (splitCandidate.mParentData.mPvs > 0) ? oldPvsSize / splitCandidate.mParentData.mPvs : 1; 
    690700 
    691701        const float parentPvs = splitCandidate.mParentData.mCorrectedPvs * oldPvsRatio; 
     
    698708 
    699709        splitCandidate.mCorrectedFrontPvs =  
    700                 mHierarchyManager->EvalCorrectedPvs(frontViewCells, parentPvs, avgRayContri); 
     710                mHierarchyManager->EvalCorrectedPvs((float)frontViewCells, parentPvs, avgRayContri); 
    701711        splitCandidate.mCorrectedBackPvs = 
    702                 mHierarchyManager->EvalCorrectedPvs(backViewCells, parentPvs, avgRayContri); 
    703  
    704         return splitCandidate.mCorrectedFrontPvs + splitCandidate.mCorrectedBackPvs - parentPvs; 
     712                mHierarchyManager->EvalCorrectedPvs((float)backViewCells, parentPvs, avgRayContri); 
     713 
     714        return (int)(splitCandidate.mCorrectedFrontPvs + splitCandidate.mCorrectedBackPvs - parentPvs); 
    705715} 
    706716 
     
    17551765 
    17561766 
     1767float BvHierarchy::EvalProb(const ObjectContainer &objects) const 
     1768{        
     1769        /////////////// 
     1770        //-- render cost heuristics 
     1771 
     1772        const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 
     1773 
     1774        // probability that view point lies in a view cell which sees this node 
     1775        return EvalViewCellsVolume(objects) / viewSpaceVol; 
     1776} 
     1777 
     1778 
    17571779AxisAlignedBox3 BvHierarchy::EvalBoundingBox(const ObjectContainer &objects, 
    17581780                                                                                         const AxisAlignedBox3 *parentBox) const 
     
    21762198        BvhLeaf *bvhLeaf = dynamic_cast<BvhLeaf *>(mRoot); 
    21772199 
    2178         // multiply termination criterium for comparison, 
    2179         // so it can be set between zero and one and 
    2180         // no division is necessary during traversal 
    2181  
    2182 #if PROBABILIY_IS_BV_VOLUME 
    2183         mTermMinProbability *= mBoundingBox.GetVolume(); 
    2184         // probability that bounding volume is seen 
    2185         const float prop = GetBoundingBox().GetVolume(); 
    2186 #else 
    2187         mTermMinProbability *= mVspTree->GetBoundingBox().GetVolume(); 
    21882200        // probability that volume is "seen" from the view cells 
    2189         const float prop = EvalViewCellsVolume(objects); 
    2190 #endif 
     2201        const float prop = EvalViewCellsVolume(objects) / GetViewSpaceVolume(); 
    21912202 
    21922203        // only rays intersecting objects in node are interesting 
     
    22102221        mPvsEntries = CountViewCells(objects); 
    22112222 
    2212         oData.mCorrectedPvs = oData.mPvs = mPvsEntries; 
    2213         oData.mCorrectedRenderCost = oData.mRenderCost = mTotalCost; 
    2214         cout << "here52 " << oData.mCorrectedPvs << " " << oData.mRenderCost << " " << oData.mCorrectedRenderCost << endl; 
    2215  
     2223        oData.mCorrectedPvs = oData.mPvs = (float)mPvsEntries; 
     2224        oData.mCorrectedVolume = oData.mVolume = prop; 
     2225        cout << "here52 " << oData.mCorrectedPvs << " " << oData.mVolume << " " << oData.mCorrectedVolume  << endl; 
    22162226 
    22172227        BvhSubdivisionCandidate *oSubdivisionCandidate =  
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1912 r1913  
    387387                mCorrectedPvs(0), 
    388388                mPvs(0), 
    389                 mCorrectedRenderCost(0), 
    390                 mRenderCost(0) 
     389                mCorrectedVolume(0), 
     390                mVolume(0) 
    391391                { 
    392392                        for (int i = 0; i < 4; ++ i) 
     
    405405                mCorrectedPvs(0), 
    406406                mPvs(0), 
    407                 mCorrectedRenderCost(0), 
    408                 mRenderCost(v) 
     407                mCorrectedVolume(0), 
     408                mVolume(v) 
    409409                { 
    410410                        for (int i = 0; i < 4; ++ i) 
     
    425425                /// current depth 
    426426                int mDepth; 
    427                 /// the render cost of the node 
    428                 float mRenderCost; 
    429                 /// the corrected render cost; 
    430                 float mCorrectedRenderCost; 
     427                /// the volume of the node 
     428                float mVolume; 
     429                /// the corrected volume 
     430                float mCorrectedVolume; 
    431431                /// how often this branch has missed the max-cost ratio 
    432432                int mMaxCostMisses; 
     
    512512                float mCorrectedBackPvs; 
    513513 
    514                 float mCorrectedFrontCost; 
    515                 float mCorrectedBackCost; 
     514                float mCorrectedFrontVolume; 
     515                float mCorrectedBackVolume; 
    516516        }; 
    517517 
     
    597597        void SetViewCellsManager(ViewCellsManager *vcm); 
    598598 
     599        float GetViewSpaceVolume() const; 
    599600        /** Writes tree to output stream 
    600601        */ 
     
    640641 
    641642        static float EvalAbsCost(const ObjectContainer &objects); 
     643 
     644        float EvalProb(const ObjectContainer &objects) const; 
    642645 
    643646        void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1912 r1913  
    743743        // assume pvs sampled sufficiently => take child pvs 
    744744        if (avgRayContri < mMinAvgRayContri) 
     745        { 
     746                cout << "here4 child" << endl; 
    745747                return childPvs; 
    746  
     748        } 
    747749        // assume pvs not sampled sufficiently => take total pvs 
    748750        if (avgRayContri > mMaxAvgRayContri) 
     751        { 
     752                cout << "here9 parent" << endl; 
    749753                return totalPvs; 
     754        } 
    750755 
    751756        const float alpha = (mMaxAvgRayContri - avgRayContri) /  
    752757                                                (mMaxAvgRayContri - mMinAvgRayContri); 
    753758 
    754         cout << "here41 **************** " << alpha << " " << childPvs << " " << totalPvs << endl; 
    755  
    756         const float beta = (1.0f - alpha) * (totalPvs + childPvs) / totalPvs; 
    757  
    758         return childPvs + beta; 
     759        const float beta = (1.0f - alpha) * (totalPvs - childPvs); 
     760 
     761        cout << "alpha " << alpha << " beta: " << beta << " child: " << childPvs << " parent: " << totalPvs << endl; 
     762         
     763        const float newPvs = childPvs + beta; 
     764 
     765        if ((newPvs < childPvs - Limits::Small) || (newPvs > totalPvs + Limits::Small)) 
     766                cout << "Error!! " << newPvs << endl; 
     767        return newPvs; 
    759768} 
    760769 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1912 r1913  
    346346VspLeaf::VspLeaf():  
    347347mViewCell(NULL), mSubdivisionCandidate(NULL) 
    348 //, mPvs(NULL) 
    349348{ 
    350349} 
     
    380379VspLeaf::VspLeaf(VspInterior *parent):  
    381380VspNode(parent), mViewCell(NULL) 
    382 //, mPvs(NULL) 
    383381{} 
    384382 
     
    386384VspLeaf::VspLeaf(VspInterior *parent, ViewCellLeaf *viewCell):  
    387385VspNode(parent), mViewCell(viewCell) 
    388 //, mPvs(NULL) 
    389386{ 
    390387} 
     
    735732                         
    736733                mTotalCost -= sc->GetRenderCostDecrease(); 
    737                 mTotalPvsSize += (int)(tFrontData.mPvs + tBackData.mPvs - tData.mPvs); 
     734                //mTotalPvsSize += (int)(tFrontData.mPvs + tBackData.mPvs - tData.mPvs); 
    738735                mPvsEntries += sc->GetPvsEntriesIncr(); 
    739736 
     
    899896        } 
    900897 
    901         const float oldPvsRatio = oldPvsSize / splitCandidate.mParentData.mPvs; 
     898        const float oldPvsRatio = (splitCandidate.mParentData.mPvs > 0) ?  
     899                oldPvsSize / splitCandidate.mParentData.mPvs : 1; 
    902900        const float correctedOldPvs = splitCandidate.mParentData.mCorrectedPvs * oldPvsRatio; 
    903901 
    904902        cout <<"here102 "<< endl; 
    905903        cout << "old pvs ratio: " << oldPvsRatio << endl; 
    906         const float correctedFrontPvs =  
     904        splitCandidate.mCorrectedFrontPvs =  
    907905                mHierarchyManager->EvalCorrectedPvs(fPvsSize,  
    908906                                                                                        correctedOldPvs,  
    909907                                                                                        splitCandidate.GetAvgRayContribution()); 
    910908        cout <<"here103 "<< endl; 
    911         const float correctedBackPvs =  
     909        splitCandidate.mCorrectedBackPvs =  
    912910                mHierarchyManager->EvalCorrectedPvs(bPvsSize,  
    913911                                                                                        correctedOldPvs,  
     
    915913 
    916914         
    917         cout << "vsp front entries " << fPvsSize << " corrected: " << correctedFrontPvs << endl; 
    918         cout << "vsp back entries " << bPvsSize << " corrected: " << correctedBackPvs << endl; 
    919  
    920         return (int)(correctedFrontPvs + correctedBackPvs - correctedOldPvs); 
     915        cout << "vsp front entries " << fPvsSize << " corrected: " << splitCandidate.mCorrectedFrontPvs << endl; 
     916        cout << "vsp back entries " << bPvsSize << " corrected: " << splitCandidate.mCorrectedBackPvs << endl; 
     917 
     918        return (int)(splitCandidate.mCorrectedFrontPvs + splitCandidate.mCorrectedBackPvs - correctedOldPvs); 
    921919} 
    922920 
     
    961959 
    962960        //-- compute render cost 
    963         frontData.mRenderCost = (float)EvalRenderCost(*frontData.mRays); 
    964         backData.mRenderCost = (float)EvalRenderCost(*backData.mRays); 
    965          
    966         frontData.mCorrectedRenderCost = sc.mCorrectedFrontPvs; 
    967         backData.mCorrectedRenderCost = sc.mCorrectedBackPvs; 
     961        frontData.mRenderCost = (float)EvalPvsCost(*frontData.mRays); 
     962        backData.mRenderCost = (float)EvalPvsCost(*backData.mRays); 
     963         
     964        frontData.mCorrectedRenderCost = sc.mCorrectedFrontRenderCost; 
     965        backData.mCorrectedRenderCost = sc.mCorrectedBackRenderCost; 
    968966 
    969967        //////// 
     
    16051603        //-- evaluate render cost heuristics 
    16061604 
    1607         const float oldRenderCostRatio = tData.mPvs ? (totalPvs / tData.mPvs) : 1; 
    1608  
    1609         const float penaltyOld = tData.mCorrectedPvs * oldRenderCostRatio; 
    1610  
    1611         cout <<"here107 " << penaltyOld << endl; 
    1612         sc.mCorrectedFrontPvs = mHierarchyManager->EvalCorrectedPvs(pvsFront, penaltyOld, avgRayContri); 
    1613         cout <<"here108 " << tData.mCorrectedPvs << " " << oldRenderCostRatio << endl; 
    1614         sc.mCorrectedBackPvs = mHierarchyManager->EvalCorrectedPvs(pvsBack, penaltyOld, avgRayContri); 
    1615  
    1616         cout << "vsp front pvs " << pvsFront << " corrected: " << sc.mCorrectedFrontPvs << endl; 
    1617         cout << "vsp back pvs " << pvsBack << " corrected: " << sc.mCorrectedBackPvs << endl; 
     1605        const float oldRenderCostRatio = (tData.mRenderCost > 0)?  
     1606                (totalPvs / tData.mRenderCost) : 1; 
     1607 
     1608        const float penaltyOld = tData.mCorrectedRenderCost * oldRenderCostRatio; 
     1609 
     1610        cout <<"here107 old render cost ratio " << oldRenderCostRatio << " old cost: " << penaltyOld << endl; 
     1611        sc.mCorrectedFrontRenderCost = mHierarchyManager->EvalCorrectedPvs(pvsFront, penaltyOld, avgRayContri); 
     1612        cout <<"here108 " << tData.mCorrectedRenderCost << " " << oldRenderCostRatio << endl; 
     1613        sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs(pvsBack, penaltyOld, avgRayContri); 
     1614 
     1615        cout << "vsp front pvs " << pvsFront << " corrected: " << sc.mCorrectedFrontRenderCost << endl; 
     1616        cout << "vsp back render cost " << pvsBack << " corrected: " << sc.mCorrectedBackRenderCost << endl; 
    16181617 
    16191618        const float oldRenderCost = pOverall * penaltyOld; 
    1620         const float newRenderCost = sc.mCorrectedFrontPvs * pFront + sc.mCorrectedBackPvs * pBack; 
     1619        const float newRenderCost = sc.mCorrectedFrontRenderCost * pFront +  
     1620                                                                sc.mCorrectedFrontRenderCost * pBack; 
    16211621 
    16221622        // we also return the old render cost 
     
    29342934        VspTraversalData vData(leaf, 0, &rays, pvsCost, prop, mBoundingBox); 
    29352935 
    2936  
    29372936#if WORK_WITH_VIEWCELL_PVS 
    29382937        // add first view cell to all the objects view cell pvs 
     
    29472946#endif 
    29482947 
    2949         mTotalCost = vData.mCorrectedPvs = pvsCost; 
    2950         mPvsEntries = EvalPvsEntriesSize(rays); 
     2948        mTotalCost = vData.mCorrectedRenderCost = vData.mRenderCost = pvsCost; 
     2949        mPvsEntries = vData.mCorrectedPvs = vData.mPvs = EvalPvsEntriesSize(rays); 
    29512950 
    29522951        ////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1912 r1913  
    531531                float mCorrectedFrontRenderCost; 
    532532                float mCorrectedBackRenderCost; 
     533                float mCorrectedFrontVolume; 
     534                float mCorrectedBackVolume; 
    533535        }; 
    534536 
Note: See TracChangeset for help on using the changeset viewer.