Changeset 584


Ignore:
Timestamp:
02/03/06 13:03:35 (18 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r583 r584  
    305305mRoot(NULL), 
    306306mUseAreaForPvs(false), 
    307 mViewCellsManager(vcm) 
     307mViewCellsManager(vcm), 
     308mIsCompressed(false) 
    308309{ 
    309310        environment->GetBoolValue("ViewCells.Visualization.exportMergedViewCells", mExportMergedViewCells); 
     
    666667 
    667668 
    668 ViewCell *ViewCellsTree::GetRoot() 
     669ViewCell *ViewCellsTree::GetRoot() const 
    669670{ 
    670671        return mRoot; 
     
    710711        int numMergedViewCells = 0; 
    711712 
    712         Debug << "updating active vc: " << viewCells.size() << endl; 
     713        Debug << "updating active vc: " << (int)viewCells.size() << endl; 
    713714        // find all already merged view cells and remove them from view cells 
    714715                 
     
    12401241} 
    12411242 
    1242  
    12431243void ViewCellsTree::CompressViewCellsPvs() 
    12441244{ 
    1245         stack<ViewCell *> tstack; 
    1246          
    1247         while (!tstack.empty()) 
    1248         { 
    1249                 ViewCell *viewCell = tstack.top(); 
    1250                 tstack.pop(); 
    1251  
    1252                 if (!viewCell->IsLeaf()) 
    1253                 { 
    1254                  
    1255                         ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(viewCell); 
    1256                         Debug << "compressing " << interior->GetPvs().GetSize() << endl; 
    1257                         ComputeCommonPvs(interior); 
    1258                         Debug << "compressed " << interior->GetPvs().GetSize() << endl; 
    1259                 } 
     1245        if (!mIsCompressed) 
     1246        { 
     1247                mIsCompressed = true; 
     1248                CompressViewCellsPvs(mRoot); 
     1249        } 
     1250} 
     1251 
     1252void ViewCellsTree::CompressViewCellsPvs(ViewCell *root) 
     1253{ 
     1254        if (!root->IsLeaf()) 
     1255        { 
     1256                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root); 
     1257 
     1258        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1259                // compress child sets first 
     1260                for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1261                { 
     1262                        CompressViewCellsPvs(*it); 
     1263                } 
     1264 
     1265                PropagateUpVisibility(interior); 
    12601266        } 
    12611267} 
     
    12951301         
    12961302 
    1297 void ViewCellsTree::ComputeCommonPvs(ViewCellInterior *interior) 
    1298 { 
    1299         Intersectable::NewMail(); 
     1303void ViewCellsTree::PropagateUpVisibility(ViewCellInterior *interior) 
     1304{ 
     1305        Intersectable::NewMail((int)interior->mChildren.size()); 
    13001306 
    13011307        ViewCellContainer::const_iterator cit, cit_end = interior->mChildren.end(); 
     
    13041310 
    13051311        // mail all objects in the leaf sets 
     1312        // we are interested in the objects which are present in all leaves 
     1313        // => count how often an object is part of a child set 
    13061314        for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit) 
    13071315        { 
     
    13121320                for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    13131321                { 
    1314                         if (!(*oit).first->Mailed()) 
    1315                                 (*oit).first->Mail(); 
     1322                        Intersectable *obj = (*oit).first; 
     1323                        if ((cit == interior->mChildren.begin()) && !obj->Mailed()) 
     1324                                obj->Mail(); 
    13161325                         
    1317                         (*oit).first->IncMail(); 
     1326                        int incm = obj->IncMail(); 
    13181327                } 
    13191328        } 
    13201329 
    13211330        interior->GetPvs().mEntries.clear(); 
    1322     cit_end = interior->mChildren.end(); 
     1331         
    13231332         
    13241333        // only the objects which are present in all leaf pvs  
    13251334        // should remain in the parent pvs 
    1326  
     1335        // these are the objects which have been mailed in all children 
    13271336        for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit) 
    13281337        { 
     
    13331342                for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    13341343                { 
     1344                        Debug << "mail: " << (*oit).first->mMailbox << endl; 
     1345 
    13351346                        if ((*oit).first->Mailed((int)interior->mChildren.size())) 
    13361347                        {        
     1348                                //Debug << "adding sample" << endl; 
    13371349                                interior->GetPvs().AddSample((*oit).first, (*oit).second.mSumPdf); 
    13381350                                //(*oit)->remove(); 
     
    13411353        } 
    13421354 
    1343         // delete all the objects from the leaf sets which were moved 
    1344         // to parent pvs 
     1355 
     1356 
     1357        // delete all the objects from the leaf sets which were moved to parent pvs 
    13451358        ObjectPvsMap::const_iterator oit_end = interior->GetPvs().mEntries.end(); 
    13461359 
     
    13491362                for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit) 
    13501363                { 
    1351                         (*cit)->GetPvs().RemoveSample((*oit).first, Limits::Infinity); 
    1352                 } 
    1353         } 
     1364                        if (!(*cit)->GetPvs().RemoveSample((*oit).first, Limits::Infinity)) 
     1365                                Debug << "should not come here!" << endl; 
     1366                } 
     1367        } 
     1368} 
     1369 
     1370 
     1371void ViewCellsTree::GetPvs(ViewCell *vc, ObjectPvs &pvs) const 
     1372{ 
     1373        if (mIsCompressed) 
     1374        { 
     1375                ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 
     1376 
     1377                for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     1378                { 
     1379                        pvs.AddSample((*oit).first, (*oit).second.mSumPdf); 
     1380                } 
     1381 
     1382                if (!vc->IsLeaf()) 
     1383                { 
     1384                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1385                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1386 
     1387                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1388                        { 
     1389                                GetPvs(*it, pvs); 
     1390                        } 
     1391                } 
     1392        } 
     1393        else 
     1394        { 
     1395                pvs = vc->GetPvs(); 
     1396        } 
     1397} 
     1398 
     1399 
     1400int ViewCellsTree::GetPvsSize(ViewCell *vc) const 
     1401{ 
     1402        int pvsSize = vc->GetPvs().GetSize(); 
     1403 
     1404        //Debug << "current size: " << pvsSize << endl; 
     1405        if (mIsCompressed && !vc->IsLeaf()) 
     1406        { 
     1407                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1408 
     1409                ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1410 
     1411                for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1412                { 
     1413                        pvsSize += GetPvsSize(*it); 
     1414                } 
     1415        } 
     1416 
     1417        return pvsSize;   
     1418 
     1419} 
     1420 
     1421 
     1422float ViewCellsTree::GetMemoryCost(ViewCell *vc) const 
     1423{ 
     1424        const float entrySize =  
     1425                sizeof(PvsData<Intersectable *>) + sizeof(Intersectable *); 
     1426 
     1427        return (float)GetNumPvsEntries(vc) * entrySize; 
     1428} 
     1429 
     1430 
     1431int ViewCellsTree::GetNumPvsEntries(ViewCell *vc) const 
     1432{ 
     1433        int pvsSize = vc->GetPvs().GetSize(); 
     1434 
     1435        if (!vc->IsLeaf()) 
     1436        { 
     1437                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1438 
     1439                ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1440 
     1441                for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1442                { 
     1443                        pvsSize += GetNumPvsEntries(*it); 
     1444                } 
     1445        } 
     1446 
     1447        return pvsSize;          
     1448} 
     1449 
     1450 
     1451bool ViewCellsTree::IsCompressed() const 
     1452{ 
     1453        return mIsCompressed; 
    13541454} 
    13551455 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r582 r584  
    285285        int RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects); 
    286286 
    287         /** Compresses the pvs of the view cells. 
     287         
     288 
     289        /** Returns optimal set of view cells for a given number of view cells. 
     290        */ 
     291        void CollectBestViewCellSet(ViewCellContainer &viewCells, const int numViewCells); 
     292 
     293        /** Root of view cells tree. 
     294        */ 
     295        ViewCell *GetRoot() const; 
     296 
     297        /** Returns pvs of view cell. 
     298                @note pvs is returned per reference if tree is not compressed, 
     299                per copy else. 
     300        */ 
     301        void GetPvs(ViewCell *vc, ObjectPvs &pvs) const; 
     302 
     303        /** Returns pvs size of view cell. 
     304        */ 
     305        int GetPvsSize(ViewCell *vc) const; 
     306 
     307        /** Returns actual number of object in this pvs and the children. 
     308        */ 
     309        int GetNumPvsEntries(ViewCell *vc) const; 
     310 
     311        /** Returns memory cost of this view cell. 
     312        */ 
     313        float GetMemoryCost(ViewCell *vc) const; 
     314 
     315        /** Compresses the pvs of the view cells from the root. 
    288316        */ 
    289317        void CompressViewCellsPvs(); 
    290318 
    291         /** Returns optimal set of view cells for a given number of view cells. 
    292         */ 
    293         void CollectBestViewCellSet(ViewCellContainer &viewCells, const int numViewCells); 
    294  
    295         /** Root of view cells tree. 
    296         */ 
    297         ViewCell *GetRoot(); 
     319        /** If view cells in this tree have compressed pvs. 
     320        */ 
     321        bool IsCompressed() const; 
    298322 
    299323protected: 
     
    365389        int UpdateActiveViewCells(ViewCellContainer &viewCells); 
    366390 
    367         void ComputeCommonPvs(ViewCellInterior *interior); 
    368  
     391        void PropagateUpVisibility(ViewCellInterior *interior); 
     392 
     393        void CompressViewCellsPvs(ViewCell *root); 
    369394 
    370395        /** Returns memory usage of view cells. 
     
    373398 
    374399 
    375  
     400        /// if the view cell tree hold compressed pvs 
     401        bool mIsCompressed; 
    376402 
    377403        ViewCellsManager *mViewCellsManager; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r583 r584  
    12441244                } 
    12451245 
    1246                 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 
     1246                Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) 
    12471247                          << ", piercing rays=" << (int)vcRays.size() << endl; 
    12481248                         // << ", leaves=" << (int)vc->mLeaves.size() << endl; 
     
    20662066 
    20672067 
    2068 void VspKdViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates) 
     2068void VspKdViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays,  
     2069                                                                                                   vector<MergeCandidate> &candidates) 
    20692070{ 
    20702071        // TODO 
     
    23652366        RefineViewCells(postProcessRays, objects); 
    23662367 
     2368        ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 
     2369 
     2370        int pvsSize = 0; 
     2371        int numPvsEntries = 0; 
     2372 
     2373        int vidx = 0; 
     2374        for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
     2375        { 
     2376                const int vcPvs = mViewCellsTree->GetPvsSize(*vit); 
     2377                const int pvsEntries = mViewCellsTree->GetNumPvsEntries(*vit); 
     2378 
     2379                pvsSize += vcPvs; 
     2380                numPvsEntries += pvsEntries; 
     2381                Debug << "Viewcell " << vidx ++ << ": " << vcPvs << endl; 
     2382        } 
     2383 
     2384        Debug << "pvs size before compress: " << pvsSize << endl; 
     2385        Debug << "number of entries before compress: " << numPvsEntries << endl; 
     2386 
    23672387        mViewCellsTree->CompressViewCellsPvs(); 
     2388 
     2389        pvsSize = numPvsEntries = vidx = 0; 
     2390 
     2391        for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
     2392        { 
     2393                const int vcPvs = mViewCellsTree->GetPvsSize(*vit); 
     2394                const int pvsEntries = mViewCellsTree->GetNumPvsEntries(*vit); 
     2395                 
     2396                pvsSize += vcPvs; 
     2397                numPvsEntries += pvsEntries; 
     2398                Debug << "Viewcell " << vidx ++ << ": " << vcPvs << endl;        
     2399        } 
     2400 
     2401        Debug << "pvs size after compress: " << pvsSize << endl; 
     2402        Debug << "number of entries after compress: " << numPvsEntries << endl; 
    23682403 
    23692404        if (1) 
Note: See TracChangeset for help on using the changeset viewer.