Changeset 547


Ignore:
Timestamp:
01/17/06 23:28:10 (18 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r546 r547  
    1313#;../data/vienna/vienna-plane.x3d 
    1414#       filename ../data/vienna/viewcells-25-sel.x3d 
    15         filename ../data/atlanta/atlanta2.x3d 
     15#       filename ../data/atlanta/atlanta2.x3d 
    1616#       filename ../data/soda/soda.dat 
    17 #       filename ../data/soda/soda5.dat 
     17        filename ../data/soda/soda5.dat 
    1818} 
    1919 
     
    3030        samplesPerPass  100000 
    3131        initialSamples 300000 
    32         vssSamples 1200000 
     32        vssSamples 700000 
    3333        vssSamplesPerPass 100000 
    3434        useImportanceSampling true 
    3535        loadInitialSamples  false 
    3636        storeInitialSamples false 
    37         useViewSpaceBox false 
     37        useViewSpaceBox true 
    3838        testBeamSampling true 
    3939} 
     
    182182        maxViewCells 100000 
    183183        #percentage of total visible objects where pvs is considered invalid 
    184         maxPvsRatio 0.5 
     184        maxPvsRatio 0.9 
    185185                 
    186186        delayedConstruction true 
     
    195195                # how much samples we use for visualization 
    196196                samples 5000 
    197                 #colorCode PVS 
     197                colorCode PVS 
    198198                #colorCode MergedLeaves 
    199199                #colorCode MergedTreeDiff 
    200                 colorCode Random 
     200                #colorCode Random 
    201201                exportRays false 
    202202                exportGeometry true 
     
    259259VspBspTree { 
    260260        Construction { 
    261                 samples 800000 
     261                samples 500000 
    262262                epsilon 0.005 
    263263                randomize false 
     
    271271        # pvs                  = 1024 
    272272         
    273         splitPlaneStrategy 1026 
     273        splitPlaneStrategy 1024 
    274274         
    275275        # maximal candidates for split planes 
     
    296296                maxDepth                30 
    297297                minPvs                  10 
    298                 #minArea                0.0001 
    299                 minArea                 -1 
    300                 maxRayContribution      0.3 
     298                #minProbability         0.0001 
     299                minProbability          -1 
     300                maxRayContribution      0.2 
    301301                maxCostRatio            0.9 
    302302                missTolerance           3 
    303303                #maxAccRayLength        100 
    304304                 
    305                 maxViewCells            5001 
     305                maxViewCells            2501 
    306306                 
    307307                # used for pvs criterium 
     
    323323        PostProcess { 
    324324                maxCostRatio 0.001 
    325                 minViewCells 2000 
     325                minViewCells 120 
    326326                useRaysForMerge true 
    327327        } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r545 r547  
    20822082    face6->mVertices.push_back(Vector3(mMax.x, mMax.y, mMax.z)); 
    20832083    face6->mVertices.push_back(Vector3(mMin.x, mMax.y, mMax.z)); 
    2084 } 
     2084 
     2085} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r542 r547  
    17081708                                        "vsp_bsp_term_min_pvs=", 
    17091709                                        "20"); 
    1710         RegisterOption("VspBspTree.Termination.minArea", 
     1710        RegisterOption("VspBspTree.Termination.minProbability", 
    17111711                                        optFloat, 
    1712                                         "vsp_bsp_term_min_area=", 
     1712                                        "vsp_bsp_term_min_probability=", 
    17131713                                        "0.001"); 
    17141714 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r520 r547  
    1111mPiercingRays(0), 
    1212mArea(0), 
    13 mVolume(0) 
     13mVolume(0), 
     14mValid(true) 
    1415{ 
    1516} 
     
    1920mPiercingRays(0), 
    2021mArea(0), 
    21 mVolume(0) 
     22mVolume(0), 
     23mValid(true) 
    2224{ 
    2325} 
     
    9698 
    9799 
     100void ViewCell::SetValid(const bool valid) 
     101{ 
     102        mValid = true; 
     103} 
     104 
     105 
     106bool ViewCell::GetValid() const 
     107{ 
     108        return mValid; 
     109} 
     110 
     111 
    98112/************************************************************************/ 
    99113/*                class ViewCellsStatistics implementation              */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r520 r547  
    131131        void SetMesh(Mesh *mesh); 
    132132 
     133        void SetValid(const bool valid); 
     134        bool GetValid() const; 
     135 
    133136protected: 
    134137 
     
    138141        float mVolume; 
    139142        float mArea; 
     143 
     144 
     145        bool mValid; 
    140146}; 
    141147 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r545 r547  
    212212BspTree::BspTree():   
    213213mRoot(NULL),  
    214 mPvsUseArea(true), 
     214mUseAreaForPvs(true), 
    215215mGenerateViewCells(true) 
    216216{ 
     
    410410                << maxCostNodes * 100 / (double)Leaves() << endl; 
    411411 
    412         app << "#N_PMINAREALEAVES  ( Percentage of leaves with mininum area )\n" 
    413                 << minAreaNodes * 100 / (double)Leaves() << endl; 
     412        app << "#N_PMINAREALEAVES  ( Percentage of leaves with mininum probability )\n" 
     413                << minProbabilityNodes * 100 / (double)Leaves() << endl; 
    414414 
    415415        app << "#N_PMAXRAYCONTRIBLEAVES  ( Percentage of leaves with maximal ray contribution )\n"  
     
    15351535                GenerateUniqueIdsForPvs(); 
    15361536 
    1537                 if (mPvsUseArea) // use front and back cell areas to approximate volume 
     1537                if (mUseAreaForPvs) // use front and back cell areas to approximate volume 
    15381538                { 
    15391539                        // construct child geometry with regard to the candidate split plane 
     
    16071607                        AddObjToPvs(ray->sourceObject.mObject, cf, frontPvs, backPvs); 
    16081608                         
    1609                         if (mPvsUseArea) 
     1609                        if (mUseAreaForPvs) 
    16101610                        { 
    16111611                                float len = 1; 
     
    18301830         
    18311831        if (data.mGeometry->GetArea() <= mTermMinArea)  
    1832                 ++ mStat.minAreaNodes; 
     1832                ++ mStat.minProbabilityNodes; 
    18331833 
    18341834#ifdef _DEBUG 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r545 r547  
    130130        int maxRayContribNodes; 
    131131        // minimum area nodes 
    132         int minAreaNodes; 
     132        int minProbabilityNodes; 
    133133        /// nodes termination because of max cost ratio; 
    134134        int maxCostNodes; 
     
    181181                minRaysNodes = 0; 
    182182                maxRayContribNodes = 0; 
    183                 minAreaNodes = 0; 
     183                minProbabilityNodes = 0; 
    184184                maxCostNodes = 0; 
    185185 
     
    310310/** BSP leaf node implementation. 
    311311*/ 
    312 class BspLeaf : public BspNode  
     312class BspLeaf: public BspNode  
    313313{ 
    314314        friend class BspTree; 
     
    340340        ObjectPvs *mPvs; 
    341341 
    342         /// leaf area 
    343         float mArea; 
     342        /// Probability that the view point lies in this leaf 
     343        float mProbability; 
    344344 
    345345protected: 
     
    886886 
    887887        /// if area or accumulated ray lenght should be used for PVS heuristics 
    888         bool mPvsUseArea; 
     888        bool mUseAreaForPvs; 
    889889 
    890890        /// epsilon where two points are still considered equal 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r544 r547  
    2525mTotalAreaValid(false), 
    2626mTotalArea(0.0f), 
    27 mViewCellsFinished(false) 
     27mViewCellsFinished(false), 
     28mMaxPvsSize(99999) 
    2829{ 
    2930        mViewSpaceBox.Initialize(); 
     
    4950        environment->GetBoolValue("ViewCells.Visualization.exportRays", mExportRays); 
    5051        environment->GetBoolValue("ViewCells.Visualization.exportGeometry", mExportGeometry); 
     52        environment->GetFloatValue("ViewCells.maxPvsRatio", mMaxPvsRatio); 
    5153 
    5254        char buf[50]; 
     
    105107        return (int)rays.size(); 
    106108} 
     109 
     110 
     111bool ViewCellsManager::CheckValid(ViewCell *vc) const 
     112{ 
     113        if (vc->GetPvs().GetSize() > mMaxPvsSize) 
     114                return false; 
     115 
     116        return true; 
     117} 
     118 
    107119 
    108120bool ViewCellsManager::LoadViewCells(const string filename, ObjectContainer *objects) 
     
    347359} 
    348360 
     361 
    349362ViewCellContainer &ViewCellsManager::GetViewCells() 
    350363{ 
     
    375388        // has to be recomputed 
    376389        mTotalAreaValid = false; 
     390} 
     391 
     392 
     393int ViewCellsManager::GetMaxPvsSize() const 
     394{ 
     395        return mMaxPvsSize; 
    377396} 
    378397 
     
    17971816float VspBspViewCellsManager::GetProbability(ViewCell *viewCell) 
    17981817{ 
    1799 #if 0 
    1800         return GetArea(viewCell) / GetViewSpaceBox().SurfaceArea(); 
    1801 #else 
    1802         return GetArea(viewCell) / GetAccVcArea(); 
    1803 #endif 
     1818        if (mVspBspTree->mUseAreaForPvs) 
     1819                return GetArea(viewCell) / GetAccVcArea(); 
     1820        else 
     1821                return GetVolume(viewCell) / mViewSpaceBox.GetVolume(); 
    18041822} 
    18051823 
     
    18071825void VspBspViewCellsManager::CollectViewCells() 
    18081826{ 
    1809         mVspBspTree->CollectViewCells(mViewCells); 
     1827        mVspBspTree->CollectViewCells(mViewCells, false); 
    18101828} 
    18111829 
     
    18521870        Debug << "saved rays: " << (int)savedRays.size() << endl; 
    18531871 
     1872        mMaxPvsSize = (int)(mMaxPvsRatio * (float)objects.size()); 
     1873         
    18541874        mVspBspTree->Construct(constructionRays, &mViewSpaceBox); 
    18551875 
     
    19291949 
    19301950        // TODO: should be done BEFORE the ray casting 
    1931         merged = mVspBspTree->MergeViewCells(rays); 
     1951        merged = mVspBspTree->MergeViewCells(rays, objects); 
    19321952 
    19331953        //-- stats and visualizations 
     
    23002320                                                                                 ViewCell *vc) const 
    23012321{ 
    2302         if (mColorCode == 0) // Random color 
     2322        if (CheckValid(vc) && (mColorCode == 0)) // Random color 
    23032323                return; 
    23042324 
    23052325        float importance = 0; 
    2306  
     2326         
     2327        Material m; 
     2328         
    23072329        switch (mColorCode) 
    23082330        { 
     
    23192341                        importance = (float)bspVc->mLeaves.size() / 
    23202342                                (float)mViewCellsStats.maxLeaves; 
     2343 
     2344                        if (CheckValid(vc)) 
     2345                                m.mDiffuseColor.b = 1.0f; 
     2346                        m.mDiffuseColor.r = importance; 
     2347                        m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 
    23212348                } 
    23222349                break; 
     
    23252352                        importance = (float)GetMaxTreeDiff(vc) / 
    23262353                                (float)(mVspBspTree->GetStatistics().maxDepth * 2); 
     2354 
     2355                        if (CheckValid(vc)) 
     2356                                m.mDiffuseColor.b = 1.0f; 
     2357                        m.mDiffuseColor.r = importance; 
     2358                        m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 
    23272359                } 
    23282360                break; 
     
    23312363        } 
    23322364 
    2333         Material m; 
    2334         m.mDiffuseColor.b = 1.0f; 
     2365        m.mDiffuseColor.b = CheckValid(vc) ? 1.0f : 0.0f; 
    23352366        m.mDiffuseColor.r = importance; 
    23362367        m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 
     2368 
    23372369        //Debug << "importance: " << importance << endl; 
    23382370        exporter->SetForcedMaterial(m); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r542 r547  
    251251        virtual int CastBeam(Beam &beam); 
    252252 
     253        /** Checks if view cell is considered as valid. 
     254        */ 
     255        virtual bool CheckValid(ViewCell *vc) const; 
     256 
     257        /** Returns maximal allowed pvs size. 
     258        */ 
     259        int GetMaxPvsSize() const; 
     260 
     261 
     262        /** Exports view cell geometry. 
     263        */ 
     264        virtual void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const = 0; 
     265 
    253266protected: 
    254267 
     
    258271        */ 
    259272        void CreateUniqueViewCellIds(); 
     273 
    260274        /** Recollects view cells and resets statistics. 
    261275        */ 
     
    281295        virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0; 
    282296 
    283         /** Exports view cell geometry. 
    284         */ 
    285         virtual void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const = 0; 
    286  
     297         
    287298        /** Creates meshes from the view cells. 
    288299        */ 
     
    316327        float mTotalAreaValid; 
    317328        float mTotalArea; 
     329 
     330        int mMaxPvsSize; 
     331 
     332        float mMaxPvsRatio; 
    318333 
    319334        ViewCellsStatistics mViewCellsStats; 
     
    324339        /// if view cells should be exported 
    325340        bool mExportViewCells; 
     341 
     342 
    326343        //-- visualization options 
    327344         
     
    380397        void CreateMesh(ViewCell *vc); 
    381398 
     399        void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const; 
     400 
    382401protected: 
    383402 
     
    396415 
    397416        void ExportColor(Exporter *exporter, ViewCell *vc) const; 
    398         void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const; 
     417         
     418 
    399419 
    400420        /// the BSP tree. 
     
    453473        void CreateMesh(ViewCell *vc); 
    454474 
     475        void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const; 
     476 
    455477protected: 
    456478 
     
    459481 
    460482        void ExportColor(Exporter *exporter, ViewCell *vc) const; 
    461         void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const; 
     483 
    462484 
    463485        /// the BSP tree. 
     
    509531        void CreateMesh(ViewCell *vc); 
    510532 
     533        void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const; 
     534 
    511535protected: 
    512536 
     
    517541 
    518542        void ExportColor(Exporter *exporter, ViewCell *vc) const; 
    519         void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const; 
     543 
    520544 
    521545 
     
    573597        int CastBeam(Beam &beam); 
    574598 
     599        void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const; 
     600 
    575601protected: 
    576602 
     
    591617 
    592618        void ExportColor(Exporter *exporter, ViewCell *vc) const; 
    593         void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const; 
    594  
    595619 
    596620        /// the view space partition BSP tree. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r545 r547  
    3636 
    3737float BspMergeCandidate::sOverallCost = 0; 
     38bool BspMergeCandidate::sUseArea = false; 
    3839 
    3940/********************************************************************/ 
     
    4344VspBspTree::VspBspTree(): 
    4445mRoot(NULL), 
    45 mPvsUseArea(true), 
     46mUseAreaForPvs(false), 
    4647mCostNormalizer(Limits::Small), 
    4748mViewCellsManager(NULL), 
    4849mOutOfBoundsCell(NULL), 
    49 mShowInvalidSpace(false), 
    5050mStoreRays(false) 
    5151{ 
     
    5959        environment->GetIntValue("VspBspTree.Termination.minPvs", mTermMinPvs); 
    6060        environment->GetIntValue("VspBspTree.Termination.minRays", mTermMinRays); 
    61         environment->GetFloatValue("VspBspTree.Termination.minArea", mTermMinArea); 
     61        environment->GetFloatValue("VspBspTree.Termination.minProbability", mTermMinProbability); 
    6262        environment->GetFloatValue("VspBspTree.Termination.maxRayContribution", mTermMaxRayContribution); 
    6363        environment->GetFloatValue("VspBspTree.Termination.minAccRayLenght", mTermMinAccRayLength); 
     
    8989        environment->GetBoolValue("VspBspTree.PostProcess.useRaysForMerge", mUseRaysForMerge); 
    9090 
    91         environment->GetFloatValue("ViewCells.maxPvsRatio", mMaxPvsRatio); 
    9291 
    9392        //-- termination criteria for axis aligned split 
     
    10099        environment->GetFloatValue("VspBspTree.maxStaticMemory", mMaxMemory); 
    101100 
     101         
     102        mStats.open("bspStats.log"); 
     103 
    102104        //-- debug output 
    103105        Debug << "******* VSP BSP options ******** " << endl; 
    104106    Debug << "max depth: " << mTermMaxDepth << endl; 
    105107        Debug << "min PVS: " << mTermMinPvs << endl; 
    106         Debug << "min area: " << mTermMinArea << endl; 
     108        Debug << "min probabiliy: " << mTermMinProbability << endl; 
    107109        Debug << "min rays: " << mTermMinRays << endl; 
    108110        Debug << "max ray contri: " << mTermMaxRayContribution << endl; 
     
    158160                mOutOfBoundsCell = new BspViewCell(); 
    159161                mOutOfBoundsCell->SetId(-1); 
    160         } 
     162                mOutOfBoundsCell->SetValid(false); 
     163        } 
     164 
    161165        return mOutOfBoundsCell; 
    162166} 
     
    311315                } 
    312316        } 
    313  
    314         mMaxPvs = (int)(mMaxPvsRatio * (float)numObj); 
    315          
    316         Debug << "maximal pvs (i.e., pvs still considered as valid) : " << mMaxPvs << endl; 
     317         
     318        Debug << "maximal pvs (i.e., pvs still considered as valid) : " << mViewCellsManager->GetMaxPvsSize() << endl; 
    317319        //-- store rays 
    318320        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
     
    334336        } 
    335337 
    336         mTermMinArea *= mBox.SurfaceArea(); // normalize 
     338        if (mUseAreaForPvs) 
     339                mTermMinProbability *= mBox.SurfaceArea(); // normalize 
     340        else  
     341                mTermMinProbability *= mBox.GetVolume(); 
     342 
    337343        mStat.polys = (int)polys.size(); 
    338344 
     
    372378        ConstructGeometry(mRoot, *geom); 
    373379 
     380        const float prop = mUseAreaForPvs ? geom->GetArea() : geom->GetVolume(); 
     381 
    374382        VspBspTraversalData tData(mRoot, 
    375383                                                          new PolygonContainer(polys), 
     
    377385                                                          rays, 
    378386                              ComputePvsSize(*rays), 
    379                                                           geom->GetArea(), 
     387                                                          prop, 
    380388                                                          geom); 
    381389 
     
    386394 
    387395        long startTime = GetTime();      
     396        // used for intermediate time measurements 
    388397        long interTime = GetTime();      
     398 
    389399        mOutOfMemory = false; 
    390400 
     
    437447                (((int)data.mRays->size() <= mTermMinRays) || 
    438448                 (data.mPvs <= mTermMinPvs)   || 
    439                  (data.mArea <= mTermMinArea) || 
     449                 (data.mProbability <= mTermMinProbability) || 
    440450                 (mStat.Leaves() >= mMaxViewCells) || 
    441451                 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 
     
    475485        { 
    476486                BspLeaf *leaf = dynamic_cast<BspLeaf *>(newNode); 
    477                 BspViewCell *viewCell; 
    478  
    479                 if (!CheckValid(tData)) 
    480                 { 
    481                         leaf->SetTreeValid(false); 
    482                         PropagateUpValidity(leaf); 
    483                         // view cell for invalid view space 
    484                         viewCell = GetOrCreateOutOfBoundsCell(); 
    485                         ++ mStat.invalidLeaves; 
    486                 } 
    487                 else 
    488                 {       // create new view cell for this leaf                    
    489                         viewCell = new BspViewCell(); 
    490                 } 
     487                BspViewCell *viewCell = new BspViewCell(); 
    491488                 
    492489                leaf->SetViewCell(viewCell); 
     
    506503                                leaf->mVssRays.push_back((*it).mRay); 
    507504                } 
    508  
    509                 viewCell->mLeaves.push_back(leaf); 
    510                 viewCell->SetArea(tData.mArea); 
    511                 leaf->mArea = tData.mArea; 
     505                 
     506                if (!mViewCellsManager->CheckValid(viewCell)) 
     507                { 
     508                        viewCell->SetValid(false); 
     509 
     510                        leaf->SetTreeValid(false); 
     511                        PropagateUpValidity(leaf); 
     512 
     513                        ++ mStat.invalidLeaves; 
     514                } 
     515                 
     516        viewCell->mLeaves.push_back(leaf); 
     517 
     518                if (mUseAreaForPvs) 
     519                        viewCell->SetArea(tData.mProbability); 
     520                else 
     521                        viewCell->SetVolume(tData.mProbability); 
     522 
     523                leaf->mProbability = tData.mProbability; 
    512524 
    513525                EvaluateLeafStats(tData);                
     
    591603 
    592604        // split front and back node geometry and compute area 
    593         if (mPvsUseArea) 
    594         { 
    595                 // if geometry was not already computed 
    596                 if (!frontData.mGeometry && !backData.mGeometry) 
    597                 { 
    598                         frontData.mGeometry = new BspNodeGeometry(); 
    599                         backData.mGeometry = new BspNodeGeometry(); 
    600  
    601                         tData.mGeometry->SplitGeometry(*frontData.mGeometry, 
    602                                                                                    *backData.mGeometry, 
    603                                                                                    interior->GetPlane(), 
    604                                                                                    mBox, 
    605                                                                                    mEpsilon); 
     605         
     606        // if geometry was not already computed 
     607        if (!frontData.mGeometry && !backData.mGeometry) 
     608        { 
     609                frontData.mGeometry = new BspNodeGeometry(); 
     610                backData.mGeometry = new BspNodeGeometry(); 
     611 
     612                tData.mGeometry->SplitGeometry(*frontData.mGeometry, 
     613                                                                           *backData.mGeometry, 
     614                                                                           interior->GetPlane(), 
     615                                                                           mBox, 
     616                                                                           mEpsilon); 
    606617                 
    607                         //frontData.mArea = frontData.mGeometry->GetArea(); 
    608                         //backData.mArea = backData.mGeometry->GetArea(); 
    609                         frontData.mArea = frontData.mGeometry->GetVolume(); 
    610                         backData.mArea = backData.mGeometry->GetVolume(); 
    611                 } 
    612         } 
    613         else 
    614         { 
    615                 frontData.mArea = (float)frontData.mRays->size(); 
    616                 backData.mArea = (float)backData.mRays->size(); 
    617         } 
     618                if (mUseAreaForPvs) 
     619                { 
     620                        frontData.mProbability = frontData.mGeometry->GetArea(); 
     621                        backData.mProbability = backData.mGeometry->GetArea(); 
     622                } 
     623                else 
     624                { 
     625                        frontData.mProbability = frontData.mGeometry->GetVolume(); 
     626                        backData.mProbability = backData.mGeometry->GetVolume(); 
     627                } 
     628        } 
     629         
    618630 
    619631        //-- create front and back leaf 
     
    836848                                                                                 BspNodeGeometry **frontGeom, 
    837849                                                                                 BspNodeGeometry **backGeom, 
    838                                                                                  float &frontArea, 
    839                                                                                  float &backArea, 
    840                                                                                  bool useKdSplit) 
     850                                                                                 float &pFront, 
     851                                                                                 float &pBack, 
     852                                                                                 const bool useKdSplit) 
    841853{ 
    842854        const bool useCostHeuristics = false; 
     
    845857        float nPosition[3]; 
    846858        float nCostRatio[3]; 
    847         float nFrontArea[3]; 
    848         float nBackArea[3]; 
     859        float nProbFront[3]; 
     860        float nProbBack[3]; 
    849861 
    850862        BspNodeGeometry *nFrontGeom[3]; 
     
    856868        AxisAlignedBox3 box; 
    857869        box.Initialize(); 
     870         
    858871        //TODO: for kd split geometry already is box 
    859         if (1 && mPvsUseArea) 
     872        if (1 && mUseAreaForPvs) 
    860873        { 
    861874                PolygonContainer::const_iterator it, it_end = tData.mGeometry->mPolys.end(); 
     
    872885        } 
    873886 
    874         int sAxis = box.Size().DrivingAxis(); 
     887        const int sAxis = box.Size().DrivingAxis(); 
    875888 
    876889        for (axis = 0; axis < 3; ++ axis) 
     
    885898                                nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 
    886899                                Vector3 normal(0,0,0); normal[axis] = 1.0f; 
    887                                  
     900 
     901                                // allows faster split because we have axis aligned kd tree boxes 
    888902                                if (useKdSplit) 
    889903                                { 
     
    891905                                                                                                                                box, 
    892906                                                                                                                                axis, 
    893                                                                                                                                 nPosition[axis]); 
     907                                                                                                                                nPosition[axis], 
     908                                                                                                                                nProbFront[axis],  
     909                                                                                                                                nProbBack[axis]); 
    894910                                         
    895911                                        Vector3 pos; 
    896912                                         
    897913                                        pos = box.Max(); pos[axis] = nPosition[axis]; 
    898                                         const AxisAlignedBox3 backBox(box.Min(), pos); 
    899                                         backBox.ExtractPolys(nBackGeom[axis]->mPolys); 
     914                                        AxisAlignedBox3 bBox(box.Min(), pos); 
     915                                        bBox.ExtractPolys(nBackGeom[axis]->mPolys); 
    900916                                         
    901917                                        pos = box.Min(); pos[axis] = nPosition[axis]; 
    902                                         const AxisAlignedBox3 frontBox(pos, box.Max()); 
    903                                         frontBox.ExtractPolys(nFrontGeom[axis]->mPolys); 
    904  
     918                                        AxisAlignedBox3 fBox(pos, box.Max()); 
     919                                        fBox.ExtractPolys(nFrontGeom[axis]->mPolys); 
    905920                                } 
    906921                                else 
     
    908923                                        nCostRatio[axis] = SplitPlaneCost(Plane3(normal, nPosition[axis]),  
    909924                                                                                                          tData, *nFrontGeom[axis], *nBackGeom[axis], 
    910                                                                                                           nFrontArea[axis], nBackArea[axis]); 
     925                                                                                                          nProbFront[axis], nProbBack[axis]); 
    911926                                } 
    912927                        } 
     
    936951        //-- assign values 
    937952        axis = bestAxis; 
    938         frontArea = nFrontArea[bestAxis]; 
    939         backArea = nBackArea[bestAxis]; 
     953        pFront = nProbFront[bestAxis]; 
     954        pBack = nProbBack[bestAxis]; 
    940955 
    941956        // assign best split nodes geometry  
     
    958973                                                                                   const AxisAlignedBox3 &box, 
    959974                                                                                   const int axis, 
    960                                                                                    const float &position) const 
    961 { 
     975                                                                                   const float &position,                                                                                  
     976                                                                                   float &pFront, 
     977                                                                                   float &pBack) const 
     978{ 
     979        int pvsTotal = 0; 
    962980        int pvsFront = 0; 
    963981        int pvsBack = 0; 
    964         int pvsTotal = 0; 
    965  
     982         
    966983        // create unique ids for pvs heuristics 
    967984        GenerateUniqueIdsForPvs(); 
     
    9841001        } 
    9851002 
    986         //-- only one of these options should be one 
    987         //-- pvs + probability heuristics 
    988         float pBack, pFront, pOverall; 
    989  
    990         if (1) 
    991         { 
     1003        //-- pvs heuristics 
     1004        float pOverall; 
     1005 
     1006        // -- simplified computation for mid split 
     1007         
     1008         
     1009        pOverall = data.mProbability; 
     1010 
     1011        if (!mUseAreaForPvs) 
     1012        {   // volume 
     1013                pBack = pFront = pOverall * 0.5f; 
    9921014                // box length substitute for probability 
     1015#if 0 
    9931016                const float minBox = box.Min(axis); 
    9941017                const float maxBox = box.Max(axis); 
     
    9971020                pFront = maxBox - position; 
    9981021                pOverall = maxBox - minBox; 
     1022#endif 
    9991023        } 
    10001024        else //-- area substitute for probability 
    10011025        { 
    1002                 pOverall = box.SurfaceArea(); 
    1003  
    1004                 const bool useMidSplit = true; 
    1005                 //const bool useMidSplit = false;        
    1006                                          
    1007                 //-- simplified computation for mid split 
    10081026                const int axis2 = (axis + 1) % 3; 
    10091027                const int axis3 = (axis + 2) % 3; 
     
    10191037        //Debug << pFront << " " << pBack << " " << pOverall << endl; 
    10201038 
    1021         // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 
    10221039        const float newCost = pvsBack * pBack + pvsFront * pFront; 
    1023         //  float oldCost = leaf->mRays.size(); 
    10241040        const float oldCost = (float)pvsSize * pOverall; 
    10251041 
     
    10941110        int axis; 
    10951111        BspNodeGeometry *fGeom, *bGeom; 
    1096         float fArea, bArea; 
     1112        float pFront, pBack; 
    10971113 
    10981114        candidateCost = SelectAxisAlignedPlane(plane, data, axis, 
    10991115                                                                                   &fGeom, &bGeom,  
    1100                                                                                    fArea, bArea, 
     1116                                                                                   pFront, pBack, 
    11011117                                                                                   onlyAxisAligned);      
    11021118 
     
    11091125                // we can do this because we always save the 
    11101126                // computed values from the axis aligned splits 
     1127                 
    11111128                frontData.mGeometry = fGeom; 
    11121129                backData.mGeometry = bGeom; 
    1113                 frontData.mArea = fArea; 
    1114                 backData.mArea = bArea; 
    1115  
     1130         
     1131                frontData.mProbability = pFront; 
     1132                backData.mProbability = pBack; 
     1133                 
    11161134                //! error also computed if cost ratio is missed 
    11171135                ++ mStat.splits[axis]; 
     
    12201238                                                                 BspNodeGeometry &geomFront, 
    12211239                                                                 BspNodeGeometry &geomBack, 
    1222                                                                  float &areaFront, 
    1223                                                                  float &areaBack) const 
     1240                                                                 float &pFront, 
     1241                                                                 float &pBack) const 
    12241242{ 
    12251243        float cost = 0; 
     
    12331251        // probability that view point lies in back / front node 
    12341252        float pOverall = 0; 
    1235         float pFront = 0; 
    1236         float pBack = 0; 
     1253        pFront = 0; 
     1254        pBack = 0; 
    12371255 
    12381256        int raysFront = 0; 
     
    12901308 
    12911309        const float raysSize = (float)data.mRays->size() + Limits::Small; 
     1310 
    12921311        if (mSplitPlaneStrategy & PVS) 
    12931312        { 
     
    12951314                GenerateUniqueIdsForPvs(); 
    12961315 
    1297                 if (mPvsUseArea) // use front and back cell areas to approximate volume 
    1298                 { 
    1299                         // construct child geometry with regard to the candidate split plane 
    1300                         data.mGeometry->SplitGeometry(geomFront, 
    1301                                                                                   geomBack, 
    1302                                                                                   candidatePlane, 
    1303                                                                                   mBox, 
    1304                                                                                   mEpsilon); 
    1305  
    1306                          
     1316                // construct child geometry with regard to the candidate split plane 
     1317                data.mGeometry->SplitGeometry(geomFront, 
     1318                                                                          geomBack, 
     1319                                                                          candidatePlane, 
     1320                                                                          mBox, 
     1321                                                                          mEpsilon); 
     1322 
     1323                pOverall = data.mProbability; 
     1324 
     1325                if (!mUseAreaForPvs) // use front and back cell areas to approximate volume 
     1326                { 
    13071327                        pFront = geomFront.GetVolume(); 
    1308                         pBack = geomBack.GetVolume(); 
    1309                         //areaFront = geomFront.GetArea(); 
    1310                         //areaBack = geomBack.GetArea(); 
    1311  
    1312                         pOverall = data.mArea; 
    1313  
    1314                 } 
    1315                 else // use number of rays to approximate volume 
    1316                 { 
    1317                         pOverall = (float)data.mRays->size(); 
    1318                         pFront = (float)raysFront; 
    1319                         pBack = (float)raysBack; 
     1328                        pBack = pOverall - geomFront.GetVolume(); 
     1329                } 
     1330                else 
     1331                { 
     1332                        pFront = geomFront.GetArea(); 
     1333                        pBack = geomBack.GetArea(); 
    13201334                } 
    13211335        } 
     
    14711485                ++ mStat.maxRayContribNodes; 
    14721486 
    1473         if (data.mArea <= mTermMinArea) 
    1474                 ++ mStat.minAreaNodes; 
     1487        if (data.mProbability <= mTermMinProbability) 
     1488                ++ mStat.minProbabilityNodes; 
    14751489         
    14761490        // accumulate depth to compute average depth 
     
    15861600 
    15871601 
    1588 void VspBspTree::CollectViewCells(ViewCellContainer &viewCells) const 
     1602void VspBspTree::CollectViewCells(ViewCellContainer &viewCells, bool onlyValid) const 
    15891603{ 
    15901604        ViewCell::NewMail(); 
    1591         CollectViewCells(mRoot, viewCells, true); 
     1605        CollectViewCells(mRoot, onlyValid, viewCells); 
    15921606} 
    15931607 
     
    16021616        nodeStack.push(mRoot); 
    16031617         
     1618        const bool addToUnbounded = false; 
     1619 
    16041620        while (!nodeStack.empty())  
    16051621        { 
     
    16111627                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
    16121628 
    1613                         if (node->TreeValid()) 
     1629                        if (!addToUnbounded && node->TreeValid()) 
    16141630                        { 
    16151631                                BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
    16161632                         
    1617                                 if (viewCell->GetPvs().GetSize() > mMaxPvs) 
     1633                                if (!mViewCellsManager->CheckValid(viewCell)) 
    16181634                                { 
    1619                                         while (!viewCell->mLeaves.empty()) 
     1635                                        vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end(); 
     1636                                        for (it = viewCell->mLeaves.begin();it != it_end; ++ it) 
    16201637                                        { 
    1621                                                 BspLeaf *l = viewCell->mLeaves.back(); 
     1638                                                BspLeaf *l = *it; 
     1639                                                 
    16221640                                                l->SetTreeValid(false); 
     1641                                                PropagateUpValidity(l); 
     1642                                                 
     1643                                                if (addToUnbounded) 
     1644                                                        l->SetViewCell(GetOrCreateOutOfBoundsCell()); 
     1645 
    16231646                                                ++ mStat.invalidLeaves; 
    1624                                                 PropagateUpValidity(l); 
    1625  
    1626                                                 l->SetViewCell(GetOrCreateOutOfBoundsCell()); 
    1627                                                 viewCell->mLeaves.pop_back(); 
    16281647                                        } 
    16291648 
    1630                                         mOutOfBoundsCell->GetPvs().AddPvs(viewCell->GetPvs()); 
    1631  
    1632                                         DEL_PTR(viewCell); 
     1649                                        // add to unbounded view cell or set to invalid 
     1650                                        if (addToUnbounded) 
     1651                                        { 
     1652                                                GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 
     1653                                                DEL_PTR(viewCell); 
     1654                                        } 
     1655                                        else 
     1656                                        { 
     1657                                                viewCell->SetValid(false); 
     1658                                        } 
    16331659                                } 
    16341660                        } 
     
    16441670} 
    16451671 
    1646 void VspBspTree::CollectViewCells(BspNode *root,  
     1672 
     1673void VspBspTree::CollectViewCells(BspNode *root, 
     1674                                                                  bool onlyValid, 
    16471675                                                                  ViewCellContainer &viewCells, 
    16481676                                                                  bool onlyUnmailed) const 
     
    16621690                if (node->IsLeaf()) 
    16631691                { 
    1664                         if (!mShowInvalidSpace && node->TreeValid()) 
     1692                        if (!onlyValid ||node->TreeValid()) 
    16651693                        { 
    16661694                                ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
     
    23572385                { 
    23582386                case -1: 
    2359                         CollectViewCells(node, beam.mViewCells, true); 
     2387                        CollectViewCells(node, true, beam.mViewCells, true); 
    23602388                        break; 
    23612389                case 0: 
     
    24272455 
    24282456        // set new size of view cell 
    2429         vc->SetArea(fVc->GetArea() + bVc->GetArea()); 
    2430  
     2457        if (mUseAreaForPvs) 
     2458                vc->SetArea(fVc->GetArea() + bVc->GetArea()); 
     2459        else 
     2460                vc->SetVolume(fVc->GetVolume() + bVc->GetVolume()); 
     2461         
    24312462        vector<BspLeaf *> fLeaves = fVc->mLeaves; 
    24322463        vector<BspLeaf *> bLeaves = bVc->mLeaves; 
     
    24802511 
    24812512                BspMergeCandidate::sOverallCost +=  
    2482                         leaf->mArea * leaf->mPvs->GetSize(); 
     2513                        leaf->mProbability * leaf->mPvs->GetSize(); 
    24832514 
    24842515                // the same leaves must not be part of two merge candidates 
     
    25102541        vector<BspRay *> bspRays; 
    25112542 
     2543        ViewCell::NewMail(); 
    25122544        long startTime = GetTime(); 
    25132545        ConstructBspRays(bspRays, rays); 
     
    25252557        {   
    25262558                BspRay *ray = bspRays[i]; 
    2527            
     2559         
    25282560                // traverse leaves stored in the rays and compare and  
    25292561                // merge consecutive leaves (i.e., the neighbors in the tree) 
     
    25412573 
    25422574                        BspMergeCandidate::sOverallCost +=  
    2543                                 leaf->mArea * leaf->mPvs->GetSize(); 
     2575                                leaf->mProbability * leaf->mPvs->GetSize(); 
    25442576                         
    25452577                        ++ numLeaves; 
     
    25662598                                 
    25672599                                BspMergeCandidate::sOverallCost +=  
    2568                                         leaf->mArea * leaf->mPvs->GetSize(); 
     2600                                        leaf->mProbability * leaf->mPvs->GetSize(); 
    25692601 
    25702602                                ++ numLeaves; 
     
    25852617                                                found = true; // already in queue 
    25862618                        } 
    2587                          
     2619                 
    25882620                        if (!found) 
    25892621                        { 
     
    25952627                                leaf->Mail(); 
    25962628                                prevLeaf->Mail(); 
    2597  
     2629                 
    25982630                                mMergeQueue.push(BspMergeCandidate(leaf, prevLeaf)); 
    25992631                        } 
     
    26112643        { 
    26122644                vector<BspLeaf *> leaves; 
    2613                 CollectLeaves(leaves, true, mMaxPvs); 
     2645                CollectLeaves(leaves, true); 
    26142646                Debug << "found " << (int)leaves.size() << " new leaves" << endl << endl; 
    26152647                CollectMergeCandidates(leaves); 
     
    26522684                        //NOTE: not sorted! 
    26532685                        for (it = vc->mLeaves.begin(); it != it_end; ++ it) 
     2686                        { 
    26542687                                ray->intersections.push_back(BspIntersection(0, *it)); 
     2688                        } 
    26552689                } 
    26562690 
     
    26602694 
    26612695 
    2662 int VspBspTree::MergeViewCells(const VssRayContainer &rays) 
    2663 { 
    2664         BspMergeCandidate::sMaxPvsSize = mMaxPvs; 
     2696int VspBspTree::MergeViewCells(const VssRayContainer &rays, const ObjectContainer &objects) 
     2697{ 
     2698        BspMergeCandidate::sMaxPvsSize = mViewCellsManager->GetMaxPvsSize(); 
     2699        BspMergeCandidate::sUseArea = mUseAreaForPvs; 
    26652700 
    26662701        MergeStatistics mergeStats; 
     
    26852720 
    26862721        int nViewCells = mStat.Leaves() - mStat.invalidLeaves; 
     2722        int pass = 0; 
     2723        const int nextPass = 200; 
    26872724 
    26882725        //-- use priority queue to merge leaf pairs 
     
    27042741                { 
    27052742                        ViewCell::NewMail(); 
    2706          
     2743                        const float mergeCost = mc.GetMergeCost(); 
     2744 
    27072745                        MergeViewCells(mc.GetLeaf1(), mc.GetLeaf2()); 
    27082746                        -- nViewCells; 
    27092747                         
    2710                         ++ mergeStats.merged; 
    27112748                         
    27122749                        // increase absolute merge cost 
    27132750                        BspMergeCandidate::sOverallCost += mc.GetMergeCost(); 
     2751 
     2752                         
    27142753 
    27152754                        if (showMergeStats) 
     
    27232762                                        mergeStats.maxTreeDist = dist; 
    27242763                                mergeStats.accTreeDist += dist; 
     2764 
     2765 
     2766                                if ((mergeStats.merged % nextPass == 0) || (nViewCells == mMergeMinViewCells)) 
     2767                                { 
     2768                                        mStats  
     2769                                                << "#Pass\n" << pass ++ << endl 
     2770                                                << "#Merged\n" << mergeStats.merged << endl  
     2771                                                << "#Viewcells\n" << nViewCells << endl  
     2772                                                << "#OverallCost\n" << BspMergeCandidate::sOverallCost << endl  
     2773                                                << "#CurrentCost\n" << mergeCost << endl 
     2774                                                << "#RelCost\n" << mc.GetMergeCost() / BspMergeCandidate::sOverallCost << endl 
     2775                                                << "#CurrentPvs\n" << mc.GetLeaf1()->GetViewCell()->GetPvs().GetSize() << endl; 
     2776 
     2777                                        ViewCellContainer viewCells;     
     2778                                        CollectViewCells(mRoot, false, viewCells); 
     2779                         
     2780                                        char s[64]; 
     2781                                        sprintf(s, "merged_viewcells%07d.x3d", nViewCells); 
     2782                                        Exporter *exporter = Exporter::GetExporter(s); 
     2783                                 
     2784                                        if (exporter) 
     2785                                        { 
     2786                                                Debug << "vc size " << viewCells.size() << endl; 
     2787                                                ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
     2788                 
     2789                                                for (it = viewCells.begin(); it != it_end; ++ it) 
     2790                                                { 
     2791                                                        exporter->ExportGeometry(objects); 
     2792                                                        mViewCellsManager->ExportVcGeometry(exporter, *it); 
     2793                                                } 
     2794                                         
     2795                                                delete exporter; 
     2796                                        } 
     2797                                } 
    27252798                        } 
     2799 
    27262800                } 
    27272801                // merge candidate not valid, because one of the leaves was already 
     
    27402814                Debug << mergeStats << endl << endl; 
    27412815         
     2816 
    27422817        //TODO: should return sample contributions? 
    27432818        return mergeStats.merged; 
     
    28362911 
    28372912 
    2838 float GetShuffledVcCost(BspLeaf *leaf, BspViewCell *vc1, BspViewCell *vc2) 
     2913float GetShuffledVcCost(BspLeaf *leaf, BspViewCell *vc1, BspViewCell *vc2, bool useArea) 
    28392914{ 
    28402915        //const int pvs1 = SubtractedPvsSize(vc1, leaf, *leaf->mPvs); 
     
    28422917        const int pvs2 = AddedPvsSize(vc2->GetPvs(), *leaf->mPvs); 
    28432918 
    2844         const float area1 = vc1->GetArea() - leaf->mArea; 
    2845         const float area2 = vc2->GetArea() + leaf->mArea; 
    2846  
    2847         const float cost1 = pvs1 * area1; 
    2848         const float cost2 = pvs2 * area2; 
     2919        float p1, p2; 
     2920 
     2921    if (useArea) 
     2922        { 
     2923                p1 = vc1->GetArea() - leaf->mProbability; 
     2924                p2 = vc2->GetArea() + leaf->mProbability; 
     2925        } 
     2926        else 
     2927        { 
     2928                p1 = vc1->GetVolume() - leaf->mProbability; 
     2929                p2 = vc2->GetVolume() + leaf->mProbability; 
     2930        } 
     2931 
     2932        const float cost1 = pvs1 * p1; 
     2933        const float cost2 = pvs2 * p2; 
    28492934 
    28502935        return cost1 + cost2; 
     
    28602945        vc2->GetPvs().AddPvs(*leaf->mPvs); 
    28612946         
    2862         vc1->SetArea(vc1->GetArea() - leaf->mArea); 
    2863         vc2->SetArea(vc2->GetArea() + leaf->mArea); 
     2947        if (mUseAreaForPvs) 
     2948        { 
     2949                vc1->SetArea(vc1->GetArea() - leaf->mProbability); 
     2950                vc2->SetArea(vc2->GetArea() + leaf->mProbability); 
     2951        } 
     2952        else 
     2953        { 
     2954                vc1->SetVolume(vc1->GetVolume() - leaf->mProbability); 
     2955                vc2->SetVolume(vc2->GetVolume() + leaf->mProbability); 
     2956        } 
    28642957 
    28652958        /// add to second view cell 
     
    28902983        BspViewCell *vc2 = leaf2->GetViewCell(); 
    28912984 
    2892         const float cost1 = vc1->GetPvs().GetSize() * vc1->GetArea(); 
    2893         const float cost2 = vc2->GetPvs().GetSize() * vc2->GetArea(); 
     2985        float cost1;  
     2986        float cost2;  
     2987 
     2988        if (mUseAreaForPvs) 
     2989        { 
     2990                cost1 = vc1->GetPvs().GetSize() * vc1->GetArea(); 
     2991                cost2 = vc2->GetPvs().GetSize() * vc2->GetArea(); 
     2992        } 
     2993        else 
     2994        { 
     2995                cost1 = vc1->GetPvs().GetSize() * vc1->GetVolume(); 
     2996                cost2 = vc2->GetPvs().GetSize() * vc2->GetVolume(); 
     2997        } 
    28942998 
    28952999        const float oldCost = cost1 + cost2; 
     
    29003004        // the view cell should not be empty after the shuffle 
    29013005        if (vc1->mLeaves.size() > 1) 
    2902                 shuffledCost1 = GetShuffledVcCost(leaf1, vc1, vc2); 
     3006                shuffledCost1 = GetShuffledVcCost(leaf1, vc1, vc2, mUseAreaForPvs); 
    29033007        if (vc2->mLeaves.size() > 1) 
    2904                 shuffledCost2 = GetShuffledVcCost(leaf2, vc2, vc1); 
     3008                shuffledCost2 = GetShuffledVcCost(leaf2, vc2, vc1, mUseAreaForPvs); 
    29053009 
    29063010        // shuffling unsuccessful 
     
    29213025        return true; 
    29223026} 
     3027 
    29233028 
    29243029bool VspBspTree::ViewPointValid(const Vector3 &viewPoint) const 
     
    29523057 
    29533058 
    2954 bool VspBspTree::CheckValid(const VspBspTraversalData &data) const 
    2955 { 
    2956         return data.mPvs <= mMaxPvs; 
    2957 } 
    2958  
    2959  
    29603059void VspBspTree::PropagateUpValidity(BspNode *node) 
    29613060{ 
     
    30193118} 
    30203119 
     3120 
    30213121float BspMergeCandidate::GetCost(ViewCell *vc) const 
    30223122{ 
    3023         return vc->GetPvs().GetSize() * vc->GetArea(); 
    3024 } 
     3123        if (sUseArea) 
     3124                return vc->GetPvs().GetSize() * vc->GetArea(); 
     3125 
     3126        return vc->GetPvs().GetSize() * vc->GetVolume(); 
     3127} 
     3128 
    30253129 
    30263130float BspMergeCandidate::GetLeaf1Cost() const 
     
    30303134} 
    30313135 
     3136 
    30323137float BspMergeCandidate::GetLeaf2Cost() const 
    30333138{ 
     
    30353140        return GetCost(vc); 
    30363141} 
     3142 
    30373143 
    30383144void BspMergeCandidate::EvalMergeCost() 
     
    30503156        const float oldCost = GetLeaf1Cost() + GetLeaf2Cost(); 
    30513157 
    3052         const float newCost = 
    3053                 (float)newPvs * (vc1->GetArea() + vc2->GetArea()); 
     3158    const float newCost = sUseArea ?  
     3159                (float)newPvs * (vc1->GetArea() + vc2->GetArea()) : 
     3160                (float)newPvs * (vc1->GetVolume() + vc2->GetVolume()); 
     3161 
    30543162 
    30553163        if (newPvs > sMaxPvsSize) // strong penalty if pvs size too large 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r544 r547  
    5252                /// rays piercing this node 
    5353                RayInfoContainer *mRays; 
    54                 /// area of current node 
    55                 float mArea; 
     54                /// the probability that this node contains view point 
     55                float mProbability; 
    5656                /// geometry of node as induced by planes 
    5757                BspNodeGeometry *mGeometry; 
     
    7777                mRays(NULL), 
    7878                mPvs(0), 
    79                 mArea(0.0), 
     79                mProbability(0.0), 
    8080                mGeometry(NULL), 
    8181                mMaxCostMisses(0) 
     
    8787                                                        const int depth,  
    8888                                                        RayInfoContainer *rays, 
    89                                                         int pvs, 
    90                                                         float area, 
     89                                                        const int pvs, 
     90                                                        const float p, 
    9191                                                        BspNodeGeometry *geom):  
    9292                mNode(node),  
     
    9595                mRays(rays), 
    9696                mPvs(pvs), 
    97                 mArea(area), 
     97                mProbability(p), 
    9898                mGeometry(geom), 
    9999                mMaxCostMisses(0) 
     
    109109                mRays(rays), 
    110110                mPvs(0), 
    111                 mArea(0), 
     111                mProbability(0), 
    112112                mGeometry(geom), 
    113113                mMaxCostMisses(0) 
     
    119119                { 
    120120#if 1 
    121                         return mPvs * mArea; 
     121                        return mPvs * mProbability; 
    122122#endif 
    123123#if 0 
     
    128128#endif 
    129129#if 0 
    130                         return mArea * (float)mRays->size(); 
     130                        return mProbabiliy * (float)mRays->size(); 
    131131#endif 
    132132                } 
     
    190190                @param viewCells returns the view cells  
    191191        */ 
    192         void CollectViewCells(ViewCellContainer &viewCells) const; 
     192        void CollectViewCells(ViewCellContainer &viewCells, bool onlyValid) const; 
    193193 
    194194        /** A ray is cast possible intersecting the tree. 
     
    250250        /** Merges view cells according to some cost heuristics. 
    251251        */ 
    252         int MergeViewCells(const VssRayContainer &rays); 
     252        int MergeViewCells(const VssRayContainer &rays, const ObjectContainer &objects); 
    253253         
    254254        /** Refines view cells using shuffling, i.e., border leaves  
     
    298298 
    299299        void CollectViewCells(BspNode *root,  
     300                                                  bool onlyValid,  
    300301                                                  ViewCellContainer &viewCells, 
    301302                                                  bool onlyUnmailed = false) const; 
    302303 
    303         /** returns maximal valid pvs. 
    304         */ 
    305         int GetMaxPvs() { return mMaxPvs;} 
    306  
     304         
    307305        /** Checks validy of view cells. 
    308306                if not valid, sets regions invalid and deletes view cell. 
     
    339337        }; 
    340338 
     339        /** faster evaluation of split plane cost for kd axis aligned cells. 
     340        */ 
    341341        float EvalAxisAlignedSplitCost(const VspBspTraversalData &data, 
    342342                                                                   const AxisAlignedBox3 &box, 
    343343                                                                   const int axis, 
    344                                                                    const float &position) const; 
     344                                                                   const float &position, 
     345                                                                   float &pFront, 
     346                                                                   float &pBack) const; 
    345347 
    346348        /** Returns view cell corresponding to  
     
    409411                                                 BspNodeGeometry &geomFront, 
    410412                                                 BspNodeGeometry &geomBack, 
    411                                                  float &areaFront, 
    412                                                  float &areaBack) const; 
     413                                                 float &pFront, 
     414                                                 float &pBack) const; 
    413415 
    414416        /** Subdivide leaf. 
     
    464466                                                                 BspNodeGeometry **frontGeom, 
    465467                                                                 BspNodeGeometry **backGeom, 
    466                                                                  float &frontArea, 
    467                                                                  float &backArea, 
    468                                                                  bool useKdSplit); 
     468                                                                 float &pFront, 
     469                                                                 float &pBack, 
     470                                                                 const bool useKdSplit); 
    469471 
    470472        /** Sorts split candidates for surface area heuristics for axis aligned splits. 
     
    482484                                                                  const int &axis, 
    483485                                                                  float &position); 
    484  
    485         /** Evaluates cost ratio for axis aligned splits. 
    486         */ 
    487         /*float EvalCostRatio(const VspBspTraversalData &tData, 
    488                                                 const AxisAlignedBox3 &box, 
    489                                                 const int axis, 
    490                                                 const float position, 
    491                                                 int &raysBack, 
    492                                                 int &raysFront, 
    493                                                 int &pvsBack, 
    494                                                 int &pvsFront);*/ 
    495486 
    496487        /** Selects an axis aligned split plane. 
     
    606597                                         BspViewCell *vc2) const; 
    607598 
    608         /** 
    609                 Checks if this traversal data corresponds to 
    610                 a valid view space region. 
    611         */ 
    612         bool CheckValid(const VspBspTraversalData &data) const; 
    613  
     599         
    614600        /** Propagates valid flag up the tree. 
    615601        */ 
     
    646632        /// maximal possible depth 
    647633        int mTermMaxDepth; 
    648         /// mininum area 
    649         float mTermMinArea; 
     634        /// mininum probability 
     635        float mTermMinProbability; 
    650636        /// mininum PVS 
    651637        int mTermMinPvs; 
     
    654640        /// minimal accumulated ray length 
    655641        float mTermMinAccRayLength; 
     642 
     643        ofstream mStats; 
    656644 
    657645        //-- termination criteria for axis aligned split 
     
    686674        float mPvsFactor; 
    687675 
    688         /// if area or accumulated ray lenght should be used for PVS heuristics 
    689         bool mPvsUseArea; 
     676        /// if area or volume should be used for PVS heuristics 
     677        bool mUseAreaForPvs; 
    690678        /// tolerance for polygon split 
    691679        float mEpsilon; 
     
    719707        bool mUseRaysForMerge; 
    720708         
    721         /// maximal allowed pvs so that view cell is valid 
    722         int mMaxPvs; 
    723  
    724         float mMaxPvsRatio; 
    725  
    726709        /// View cell corresponding to the space outside the valid view space 
    727710        BspViewCell *mOutOfBoundsCell; 
    728  
    729         /// if invalid space should be shown 
    730         bool mShowInvalidSpace; 
    731711 
    732712        int mCurrentViewCellsId; 
     
    797777        /// overall cost used to normalize cost ratio 
    798778        static float sOverallCost; 
     779        // if area or volume should be used for the merge heuristics 
     780        static bool sUseArea; 
    799781 
    800782        /** Evaluates the merge costs of the leaves. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r540 r547  
    517517{ 
    518518  Mesh *mesh = new Mesh; 
    519   // add 6 vertices of the box 
     519  // add 8 vertices of the box 
    520520  int index = (int)mesh->mVertices.size(); 
    521521  for (int i=0; i < 8; i++) { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/default.env

    r535 r547  
    289289                maxDepth                30 
    290290                minPvs                  2 
    291                 #minArea                0.0001 
    292                 minArea                 0.000 
     291                #minProbability         0.0001 
     292                minProbabilty           0.000 
    293293                maxRayContribution      0.005 
    294294                maxCostRatio            0.9 
Note: See TracChangeset for help on using the changeset viewer.