Changeset 2347


Ignore:
Timestamp:
05/03/07 18:46:37 (17 years ago)
Author:
mattausch
Message:

debug version

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
11 edited

Legend:

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

    r2342 r2347  
    5353/*              class BvhNode implementation                   */ 
    5454/***************************************************************/ 
     55 
    5556 
    5657BvhNode::BvhNode():  
     
    394395        CollectViewCells(sc.mSampledBackObjects, backViewCells, false, false); 
    395396 
    396         const float frontTri = (float)sc.mFrontObjects.size(); 
    397         const float backTri = (float)sc.mBackObjects.size(); 
    398         const float totalTri = (float)(*sc.mParentData.mSortedObjects[0]).size(); 
     397        const int frontTri = (int)sc.mFrontObjects.size(); 
     398        const int backTri = (int)sc.mBackObjects.size(); 
     399        const int totalTri = (int)(*sc.mParentData.mSortedObjects[0]).size(); 
     400 
     401        //cout << "totalTri: " << totalTri << " f: " << frontTri << " back: " << backTri << endl; 
    399402 
    400403        ViewCell::NewMail(3); 
     
    405408        for (fit = frontViewCells.begin(); fit != fit_end; ++ fit) 
    406409        { 
    407                 ViewCell *vc = *fit; 
    408                 vc->Mail(0); 
     410                (*fit)->Mail(0); 
    409411        } 
    410412 
     
    422424        } 
    423425 
     426        // traverse through view cells and compute changes 
    424427        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    425428         
     
    428431                ViewCell *vc = *vit; 
    429432 
    430                 float vcTri; 
     433                int vcTri; 
    431434                int vcObj; 
    432435 
    433                 float oldVcTri = vc->GetTrianglesInPvs(); 
     436                int oldVcTri = (int)vc->GetTrianglesInPvs(); 
    434437                int oldVcObj = vc->GetEntriesInPvs(); 
    435438 
     
    445448                else if (vc->Mailed(1)) 
    446449                { 
    447                         vcTri = oldVcTri - totalTri + backTri;  
     450                        vcTri = oldVcTri + backTri - totalTri;  
    448451                        vcObj = oldVcObj;    
    449452                } 
    450453                else // front object 
    451454                { 
    452                         vcTri = oldVcTri - totalTri + frontTri;  
     455                        vcTri = oldVcTri + frontTri - totalTri;  
    453456                        vcObj = oldVcObj; 
    454457                } 
    455458 
    456                 vc->SetTrianglesInPvs(vcTri); 
     459                vc->SetTrianglesInPvs((float)vcTri); 
    457460                vc->SetEntriesInPvs(vcObj); 
    458461 
    459462                //cout << "old pvs tri: " << oldVcTri << " new: " << vcTri << endl; 
    460                 //cout << "old pvs obj: " << oldVcObj << " new: " << vcObj<< endl; 
    461         } 
    462 } 
     463                //cout << "old pvs obj: " << oldVcObj << " new: " << vcObj << endl; 
     464        } 
     465} 
     466 
     467 
     468void BvHierarchy::TestEvaluation(const BvhSubdivisionCandidate &sc) 
     469{ 
     470        ViewCellContainer viewCells, frontViewCells, backViewCells; 
     471         
     472        CollectViewCells(*sc.mParentData.mSampledObjects, viewCells, false, false); 
     473 
     474        // traverse through view cells and compute changes 
     475        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     476         
     477        for (vit = viewCells.begin(); vit != viewCells.end(); ++ vit) 
     478        { 
     479                ViewCell *vc = *vit; 
     480 
     481                int vcTri; 
     482                int vcObj; 
     483 
     484                int oldVcTri = (int)vc->GetTrianglesInPvs(); 
     485                int oldVcObj = vc->GetEntriesInPvs(); 
     486 
     487                int nTriangles = 0; 
     488                int nObjects = 0; 
     489 
     490                Intersectable::NewMail(); 
     491 
     492                VspViewCell *vspVc = static_cast<VspViewCell *>(vc); 
     493                VssRayContainer::const_iterator vit, vit_end = vspVc->mLeaves[0]->mVssRays.end(); 
     494 
     495                for (vit = vspVc->mLeaves[0]->mVssRays.begin(); vit != vit_end; ++ vit) 
     496                { 
     497                        VssRay *ray = *vit; 
     498                         
     499                        BvhLeaf *obj = ray->mTerminationObject->mBvhLeaf; 
     500                 
     501                        if (!obj->Mailed()) 
     502                        { 
     503                                obj->Mail(); 
     504 
     505                                nTriangles += (int)obj->mObjects.size(); 
     506                                nObjects ++; 
     507                        } 
     508 
     509                        if (ray->mOriginObject) 
     510                        { 
     511                                obj = ray->mOriginObject->mBvhLeaf; 
     512                         
     513                                if (!obj->Mailed()) 
     514                                { 
     515                                        obj->Mail(); 
     516                                        nTriangles += (int)obj->mObjects.size(); 
     517                                        nObjects ++; 
     518                                } 
     519                        } 
     520                } 
     521 
     522                cout << "old pvs tri: " << oldVcTri << " real: " << nTriangles << endl; 
     523                cout << "old pvs obj: " << oldVcObj << " real: " << nObjects << endl; 
     524        } 
     525} 
     526 
    463527 
    464528 
     
    467531                                                                                BvhTraversalData &backData) 
    468532{  
     533        //TestEvaluation(sc); 
     534 
    469535        // fill view cells cache 
    470536        mNodeTimer.Entry(); 
     
    627693                AssociateViewCellsWithObjects(*tData.mSampledObjects); 
    628694 
     695                EvalSubdivisionCandidate2(*frontCandidate, true, false); 
     696                cout << "\nfc2: " << frontCandidate->GetPriority() << endl; 
    629697                EvalSubdivisionCandidate(*frontCandidate, true, false); 
     698                cout << "fc1: " << frontCandidate->GetPriority() << endl; 
    630699                EvalSubdivisionCandidate(*backCandidate, true, false); 
    631700 
     
    680749        BvhLeaf *leaf = splitCandidate.mParentData.mNode; 
    681750 
    682         // surface area heuristics is used when there is  
    683         // no view space subdivision available.  
    684         // In order to have some prioritized traversal,  
    685         // we use this formula instead 
     751        // use urface area heuristics if no view space subdivision available.  
     752        // For prioritized traversal we use this formula instead 
    686753        if (mHierarchyManager->GetViewSpaceSubdivisionType() ==  
    687754                HierarchyManager::NO_VIEWSPACE_SUBDIV) 
     
    693760                // take render cost of node into account  
    694761                // otherwise danger of being stuck in a local minimum! 
    695                 const float factor = mRenderCostDecreaseWeight; 
    696  
    697                 priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost; 
     762                priority = mRenderCostDecreaseWeight          * renderCostDecr +  
     763                               (1.0f - mRenderCostDecreaseWeight) * oldRenderCost; 
    698764                 
    699765                if (mHierarchyManager->mConsiderMemory) 
     
    723789 
    724790 
    725 void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate,  
     791void BvHierarchy::EvalSubdivisionCandidate2(BvhSubdivisionCandidate &splitCandidate,  
    726792                                                                                   const bool computeSplitPlane, 
    727793                                                                                   const bool preprocessViewCells) 
     
    778844        mEvalTimer.Entry(); 
    779845 
     846        // mark view cells according to what part of the split they see 
     847        // and compute volume 
    780848        ViewCellContainer viewCells, frontViewCells, backViewCells; 
    781849         
     
    784852        CollectViewCells(splitCandidate.mSampledBackObjects, backViewCells, false, false); 
    785853 
    786         // compute view cells seen from front and back side of the split 
    787854        float volFront = 0, volBack = 0, parentVol = 0; 
    788855 
     
    810877                if (vc->Mailed(0)) 
    811878                { 
    812                         // view cell sees front AND on back side 
     879                        // view cell sees front AND back object 
    813880                        ++ frontAndBackViewCells; 
    814881                        vc->Mail(2); 
     
    823890        } 
    824891 
    825          
     892        //cout << "pvol: " << parentVol << " front: " << volFront << " back: " << volBack << " diff: " <<  parentVol - volFront - volBack << endl; 
     893         
     894 
    826895        ///////////////////// 
    827896        //-- this bvh node is a pvs entry in all the view cells that see one of the objects. 
     
    829898        // pvs size induced by this bvh node is #view cells 
    830899        const float pvs = (float)viewCells.size(); 
     900         
     901        // for low #rays per object => the result is influenced by undersampling 
    831902        const float avgRaysPerObject = AvgRaysPerObject((int)pvs, tData.mNumRays); 
    832  
    833         // for low #rays per object => the result is influenced by undersampling 
    834903        splitCandidate.SetAvgRaysPerObject(avgRaysPerObject); 
     904 
    835905        const float viewSpaceVol = GetViewSpaceVolume(); 
    836906 
     
    841911        splitCandidate.mNumBackViewCells = (int)backViewCells.size(); 
    842912 
    843         // currently not working!! 
    844         // todo matt: fix this to cope with undersampling for new evaluation method 
     913         
     914        //////////////////////// 
     915        // warning: currently not working for new evaluation method! 
     916 
     917        // todo matt: fix this to cope with undersampling 
    845918        splitCandidate.mCorrectedFrontVolume =  
    846919                mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells,  
     
    858931        float newRenderCost = 0, oldRenderCost = 0; 
    859932 
    860         const float frontTri = (float)splitCandidate.mFrontObjects.size(); 
    861         const float backTri = (float)splitCandidate.mBackObjects.size(); 
    862         // total #triangles in parent 
    863         const float totalTri = (float)(*tData.mSortedObjects[0]).size(); 
    864  
    865  
    866         // compute render cost decrease in the seen view cells 
     933        // total #triangles in parent node 
     934        const int totalTri = (int)(*tData.mSortedObjects[0]).size(); 
     935        const int frontTri = (int)splitCandidate.mFrontObjects.size(); 
     936        const int backTri = (int)splitCandidate.mBackObjects.size(); 
     937         
     938        if (totalTri - frontTri - backTri != 0) 
     939                cout << "big error!!!" << endl; 
     940 
     941        // compute render cost decrease in the view cells which can see the object 
    867942        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    868943         
     
    871946                ViewCell *vc = *vit; 
    872947 
     948                const int oldVcTri = (int)vc->GetTrianglesInPvs(); 
     949                const int oldVcObj = vc->GetEntriesInPvs(); 
     950 
    873951                // triangles in this view cell 
    874                 float vcTri; 
     952                int vcTri; 
    875953                // #entries in this view cell 
    876954                int vcObj; 
    877  
    878                 float oldVcTri = vc->GetTrianglesInPvs(); 
    879                 int oldVcObj = vc->GetEntriesInPvs(); 
    880  
     955                 
    881956                // both nodes in this view cell 
    882957                if (vc->Mailed(2)) 
     
    888963                else if (vc->Mailed(1)) 
    889964                { 
     965                        // only back node in this view cell: #triangles is decreasing 
     966                        vcTri = oldVcTri + backTri - totalTri;  
     967                        vcObj = oldVcObj;    
     968                } 
     969                else // (vc->Mailed(0)) 
     970                { 
    890971                        // only front node in this view cell: #triangles is decreasing 
    891                         vcTri = oldVcTri - totalTri + backTri;  
    892                         vcObj = oldVcObj;    
    893                 } 
    894                 else // (vc->Mailed(0)) 
    895                 { 
    896                         // // only back node in this view cell: #triangles is decreasing 
    897                         vcTri = oldVcTri - totalTri + frontTri;  
     972                        vcTri = oldVcTri + frontTri - totalTri;  
    898973                        vcObj = oldVcObj; 
    899974                } 
    900975 
    901                 oldRenderCost += mViewCellsManager->ComputeRenderCost((int)oldVcTri, (int)oldVcObj) * vc->GetVolume()  / viewSpaceVol; 
    902                 newRenderCost += mViewCellsManager->ComputeRenderCost((int)vcTri, (int)vcObj) * vc->GetVolume() / viewSpaceVol; 
     976                const float oldRc = mViewCellsManager->ComputeRenderCost(oldVcTri, oldVcObj); 
     977                const float newRc = mViewCellsManager->ComputeRenderCost(vcTri, vcObj); 
     978 
     979                // compute weighted render cost  
     980                oldRenderCost += oldRc * vc->GetVolume() / viewSpaceVol; 
     981                newRenderCost += newRc * vc->GetVolume() / viewSpaceVol; 
    903982                //cout << "old rc=" << oldRenderCost << " new rc " << newRenderCost << endl; 
    904983        } 
    905984 
     985 
     986        const float dummyFrontVol = EvalViewCellsVolume(splitCandidate.mSampledFrontObjects) / viewSpaceVol; 
     987        const float dummyBackVol = EvalViewCellsVolume(splitCandidate.mSampledBackObjects) / viewSpaceVol; 
     988        const float dummyParentVol = EvalViewCellsVolume(leaf->mObjects) / viewSpaceVol; 
     989 
     990        const int dummyNumFrontViewCells = CountViewCells(splitCandidate.mSampledFrontObjects); 
     991        const int dummyNumBackViewCells = CountViewCells(splitCandidate.mSampledBackObjects); 
     992        const int dummyPvs = CountViewCells(*tData.mSampledObjects); 
     993         
     994        const int dummyPvsEntriesIncr = - dummyPvs + dummyNumFrontViewCells + dummyNumBackViewCells; 
     995 
     996        const float relfrontCost = dummyFrontVol * (float)splitCandidate.mFrontObjects.size(); 
     997        const float relBackCost =  dummyBackVol * (float)splitCandidate.mBackObjects.size(); 
     998        const float relParentCost = dummyParentVol * (float)leaf->mObjects.size(); 
     999 
    9061000        // compute global decrease in render cost 
    907         const float renderCostDecr = (oldRenderCost - newRenderCost); 
    908  
    909         // for each view cell seen from front and back there is a new entry 
    910         const int pvsEntriesIncr = frontAndBackViewCells; 
    911  
     1001        const float dummyNewRenderCost = relfrontCost + relBackCost; 
     1002        const float dummyRenderCostDecr = relParentCost - dummyNewRenderCost; 
     1003 
     1004 
     1005 
     1006        // compute global decrease in render cost 
     1007        const float renderCostDecr = oldRenderCost - newRenderCost; 
     1008 
     1009        // for each view cell seeing both front and back object there is a new pvs entry 
     1010        splitCandidate.SetPvsEntriesIncr(frontAndBackViewCells); 
    9121011        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
     1012         
     1013        float pseudoOldRenderCost = parentVol * (float)leaf->mObjects.size() / viewSpaceVol; 
     1014 
     1015        //cout << "cor. entries: " << dummyPvsEntriesIncr << " entries: " << frontAndBackViewCells << endl; 
     1016        cout << "\nv1: " << renderCostDecr << " " << pseudoOldRenderCost << " " << newRenderCost << endl; 
     1017        cout << "v2: " << dummyRenderCostDecr << " " << relParentCost << " " << dummyNewRenderCost << endl; 
     1018 
     1019        // at last computed priority based on render cost reduction / memory increase 
     1020        const float priority = EvalPriority(splitCandidate, renderCostDecr,     pseudoOldRenderCost); 
     1021        cout << "\nfc0: " << priority << endl; 
     1022        const float priority2 = EvalPriority(splitCandidate, dummyRenderCostDecr, relParentCost); 
     1023        splitCandidate.SetPriority(priority2); 
     1024 
     1025#if STORE_VIEWCELLS_WITH_BVH 
     1026        if (preprocessViewCells) 
     1027                ReleaseViewCells(*splitCandidate.mParentData.mSampledObjects); 
     1028#endif 
     1029 
     1030        mEvalTimer.Exit(); 
     1031} 
     1032 
     1033 
     1034void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate,  
     1035                                                                                   const bool computeSplitPlane, 
     1036                                                                                   const bool preprocessViewCells) 
     1037{ 
     1038        mPlaneTimer.Entry(); 
     1039 
     1040#if STORE_VIEWCELLS_WITH_BVH 
     1041        if (preprocessViewCells) // fill view cells cache 
     1042                AssociateViewCellsWithObjects(*splitCandidate.mParentData.mSampledObjects); 
     1043#endif 
     1044 
     1045        if (computeSplitPlane) 
     1046        { 
     1047                splitCandidate.mFrontObjects.clear(); 
     1048                splitCandidate.mBackObjects.clear(); 
     1049                splitCandidate.mSampledFrontObjects.clear(); 
     1050                splitCandidate.mSampledBackObjects.clear(); 
     1051 
     1052                const bool sufficientSamples =  
     1053                        splitCandidate.mParentData.mNumRays > mMinRaysForVisibility; 
     1054 
     1055                //if (!sufficientSamples) cout << splitCandidate.mParentData.mNumRays << " "; 
     1056 
     1057                const bool useVisibiliyBasedHeuristics =  
     1058                                        !mUseSah && 
     1059                                        (mHierarchyManager->GetViewSpaceSubdivisionType() ==  
     1060                                        HierarchyManager::KD_BASED_VIEWSPACE_SUBDIV) && 
     1061                                        sufficientSamples; 
     1062 
     1063                // compute best object partition 
     1064                const float ratio =     SelectObjectPartition(splitCandidate.mParentData,  
     1065                                                                                                  splitCandidate.mFrontObjects,  
     1066                                                                                                  splitCandidate.mBackObjects, 
     1067                                                                                                  useVisibiliyBasedHeuristics); 
     1068         
     1069                // cost ratio violated? 
     1070                const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 
     1071                const int previousMisses = splitCandidate.mParentData.mMaxCostMisses; 
     1072 
     1073                splitCandidate.SetMaxCostMisses(maxCostRatioViolated ?  
     1074                                                                                previousMisses + 1 : previousMisses); 
     1075 
     1076                StoreSampledObjects(splitCandidate.mSampledFrontObjects, splitCandidate.mFrontObjects); 
     1077                StoreSampledObjects(splitCandidate.mSampledBackObjects, splitCandidate.mBackObjects); 
     1078        } 
     1079 
     1080        mPlaneTimer.Exit(); 
     1081 
     1082        mEvalTimer.Entry(); 
     1083 
     1084        const BvhTraversalData &tData = splitCandidate.mParentData; 
     1085        BvhLeaf *leaf = tData.mNode; 
     1086 
     1087        // avg contribution of a ray to a pvs 
     1088        const float pvs = (float)CountViewCells(*tData.mSampledObjects); 
     1089        //const float avgRayContri = AvgRayContribution((int)pvs, tData.mNumRays); 
     1090        const float avgRaysPerObject = AvgRaysPerObject((int)pvs, tData.mNumRays); 
     1091 
     1092        // high avg ray contri, the result is influenced by undersampling 
     1093        splitCandidate.SetAvgRaysPerObject(avgRaysPerObject); 
     1094        const float viewSpaceVol = GetViewSpaceVolume(); 
     1095 
     1096        const float oldVolume = EvalViewCellsVolume(*tData.mSampledObjects) / viewSpaceVol; 
     1097        const float oldRatio = (tData.mVolume > 0) ? oldVolume / tData.mVolume : 1; 
     1098        const float parentVol = tData.mCorrectedVolume * oldRatio; 
     1099 
     1100        // this leaf is a pvs entry in all the view cells 
     1101        // that see one of the objects. 
     1102        splitCandidate.mVolumeFrontViewCells = EvalViewCellsVolume(splitCandidate.mSampledFrontObjects) / viewSpaceVol; 
     1103        splitCandidate.mVolumeBackViewCells = EvalViewCellsVolume(splitCandidate.mSampledBackObjects) / viewSpaceVol; 
     1104 
     1105        splitCandidate.mNumFrontViewCells = CountViewCells(splitCandidate.mSampledFrontObjects); 
     1106        splitCandidate.mNumBackViewCells = CountViewCells(splitCandidate.mSampledBackObjects); 
     1107 
     1108        splitCandidate.mCorrectedFrontVolume =  
     1109                mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells, parentVol, avgRaysPerObject); 
     1110         
     1111        splitCandidate.mCorrectedBackVolume =  
     1112                mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeBackViewCells, parentVol, avgRaysPerObject); 
     1113 
     1114#if 0 
     1115        const float relfrontCost = splitCandidate.mCorrectedFrontVolume * splitCandidate.mFrontObjects.size(); 
     1116        const float relBackCost =  splitCandidate.mCorrectedBackVolume * splitCandidate.mBackObjects.size(); 
     1117        const float relParentCost = parentVol * leaf->mObjects.size(); 
     1118#else 
     1119        const float relfrontCost = splitCandidate.mVolumeFrontViewCells * splitCandidate.mFrontObjects.size(); 
     1120        const float relBackCost =  splitCandidate.mVolumeBackViewCells * splitCandidate.mBackObjects.size(); 
     1121        const float relParentCost = oldVolume * leaf->mObjects.size(); 
     1122#endif 
     1123        // compute global decrease in render cost 
     1124        const float newRenderCost = relfrontCost + relBackCost; 
     1125        const float renderCostDecr = relParentCost - newRenderCost; 
     1126         
     1127        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
     1128 
     1129        // increase in pvs entries 
     1130        const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate,  
     1131                                                                                                  avgRaysPerObject,  
     1132                                                                                                  (int)pvs,  
     1133                                                                                                  splitCandidate.mNumFrontViewCells,  
     1134                                                                                                  splitCandidate.mNumBackViewCells); 
     1135 
    9131136        splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 
    9141137 
    915         //cout << "bvh render cost decrease=" << renderCostDecr << endl; 
    916  
    917         // at last computed priority based on render cost reduction / memory increase 
    918         const float priority = EvalPriority(splitCandidate, renderCostDecr,     oldRenderCost); 
     1138#ifdef GTP_DEBUG 
     1139        Debug << "old render cost: " << oldRenderCost << endl; 
     1140        Debug << "new render cost: " << newRenderCost << endl; 
     1141        Debug << "render cost decrease: " << renderCostDecr << endl; 
     1142#endif 
     1143 
     1144        float priority = EvalPriority(splitCandidate,  
     1145                                                                  renderCostDecr, 
     1146                                                                  relParentCost); 
     1147 
     1148        // compute global decrease in render cost 
    9191149        splitCandidate.SetPriority(priority); 
    9201150 
     
    9481178                mHierarchyManager->EvalCorrectedPvs((float)backViewCells, parentPvs, avgRaysPerObjects); 
    9491179 
    950         if (0) 
    951         cout << "bvh pvs" 
    952                  << " avg ray contri: " << avgRaysPerObjects << " ratio: " << oldPvsRatio  
    953                  << " parent: " << parentPvs << " " << " old vol: " << oldPvsSize 
    954                  << " frontpvs: " << frontViewCells << " corr. " << splitCandidate.mCorrectedFrontPvs  
    955                  << " backpvs: " << frontViewCells << " corr. " << splitCandidate.mCorrectedBackPvs << endl; 
     1180#if GTP_DEBUG 
     1181        Debug << "bvh node pvs" 
     1182                  << " avg ray contri: " << avgRaysPerObjects << " ratio: " << oldPvsRatio  
     1183                  << " parent: " << parentPvs << " " << " old vol: " << oldPvsSize 
     1184                  << " frontpvs: " << frontViewCells << " corr. " << splitCandidate.mCorrectedFrontPvs  
     1185                  << " backpvs: " << frontViewCells << " corr. " << splitCandidate.mCorrectedBackPvs << endl; 
     1186#endif 
    9561187 
    9571188        return (int)(splitCandidate.mCorrectedFrontPvs + splitCandidate.mCorrectedBackPvs - parentPvs); 
     
    9711202        if (terminationCriteriaMet) 
    9721203        { 
    973                 cout << "bvh local termination criteria met:" << endl; 
    974                 cout << "objects: " << (int)tData.mNode->mObjects.size() << " (" << mTermMinObjects << ")" << endl; 
     1204                Debug << "bvh local termination criteria met:" << endl; 
     1205                Debug << "objects: " << (int)tData.mNode->mObjects.size() << " (" << mTermMinObjects << ")" << endl; 
    9751206        } 
    9761207#endif 
     
    10111242        ++ mCreatedLeaves; 
    10121243 
    1013          
    1014         /*if (data.mProbability <= mTermMinProbability) 
    1015         { 
    1016                 ++ mBvhStats.minProbabilityNodes; 
    1017         }*/ 
    1018  
    1019         //////////////////////////////////////////// 
     1244        //////////////// 
    10201245        // depth related stuff 
    10211246 
     
    10341259 
    10351260 
    1036         //////////////////////////////////////////// 
     1261        ////////////////////// 
    10371262        // objects related stuff 
    10381263 
     
    10821307 
    10831308#ifdef _DEBUG 
    1084         cout << "depth: " << data.mDepth << " objects: " << (int)leaf->mObjects.size()  
    1085                  << " rays: " << data.mNumRays << " rays / objects "  
    1086                  << (float)data.mNumRays / (float)leaf->mObjects.size() << endl; 
     1309        Debug << "depth: " << data.mDepth << " objects: " << (int)leaf->mObjects.size()  
     1310                  << " rays: " << data.mNumRays << " rays / objects "  
     1311                  << (float)data.mNumRays / (float)leaf->mObjects.size() << endl; 
    10871312#endif 
    10881313} 
     
    11281353 
    11291354        const float oldRenderCost = (float)tData.mNode->mObjects.size() * parentBox.SurfaceArea(); 
    1130         const float newRenderCost = (float)objectsFront.size() * fbox.SurfaceArea() +  (float)objectsBack.size() * bbox.SurfaceArea(); 
     1355        const float newRenderCost = (float)objectsFront.size() * fbox.SurfaceArea() + (float)objectsBack.size() * bbox.SurfaceArea(); 
    11311356 
    11321357        const float ratio = newRenderCost / oldRenderCost; 
     
    13011526   
    13021527#ifdef GTP_DEBUG 
    1303         cout << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of "  
    1304                  << (int)tData.mNode->mObjects.size() << ")\t area=("  
    1305                  << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl 
    1306                  << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl; 
     1528        Debug << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of "  
     1529                  << (int)tData.mNode->mObjects.size() << ")\t area=("  
     1530                  << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl 
     1531                  << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl; 
    13071532#endif 
    13081533 
     
    14351660   
    14361661#ifdef GTP_DEBUG 
    1437         cout << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of "  
    1438                  << (int)tData.mNode->mObjects.size() << ")\t area=("  
    1439                  << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl 
    1440                  << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl; 
     1662        Debug << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of "  
     1663                  << (int)tData.mNode->mObjects.size() << ")\t area=("  
     1664                  << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl 
     1665                  << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl; 
    14411666#endif 
    14421667 
     
    14951720                                                                                   ObjectContainer &objectsBack) 
    14961721{ 
    1497         ///////////////////////////////////////////// 
    1498         //-- go through the lists, count the number of objects  
    1499         //-- left and right and evaluate the cost funcion 
     1722        //////// 
     1723        // traverse split candidates, count the number of objects  
     1724        // left and right and evaluate the cost funcion 
    15001725 
    15011726        // prepare the heuristics, set mailboxes and counters 
     
    16031828 
    16041829#ifdef GTP_DEBUG 
    1605         Debug << "\n§§§§ bvh eval const decrease §§§§" << endl 
     1830        Debug << "\neval bvh split cost decrease" << endl 
    16061831                  << "back pvs: " << (int)objectsBack.size() << " front pvs: "  
    16071832                  << (int)objectsFront.size() << " total pvs: " << nTotalObjects << endl  
     
    17131938} 
    17141939 
     1940 
     1941 
    17151942/////////////////////////////////////////////////////////// 
    17161943 
    17171944 
    1718 void BvHierarchy::EvalHeuristicsContribution(Intersectable *obj, 
     1945void BvHierarchy::EvalHeuristicsContribution(Intersectable *obj,  
    17191946                                                                                         float &volLeft,  
    17201947                                                                                         float &volRight) 
     
    18042031        } 
    18052032 
    1806         // if #rays high consider only use a subset of the rays for  
     2033        // if #rays high, consider only use a subset of the rays for  
    18072034        // visibility based heuristics 
    18082035        VssRay::NewMail(); 
    18092036 
    1810         /*if ((mMaxTests < tData.mNumRays) && mUseCostHeuristics && useVisibilityBasedHeuristics) 
    1811         { 
    1812                 VssRayContainer rays; 
    1813  
    1814                 // maximal 2 objects share the same ray 
    1815                 rays.reserve(tData.mNumRays * 2); 
    1816                 CollectRays(tData.mNode->mObjects, rays); 
    1817  
    1818                 const float prop = (float)mMaxTests / (float)rays.size(); 
    1819  
    1820                 VssRayContainer::const_iterator rit, rit_end = rays.end(); 
    1821  
    1822                 // mail rays which will not be considered 
    1823                 for (rit = rays.begin(); rit != rit_end; ++ rit) 
    1824                 { 
    1825                         if (Random(1.0f) > prop) 
    1826                         { 
    1827                                 (*rit)->Mail(); 
    1828                         } 
    1829                 }                
    1830         }*/ 
    18312037 
    18322038        //////////////////////////////////// 
     
    19922198        //-- surface area heuristics 
    19932199 
    1994         // eraly exit 
    1995         //if (leaf->mObjects.empty())   return 0.0f; 
    1996  
    19972200        const AxisAlignedBox3 box = GetBoundingBox(leaf); 
    19982201        const float area = box.SurfaceArea(); 
     
    28543057                backData.mSortedObjects[i] = new ObjectContainer(); 
    28553058 
    2856                 frontData.mSortedObjects[i]->reserve((int)sc.mFrontObjects.size()); 
    2857                 backData.mSortedObjects[i]->reserve((int)sc.mBackObjects.size()); 
     3059                frontData.mSortedObjects[i]->reserve(sc.mFrontObjects.size()); 
     3060                backData.mSortedObjects[i]->reserve(sc.mBackObjects.size()); 
    28583061 
    28593062                ObjectContainer::const_iterator oit, oit_end = sc.mParentData.mSortedObjects[i]->end(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r2332 r2347  
    579579                                                                  const bool preprocessViewCells); 
    580580 
     581        void EvalSubdivisionCandidate2(BvhSubdivisionCandidate &splitData, 
     582                                                                  const bool computeSplitPlane, 
     583                                                                  const bool preprocessViewCells); 
     584 
    581585        /** Returns vector of leaves. 
    582586        */ 
     
    990994 
    991995        void UpdateViewCells(const BvhSubdivisionCandidate &sc); 
     996        void TestEvaluation(const BvhSubdivisionCandidate &sc); 
    992997 
    993998 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r2342 r2347  
    4949#define USE_AVGRAYCONTRI 0 
    5050 
    51 #define BOUND_RENDERCOST 0 
    52  
    53 static const float MIN_RENDERCOST = 100.0f; 
    54  
    5551 
    5652 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.cpp

    r2332 r2347  
    109109 
    110110 
    111  
    112  
    113111void GetRayInfoSets(const RayInfoContainer &sourceRays, 
    114112                    const int maxSize, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.h

    r2332 r2347  
    120120} 
    121121 
     122 
     123 
    122124#if USE_FIXEDPOINT_T 
    123125        float RayInfo::GetMinT () const  
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj

    r2342 r2347  
    226226                                Name="VCLinkerTool" 
    227227                                AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib" 
    228                                 OutputFile="../bin/release/Preprocessor.exe" 
     228                                OutputFile="../bin/release/Preprocessor2.exe" 
    229229                                LinkIncremental="1" 
    230230                                AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.cpp

    r2332 r2347  
    6060 * Programmer. 
    6161 */ 
    62 #define TRACKBALLSIZE  (0.8) 
     62#define TRACKBALLSIZE  (0.8f) 
    6363 
    6464/* 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2342 r2347  
    17081708 
    17091709 
    1710  
    17111710float ViewCellsManager::ComputeRenderCost(const int tri, const int obj) //const 
    17121711{ 
     1712        return (float)tri; 
    17131713        return max((float)tri * mTriangleWeight, (float)obj * mObjectWeight); 
    17141714} 
     
    20872087                        sum += ComputeSampleContribution(*(*it), addContributions, storeViewCells, useHitObjects); 
    20882088                } 
    2089  
    20902089        } 
    20912090 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r2283 r2347  
    10661066 
    10671067        // max cost threshold violated? 
    1068         splitCandidate.mMaxCostMisses = costRatioViolated ?  
    1069                 splitCandidate.mParentData.mMaxCostMisses :  
    1070                 splitCandidate.mParentData.mMaxCostMisses + 1; 
     1068        splitCandidate.mMaxCostMisses = costRatioViolated ? splitCandidate.mParentData.mMaxCostMisses :  
     1069                                                            splitCandidate.mParentData.mMaxCostMisses + 1; 
    10711070 
    10721071        float oldRenderCost; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r2342 r2347  
    3131#define HACK_PERFORMANCE 1 
    3232 
     33#define HAS_TO_BE_REDONE 0 
    3334 
    3435///////////// 
     
    258259{ 
    259260        VssRayContainer::const_iterator vit, vit_end = mVssRays.end(); 
     261 
    260262        for (vit = mVssRays.begin(); vit != vit_end; ++ vit) 
    261263        { 
     
    266268                        delete ray; 
    267269        } 
    268         //CLEAR_CONTAINER(mVssRays); 
    269270} 
    270271 
     
    312313mRoot(NULL), 
    313314mOutOfBoundsCell(NULL), 
    314 mStoreRays(false), 
     315//mStoreRays(false), 
     316mStoreRays(true), 
    315317mTimeStamp(1), 
    316318mHierarchyManager(NULL) 
     
    554556        if (updatePvs) 
    555557        { 
    556                 // update pvs of view cell 
     558                // store pvs of view cell 
    557559                AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 
    558560 
     
    579581                //-- store sampling rays 
    580582 
    581         RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
    582  
    583                 for (it = tData.mRays->begin(); it != it_end; ++ it) 
    584                 { 
    585                         (*it).mRay->Ref();                       
     583        RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
     584 
     585                for (rit = tData.mRays->begin(); rit != rit_end; ++ rit) 
     586                { 
     587                        VssRay *ray = new VssRay(*(*rit).mRay); 
     588                        ray->Ref(); 
     589 
    586590                        // note: should rather store rays with view cell 
    587                         leaf->mVssRays.push_back((*it).mRay); 
     591                        leaf->mVssRays.push_back(ray); 
    588592                } 
    589593        } 
     
    668672        { 
    669673                VspLeaf *leaf = static_cast<VspLeaf *>(newNode); 
    670                  
    671 #if 0 
    672         ///////////// 
    673                 //-- store pvs optained from rays 
    674  
    675                 // view cell is created during subdivision 
    676                 ViewCell *viewCell = leaf->GetViewCell(); 
    677  
    678                 int conSamp = 0; 
    679                 float sampCon = 0.0f; 
    680  
    681                 AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 
    682  
    683                 // update scalar pvs size value 
    684                 ObjectPvs &pvs = viewCell->GetPvs(); 
    685                 mViewCellsManager->UpdateScalarPvsSize(viewCell, pvs.EvalPvsCost(), pvs.GetSize()); 
    686  
    687                 mVspStats.contributingSamples += conSamp; 
    688                 mVspStats.sampleContributions += (int)sampCon; 
    689 #endif 
    690                 if (mStoreRays) 
     674         
     675                if (0 && mStoreRays) 
    691676                { 
    692677                        ////////// 
    693678                        //-- store rays piercing this view cell 
     679 
    694680                        RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
    695681                        for (it = tData.mRays->begin(); it != it_end; ++ it) 
     
    697683                                (*it).mRay->Ref();                       
    698684                                leaf->mVssRays.push_back((*it).mRay); 
    699                                 //leaf->mVssRays.push_back(new VssRay(*(*it).mRay)); 
    700685                        } 
    701686                } 
     
    753738        RayInfoContainer::const_iterator rit, rit_end = splitCandidate.mParentData.mRays->end(); 
    754739 
    755         float frontTriangles = 0, backTriangles = 0, totalTriangles = 0; 
    756         int frontObjects = 0, backObjects = 0, totalObjects = 0; 
     740        SplitData sData; 
    757741 
    758742        Intersectable::NewMail(3); 
     
    779763                // evaluate contribution of ray endpoint to front  
    780764                // and back pvs with respect to the classification 
    781                 UpdateContributionsToPvs(leaf, cf,  
    782                                                                  frontTriangles, backTriangles, totalTriangles, 
    783                                                                  frontObjects, backObjects, totalObjects); 
     765                UpdateContributionsToPvs(leaf, cf, sData); 
    784766 
    785767#if COUNT_ORIGIN_OBJECTS 
     
    791773                        leaf = mBvHierarchy->GetLeaf(obj); 
    792774 
    793                         UpdateContributionsToPvs(leaf, cf,  
    794                                                                          frontTriangles, backTriangles, totalTriangles, 
    795                                                                          frontObjects, backObjects, totalObjects); 
     775                        UpdateContributionsToPvs(leaf, cf, sData);  
    796776                } 
    797777#endif 
     
    802782        } 
    803783 
    804         const float totalRenderCost = mViewCellsManager->ComputeRenderCost((int)totalTriangles, totalObjects); 
    805         const float backRenderCost = mViewCellsManager->ComputeRenderCost((int)backTriangles, backObjects); 
    806         const float frontRenderCost = mViewCellsManager->ComputeRenderCost((int)frontTriangles, frontObjects); 
     784        sData.mTotalRenderCost = mViewCellsManager->ComputeRenderCost(sData.mTotalTriangles, sData.mTotalObjects); 
     785        sData.mBackRenderCost = mViewCellsManager->ComputeRenderCost(sData.mBackTriangles, sData.mBackObjects); 
     786        sData.mFrontRenderCost = mViewCellsManager->ComputeRenderCost(sData.mFrontTriangles, sData.mFrontObjects); 
    807787         
    808788 
     
    810790        // avg ray contri 
    811791 
    812         const float avgRayContri = (float)totalObjects /  
     792        const float avgRayContri = (float)sData.mTotalObjects /  
    813793                ((float)splitCandidate.mParentData.mRays->size() + Limits::Small); 
    814794 
    815         splitCandidate.SetAvgRayContribution(avgRayContri); 
    816  
    817         const float avgRaysPerObject =  
    818                 (float)splitCandidate.mParentData.mRays->size() / ((float)totalTriangles + Limits::Small); 
     795        const float avgRaysPerObject = (float)splitCandidate.mParentData.mRays->size() /  
     796                ((float)sData.mTotalObjects + Limits::Small); 
     797 
     798        //cout << "avg rays per obj: " << avgRaysPerObject << endl; 
    819799 
    820800        splitCandidate.SetAvgRayContribution(avgRayContri); 
    821801        splitCandidate.SetAvgRaysPerObject(avgRaysPerObject); 
    822  
    823802 
    824803        // todo: compute old render cost in the function 
    825804        // using michi's render cost evaluation 
    826805        float oldRenderCost; 
    827         const float renderCostDecr = EvalRenderCostDecrease(splitCandidate,  
    828                                                                                                                 oldRenderCost, 
    829                                                                                                                 totalRenderCost,  
    830                                                                                                                 frontRenderCost,  
    831                                                                                                                 backRenderCost); 
    832  
     806        const float renderCostDecr = EvalRenderCostDecrease(splitCandidate, oldRenderCost, sData); 
    833807        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
    834808 
    835809        // the increase in pvs entries num induced by this split 
    836         const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, totalObjects, frontObjects, backObjects); 
     810        const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, sData); 
    837811        splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 
    838812 
    839         splitCandidate.mFrontTriangles = frontTriangles; 
    840         splitCandidate.mBackTriangles = backTriangles; 
     813        splitCandidate.mFrontTriangles = (float)sData.mFrontTriangles; 
     814        splitCandidate.mBackTriangles = (float)sData.mBackTriangles; 
    841815         
    842816        // take render cost of node into account  
     
    857831 
    858832int VspTree::EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate, 
    859                                                                 const int oldPvsSize, 
    860                                                                 const int fPvsSize, 
    861                                                                 const int bPvsSize) const 
    862 { 
    863          
    864         RayInfoContainer::const_iterator rit, rit_end = splitCandidate.mParentData.mRays->end(); 
    865  
     833                                                                const SplitData &sData) const 
     834{ 
    866835        const float oldPvsRatio = (splitCandidate.mParentData.mPvs > 0) ?  
    867                 oldPvsSize / splitCandidate.mParentData.mPvs : 1; 
     836                sData.mTotalObjects / splitCandidate.mParentData.mPvs : 1; 
    868837        const float correctedOldPvs = splitCandidate.mParentData.mCorrectedPvs * oldPvsRatio; 
    869838 
    870839        splitCandidate.mCorrectedFrontPvs =  
    871                 mHierarchyManager->EvalCorrectedPvs((float)fPvsSize,  
     840                mHierarchyManager->EvalCorrectedPvs((float)sData.mFrontObjects,  
    872841                                                                                        (float)correctedOldPvs,  
    873842                                                                                        splitCandidate.GetAvgRaysPerObject()); 
    874843        splitCandidate.mCorrectedBackPvs =  
    875                 mHierarchyManager->EvalCorrectedPvs((float)bPvsSize,  
     844                mHierarchyManager->EvalCorrectedPvs((float)sData.mBackObjects,  
    876845                                                                                        (float)correctedOldPvs,  
    877846                                                                                        splitCandidate.GetAvgRaysPerObject()); 
    878847         
    879         splitCandidate.mFrontPvs = (float)fPvsSize; 
    880         splitCandidate.mBackPvs = (float)bPvsSize; 
    881  
    882 #if TODO 
     848        splitCandidate.mFrontPvs = (float)sData.mFrontObjects; 
     849        splitCandidate.mBackPvs = (float)sData.mBackObjects; 
     850 
     851#if HAS_TO_BE_REDONE 
    883852        return (int)(splitCandidate.mCorrectedFrontPvs + splitCandidate.mCorrectedBackPvs - correctedOldPvs); 
    884853#else 
    885         return fPvsSize + bPvsSize - oldPvsSize; 
     854        return sData.mFrontObjects + sData.mBackObjects - sData.mTotalObjects; 
    886855#endif 
    887856} 
     
    10381007                        ++ contributingSamples; 
    10391008                } 
    1040  
    1041                 // store rays for visualization 
    1042                 if (0) leaf->mVssRays.push_back(new VssRay(*ray)); 
    10431009        } 
    10441010} 
     
    14751441 
    14761442                        exporter->SetForcedMaterial(m); 
    1477  
    14781443                        exporter->ExportIntersectable(leaf); 
    14791444 
     
    15051470 
    15061471#ifdef GTP_DEBUG 
    1507         cout << "\n((((( eval local cost )))))" << endl 
     1472        Debug << "\n((((( eval local vsp cost )))))" << endl 
    15081473                  << "back pvs: " << penaltyBack << " front pvs: " << penaltyFront << " total pvs: " << penaltyOld << endl  
    15091474                  << "back p: " << pBack * volRatio << " front p " << pFront * volRatio << " p: " << pOverall * volRatio << endl 
     
    16261591float VspTree::EvalRenderCostDecrease(VspSubdivisionCandidate &sc, 
    16271592                                                                          float &normalizedOldRenderCost, 
    1628                                                                           const float totalRenderCost, 
    1629                                                                           const float frontRenderCost, 
    1630                                                                           const float backRenderCost) const 
     1593                                                                          const SplitData &sData) const 
    16311594{ 
    16321595        const float viewSpaceVol = mBoundingBox.GetVolume(); 
     
    16551618 
    16561619        // ratio of how render cost changed since last evaluation 
    1657         const float oldRenderCostRatio = (tData.mRenderCost > 0)? (totalRenderCost / tData.mRenderCost) : 1; 
     1620        const float oldRenderCostRatio = (tData.mRenderCost > 0)? (sData.mTotalRenderCost / tData.mRenderCost) : 1; 
    16581621        const float penaltyOld = tData.mCorrectedRenderCost * oldRenderCostRatio; 
    16591622 
    1660         sc.mCorrectedFrontRenderCost = mHierarchyManager->EvalCorrectedPvs(frontRenderCost, penaltyOld, avgRaysPerObject); 
    1661         sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs(backRenderCost, penaltyOld, avgRaysPerObject); 
    1662  
    1663         sc.mFrontRenderCost = frontRenderCost; 
    1664         sc.mBackRenderCost = backRenderCost; 
    1665  
    1666 #if TODO // undersampling evalution does not work yet 
     1623        sc.mCorrectedFrontRenderCost = mHierarchyManager->EvalCorrectedPvs(sData.mFrontRenderCost, penaltyOld, avgRaysPerObject); 
     1624        sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs(sData.mBackRenderCost, penaltyOld, avgRaysPerObject); 
     1625 
     1626        sc.mFrontRenderCost = sData.mFrontRenderCost; 
     1627        sc.mBackRenderCost = sData.mBackRenderCost; 
     1628 
     1629#if HAS_TO_BE_REDONE // undersampling evalution does not work yet 
    16671630 
    16681631        const float oldRenderCost = penaltyOld * pOverall; 
     
    16721635#else 
    16731636 
    1674         const float oldRenderCost = totalRenderCost * pOverall; 
    1675         const float newRenderCost = frontRenderCost * pFront + backRenderCost * pBack; 
     1637        const float oldRenderCost = sData.mTotalRenderCost * pOverall; 
     1638        const float newRenderCost = sData.mFrontRenderCost * pFront + sData.mBackRenderCost * pBack; 
    16761639 
    16771640#endif 
     
    16821645        // the render cost decrase for this split 
    16831646        const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 
     1647 
     1648        //cout << "old: " << normalizedOldRenderCost << " new: " << newRenderCost / viewSpaceVol << " corr: " << tData.mCorrectedRenderCost << " ratio: " << oldRenderCostRatio << endl; 
    16841649 
    16851650        return renderCostDecrease; 
     
    18341799void VspTree::UpdateContributionsToPvs(BvhLeaf *leaf, 
    18351800                                                                           const int cf, 
    1836                                                                            float &frontPvs, 
    1837                                                                            float &backPvs, 
    1838                                                                            float &totalPvs, 
    1839                                                                            int &frontSize, 
    1840                                                                            int &backSize, 
    1841                                                                            int &totalSize) const 
    1842 { 
    1843         const float triSize = (float)leaf->mObjects.size(); 
     1801                                                                           SplitData &sData) const 
     1802{ 
     1803        const int triSize = (int)leaf->mObjects.size(); 
    18441804         
    18451805        // object in no pvs => count as new 
    18461806        if (!leaf->Mailed() && !leaf->Mailed(1) && !leaf->Mailed(2)) 
    18471807        { 
    1848                 totalPvs += triSize; 
    1849                 ++ totalSize; 
     1808                sData.mTotalTriangles += (int)triSize; 
     1809                ++ sData.mTotalObjects; 
    18501810        } 
    18511811 
     
    18541814                if (!leaf->Mailed() && !leaf->Mailed(2)) 
    18551815                { 
    1856                         frontPvs += triSize; 
    1857                         ++ frontSize; 
     1816                        sData.mFrontTriangles += triSize; 
     1817                        ++ sData.mFrontObjects; 
    18581818 
    18591819                        // already in back pvs => in both pvss 
     
    18691829                if (!leaf->Mailed(1) && !leaf->Mailed(2)) 
    18701830                { 
    1871                         backPvs += triSize; 
    1872                         ++ backSize; 
     1831                        sData.mBackTriangles += triSize; 
     1832                        ++ sData.mBackObjects; 
    18731833 
    18741834                        // already in front pvs => in both pvss 
     
    20442004 
    20452005 
    2046 void VspTree::CollapseViewCells() 
    2047 { 
    2048 // TODO matt 
    2049 #if HAS_TO_BE_REDONE 
    2050         stack<VspNode *> nodeStack; 
    2051  
     2006void VspTree::CollectRays(VssRayContainer &rays) 
     2007{ 
     2008        vector<VspLeaf *> leaves; 
     2009        CollectLeaves(leaves); 
     2010 
     2011        vector<VspLeaf *>::const_iterator lit, lit_end = leaves.end(); 
     2012 
     2013        for (lit = leaves.begin(); lit != lit_end; ++ lit) 
     2014        { 
     2015                VspLeaf *leaf = *lit; 
     2016                VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end(); 
     2017 
     2018                for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit) 
     2019                        rays.push_back(*rit); 
     2020        } 
     2021} 
     2022 
     2023 
     2024void VspTree::SetViewCellsManager(ViewCellsManager *vcm) 
     2025{ 
     2026        mViewCellsManager = vcm; 
     2027} 
     2028 
     2029 
     2030void VspTree::ValidateTree() 
     2031{ 
    20522032        if (!mRoot) 
    20532033                return; 
    20542034 
     2035        mVspStats.invalidLeaves = 0; 
     2036        stack<VspNode *> nodeStack; 
     2037 
    20552038        nodeStack.push(mRoot); 
    2056          
     2039 
    20572040        while (!nodeStack.empty())  
    20582041        { 
     
    20612044                 
    20622045                if (node->IsLeaf()) 
    2063         { 
    2064                         BspViewCell *viewCell = static_cast<VspLeaf *>(node)->GetViewCell(); 
    2065  
    2066                         if (!viewCell->GetValid()) 
    2067                         { 
    2068                                 BspViewCell *viewCell = static_cast<VspLeaf *>(node)->GetViewCell(); 
    2069          
    2070                                 ViewCellContainer leaves; 
    2071                                 mViewCellsTree->CollectLeaves(viewCell, leaves); 
    2072  
    2073                                 ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    2074  
    2075                                 for (it = leaves.begin(); it != it_end; ++ it) 
    2076                                 { 
    2077                                         VspLeaf *l = static_cast<BspViewCell *>(*it)->mLeaf; 
    2078                                         l->SetViewCell(GetOrCreateOutOfBoundsCell()); 
    2079                                         ++ mVspStats.invalidLeaves; 
    2080                                 } 
    2081  
    2082                                 // add to unbounded view cell 
    2083                                 ViewCell *outOfBounds = GetOrCreateOutOfBoundsCell(); 
    2084                                 outOfBounds->GetPvs().AddPvs(viewCell->GetPvs()); 
    2085                                 DEL_PTR(viewCell); 
     2046                { 
     2047                        VspLeaf *leaf = static_cast<VspLeaf *>(node); 
     2048 
     2049                        if (!leaf->GetViewCell()->GetValid()) 
     2050                                ++ mVspStats.invalidLeaves; 
     2051 
     2052                        // validity flags don't match => repair 
     2053                        if (leaf->GetViewCell()->GetValid() != leaf->TreeValid()) 
     2054                        { 
     2055                                leaf->SetTreeValid(leaf->GetViewCell()->GetValid()); 
     2056                                PropagateUpValidity(leaf); 
    20862057                        } 
    20872058                } 
     
    20962067 
    20972068        Debug << "invalid leaves: " << mVspStats.invalidLeaves << endl; 
    2098 #endif 
    2099 } 
    2100  
    2101  
    2102 void VspTree::CollectRays(VssRayContainer &rays) 
    2103 { 
    2104         vector<VspLeaf *> leaves; 
    2105         CollectLeaves(leaves); 
    2106  
    2107         vector<VspLeaf *>::const_iterator lit, lit_end = leaves.end(); 
    2108  
    2109         for (lit = leaves.begin(); lit != lit_end; ++ lit) 
    2110         { 
    2111                 VspLeaf *leaf = *lit; 
    2112                 VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end(); 
    2113  
    2114                 for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit) 
    2115                         rays.push_back(*rit); 
    2116         } 
    2117 } 
    2118  
    2119  
    2120 void VspTree::SetViewCellsManager(ViewCellsManager *vcm) 
    2121 { 
    2122         mViewCellsManager = vcm; 
    2123 } 
    2124  
    2125  
    2126 void VspTree::ValidateTree() 
    2127 { 
    2128         if (!mRoot) 
    2129                 return; 
    2130  
    2131         mVspStats.invalidLeaves = 0; 
    2132         stack<VspNode *> nodeStack; 
    2133  
    2134         nodeStack.push(mRoot); 
    2135  
    2136         while (!nodeStack.empty())  
    2137         { 
    2138                 VspNode *node = nodeStack.top(); 
    2139                 nodeStack.pop(); 
    2140                  
    2141                 if (node->IsLeaf()) 
    2142                 { 
    2143                         VspLeaf *leaf = static_cast<VspLeaf *>(node); 
    2144  
    2145                         if (!leaf->GetViewCell()->GetValid()) 
    2146                                 ++ mVspStats.invalidLeaves; 
    2147  
    2148                         // validity flags don't match => repair 
    2149                         if (leaf->GetViewCell()->GetValid() != leaf->TreeValid()) 
    2150                         { 
    2151                                 leaf->SetTreeValid(leaf->GetViewCell()->GetValid()); 
    2152                                 PropagateUpValidity(leaf); 
    2153                         } 
    2154                 } 
    2155                 else 
    2156                 { 
    2157                         VspInterior *interior = static_cast<VspInterior *>(node); 
    2158                  
    2159                         nodeStack.push(interior->GetFront()); 
    2160                         nodeStack.push(interior->GetBack()); 
    2161                 } 
    2162         } 
    2163  
    2164         Debug << "invalid leaves: " << mVspStats.invalidLeaves << endl; 
    21652069} 
    21662070 
     
    21682072 
    21692073void VspTree::CollectViewCells(VspNode *root, 
    2170                                                                   bool onlyValid, 
    2171                                                                   ViewCellContainer &viewCells, 
    2172                                                                   bool onlyUnmailed) const 
     2074                                                           bool onlyValid, 
     2075                                                           ViewCellContainer &viewCells, 
     2076                                                           bool onlyUnmailed) const 
    21732077{ 
    21742078        if (!root) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r2342 r2347  
    500500    }; 
    501501 
     502        struct SplitData  
     503        { 
     504                SplitData():  
     505        mFrontRenderCost(0),  
     506                mBackRenderCost(0),  
     507                mTotalRenderCost(0),  
     508                mFrontObjects(0), 
     509        mBackObjects(0), 
     510                mTotalObjects(0), 
     511                mFrontTriangles(0), 
     512                mBackTriangles(0), 
     513                mTotalTriangles(0) {} 
     514 
     515 
     516                float mFrontRenderCost; 
     517                float mBackRenderCost; 
     518                float mTotalRenderCost; 
     519 
     520                int mFrontObjects; 
     521                int mBackObjects; 
     522                int mTotalObjects; 
     523 
     524                int mFrontTriangles; 
     525                int mBackTriangles; 
     526                int mTotalTriangles; 
     527        }; 
     528 
     529 
    502530        /** Candidate for a view space split. 
    503531        */ 
     
    707735        */ 
    708736        void ValidateTree(); 
    709  
    710         /** Invalid view cells are added to the unbounded space 
    711         */ 
    712         void CollapseViewCells(); 
    713737 
    714738        /** Collects rays stored in the leaves. 
     
    797821        float EvalRenderCostDecrease(VspSubdivisionCandidate &splitData,  
    798822                                                                 float &normalizedOldRenderCost, 
    799                                                                  const float totalRenderCost, 
    800                                                                  const float frontRenderCost, 
    801                                                                  const float backRenderCost) const; 
     823                                                                 const SplitData &data) const; 
    802824 
    803825        /** Collects view cells in the subtree under root. 
     
    889911 
    890912        int EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate, 
    891                                                    const int oldPvsSize, 
    892                                                    const int fPvsSize, 
    893                                                    const int bPvsSize) const; 
     913                                                   const SplitData &sData) const; 
    894914 
    895915        /** Returns number of effective entries in the pvs. 
     
    10131033        inline void UpdateContributionsToPvs(BvhLeaf *leaf, 
    10141034                                                                                 const int cf, 
    1015                                                                                  float &frontPvs,  
    1016                                                                                  float &backPvs,  
    1017                                                                                  float &totalPvs, 
    1018                                                                                  int &frontSize,  
    1019                                                                                  int &backSize,  
    1020                                                                                  int &totalSize) const; 
     1035                                                                                 SplitData &sdata) const; 
    10211036 
    10221037        /** Evaluates the contribution for kd leaves. 
Note: See TracChangeset for help on using the changeset viewer.