Changeset 719


Ignore:
Timestamp:
03/27/06 18:56:45 (18 years ago)
Author:
mattausch
Message:

updating view cell hierarchy before pvs statistics

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

Legend:

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

    r710 r719  
    15661566        if (!mIsCompressed) 
    15671567                return vc->GetPvs().GetSize(); 
     1568 
     1569 
     1570        ////////////////////////777 
     1571        //-- compressed pvs 
    15681572 
    15691573        int pvsSize = 0; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r711 r719  
    4444 
    4545 
    46 /****************************************************************/ 
    47 /*                  class BspNode implementation                */ 
    48 /****************************************************************/ 
     46/******************************************************************/ 
     47/*                  class BspNode implementation                  */ 
     48/******************************************************************/ 
    4949 
    5050 
     
    20862086        stack<BspRayTraversalData> tStack; 
    20872087 
    2088         float mint = 0.0f, maxt = 1.0f; 
     2088                float mint = 0.0f, maxt = 1.0f; 
    20892089 
    20902090        Intersectable::NewMail(); 
     
    20972097        BspNode *farChild = NULL; 
    20982098 
     2099 
    20992100        const float thresh = 1 ? 1e-6f : 0.0f; 
    21002101 
     
    21042105                { 
    21052106                        BspInterior *in = dynamic_cast<BspInterior *>(node); 
    2106                  
     2107 
    21072108                        Plane3 splitPlane = in->GetPlane(); 
    21082109                         
     
    21132114                        { 
    21142115                                node = in->GetBack(); 
    2115                  
    2116                                 if(extSide <= 0) // plane does not split ray => no far child 
     2116                                 
     2117                                // plane does not split ray => no far child 
     2118                                if (extSide <= 0)  
    21172119                                        continue; 
    2118                  
     2120   
    21192121                                farChild = in->GetFront(); // plane splits ray 
    2120                  
    21212122                        }  
    2122                         else if (entSide > 0)  
     2123                        else if (entSide > 0) 
    21232124                        { 
    21242125                                node = in->GetFront(); 
    2125                          
     2126 
    21262127                                if (extSide >= 0) // plane does not split ray => no far child 
    21272128                                        continue; 
    2128                          
    2129                                 farChild = in->GetBack(); // plane splits ray                    
     2129 
     2130                                farChild = in->GetBack(); // plane splits ray 
    21302131                        } 
    2131                         else // ray and plane are coincident 
    2132                         { 
    2133                                 // NOTE: what to do if ray is coincident with plane? 
     2132                        else // one of the ray end points is on the plane 
     2133                        {       // NOTE: what to do if ray is coincident with plane? 
    21342134                                if (extSide < 0) 
    21352135                                        node = in->GetBack(); 
    21362136                                else //if (extSide > 0) 
    21372137                                        node = in->GetFront(); 
    2138                                 //else break; 
     2138                                //else break; // coincident => count no intersections 
    21392139 
    21402140                                continue; // no far child 
    21412141                        } 
    2142                  
     2142 
    21432143                        // push data for far child 
    21442144                        tStack.push(BspRayTraversalData(farChild, extp, maxt)); 
     
    21772177                } 
    21782178        } 
     2179 
    21792180        return hits; 
    21802181} 
     
    23192320                // split plane of node itself 
    23202321                n = n->GetParent(); 
    2321                  
     2322 
    23222323                if (n) 
    23232324                { 
     
    23612362        vector<Plane3> candidatePlanes; 
    23622363 
     2364        vector<Plane3>::const_iterator pit, pit_end = halfSpaces.end(); 
     2365 
    23632366        // bounded planes are added to the polygons 
    2364         for (int i = 0; i < (int)halfSpaces.size(); ++ i) 
    2365         { 
    2366                 Polygon3 *p = GetBoundingBox().CrossSection(halfSpaces[i]); 
     2367        for (pit = halfSpaces.begin(); pit != pit_end; ++ pit) 
     2368        { 
     2369                Polygon3 *p = GetBoundingBox().CrossSection(*pit); 
    23672370 
    23682371                if (p->Valid(mEpsilon)) 
    23692372                { 
    23702373                        candidatePolys.push_back(p); 
    2371                         candidatePlanes.push_back(halfSpaces[i]); 
     2374                        candidatePlanes.push_back(*pit); 
    23722375                } 
    23732376        } 
     
    24152418                                        DEL_PTR(candidatePolys[i]); 
    24162419 
    2417                                         if (frontPoly->Valid(mEpsilon)) 
    2418                                                 candidatePolys[i] = frontPoly; 
     2420                                        if (backPoly->Valid(mEpsilon)) 
     2421                                                candidatePolys[i] = backPoly; 
    24192422                                        else 
    2420                                                 DEL_PTR(frontPoly); 
    2421  
    2422                                         DEL_PTR(backPoly); 
     2423                                                DEL_PTR(backPoly); 
     2424 
     2425                                        // outside, don't need this 
     2426                                        DEL_PTR(frontPoly); 
    24232427                                        break; 
    24242428                                // polygon outside of halfspace 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r718 r719  
    4747mMaxPvsSize(9999999), 
    4848mMinPvsSize(0), // one means only empty view cells are invalid 
    49 mMaxPvsRatio(1.0) 
     49mMaxPvsRatio(1.0), 
     50mViewCellPvsIsUpdated(false) 
    5051{ 
    5152        mViewSpaceBox.Initialize(); 
     
    558559        // find empty view cells bug 
    559560        if (TEST_EMPTY_VIEW_CELLS) 
     561        { 
    560562                TestEmptyViewCells(preprocessor->mObjects); 
     563        } 
    561564} 
    562565 
     
    11311134 
    11321135 
     1136void ViewCellsManager::UpdatePvs() 
     1137{ 
     1138        if (mViewCellPvsIsUpdated) 
     1139                return; 
     1140 
     1141        mViewCellPvsIsUpdated = true; 
     1142 
     1143        ViewCellContainer leaves; 
     1144        mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves); 
     1145 
     1146        ViewCellContainer::const_iterator it, it_end = leaves.end(); 
     1147 
     1148        for (it = leaves.begin(); it != it_end; ++ it) 
     1149        { 
     1150                mViewCellsTree->PropagatePvs(*it); 
     1151        } 
     1152} 
     1153 
     1154 
    11331155void ViewCellsManager::GetPvsStatistics(PvsStatistics &stat) 
    11341156{ 
    1135   ViewCellContainer::const_iterator it = mViewCells.begin(); 
    1136   stat.viewcells = 0; 
    1137   stat.minPvs = 100000000; 
    1138   stat.maxPvs = 0; 
    1139   stat.avgPvs = 0.0f; 
    1140  
    1141   for (; it != mViewCells.end(); ++it) { 
    1142         ViewCell *viewcell = *it; 
    1143         int pvsSize = viewcell->GetPvs().GetSize(); 
    1144         if ( pvsSize < stat.minPvs) 
    1145           stat.minPvs = pvsSize; 
    1146         if (pvsSize > stat.maxPvs) 
    1147           stat.maxPvs = pvsSize; 
    1148         stat.avgPvs += pvsSize; 
    1149         stat.viewcells++; 
    1150   } 
    1151   if (stat.viewcells) 
    1152         stat.avgPvs/=stat.viewcells; 
     1157        // update pvs of view cells tree if necessary 
     1158        UpdatePvs(); 
     1159 
     1160        ViewCellContainer::const_iterator it = mViewCells.begin(); 
     1161 
     1162        stat.viewcells = 0; 
     1163        stat.minPvs = 100000000; 
     1164        stat.maxPvs = 0; 
     1165        stat.avgPvs = 0.0f; 
     1166 
     1167        for (; it != mViewCells.end(); ++ it)  
     1168        { 
     1169                ViewCell *viewcell = *it; 
     1170                 
     1171                const int pvsSize = mViewCellsTree->GetPvsSize(viewcell); 
     1172                 
     1173                if (pvsSize < stat.minPvs) 
     1174                        stat.minPvs = pvsSize; 
     1175                if (pvsSize > stat.maxPvs) 
     1176                        stat.maxPvs = pvsSize; 
     1177                stat.avgPvs += pvsSize; 
     1178                 
     1179                ++ stat.viewcells; 
     1180        } 
     1181 
     1182        if (stat.viewcells) 
     1183                stat.avgPvs/=stat.viewcells; 
    11531184} 
    11541185 
     
    15711602                ComputeSampleContributions(savedRays, true, false); 
    15721603 
     1604        // real meshes are contructed at this stage 
     1605        if (0) 
     1606        { 
     1607                cout << "finalizing view cells ... "; 
     1608                FinalizeViewCells(true); 
     1609                cout << "finished" << endl;      
     1610        } 
     1611 
    15731612        return sampleContributions; 
    15741613} 
     
    17321771        mColorCode = savedColorCode; 
    17331772 
    1734         FinalizeViewCells(true); 
    1735          
     1773        // compute final meshes and volume / area 
     1774        if (1) FinalizeViewCells(true); 
     1775 
    17361776        // write view cells to disc 
    17371777        if (mExportViewCells) 
     
    21132153                mBspTree->ConstructGeometry(leaf, geom); 
    21142154 
    2115                 float lVol = geom.GetVolume(); 
    2116                 float lArea = geom.GetArea(); 
     2155                const float lVol = geom.GetVolume(); 
     2156                const float lArea = geom.GetArea(); 
    21172157 
    21182158                //(*it)->SetVolume(vol); 
     
    30623102        cout << "construction finished" << endl; 
    30633103 
     3104        // real meshes are contructed at this stage 
     3105        if (0) 
     3106        { 
     3107                cout << "finalizing view cells ... "; 
     3108                FinalizeViewCells(true); 
     3109                cout << "finished" << endl; 
     3110        } 
     3111 
    30643112        return sampleContributions; 
    30653113} 
     
    32963344        // should maybe be done here to allow merge working with area or volume 
    32973345        // and to correct the rendering statistics 
    3298         if (0) 
    3299         { 
    3300                 FinalizeViewCells(false); 
    3301         } 
    3302  
     3346        if (0) FinalizeViewCells(false); 
     3347         
    33033348         
    33043349        //-- merge the individual view cells 
     
    33123357                RefineViewCells(postProcessRays, objects); 
    33133358 
    3314  
     3359         
    33153360        //-- render simulation after merge + refine 
    33163361         
     
    33473392        ResetViewCells(); 
    33483393 
    3349         // real meshes are only contructed only at this stage 
    3350         FinalizeViewCells(true); 
     3394        // compute final meshes and volume / area 
     3395        if (1) FinalizeViewCells(true); 
     3396 
    33513397 
    33523398        // write view cells to disc 
     
    39674013                vm->mMaxPvsSize = (int)objects->size(); 
    39684014 
     4015                // create the meshes and compute volumes 
    39694016                vm->FinalizeViewCells(true); 
    39704017 
     
    39774024                DEL_PTR(vm); 
    39784025        } 
    3979  
    39804026 
    39814027        return vm; 
     
    40614107                mVspBspTree->ConstructGeometry(leaf, geom); 
    40624108 
    4063                 float lVol = geom.GetVolume(); 
    4064                 float lArea = geom.GetArea(); 
     4109                const float lVol = geom.GetVolume(); 
     4110                const float lArea = geom.GetArea(); 
    40654111 
    40664112                //(*it)->SetVolume(vol); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r713 r719  
    267267        virtual void PrintPvsStatistics(ostream &s); 
    268268 
     269        /** Updates pvs of the view cell hierarchy if necessary. 
     270        */ 
     271        void UpdatePvs(); 
     272 
    269273        /** Returns probability that view point lies in one view cell. 
    270274        */ 
     
    529533        bool mPruneEmptyViewCells; 
    530534 
     535        bool mViewCellPvsIsUpdated; 
    531536        /// maximum number of samples taken for construction of the view cells 
    532537        int mConstructionSamples; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r711 r719  
    26412641        vector<Plane3> candidatePlanes; 
    26422642 
     2643        vector<Plane3>::const_iterator pit, pit_end = halfSpaces.end(); 
     2644 
    26432645        // bounded planes are added to the polygons 
    2644         for (int i = 0; i < (int)halfSpaces.size(); ++ i) 
    2645         { 
    2646                 Polygon3 *p = GetBoundingBox().CrossSection(halfSpaces[i]); 
     2646        for (pit = halfSpaces.begin(); pit != pit_end; ++ pit) 
     2647        { 
     2648                Polygon3 *p = GetBoundingBox().CrossSection(*pit); 
    26472649 
    26482650                if (p->Valid(mEpsilon)) 
    26492651                { 
    26502652                        candidatePolys.push_back(p); 
    2651                         candidatePlanes.push_back(halfSpaces[i]); 
     2653                        candidatePlanes.push_back(*pit); 
    26522654                } 
    26532655        } 
     
    31373139{ 
    31383140        int hits = 0; 
    3139         stack<BspRayTraversalData> tQueue; 
     3141        stack<BspRayTraversalData> tStack; 
    31403142 
    31413143        float mint = 0.0f, maxt = 1.0f; 
     
    31953197 
    31963198                        // push data for far child 
    3197                         tQueue.push(BspRayTraversalData(farChild, extp)); 
     3199                        tStack.push(BspRayTraversalData(farChild, extp)); 
    31983200 
    31993201                        // find intersection of ray segment with plane 
     
    32193221 
    32203222                        //-- fetch the next far child from the stack 
    3221                         if (tQueue.empty()) 
     3223                        if (tStack.empty()) 
    32223224                                break; 
    32233225 
    32243226                        entp = extp; 
    32253227                         
    3226                         BspRayTraversalData &s = tQueue.top(); 
     3228                        const BspRayTraversalData &s = tStack.top(); 
    32273229 
    32283230                        node = s.mNode; 
    32293231                        extp = s.mExitPoint; 
    32303232 
    3231                         tQueue.pop(); 
     3233                        tStack.pop(); 
    32323234                } 
    32333235        } 
Note: See TracChangeset for help on using the changeset viewer.