Ignore:
Timestamp:
02/17/06 20:41:22 (18 years ago)
Author:
mattausch
Message:

added spatial hierarchy based merge tree

File:
1 edited

Legend:

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

    r649 r650  
    249249 
    250250 
    251 void ViewCellInterior::SetupChildLink(ViewCell *l) 
    252 { 
    253     mChildren.push_back(l); 
    254     l->mParent = this; 
     251void ViewCellInterior::SetupChildLink(ViewCell *vc) 
     252{ 
     253    mChildren.push_back(vc); 
     254    vc->mParent = this; 
    255255} 
    256256 
     
    333333 
    334334        MergeCandidate::sRenderCostWeight = mRenderCostWeight; 
    335  
    336         mStats.open("mergeStats.log"); 
    337335} 
    338336 
     
    473471 
    474472        // frequency stats are updated 
    475         const int statsOut = 1; 
     473        const int statsOut = 500; 
    476474 
    477475        // passes are needed for statistics, because we don't want to record 
     
    493491 
    494492        cout << "actual merge starts now ... " << endl; 
    495          
    496         mStats << "#Pass\n" << pass << endl 
    497                    << "#Merged\n" << mergeStats.merged << endl  
    498                    << "#ViewCells\n" << realNumActiveViewCells << endl  
    499                    << "#RenderCostIncrease\n" << 0 << endl 
    500                    << "#TotalRenderCost\n" << totalRenderCost << endl 
    501                    << "#CurrentPvs\n" << 0 << endl 
    502                    << "#ExpectedCost\n" << realExpectedCost << endl 
    503                    << "#AvgRenderCost\n" << realAvgRenderCost << endl 
    504                    << "#Deviation\n" << mDeviation << endl 
    505                    << "#TotalPvs\n" << totalPvs << endl 
    506                    << "#PvsSizeDecrease\n0" << endl 
    507                    << "#Volume\n0" << endl 
    508                    //<< "#Siblings\n" << mergeStats.siblings << endl 
    509                    << endl; 
    510493 
    511494        //-- use priority queue to merge leaf pairs 
     
    604587                        mergedVc->SetCost(realExpectedCost); 
    605588 
    606                         if (((mergeStats.merged % statsOut) == 0) ||  
    607                         (realNumActiveViewCells == mMergeMinViewCells)) 
    608                         { 
     589                        if ((mergeStats.merged % statsOut) == 0) 
    609590                                cout << "merged " << mergeStats.merged << " view cells" << endl; 
    610591 
    611                                 mStats  
    612                                         << "#Pass\n" << pass << endl 
    613                                         << "#Merged\n" << mergeStats.merged << endl  
    614                                         << "#ViewCells\n" << realNumActiveViewCells << endl  
    615                     << "#RenderCostIncrease\n" << renderCostIncr << endl 
    616                                         << "#TotalRenderCost\n" << totalRenderCost << endl 
    617                                         << "#CurrentPvs\n" << mergedVc->GetPvs().GetSize() << endl 
    618                     << "#ExpectedCost\n" << realExpectedCost << endl 
    619                                         << "#AvgRenderCost\n" << realAvgRenderCost << endl 
    620                                         << "#Deviation\n" << mDeviation << endl 
    621                                         << "#TotalPvs\n" << totalPvs << endl 
    622                                         << "#PvsSizeDecrease\n" << -pvsDiff << endl 
    623                                         << "#Volume\n" << mergedVc->GetVolume() << endl 
    624                                         << endl; 
    625                                  
    626                         } 
    627592                } 
    628593                else 
     
    663628                // $$JB keep this 0 temporarilly 
    664629                root->SetCost(0.0f); 
    665                  
    666                 mStats  
    667                         << "#Pass\n" << pass << endl 
    668                         << "#Merged\n" << mergeStats.merged << endl  
    669                         << "#ViewCells\n" << realNumActiveViewCells << endl  
    670             << "#RenderCostIncrease\n" << 0 << endl // TODO 
    671                         << "#TotalRenderCost\n" << totalRenderCost << endl 
    672                         << "#CurrentPvs\n" << root->GetPvs().GetSize() << endl 
    673             << "#ExpectedCost\n" << realExpectedCost << endl 
    674                         << "#AvgRenderCost\n" << realAvgRenderCost << endl 
    675                         << "#Deviation\n" << mDeviation << endl 
    676                         << "#TotalPvs\n" << totalPvs << endl 
    677                         << "#PvsSizeDecrease\n" << 0 << endl // TODO 
    678                         << "#Volume\n" << root->GetVolume() << endl 
    679                         << endl; 
    680630 
    681631                mRoot = root; 
     
    705655        mergeStats.mergeTime = TimeDiff(startTime, GetTime()); 
    706656        mergeStats.Stop(); 
    707  
    708657        Debug << mergeStats << endl << endl; 
    709658 
     
    13021251 
    13031252 
     1253void ViewCellsTree::ExportStats() 
     1254{ 
     1255        TraversalQueue tqueue; 
     1256 
     1257        tqueue.push(mRoot); 
     1258        int numViewCells = 1; 
     1259         
     1260        const AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 
     1261        const float vol = box.GetVolume(); 
     1262 
     1263        int totalPvs; 
     1264        float totalRenderCost, float avgRenderCost, float expectedCost; 
     1265 
     1266        float deviation = 0; 
     1267        totalPvs = (int)mRoot->GetPvs().GetSize(); 
     1268        totalRenderCost = avgRenderCost = expectedCost = (float)mRoot->GetPvs().GetSize(); 
     1269 
     1270        ofstream stats; 
     1271        stats.open("mergeStats.log"); 
     1272 
     1273        Debug << "here343" << endl; 
     1274 
     1275        stats  
     1276                << "#Pass\n" << 0 << endl 
     1277                //<< "#Merged\n" << mergeStats.merged << endl  
     1278                << "#ViewCells\n" << numViewCells << endl  
     1279        << "#RenderCostDecrease\n" << 0 << endl // TODO 
     1280                << "#TotalRenderCost\n" << totalRenderCost << endl 
     1281                << "#CurrentPvs\n" << mRoot->GetPvs().GetSize() << endl 
     1282                << "#ExpectedCost\n" << expectedCost << endl 
     1283                << "#AvgRenderCost\n" << avgRenderCost << endl 
     1284                << "#Deviation\n" << deviation << endl 
     1285                << "#TotalPvs\n" << totalPvs << endl 
     1286                << "#PvsSizeDecrease\n" << 0 << endl // TODO 
     1287                << "#Volume\n" << mRoot->GetVolume() << endl 
     1288                << endl; 
     1289 
     1290 
     1291        while (!tqueue.empty()) 
     1292        { 
     1293                ViewCell *vc = tqueue.top(); 
     1294                tqueue.pop(); 
     1295 
     1296                if (!vc->IsLeaf())  
     1297                {        
     1298                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1299                         
     1300                        const int parentPvs = interior->GetPvs().GetSize(); 
     1301                        const float parentCost = (float)parentPvs * interior->GetVolume(); 
     1302                        float childCost = 0; 
     1303                        int childPvs = 0; 
     1304 
     1305                        -- numViewCells; 
     1306 
     1307                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1308 
     1309                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1310                        { 
     1311                                childCost += (float)(*it)->GetPvs().GetSize() * (*it)->GetVolume(); 
     1312                                childPvs += (*it)->GetPvs().GetSize(); 
     1313 
     1314                                tqueue.push(*it); 
     1315                                ++ numViewCells; 
     1316                        } 
     1317 
     1318                 
     1319                        const float costDecr = (parentCost - childCost) / vol; 
     1320 
     1321                        totalRenderCost -= costDecr; 
     1322                        totalPvs += childPvs - parentPvs; 
     1323                         
     1324                        expectedCost = totalRenderCost / (float)numViewCells; 
     1325                        avgRenderCost = (float)totalPvs / (float)numViewCells; 
     1326 
     1327                        stats  
     1328                                << "#Pass\n" << 0 << endl 
     1329                                //<< "#Merged\n" << mergeStats.merged << endl  
     1330                                << "#ViewCells\n" << numViewCells << endl  
     1331                                << "#RenderCostDecrease\n" << costDecr << endl // TODO 
     1332                                << "#TotalRenderCost\n" << totalRenderCost << endl 
     1333                                << "#CurrentPvs\n" << vc->GetPvs().GetSize() << endl 
     1334                                << "#ExpectedCost\n" << expectedCost << endl 
     1335                                << "#AvgRenderCost\n" << avgRenderCost << endl 
     1336                                << "#Deviation\n" << deviation << endl 
     1337                                << "#TotalPvs\n" << totalPvs << endl 
     1338                                << "#PvsSizeDecrease\n" << childPvs - parentPvs << endl // TODO 
     1339                                << "#Volume\n" << vc->GetVolume() << endl 
     1340                                << endl; 
     1341 
     1342                } 
     1343        } 
     1344 
     1345        stats.close(); 
     1346} 
     1347 
     1348 
     1349/*float ViewCellsTree::ComputeVolume(ViewCell *vc) 
     1350{ 
     1351        if (vc->IsLeaf()) 
     1352        { 
     1353                return vc->GetVolume(); 
     1354        } 
     1355        else 
     1356        { 
     1357                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1358 
     1359                ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1360 
     1361                float volume = 0; 
     1362 
     1363                for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1364                { 
     1365                        volume += ComputeVolume(*it);    
     1366                } 
     1367 
     1368                interior->SetVolume(volume); 
     1369                return volume; 
     1370        } 
     1371}*/ 
     1372 
     1373 
     1374void ViewCellsTree::SetRoot(ViewCell *root) 
     1375{ 
     1376        mRoot = root; 
     1377} 
     1378 
    13041379void ViewCellsTree::CollectBestViewCellSet(ViewCellContainer &viewCells,  
    13051380                                                                                   const int numViewCells) 
     
    13111386        { 
    13121387                ViewCell *vc = tqueue.top(); 
    1313                  
     1388                tqueue.pop(); 
     1389 
    13141390                // save the view cells if it is a leaf or if enough view cells have already been traversed 
    13151391                // because of the priority queue, this will be the optimal set of v 
    1316                 if (vc->IsLeaf() || ((viewCells.size() + tqueue.size()) >= numViewCells)) 
     1392                if (vc->IsLeaf() || ((viewCells.size() + tqueue.size() + 1) >= numViewCells)) 
    13171393                { 
    13181394                        // todo: should be done with a function taking the active flag and some  
     
    13331409                        } 
    13341410                } 
    1335  
    1336                 tqueue.pop(); 
    13371411        } 
    13381412} 
     
    14111485 
    14121486 
    1413 void ViewCellsTree::ExportStats() 
    1414 { 
    1415  
    1416 } 
    1417  
    14181487void ViewCellsTree::GetPvs(ViewCell *vc, ObjectPvs &pvs) const 
    14191488{ 
     
    15621631 
    15631632 
    1564 void 
    1565 ViewCellsTree::AssignRandomColors() 
     1633void ViewCellsTree::AssignRandomColors() 
    15661634{ 
    15671635  TraversalQueue tqueue; 
     
    15711639        { 
    15721640          ViewCell *vc = tqueue.top(); 
    1573            
     1641          tqueue.pop(); 
     1642 
    15741643          // save the view cells if it is a leaf or if enough view cells have already been traversed 
    15751644          // because of the priority queue, this will be the optimal set of v 
     
    15931662                 
    15941663          } 
    1595            
    1596           tqueue.pop(); 
     1664          
    15971665        } 
    15981666} 
     
    16061674  while (!tqueue.empty()) { 
    16071675        ViewCell *vc = tqueue.top(); 
    1608          
     1676        tqueue.pop(); 
    16091677        // save the view cells if it is a leaf or if enough view cells have already been traversed 
    16101678        // because of the priority queue, this will be the optimal set of v 
     
    16201688           
    16211689        } 
    1622          
    1623         tqueue.pop(); 
    16241690  } 
    16251691} 
Note: See TracChangeset for help on using the changeset viewer.