Changeset 735


Ignore:
Timestamp:
04/08/06 12:15:50 (18 years ago)
Author:
mattausch
Message:

added histogram functionality

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

Legend:

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

    r734 r735  
    12241224                                        "viewCells"); 
    12251225 
     1226        RegisterOption("ViewCells.Evaluation.histogram", 
     1227                                        optBool, 
     1228                                        "view_cells_evaluation_histogram=", 
     1229                                        "false"); 
     1230 
     1231        RegisterOption("ViewCells.Evaluation.histoPasses", 
     1232                                        optInt, 
     1233                                        "view_cells_evaluation_histo_passes=", 
     1234                                        "5"); 
     1235 
     1236 
    12261237        RegisterOption("ViewCells.renderCostEvaluationType", 
    12271238                                        optString, 
     
    20592070                "false"); 
    20602071 
    2061         RegisterOption("VspBspTree.useBreathFirstSplits", 
    2062                 optBool, 
    2063                 "vsp_bsp_breath_first_splits=", 
    2064                 "false"); 
    2065  
    2066         RegisterOption("VspBspTree.useDepthFirstSplits", 
    2067                 optBool, 
    2068                 "vsp_bsp_depth_first_splits=", 
    2069                 "false"); 
     2072        RegisterOption("VspBspTree.nodePriorityQueueType", 
     2073                optInt, 
     2074                "vsp_bsp_node_queue_type=", 
     2075                "0"); 
    20702076 
    20712077        RegisterOption("VspBspTree.useRandomAxis", 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r734 r735  
    541541        outstream.open(filename.c_str()); 
    542542 
    543         Debug << "here3" << endl; 
    544543        ViewCellContainer viewCells; 
    545         mViewCellsTree->CollectBestViewCellSet(mViewCells, nViewCells); 
     544        mViewCellsTree->CollectBestViewCellSet(viewCells, nViewCells); 
    546545 
    547546        float maxRenderCost, minRenderCost; 
    548  
    549         /// find out the range for valid render cost 
    550         ComputeMinMaxRenderCost(minRenderCost, maxRenderCost, viewCells); 
    551547 
    552548        // sort by render cost 
     
    556552        maxRenderCost = viewCells.back()->GetRenderCost(); 
    557553 
    558         const int intervals = 10000; 
     554        const int intervals = min(10000, (int)viewCells.size()); 
     555 
    559556        const float range = maxRenderCost - minRenderCost; 
    560         int currentRenderCost = (int)ceil(minRenderCost); 
    561         const int stepSize = (int)((float)range / (float)intervals); 
     557        const float stepSize = range / (float)intervals; 
     558 
     559        float currentRenderCost = minRenderCost;//(int)ceil(minRenderCost); 
     560 
     561        const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost(); 
     562        const float totalVol = GetViewSpaceBox().GetVolume(); 
    562563 
    563564        float vol = 0; 
    564565        int smallerCost = 0; 
    565  
     566        int i = 0; 
     567        int j = 0; 
     568 
     569         
    566570        ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end();              
    567571 
    568         int i = 0; 
    569  
     572         
    570573        // note can skip computations for view cells already evaluated and delete them from vector ... 
    571574    while (1) 
    572575        { 
    573         Debug << "here4" << endl; 
    574576                while ((i < (int)viewCells.size()) && (viewCells[i]->GetRenderCost() < currentRenderCost)) 
    575577                { 
    576                          
    577         Debug << "here5" << endl; 
     578                        vol += viewCells[i]->GetVolume(); 
    578579                        ++ i; 
    579580                        ++ smallerCost; 
    580                         vol += viewCells[i]->GetVolume(); 
    581                 } 
    582  
     581                } 
     582 
     583                if ((i >= (int)viewCells.size()) || (currentRenderCost >= maxRenderCost)) 
     584                        break; 
     585 
     586                float rcRatio = currentRenderCost / maxRenderCost; 
     587                float volRatio = vol / totalVol; 
     588 
     589                outstream << "#Pass\n" << j ++ << endl; 
     590                outstream << "#RenderCost\n" << rcRatio << endl; 
     591                //fprintf(outstream, "#RenderCost\n%3.3f", rcRatio); 
     592                outstream << "#ViewCells\n" << i << endl;                
     593                outstream << "#Volume\n" << volRatio << endl << endl; 
     594 
     595                // increase current render cost 
    583596                currentRenderCost += stepSize; 
    584                  
    585                 outstream << "#RenderCost: " << currentRenderCost << endl; 
    586                 outstream << "#ViewCells: " << smallerCost << endl;              
    587                 outstream << "#Volume: " << vol << endl << endl; 
    588         } 
     597        } 
     598 
    589599        outstream.close(); 
    590         Debug << "here6" << endl; 
    591 } 
    592  
    593 /* 
    594 void ViewCellsManager::EvalViewCellHistogramForPvs(const string filename, const int nViewCells) 
     600} 
     601 
     602 
     603void ViewCellsManager::EvalViewCellHistogramForPvsSize(const string filename,  
     604                                                                                                          const int nViewCells) 
    595605{ 
    596606        std::ofstream outstream; 
     
    598608 
    599609        ViewCellContainer viewCells; 
    600         mViewCellsTree->CollectBestViewCellSet(mViewCells, nViewCells); 
    601  
    602         float maxRenderCost, minRenderCost; 
    603         /// find out the range for valid render cost 
    604         ComputeMinMaxRenderCost(minRenderCost, maxRenderCost, viewCells); 
    605  
    606         const int intervals = 10000; 
    607         const float range = maxRenderCost - minRenderCost; 
    608         int currentRenderCost = (int)ceil(minRenderCost); 
    609         const int stepSize = (int)((float)range / (float)intervals); 
     610        mViewCellsTree->CollectBestViewCellSet(viewCells, nViewCells); 
     611 
     612        int maxPvsSize, minPvsSize; 
     613 
     614        // sort by render cost 
     615        sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs); 
     616 
     617        minPvsSize = viewCells.front()->GetPvs().GetSize(); 
     618        maxPvsSize = viewCells.back()->GetPvs().GetSize(); 
     619 
     620        const int intervals = min(10000, (int)viewCells.size()); 
     621        const int range = maxPvsSize - minPvsSize; 
     622        int stepSize = range / intervals; 
     623 
     624        if (!stepSize) stepSize = 1; 
     625 
     626        const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost(); 
     627        const float totalVol = GetViewSpaceBox().GetVolume(); 
     628 
     629        int currentPvsSize = minPvsSize;//(int)ceil(minRenderCost); 
     630 
    610631        float vol = 0; 
    611  
    612         ViewCell::NewMail(); 
    613  
    614         for (; currentRenderCost < (int)maxRenderCost; currentRenderCost += stepSize) 
    615         { 
    616                 ViewCellContainer::const_iterator it, it_end = viewCells.end();          
    617  
    618                 int smallerCost = 0; 
    619  
    620                 // note can skip computations for view cells already evaluated and delete them from vector ... 
    621         for (it = viewCells.begin(); it != viewCells.end(); ++ it) 
    622                 { 
    623                         if (!vc->Mailed()) 
    624                         { 
    625                                 vc->Mail(); 
    626                         ViewCell *vc = *it; 
    627  
    628                         if (EvalRenderCost(vc) < currentRenderCost) 
    629                         { 
    630                                 ++ smallerCost; 
    631                                 vol = (*it)->GetVolume(); 
    632                         } 
    633                 } 
    634                 // note: can remove already found view cells 
    635                 //swap(neighborhood[bestViewCellIdx], neighborhood.back()); 
    636                 //neighborhood.pop_back(); 
    637          
    638  
    639                 outstream << "#RenderCost: " << currentRenderCost << endl; 
    640                 outstream << "#ViewCells: " << smallerCost << endl;              
    641                 outstream << "#Volume: " << vol << endl << endl; 
    642         } 
    643 } 
    644 */ 
     632        int smallerCost = 0; 
     633 
     634        int i = 0; 
     635        int j = 0; 
     636 
     637         
     638        ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end();              
     639         
     640        // note can skip computations for view cells already evaluated and delete them from vector ... 
     641    while (1) 
     642        { 
     643                while ((i < (int)viewCells.size()) && (viewCells[i]->GetPvs().GetSize() < currentPvsSize)) 
     644                { 
     645                        vol += viewCells[i]->GetVolume(); 
     646                        ++ i; 
     647                        ++ smallerCost; 
     648                } 
     649 
     650                if ((i >= (int)viewCells.size()) || (currentPvsSize >= maxPvsSize)) 
     651                        break; 
     652 
     653                float volRatio = vol / totalVol; 
     654 
     655                outstream << "#Pass\n" << j ++ << endl; 
     656                outstream << "#Pvs\n" << currentPvsSize << endl; 
     657                //fprintf(outstream, "#RenderCost\n%3.3f", rcRatio); 
     658                outstream << "#ViewCells\n" << i << endl;                
     659                outstream << "#Volume\n" << volRatio << endl << endl; 
     660 
     661 
     662                // increase current pvs size 
     663                currentPvsSize += stepSize; 
     664        } 
     665        outstream.close(); 
     666} 
     667 
    645668 
    646669void ViewCellsManager::EvalViewCellPartition(Preprocessor *preprocessor) 
     
    688711        } 
    689712         
    690  
     713         
    691714        while (castSamples < numSamples) 
    692715        { 
     
    727750        } 
    728751         
    729 #if 0 
    730         // evaluate view cells in a histogram 
    731         vector<int> nViewCells; 
    732         nViewCells.push_back(10000); 
    733         nViewCells.push_back(5000); 
    734         nViewCells.push_back(1000); 
    735         nViewCells.push_back(500); 
    736         nViewCells.push_back(100); 
    737  
    738         vector<int>::const_iterator iit, iit_end = nViewCells.end(); 
    739         char filename[64]; 
    740  
    741         for (iit = nViewCells.begin(); iit != nViewCells.end(); ++ iit) 
    742         { 
    743                 Debug << "here2" << endl; 
    744                 int n = *iit; 
     752        bool useHisto; 
     753        int histoPasses; 
     754 
     755        environment->GetBoolValue("ViewCells.Evaluation.histogram", useHisto); 
     756        environment->GetIntValue("ViewCells.Evaluation.histoPasses", histoPasses); 
     757 
     758        if (useHisto) 
     759        { 
     760                // evaluate view cells in a histogram            
     761                char s[64]; 
     762 
     763                for (int passes = 1; passes <= histoPasses; ++ passes) 
     764                { 
     765                        int n = (int)mViewCells.size() * passes / histoPasses; 
    745766                 
    746                 sprintf(filename, "histogram%06d.log", n); 
    747                 EvalViewCellHistogram(filename, n); 
    748         } 
    749  
    750 #endif 
     767                        cout << "computing histogram for " << n << " view cells" << endl; 
     768 
     769                        //-- evaluate histogram for render cost 
     770                        sprintf(s, "-%09d-histo.log", n); 
     771                        string filename = string(statsPrefix) + string(s); 
     772 
     773                        EvalViewCellHistogram(filename, n); 
     774 
     775                        ////////////////////////////////////////// 
     776            // --evaluate histogram for pvs size 
     777 
     778                        cout << "computing pvs histogram for " << n << " view cells" << endl; 
     779 
     780                        sprintf(s, "-%09d-histo-pvs.log", n); 
     781                        filename = string(statsPrefix) + string(s); 
     782 
     783                        EvalViewCellHistogramForPvsSize(filename, n); 
     784                } 
     785        } 
     786 
    751787        // find empty view cells bug 
    752788        if (TEST_EMPTY_VIEW_CELLS) 
     
    802838         
    803839        case PER_TRIANGLE: 
    804                 { 
     840                {cout << "pertriangle" << endl; 
    805841                        // HACK 
    806842                        MeshInstance *mi = dynamic_cast<MeshInstance *>(obj); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r728 r735  
    405405        void EvalViewCellHistogram(const string filename, const int nViewCells); 
    406406 
     407        /** Evaluautes histogram for a given number of view cells. 
     408        */ 
     409        void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells); 
     410 
    407411        /** Evaluates the render cost of a view cell. 
    408412        */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r734 r735  
    120120        environment->GetBoolValue("VspBspTree.simulateOctree", mSimulateOctree); 
    121121        environment->GetBoolValue("VspBspTree.useRandomAxis", mUseRandomAxis); 
    122         environment->GetBoolValue("VspBspTree.useBreathFirstSplits", mBreathFirstSplits); 
     122        environment->GetIntValue("VspBspTree.nodePriorityQueueType", mNodePriorityQueueType); 
    123123 
    124124        environment->GetBoolValue("ViewCells.PostProcess.emptyViewCellsMerge", mEmptyViewCellsMergeAllowed); 
     
    154154        Debug << "subdivision stats log: " << subdivisionStatsLog << endl; 
    155155        Debug << "use random axis: " << mUseRandomAxis << endl; 
    156         Debug << "breath first splits: " << mBreathFirstSplits << endl; 
    157         Debug << "depth first splits: " << mDepthFirstSplits << endl; 
    158  
     156        Debug << "priority queue type: " << mNodePriorityQueueType << endl; 
    159157        Debug << "empty view cells merge: " << mEmptyViewCellsMergeAllowed << endl; 
    160  
    161158        Debug << "octree: " << mSimulateOctree << endl; 
    162159 
     
    942939void VspBspTree::EvalPriority(VspBspTraversalData &tData) const 
    943940{ 
    944         if (mBreathFirstSplits) 
     941    switch (mNodePriorityQueueType)  
     942        { 
     943        case BREATH_FIRST: 
    945944                tData.mPriority = (float)-tData.mDepth; 
    946         else if (mDepthFirstSplits) 
     945                break; 
     946        case DEPTH_FIRST: 
    947947                tData.mPriority = (float)tData.mDepth; 
    948         else 
     948                break; 
     949        default: 
    949950                tData.mPriority = tData.mPvs * tData.mProbability; 
    950         //cout << "priority: " << tData.mPriority << endl; 
     951                //Debug << "priority: " << tData.mPriority << endl; 
     952                break; 
     953        } 
    951954} 
    952955 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h

    r734 r735  
    810810 
    811811        /// if we should use breath first priority for the splits 
    812         bool mBreathFirstSplits; 
    813         bool mDepthFirstSplits; 
     812        int mNodePriorityQueueType; 
     813 
    814814        bool mEmptyViewCellsMergeAllowed; 
    815815 
     816        // priority queue strategy 
     817        enum {BREATH_FIRST, DEPTH_FIRST, COST_BASED}; 
    816818private: 
    817819 
Note: See TracChangeset for help on using the changeset viewer.