Changeset 1705


Ignore:
Timestamp:
10/31/06 21:15:07 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
7 edited

Legend:

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

    r1703 r1705  
    307307        Debug << "max memory: " << mMaxMemory << endl; 
    308308        Debug << "use cost heuristics: " << mUseCostHeuristics << endl; 
     309        Debug << "use sah (surface area heuristics: " << mUseSah << endl; 
    309310        Debug << "subdivision stats log: " << subdivisionStatsLog << endl; 
    310311        Debug << "split borders: " << mSplitBorder << endl; 
     
    572573                HierarchyManager::NO_VIEWSPACE_SUBDIV) 
    573574        { 
    574                 //////////////// 
    575                 //-- surface area heuristics 
    576  
    577                 const AxisAlignedBox3 box = EvalBoundingBox(leaf->mObjects); 
    578                 const float area = box.SurfaceArea(); 
    579                 const float viewSpaceArea = mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 
    580  
    581                 priority = (float)leaf->mObjects.size() * area / viewSpaceArea; 
     575                priority = EvalSahCost(leaf); 
    582576        } 
    583577        else 
     
    612606inline bool BvHierarchy::LocalTerminationCriteriaMet(const BvhTraversalData &data) const 
    613607{ 
    614         return ( 0 
    615                         || ((int)data.mNode->mObjects.size() <= mTermMinObjects) 
     608        const bool terminationCriteriaMet = 
     609                        (0 
     610                        || ((int)data.mNode->mObjects.size() <= 1)//mTermMinObjects) 
    616611                        //|| (data.mProbability <= mTermMinProbability) 
    617                         || (data.mNumRays <= mTermMinRays) 
     612                        //|| (data.mNumRays <= mTermMinRays) 
    618613                 ); 
     614 
     615#ifdef _DEBUG 
     616        if (terminationCriteriaMet) 
     617        { 
     618                cout << "bvh local termination criteria met:" << endl; 
     619                cout << "objects: " << data.mNode->mObjects.size() << " " << mTermMinObjects << endl; 
     620        } 
     621#endif 
     622        return terminationCriteriaMet;  
    619623} 
    620624 
     
    722726        } 
    723727 
    724 #if 0 
     728#ifdef _DEBUG 
    725729        cout << "depth: " << data.mDepth << " objects: " << (int)leaf->mObjects.size()  
    726730                 << " rays: " << data.mNumRays << " rays / objects "  
     
    764768 
    765769        const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 
    766         const float newRenderCost =  
    767                 EvalRenderCost(objectsFront) * EvalRenderCost(objectsBack); 
     770        const float newRenderCost = EvalRenderCost(objectsFront) * EvalRenderCost(objectsBack); 
    768771 
    769772        const float ratio = newRenderCost / oldRenderCost; 
     
    801804        } 
    802805 
    803         float heur = 0; 
    804  
    805         if (tData.mNode->GetBoundingBox().Size().DrivingAxis() == axis) 
    806         { 
    807                 heur = -1; 
    808         } 
    809  
    810         return heur; 
     806#if 1 
     807        const float cost = (tData.mNode->GetBoundingBox().Size().DrivingAxis() == axis) ? -1.0f : 0.0f; 
     808#else 
     809        const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 
     810        const float newRenderCost = EvalRenderCost(objectsFront) * EvalRenderCost(objectsBack); 
     811 
     812        const float cost = newRenderCost / oldRenderCost; 
     813#endif 
     814 
     815        return cost; 
    811816} 
    812817#endif 
     
    918923                } 
    919924 
    920                 const float sum = objectsLeft * al + objectsRight * ar; 
     925                const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small)); 
     926 
     927                const float sum =  noValidSplit ? 1e25 : objectsLeft * al + objectsRight * ar; 
    921928       
    922929                /*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=("  
     
    925932            cout << "cost= " << sum << endl; 
    926933*/ 
     934         
    927935                if (sum < minSum)  
    928                 { 
     936                {       //cout <<" sum: " << sum; 
    929937                        minSum = sum; 
    930938                        areaLeft = al; 
     
    935943                } 
    936944        } 
    937  
    938945 
    939946        //////////////////////////////////////////// 
     
    952959   
    953960#ifdef _DEBUG 
     961//      if (objectsBack.empty() ||objectsFront.empty()) 
    954962        cout << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of "  
    955963                 << (int)tData.mNode->mObjects.size() << ")\t area=("  
    956                  << areaLeft << "," << areaRight << ")" << endl 
    957                  << "cost= " << minSum << endl; 
     964                 << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl 
     965                 << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl; 
    958966#endif 
    959967 
     
    10691077                nObjectsRight -= rc; 
    10701078                 
     1079                const bool noValidSplit = ((nObjectsLeft <= Limits::Small) || (nObjectsRight <= Limits::Small)); 
     1080 
    10711081                // the heuristics 
    1072             const float sum = volLeft * (float)nObjectsLeft +  
    1073                                                   volRight * (float)nObjectsRight; 
     1082            const float sum = noValidSplit ?  
     1083                        1e25 : volLeft * (float)nObjectsLeft + volRight * (float)nObjectsRight; 
    10741084 
    10751085#ifdef _DEBUG 
     
    14421452 
    14431453 
     1454float BvHierarchy::EvalSahCost(BvhLeaf *leaf) 
     1455{ 
     1456        //////////////// 
     1457        //-- surface area heuristics 
     1458        if (leaf->mObjects.empty()) 
     1459                return 0.0f; 
     1460 
     1461        const AxisAlignedBox3 box = GetBoundingBox(leaf); 
     1462        const float area = box.SurfaceArea(); 
     1463        const float viewSpaceArea = mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 
     1464 
     1465        return EvalAbsCost(leaf->mObjects) * area / viewSpaceArea; 
     1466} 
     1467 
     1468 
    14441469float BvHierarchy::EvalRenderCost(const ObjectContainer &objects) const 
    14451470{        
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1703 r1705  
    7070                splits = 0; 
    7171                maxDepth = 0; 
     72 
    7273                minDepth = 99999; 
    7374                accumDepth = 0; 
     
    7576                minProbabilityNodes = 0; 
    7677                maxCostNodes = 0; 
    77                          
    7878                /////////////////// 
    7979                minObjectsNodes = 0; 
     
    421421                void EvalCandidate(bool computeSplitplane = true) 
    422422                { 
    423                         mDirty = false; 
     423            mDirty = false; 
    424424                        sBvHierarchy->EvalSubdivisionCandidate(*this, computeSplitplane); 
    425425                } 
     
    452452                float GetPriority() const 
    453453                { 
    454                         HierarchyManager *hm = sBvHierarchy->mHierarchyManager; 
    455                  
    456                         if (hm->ConsiderMemory()) 
    457                         { 
    458                                 const float rc = mRenderCostDecrease / (hm->mInitialRenderCost - hm->GetHierarchyStats().mTotalCost + 1.0f); 
    459                                 //const float mc = mMemoryIncr /  / hm->GetHierarchyStats().mMemory; 
    460                 //const float rc = mPriority / (hm->mInitialRenderCost - hm->GetHierarchyStats().mTotalCost + 1.0f); 
    461                                 const float mc = (float)mPvsEntriesIncr / (float)hm->GetHierarchyStats().mPvsEntries;    
    462                                  
    463                                 //cout << "\np: " << mPriority << " i: " << hm->mInitialRenderCost << " t: " << hm->GetHierarchyStats().mTotalCost << endl; 
    464                                 //cout << "osp rc: " << rc << " mc: " << mc << endl; 
    465  
    466                                 return hm->GetMemoryConst() * rc - (1.0f - hm->GetMemoryConst()) * mc; 
    467                         } 
    468                         else 
    469                         { 
    470                                 return mPriority; 
    471                         } 
     454                        return mPriority; 
    472455                } 
    473456 
     
    755738        float PrepareHeuristics(const BvhTraversalData &tData, const int axis); 
    756739         
     740        /** Evaluates cost for a leaf given the surface area heuristics. 
     741        */ 
     742        float EvalSahCost(BvhLeaf *leaf); 
    757743 
    758744        //////////////////////////////////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1701 r1705  
    144144        mTermMaxMemory *= (1024.0f * 1024.0f); 
    145145 
    146         Debug << "******** Hierachy Manager Options ***********" << endl; 
     146        Debug << "******** Hierarchy Manager Options ***********" << endl; 
    147147        Debug << "max leaves: " << mTermMaxLeaves << endl; 
    148148        Debug << "min global cost ratio: " << mTermMinGlobalCostRatio << endl; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1703 r1705  
    4040// HACK 
    4141const static bool SAMPLE_AFTER_SUBDIVISION = true; 
    42 const static bool CLAMP_TO_BOX = false; 
     42//const static bool CLAMP_TO_BOX = false; 
     43const static bool CLAMP_TO_BOX = true; 
     44 
    4345 
    4446int ViewCellsManager::sRenderCostEvaluationType = 0; 
     
    511513        if (mEvaluateViewCells) 
    512514        { 
     515cout << "here42 ***********" << endl; 
    513516                EvalViewCellPartition(); 
    514517        } 
    515          
     518                 
     519        // write view cells to disc 
     520        if (1 && mExportViewCells) 
     521        { 
     522                char filename[100]; 
     523                Environment::GetSingleton()->GetStringValue("ViewCells.filename", filename); 
     524                ExportViewCells(filename, mExportPvs, mPreprocessor->mObjects); 
     525        } 
     526 
    516527        ///////////////// 
    517528        //-- Finally, we do some visualization 
     
    28932904        // compute final meshes and volume / area 
    28942905        if (1) FinalizeViewCells(true); 
    2895  
    2896         // write view cells to disc 
    2897         if (1 && mExportViewCells) 
    2898         { 
    2899                 char filename[100]; 
    2900                 Environment::GetSingleton()->GetStringValue("ViewCells.filename", filename); 
    2901                 ExportViewCells(filename, mExportPvs, objects); 
    2902         } 
    29032906         
    29042907        return 0; 
     
    41534156        if (1) FinalizeViewCells(true); 
    41544157 
    4155         // write view cells to disc 
    4156         if (1 && mExportViewCells) 
    4157         { 
    4158                 char filename[100]; 
    4159                 Environment::GetSingleton()->GetStringValue("ViewCells.filename", filename); 
    4160                 ExportViewCells(filename, mExportPvs, objects); 
    4161         } 
    4162  
    41634158        return 0; 
    41644159} 
     
    50205015 
    50215016        if (1) FinalizeViewCells(true); 
    5022  
    5023         // write out view cells (this moved to preprocessor) 
    5024         if (mExportViewCells) 
    5025         { 
    5026                 char filename[100]; 
    5027                 Environment::GetSingleton()->GetStringValue("ViewCells.filename", filename); 
    5028                 ExportViewCells(filename, mExportPvs, objects); 
    5029         } 
    50305017 
    50315018        return 0; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1667 r1705  
    789789 
    790790        //viewCell = GetOrCreateViewCell(id, isLeaf); 
    791          
    792                 if (isLeaf) 
    793                 { 
    794                         viewCell = new ViewCellLeaf(); 
    795                 } 
    796                 else 
    797                 { 
    798                         viewCell = new ViewCellInterior(); 
    799                 } 
     791 
     792        if (isLeaf) 
     793        { 
     794                viewCell = new ViewCellLeaf(); 
     795        } 
     796        else 
     797        { 
     798                viewCell = new ViewCellInterior(); 
     799        } 
    800800 
    801801        for (int i = 0; i < len; ++ i)  
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1696 r1705  
    509509                float GetPriority() const 
    510510                { 
    511                         HierarchyManager *hm = sVspTree->mHierarchyManager; 
    512                          
    513                         if (hm->ConsiderMemory()) 
    514                         { 
    515                                 const float rc = mRenderCostDecrease / (hm->mInitialRenderCost - hm->GetHierarchyStats().mTotalCost + 1.0f); 
    516                                 //const float mc = mMemoryIncr /  / hm->GetHierarchyStats().mMemory; 
    517                                 //const float rc = mPriority / (hm->mInitialRenderCost - hm->GetHierarchyStats().mTotalCost + 1.0f); 
    518                                 const float mc = (float)mPvsEntriesIncr / (float)hm->GetHierarchyStats().mPvsEntries;    
    519                                  
    520                                 //cout << "\np: " << mPriority << " i: " << hm->mInitialRenderCost << " t: " << hm->GetHierarchyStats().mTotalCost << endl; 
    521                                 //cout << "vsp rc: " << rc << " mc: " << mc << endl; 
    522                                  
    523                                 return hm->GetMemoryConst() * rc - (1.0f - hm->GetMemoryConst()) * mc; 
    524                         } 
    525                         else 
    526                         { 
    527                                 return mPriority; 
    528                         } 
     511                        return mPriority; 
    529512                } 
    530513        }; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp

    r1577 r1705  
    392392        } 
    393393 
    394  
    395394        mSceneGraph->CollectObjects(&mObjects); 
    396395 
Note: See TracChangeset for help on using the changeset viewer.