Ignore:
Timestamp:
02/03/06 13:03:35 (18 years ago)
Author:
mattausch
Message:
 
File:
1 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 
Note: See TracChangeset for help on using the changeset viewer.