Changeset 728


Ignore:
Timestamp:
04/06/06 17:54:00 (18 years ago)
Author:
mattausch
Message:

added histogram (not tested)
last version before updating render cost evaluation

Location:
GTP/trunk/Lib/Vis
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj

    r727 r728  
    267267                                        RelativePath="..\src\OgreVisibilitySceneManagerDll.cpp"> 
    268268                                </File> 
    269                                 <File 
    270                                         RelativePath="..\src\ViewCellBspTree.cpp"> 
    271                                 </File> 
    272269                        </Filter> 
    273270                </Filter> 
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj

    r726 r728  
    2020                                Name="VCCLCompilerTool" 
    2121                                Optimization="0" 
    22                                 AdditionalIncludeDirectories="..\support;..\support\devil\include;..\support\zlib\include;..\include..\support;&quot;..\include  ..\support&quot;;..\include;&quot;$(GTPDIR)\NonGTP\Devil\include&quot;;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(GTPDIR)\NonGTP\Xerces&quot;;&quot;$(CG_INC_PATH)&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(GTPDIR)\NonGTP\Zlib\include&quot;" 
     22                                AdditionalIncludeDirectories="..\support;..\support\devil\include;..\support\zlib\include;..\include..\support;&quot;..\include  ..\support&quot;;..\include;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(CG_INC_PATH)&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(GTPDIR)\NonGTP\Zlib\include&quot;;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Devil\include" 
    2323                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB" 
    2424                                MinimalRebuild="TRUE" 
     
    6767                                InlineFunctionExpansion="2" 
    6868                                FavorSizeOrSpeed="1" 
    69                                 OptimizeForWindowsApplication="TRUE" 
    7069                                AdditionalIncludeDirectories="..\support;..\support\devil\include;..\support\zlib\include;..\include;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;..\src;&quot;$(CG_INC_PATH)&quot;;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces" 
    7170                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB;" 
     
    8483                                AdditionalDependencies="xerces-c_2.lib zdll.lib zziplib.lib devil.lib qtmain.lib QtOpenGL4.lib QtCore4.lib QtGui4.lib Qt3Supportd4.lib QAxContainer.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib" 
    8584                                AdditionalLibraryDirectories="..\support\xercesc\lib\;..\support\zlib\lib\;..\support\devil\lib;&quot;$(QTDIR)\lib&quot;;..\include;..\src\GL;&quot;$(CG_LIB_PATH)&quot;;&quot;$(GTPDIR)\NonGTP\Xerces&quot;;&quot;$(GTPDIR)\NonGTP\Xerces\xercesc\lib&quot;;&quot;$(GTPDIR)\NonGTP\zlib\lib&quot;;&quot;$(GTPDIR)\NonGTP\Devil\lib&quot;" 
     85                                GenerateDebugInformation="TRUE" 
    8686                                LargeAddressAware="2"/> 
    8787                        <Tool 
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env

    r697 r728  
    177177        # samples used for view cell construction 
    178178        Construction { 
    179                 samples 100000 
     179                samples 1000000 
    180180                samplesPerPass 200000 
    181181        } 
     
    199199        #percentage of total visible objects where pvs is considered invalid 
    200200        maxPvsRatio 1.0 
    201                  
     201 
     202        renderCostEvaluationType perobject 
     203        #renderCostEvaluationType pertriangle 
     204 
    202205        pruneEmptyViewCells false 
    203206        processOnlyValidViewCells false 
     
    242245        } 
    243246 
    244         showVisualization true   
     247        showVisualization false 
    245248        evaluateViewCells false 
    246249         
    247250        Evaluation { 
    248251                samplesPerPass 800000 
    249                 samples 1000000 
     252                samples 800000 
    250253                statsPrefix ../scripts/viewCells 
    251254        } 
     
    308311VspBspTree { 
    309312        Construction { 
    310                 samples 200000 
     313                samples 50000 
    311314                epsilon 0.00005 
    312315                randomize false 
     
    363366                 
    364367                AxisAligned { 
    365                         minRays                 50000 
     368                        minRays                 5000 
    366369                        maxRayContribution      9.9 
    367370                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r722 r728  
    12231223                                        "view_cells_evaluation_stats_prefix=", 
    12241224                                        "viewCells"); 
    1225          
     1225 
     1226        RegisterOption("ViewCells.renderCostEvaluationType", 
     1227                                        optString, 
     1228                                        "view_cells_render_cost_evaluation=", 
     1229                                        "perobject"); 
     1230 
    12261231        RegisterOption("ViewCells.active", 
    12271232                                        optInt, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RenderSimulator.cpp

    r605 r728  
    105105                // that view point is in view cell 
    106106                const float vcCost = pInVc *  
    107                         mViewCellsManager->GetRendercost(vc, mObjRenderCost); 
     107                        mViewCellsManager->GetRendercost(vc/*, mObjRenderCost*/); 
    108108         
    109109                renderTime += vcCost; 
     
    113113                loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 
    114114                 
     115 
    115116                //-- update statistics 
    116117 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.cpp

    r492 r728  
    123123  ViewN = -N; // forwards 
    124124#ifdef _DEBUG 
    125   const float eps = 1e-3; 
     125  const float eps = 1e-3f; 
    126126  if (fabs(Magnitude(ViewU) - 1.0) > eps) { 
    127127    Debug << "ViewU magnitude error= " << Magnitude(ViewU) << "\n"; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r720 r728  
    3939 
    4040// pvs penalty can be different from pvs size 
    41 inline float EvalPvsPenalty(const int pvs,  
    42                                                         const int lower, 
    43                                                         const int upper) 
     41inline float EvalPvsPenalty(const int pvs, const int lower, const int upper) 
    4442{ 
    4543        // clamp to minmax values 
    46         /*if (pvs < lower) 
     44#if HAS_TO_BE_REDONE 
     45        if (pvs < lower) 
    4746                return (float)lower; 
    4847        if (pvs > upper) 
    4948                return (float)upper; 
    50 */ 
     49#endif 
    5150        return (float)pvs; 
    5251} 
     
    204203{ 
    205204        mMergeCost = mergeCost; 
     205} 
     206 
     207 
     208float ViewCell::GetRenderCost() const 
     209{ 
     210        return (float)mPvs.GetSize() * GetVolume(); 
    206211} 
    207212 
     
    791796        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    792797        { 
    793                 int lower = mViewCellsManager->GetMinPvsSize(); 
    794                 int upper = mViewCellsManager->GetMaxPvsSize(); 
    795                 float penalty = EvalPvsPenalty((*vit)->GetPvs().GetSize(), lower, upper); 
     798                const int lower = mViewCellsManager->GetMinPvsSize(); 
     799                const int upper = mViewCellsManager->GetMaxPvsSize(); 
     800                const float penalty = EvalPvsPenalty((*vit)->GetPvs().GetSize(), lower, upper); 
    796801                 
    797802                mDeviation += fabs(mAvgRenderCost - penalty); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r703 r728  
    147147        bool GetValid() const; 
    148148 
     149        /** Returns estimated render cost of this view cell. 
     150        */ 
     151        float GetRenderCost() const; 
    149152 
    150153  /** set color for visiualizations */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r727 r728  
    9191        environment->GetIntValue("ViewCells.Filter.maxSize", mMaxFilterSize); 
    9292        environment->GetFloatValue("ViewCells.Filter.width", mFilterWidth); 
     93        environment->GetIntValue("ViewCells.mRenderCostEvaluationType", mRenderCostEvaluationType); 
    9394 
    9495        char buf[100]; 
     
    119120        { 
    120121                mEvaluationSamplingType = Preprocessor::DIRECTION_BASED_DISTRIBUTION; 
     122        } 
     123        else  
     124        { 
     125                Debug << "error! wrong sampling type" << endl; 
     126                exit(0); 
     127        } 
     128 
     129        environment->GetStringValue("ViewCells.renderCostEvaluationType", buf); 
     130         
     131        if (strcmp(buf, "box") == 0) 
     132        { 
     133                mRenderCostEvaluationType = ViewCellsManager::PER_OBJECT; 
     134        } 
     135        else if (strcmp(buf, "directional") == 0) 
     136        { 
     137                mRenderCostEvaluationType = ViewCellsManager::PER_TRIANGLE; 
    121138        } 
    122139        else  
     
    162179        Debug << "evaluate view cells: " << mEvaluateViewCells << endl; 
    163180        Debug << "sampling type: " << mSamplingType << endl; 
     181        Debug << "render cost evaluation type" << mRenderCostEvaluationType << endl; 
     182        Debug << "evaluation sampling type: " << mEvaluationSamplingType << endl; 
    164183        Debug << "show visualization: " << mShowVisualization << endl; 
    165184        Debug << "filter width: " << mFilterWidth << endl; 
     
    219238                        { 
    220239                                Ray *pray = (*it)->mPiercingRays[0]; 
    221                                 Debug << "view cell " << (*it)->GetId() << " not empty, pvs: " << (*it)->GetPvs().GetSize() << " " << (int)pray->intersections.size() << endl; 
     240                                Debug << "view cell " << (*it)->GetId() << " not empty, pvs: "  
     241                                          << (*it)->GetPvs().GetSize() << " " << (int)pray->intersections.size() << endl; 
    222242 
    223243                                exporter->ExportRays((*it)->mPiercingRays); 
     
    493513 
    494514        return numSamples; 
     515} 
     516 
     517 
     518void ComputeMinMaxRenderCost(float &minRenderCost, 
     519                                                         float &maxRenderCost,  
     520                                                         const ViewCellContainer &viewCells) 
     521{ 
     522        minRenderCost = 1e20f; 
     523        maxRenderCost = -1; 
     524 
     525        ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
     526 
     527        for (it = viewCells.begin(); it != it_end; ++ it) 
     528        { 
     529                const float renderCost = (float)(*it)->GetPvs().GetSize() * (*it)->GetVolume(); 
     530                if (renderCost > maxRenderCost) 
     531                        maxRenderCost = renderCost; 
     532                else if (renderCost < minRenderCost) 
     533                        minRenderCost = renderCost; 
     534        } 
     535} 
     536 
     537void ViewCellsManager::EvalViewCellHistogram(const string filename, const int nViewCells) 
     538{ 
     539        std::ofstream outstream; 
     540        outstream.open(filename.c_str()); 
     541 
     542        ViewCellContainer viewCells; 
     543        mViewCellsTree->CollectBestViewCellSet(mViewCells, nViewCells); 
     544 
     545        float maxRenderCost, minRenderCost; 
     546        /// find out the range for valid render cost 
     547        ComputeMinMaxRenderCost(minRenderCost, maxRenderCost, viewCells); 
     548 
     549        const int intervals = 10000; 
     550        const float range = maxRenderCost - minRenderCost; 
     551        int currentRenderCost = (int)ceil(minRenderCost); 
     552        const int stepSize = (int)((float)range / (float)intervals); 
     553 
     554        for (; currentRenderCost < (int)maxRenderCost; currentRenderCost += stepSize) 
     555        { 
     556                ViewCellContainer::const_iterator it, it_end = viewCells.end();          
     557 
     558                int smallerCost = 0; 
     559 
     560                for (it = viewCells.begin(); it != viewCells.end(); ++ it) 
     561                { 
     562                        ViewCell *vc = *it; 
     563 
     564                        if (EvalRenderCost(vc) < currentRenderCost) 
     565                                ++ smallerCost; 
     566                } 
     567                 
     568                outstream << "#RenderCost: " << currentRenderCost << endl; 
     569                outstream << "#ViewCells: " << smallerCost << endl;              
     570        } 
     571 
    495572} 
    496573 
     
    578655                disposeRays(evaluationSamples, NULL); 
    579656        } 
     657         
     658        string filename = "histogram.log"; 
     659        int nViewCells = 5000; 
     660 
     661        EvalViewCellHistogram(filename, nViewCells); 
    580662 
    581663        // find empty view cells bug 
     
    593675 
    594676 
     677// Returns index of the best view cells of the neighborhood 
    595678int GetBestViewCellIdx(ViewCell *root, const ViewCellContainer &neighborhood) 
    596679{ 
     
    614697 
    615698        return bestViewCellIdx; 
     699} 
     700 
     701 
     702void ViewCellsManager::SetMaxFilterSize(const int size)  
     703{ 
     704        mMaxFilterSize = size; 
     705} 
     706 
     707 
     708float ViewCellsManager::EvalRenderCost(Intersectable *obj) const 
     709{ 
     710        switch (mRenderCostEvaluationType) 
     711        { 
     712        case PER_OBJECT: 
     713                return 1; 
     714         
     715        case PER_TRIANGLE: 
     716                { 
     717                        // HACK 
     718                        MeshInstance *mi = dynamic_cast<MeshInstance *>(obj); 
     719 
     720                        // HACK: assume meshes are triangles 
     721                        if (mi->GetMesh()) 
     722                        { 
     723                                return mi->GetMesh()->mFaces.size(); 
     724                        } 
     725                } 
     726        default: 
     727                return 1; 
     728        } 
     729 
     730        // should not come here 
     731        return 0; 
    616732} 
    617733 
     
    691807  //cout << "neighborhood: " << neighborhood.size() << endl; 
    692808  for (int nMergedViewCells = 0; nMergedViewCells < n; ++ nMergedViewCells) 
    693         { 
     809  { 
    694810          ViewCell *bestViewCell = neighborhood[nMergedViewCells].mViewCell; 
    695811          //cout <<nMergedViewCells<<":"<<"homogenity=" <<neighborhood[nMergedViewCells].mValue<<endl; 
     
    698814          // set negative cost so that this view cell gets deleted 
    699815          root->SetMergeCost(-1.0f); 
    700         } 
     816  } 
    701817   
    702818  return root;   
     
    14531569 
    14541570 
    1455 float ViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const 
    1456 { 
    1457         return mViewCellsTree->GetPvsSize(viewCell) * objRendercost; 
     1571float ViewCellsManager::GetRendercost(ViewCell *viewCell) const 
     1572{ 
     1573        const ObjectPvs &pvs = viewCell->GetPvs(); 
     1574 
     1575        ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end(); 
     1576 
     1577        for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
     1578        { 
     1579                 
     1580        } 
     1581 
     1582        return mViewCellsTree->GetPvsSize(viewCell); 
    14581583} 
    14591584 
     
    14631588        // if already computed 
    14641589        if (mTotalAreaValid) 
     1590        { 
    14651591                return mTotalArea; 
     1592        } 
    14661593 
    14671594        mTotalArea = 0; 
     
    25482675                        exporter->ExportKdTree(*mKdTree); 
    25492676 
    2550                         for (i=0; i < pvsOut; i++) 
     2677                        for (i = 0; i < pvsOut; i++) 
    25512678                                exporter->ExportRays(rays[i], RgbColor(1, 0, 0)); 
    25522679 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r722 r728  
    5757class ViewCellsManager 
    5858{ 
    59  
    6059public: 
    61   struct PvsStatistics { 
    62         int minPvs; 
    63         int maxPvs; 
    64         float avgPvs; 
    65         int viewcells; 
     60        struct PvsStatistics  
     61        { 
     62                int minPvs; 
     63                int maxPvs; 
     64                float avgPvs; 
     65                int viewcells; 
    6666  }; 
     67 
     68        /// view cell container types 
     69        enum {BSP, KD, VSP_KD, VSP_BSP}; 
    6770   
    68   /** 
    69         Candidate for leaf merging based on priority. 
    70         */ 
    71         class LocalMergeCandidate 
    72         {   
    73         public: 
    74                 LocalMergeCandidate(ViewCell *l, ViewCell *r); 
    75  
    76                 /** If this merge pair is still valid. 
    77                 */ 
    78                 //bool IsValid() const; 
    79          
    80                 friend bool operator<(const LocalMergeCandidate &leafa, const LocalMergeCandidate &leafb) 
    81                 { 
    82                         return leafb.GetMergeCost() < leafa.GetMergeCost(); 
    83                 } 
    84  
    85                 void SetLeftViewCell(ViewCell *l) {mLeftViewCell = l;} 
    86                 void SetRightViewCell(ViewCell *l) {mRightViewCell = l;} 
    87  
    88                 ViewCell *GetLeftViewCell() const {return mLeftViewCell;} 
    89                 ViewCell *GetRightViewCell() const { return mRightViewCell;} 
    90  
    91                 float GetMergeCost() const {return mMergeCost;}  
    92                 void SetMergeCost(const float cost) {mMergeCost = cost;}  
    93  
    94         protected: 
    95  
    96                 /// render cost increase by this merge 
    97                 float mMergeCost; 
    98          
    99                 ViewCell *mLeftViewCell; 
    100                 ViewCell *mRightViewCell; 
    101         }; 
    102  
    103  
    104  
    105   /// view cell container types 
    106   enum {BSP, KD, VSP_KD, VSP_BSP}; 
    107    
     71        /// view cells evaluation type 
     72        enum {PER_OBJECT, PER_TRIANGLE}; 
     73 
    10874        /** Constructor taking the initial and construction samples. 
    10975                @param initialSamples the maximal number of samples used for creating the hierarchy 
     
    277243        /** Returns render cost of a single view cell given the render cost of an object. 
    278244        */ 
    279         float GetRendercost(ViewCell *viewCell, float objRendercost) const; 
     245        float GetRendercost(ViewCell *viewCell) const; 
    280246 
    281247        /** Returns reference to container of loaded / generated view cells. 
     
    427393        void EvalViewCellPartition(Preprocessor *preprocessor); 
    428394 
    429   void SetMaxFilterSize(const int size) { 
    430         mMaxFilterSize = size; 
    431   } 
    432  
    433   /** deletes interior nodes from the tree which have negative merge cost set (local merge) */ 
    434   void 
    435   DeleteLocalMergeTree(ViewCell *vc 
    436                                            ) const; 
     395        /** Sets maximal size of a view cell filter. 
     396        */ 
     397        void SetMaxFilterSize(const int size); 
     398 
     399        /** Deletes interior nodes from the tree which have negative merge cost set (local merge)  
     400        */ 
     401        void DeleteLocalMergeTree(ViewCell *vc) const; 
    437402   
     403        /** Evaluautes histogram for a given number of view cells. 
     404        */ 
     405        void EvalViewCellHistogram(const string filename, const int nViewCells); 
     406 
     407        /** Evaluates the render cost of a view cell. 
     408        */ 
     409        float EvalRenderCost(Intersectable *obj) const; 
     410 
    438411protected: 
    439412 
     
    591564 
    592565        ViewCellContainer mEmptyViewCells; 
     566 
     567        int mRenderCostEvaluationType; 
    593568}; 
    594569 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r727 r728  
    20782078        if (!obj) 
    20792079                return; 
     2080 
    20802081        // new object 
    20812082        if ((obj->mMailbox != sFrontId) && 
     
    23302331{ 
    23312332// TODO 
    2332 #if VC_HISTORY 
     2333#if HAS_TO_BE_REDONE 
    23332334        stack<BspNode *> nodeStack; 
    23342335 
     
    32743275{ 
    32753276// TODO 
    3276 #if VC_HISTORY 
     3277#if HAS_TO_BE_REDONE 
    32773278        if (node->IsLeaf()) 
    32783279                return node; 
     
    33173318        int collapsed = 0; 
    33183319        //TODO 
    3319 #if VC_HISTORY 
     3320#if HAS_TO_BE_REDONE 
    33203321        (void)CollapseTree(mRoot, collapsed); 
    33213322 
     
    33303331{ 
    33313332// TODO 
    3332 #if VC_HISTORY 
     3333#if HAS_TO_BE_REDONE 
    33333334        // list not valid anymore => clear 
    33343335        stack<BspNode *> nodeStack; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspKdTree.cpp

    r667 r728  
    22032203        if (!vc) return false; 
    22042204// TODO 
    2205 #if VC_HISTORY 
     2205#if HAS_TO_BE_REDONE 
    22062206        // set new size of view cell 
    22072207        vc->SetVolume(fVc->GetVolume() + bVc->GetVolume()); 
     
    23422342 
    23432343                        VspKdViewCell *viewCell = leaf->GetViewCell(); 
    2344 #if VC_HISTORY 
     2344#if HAS_TO_BE_REDONE 
    23452345                        if (!viewCell->Mailed()) 
    23462346                        { 
     
    24862486{ 
    24872487        // compute new pvs and area 
    2488         //      TODO 
    2489 #if VC_HISTORY 
     2488#if HAS_TO_BE_REDONE 
    24902489        vc1->GetPvs().SubtractPvs(*leaf->mPvs); 
    24912490        vc2->GetPvs().AddPvs(*leaf->mPvs); 
Note: See TracChangeset for help on using the changeset viewer.