Ignore:
Timestamp:
12/21/06 23:52:10 (18 years ago)
Author:
mattausch
Message:

added mechanism for histogram on certain MB in hierarchymanager
no more bug in undersampling estimation
added sampling strategy to spatial box based (also for eval)
added testing scripts

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

Legend:

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

    r1912 r1919  
    13141314                                        "5000"); 
    13151315 
     1316        RegisterOption("ViewCells.Evaluation.histoMem", 
     1317                                        optInt, 
     1318                                        "view_cells_evaluation_histo_mem=", 
     1319                                        "50"); 
     1320 
    13161321        RegisterOption("ViewCells.renderCostEvaluationType", 
    13171322                                        optString, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1917 r1919  
    20582058                                                                                int &viewSpaceSplits, 
    20592059                                                                                int &objectSpaceSplits, 
    2060                                                                                 const bool useFilter) 
     2060                                                                                const bool useFilter, 
     2061                                                                                const bool useHisto, 
     2062                                                                                const int histoMem, 
     2063                                                                                const int pass, 
     2064                                                                                bool &histoUsed) 
    20612065{ 
    20622066        ViewCellContainer viewCells; 
     
    21212125                { 
    21222126                        ComputePvs(vc->GetPvs(), rc, pvsEntries); 
     2127                        vc->SetPvsCost(rc); 
    21232128                } 
    21242129 
     
    21322137        viewSpaceSplits = (int)viewCells.size(); 
    21332138        objectSpaceSplits = (int)bvhNodes.size(); 
     2139 
     2140        //////////////////////// 
     2141    //-- evaluate histogram for pvs size 
     2142 
     2143        if (useHisto && (memory <= (float)histoMem)) 
     2144        { 
     2145                char str[100]; 
     2146                char statsPrefix[100]; 
     2147                int histoStepSize; 
     2148 
     2149                Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix); 
     2150         
     2151                cout << "computing pvs histogram for " << histoMem << " memory" << endl; 
     2152                Debug << "computing pvs histogram for " << histoMem << " memory" << endl; 
     2153                 
     2154                sprintf(str, "-%05d-%05d-histo-pvs.log", pass, histoMem); 
     2155                const string filename = string(statsPrefix) + string(str); 
     2156 
     2157                mVspTree->mViewCellsManager->EvalViewCellHistogramForPvsSize(filename, viewCells); 
     2158 
     2159                histoUsed = true; 
     2160        } 
     2161 
    21342162        //cout << "viewCells: " << (int)viewCells.size() << " nodes: " << (int)bvhNodes.size() << " rc: " << renderCost << " entries: " << pvsEntries << endl; 
    21352163 
     
    23252353void HierarchyManager::EvaluateSubdivision2(ofstream &splitsStats, 
    23262354                                                                                        const int splitsStepSize, 
    2327                                                                                         const bool useFilter) 
     2355                                                                                        const bool useFilter, 
     2356                                                                                        const bool useHisto, 
     2357                                                                                        const int histoMem, 
     2358                                                                                        const int pass) 
    23282359{ 
    23292360        vector<HierarchySubdivisionStats> subStatsContainer; 
     
    23312362        int splits = (1 + (mHierarchyStats.Leaves() - 1) / splitsStepSize) * splitsStepSize; 
    23322363        cout << "splits: " << splits << endl; 
     2364 
     2365        bool histoUsed = false; 
    23332366 
    23342367        while (1) 
     
    23422375                                                                                                subStats.mViewSpaceSplits, 
    23432376                                                                                                subStats.mObjectSpaceSplits, 
    2344                                                                                                 useFilter); 
     2377                                                                                                useFilter, 
     2378                                                                                                useHisto && !histoUsed, 
     2379                                                                                                histoMem, 
     2380                                                                                                pass, 
     2381                                                                                                histoUsed); 
    23452382 
    23462383                 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1912 r1919  
    288288        void EvaluateSubdivision2(ofstream &splitsStats, 
    289289                                                          const int splitsStepSize, 
    290                                                           const bool useFilter); 
     290                                                          const bool useFilter, 
     291                                                          const bool useHisto, 
     292                                                          const int histoMem, 
     293                                                          const int pass); 
    291294 
    292295 
     
    526529                                                  int &viewSpaceSplits, 
    527530                                                  int &objectSpaceSplits, 
    528                                                   const bool useFilter); 
     531                                                  const bool useFilter, 
     532                                                  const bool useHisto, 
     533                                                  const int histoMem, 
     534                                                  const int pass, 
     535                                                  bool &histoUsed); 
    529536 
    530537        void ComputePvs(const ObjectPvs &pvs, float &rc, int &pvsEntries); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj

    r1918 r1919  
    9292                                Name="VCLinkerTool" 
    9393                                AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib" 
    94                                 OutputFile="$(OutDir)/Preprocessor2.exe" 
     94                                OutputFile="$(OutDir)/Preprocessor.exe" 
    9595                                LinkIncremental="1" 
    9696                                AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1918 r1919  
    147147 
    148148        // mix of sampling strategies 
    149         mStrategies.push_back(SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION); 
    150          
    151         /*mStrategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 
    152         mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    153         mStrategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 
    154         */ 
    155         //mStrategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 
     149        if (0) 
     150        { 
     151                mStrategies.push_back(SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION); 
     152        } 
     153        else 
     154        { 
     155                /*mStrategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 
     156                mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
     157                mStrategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 
     158                */ 
     159         
     160                mStrategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 
     161        } 
    156162                 
    157163    Debug << "casting strategies: "; 
     
    955961 
    956962        it = viewCells.begin(); 
     963         
     964        for (int j = 0; j < intervals; ++ j) 
     965        { 
     966                float volDif = 0; 
     967                int smallerDif = 0; 
     968 
     969                while ((i < (int)viewCells.size()) &&  
     970                           (viewCells[i]->GetPvsCost() < currentPvs)) 
     971                { 
     972                        volDif += viewCells[i]->GetVolume(); 
     973                        volSum += viewCells[i]->GetVolume(); 
     974 
     975                        ++ i; 
     976                        ++ smallerDif; 
     977                        ++ smallerSum; 
     978                } 
     979                 
     980                //              if (0 && (i < (int)viewCells.size())) 
     981                //                Debug << "new pvs cost increase: " << mViewCellsTree->GetPvsCost(viewCells[i])  
     982                //                              << " " << currentPvs << endl; 
     983                 
     984                const float volRatioDif = volDif / totalVol; 
     985                const float volRatioSum = volSum / totalVol; 
     986 
     987                outstream << "#Pass\n" << j << endl; 
     988                outstream << "#Pvs\n" << currentPvs << endl; 
     989                outstream << "#ViewCellsDif\n" << smallerDif << endl; 
     990                outstream << "#ViewCellsSum\n" << smallerSum << endl;    
     991                outstream << "#VolumeDif\n" << volRatioDif << endl << endl; 
     992                outstream << "#VolumeSum\n" << volRatioSum << endl << endl; 
     993         
     994                //-- increase current pvs size to define next interval 
     995                currentPvs += stepSize; 
     996        } 
     997 
     998        outstream.close(); 
     999} 
     1000 
     1001 
     1002void ViewCellsManager::EvalViewCellHistogramForPvsSize(const string filename,  
     1003                                                                                                           ViewCellContainer &viewCells) 
     1004{ 
     1005        std::ofstream outstream; 
     1006        outstream.open(filename.c_str()); 
     1007 
     1008        float maxPvs, maxVal, minVal; 
     1009         
     1010        // sort by pvs size 
     1011        sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs); 
     1012 
     1013        maxPvs = viewCells.back()->GetPvsCost(); 
     1014        minVal = 0; 
     1015 
     1016        // hack: normalize pvs size 
     1017        int histoMaxVal; 
     1018        Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal); 
     1019        maxVal = max((float)histoMaxVal, maxPvs); 
     1020                 
     1021        Debug << "histogram minpvssize: " << minVal << " maxpvssize: " << maxVal  
     1022                << " real maxpvs " << maxPvs << endl; 
     1023 
     1024        int histoIntervals; 
     1025        Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.intervals", histoIntervals); 
     1026        const int intervals = min(histoIntervals, (int)viewCells.size()); 
     1027 
     1028        const float range = maxVal - minVal; 
     1029        int stepSize = (int)(range / intervals); 
     1030 
     1031        // set step size to avoid endless loop 
     1032        if (!stepSize) stepSize = 1; 
     1033         
     1034        Debug << "intervals " << histoIntervals << endl; 
     1035        Debug << "stepsize: " << stepSize << endl; 
     1036        cout << "intervals " << histoIntervals << endl; 
     1037        cout << "stepsize: " << stepSize << endl; 
     1038 
     1039        const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost(); 
     1040        const float totalVol = GetViewSpaceBox().GetVolume(); 
     1041 
     1042        float currentPvs = minVal; 
     1043         
     1044        int i = 0; 
     1045        int j = 0; 
     1046        float volSum = 0; 
     1047        int smallerSum = 0; 
     1048 
     1049        //ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end();    
    9571050         
    9581051        for (int j = 0; j < intervals; ++ j) 
     
    60316124        Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.stepSize", splitsStepSize); 
    60326125         
     6126        bool useHisto; 
     6127        int histoMem; 
     6128 
     6129        Environment::GetSingleton()->GetBoolValue("ViewCells.Evaluation.histogram", useHisto); 
     6130        Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.histoMem", histoMem); 
     6131 
    60336132        Debug << "step size: " << splitsStepSize << endl; 
    60346133        Debug << "view cell evaluation samples per pass: " << samplesPerPass << endl; 
     
    60476146 
    60486147        // mix of sampling strategies 
    6049         evalStrats.push_back(SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION); 
    6050  
    6051         /*evalStrats.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 
    6052         evalStrats.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
    6053         evalStrats.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 
    6054 */ 
    6055         //evalStrats.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 
     6148        if (0) 
     6149        { 
     6150                evalStrats.push_back(SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION); 
     6151        } 
     6152        else 
     6153        { 
     6154                /*evalStrats.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 
     6155                evalStrats.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 
     6156                evalStrats.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 
     6157                */ 
     6158                evalStrats.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 
     6159        } 
    60566160                         
    60576161    Debug << "casting eval strategies: "; 
     
    60646168                cout << evalStrats[i] << " "; 
    60656169        cout << endl; 
     6170 
     6171        int pass = 0; 
    60666172 
    60676173        while (castSamples < numSamples) 
     
    61226228 
    61236229                        ofstream ofstr(filename.c_str()); 
    6124                         mHierarchyManager->EvaluateSubdivision2(ofstr, splitsStepSize, false); 
     6230                        mHierarchyManager->EvaluateSubdivision2(ofstr, splitsStepSize, false, useHisto, histoMem, pass); 
    61256231 
    61266232                        timeDiff = TimeDiff(startTime, GetTime()); 
     
    61676273                                         << (float)pvsSize * ObjectPvs::GetEntrySize() << endl; 
    61686274                        } 
     6275                        ++ pass; 
    61696276                } 
    61706277 
     
    61746281        //////////// 
    61756282        //-- histogram 
    6176  
     6283#if 1 
    61776284        const int numLeaves = mViewCellsTree->GetNumInitialViewCells(mViewCellsTree->GetRoot()); 
    6178         bool useHisto; 
    61796285        int histoStepSize; 
    61806286 
     
    61856291        { 
    61866292                // evaluate view cells in a histogram            
    6187                 char s[64]; 
     6293                char str[64]; 
    61886294 
    61896295                // hack: just show final view cells 
     
    61956301 
    61966302                        cout << "computing histogram for " << pass << " view cells" << endl; 
    6197 #if 0 
    6198                         //-- evaluate histogram for render cost 
    6199                         sprintf(s, "-%09d-histo.log", pass); 
    6200                         filename = string(statsPrefix) + string(s); 
    6201  
    6202                         EvalViewCellHistogram(filename, pass); 
    6203  
    6204 #endif 
     6303 
    62056304                        ////////////////////////////////////////// 
    62066305            //-- evaluate histogram for pvs size 
     
    62086307                        cout << "computing pvs histogram for " << pass << " view cells" << endl; 
    62096308 
    6210                         sprintf(s, "-%09d-histo-pvs.log", pass); 
    6211                         filename = string(statsPrefix) + string(s); 
     6309                        sprintf(str, "-%09d-histo-pvs2.log", pass); 
     6310                        filename = string(statsPrefix) + string(str); 
    62126311 
    62136312                        EvalViewCellHistogramForPvsSize(filename, pass); 
    62146313                } 
    62156314        } 
    6216 } 
    6217  
    62186315#endif 
    6219  
    6220  
    6221  
    6222 } 
     6316} 
     6317 
     6318#endif 
     6319 
     6320 
     6321 
     6322} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1903 r1919  
    440440        void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells); 
    441441 
     442        void EvalViewCellHistogramForPvsSize(const string filename,  
     443                                                                                 ViewCellContainer &viewCells); 
     444 
    442445        /** Evaluates the render cost of a view cell. 
    443446        */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1918 r1919  
    29492949 
    29502950        mTotalCost = vData.mCorrectedRenderCost = vData.mRenderCost = pvsCost; 
    2951         mPvsEntries = vData.mCorrectedPvs = vData.mPvs = EvalPvsEntriesSize(rays); 
     2951        mPvsEntries = EvalPvsEntriesSize(rays); 
     2952        vData.mCorrectedPvs = vData.mPvs = (float)mPvsEntries; 
    29522953 
    29532954        ////////////// 
Note: See TracChangeset for help on using the changeset viewer.