Changeset 650


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

added spatial hierarchy based merge tree

Location:
GTP/trunk/Lib/Vis
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env

    r649 r650  
    331331                missTolerance           6 
    332332                 
    333                 maxViewCells            10000 
    334                  
     333                maxViewCells            100 
     334         
    335335                # used for pvs criterium 
    336336                ct_div_ci 0.0 
     
    354354BspTree { 
    355355        Construction { 
    356                 samples 500000 
     356                samples 50000 
    357357                epsilon 0.005 
    358358        } 
     
    420420                minProbability 0.00001 
    421421                maxRayContribution 9999 
    422                 maxViewCells    10000 
     422                maxViewCells    100 
    423423 
    424424                # used for pvs criterium 
  • 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} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r649 r650  
    361361        void ExportStats(); 
    362362 
     363        /** Sets root of hierarchy. 
     364        */ 
     365        void SetRoot(ViewCell *root); 
     366 
     367        //float ComputeVolume(ViewCell *vc); 
     368 
    363369protected: 
    364370 
     
    480486        /// maximal cost ratio for the merge 
    481487        float mMergeMaxCostRatio; 
    482  
    483         ofstream mStats; 
    484488 
    485489        typedef priority_queue<MergeCandidate> MergeQueue; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r649 r650  
    5353{} 
    5454 
     55 
    5556BspNode::BspNode(BspInterior *parent):  
    5657mParent(parent), mTreeValid(true) 
     
    217218mUseAreaForPvs(false), 
    218219mGenerateViewCells(true), 
    219 mTimeStamp(0) 
     220mTimeStamp(1) 
    220221{ 
    221222        Randomize(); // initialise random generator for heuristics 
     
    11821183        backData.mNode = interior->GetBack(); 
    11831184         
    1184         interior->mTimeStamp = leaf->mTimeStamp; 
    1185         frontData.mNode->mTimeStamp = mTimeStamp; 
    1186         backData.mNode->mTimeStamp = mTimeStamp ++; 
    1187  
    1188         Debug << "time stamp: " << mTimeStamp << endl; 
     1185        interior->mTimeStamp = mTimeStamp ++; 
     1186         
    11891187        //DEL_PTR(leaf); 
    11901188        return interior; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r649 r650  
    11421142 
    11431143        //-- merge view cells 
    1144         int merged; 
    1145          
    11461144        cout << "starting post processing using " << mPostProcessSamples << " samples ... "; 
    11471145        long startTime = GetTime(); 
     
    11531151        { 
    11541152                Debug << "constructing visibility based merge tree" << endl; 
    1155                 merged = mViewCellsTree->ConstructMergeTree(rays, objects); 
     1153                mViewCellsTree->ConstructMergeTree(rays, objects); 
    11561154        } 
    11571155        else 
     
    11591157                Debug << "constructing spatial merge tree" << endl; 
    11601158                // create spatial merge hierarchy 
    1161                 merged = ConstructSpatialMergeTree(); 
    1162         } 
     1159                mViewCellsTree->SetRoot(ConstructSpatialMergeTree(mBspTree->GetRoot())); 
     1160        } 
     1161 
     1162        mViewCellsTree->ExportStats(); 
    11631163 
    11641164        //-- stats and visualizations 
    11651165        cout << "finished" << endl; 
    1166         cout << "merged " << merged << " view cells in " 
     1166        cout << "merged view cells in " 
    11671167                 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
    11681168 
    1169         Debug << "Postprocessing: Merged " << merged << " view cells in " 
     1169        Debug << "Postprocessing: Merged view cells in " 
    11701170                << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 
    11711171         
     
    12401240        } 
    12411241 
    1242         return merged; 
     1242        return 0; 
    12431243} 
    12441244 
     
    16821682 
    16831683 
    1684 int BspViewCellsManager::ConstructSpatialMergeTree() 
    1685 { 
    1686         TraversalQueue tQueue; 
    1687  
    1688         tQueue.push(TraversalData(mBspTree->GetRoot(), NULL)); 
    1689  
    1690         int merged = 0; 
    1691  
    1692         int numViewCells = (int)mViewCells.size(); 
    1693  
    1694         float var = 0; 
    1695         float dev = 0; 
    1696         int totalPvs = 0; 
    1697         float totalRenderCost = 0; 
    1698         float avgRenderCost = 0; 
    1699         float expCost = 0; 
    1700  
    1701         //-- compute statistics values of initial view cells 
    1702         EvaluateRenderStatistics(totalRenderCost, 
    1703                                                      expCost, 
    1704                                                          dev, 
    1705                                                          var, 
    1706                                                          totalPvs, 
    1707                                                          avgRenderCost); 
    1708  
    1709         Debug/*mStats*/ << "#Pass\n" << 0 << endl 
    1710                    << "#Merged\n" << merged << endl  
    1711                    << "#ViewCells\n" << numViewCells << endl  
    1712                    << "#RenderCostIncrease\n" << 0 << endl 
    1713                    << "#TotalRenderCost\n" << totalRenderCost << endl 
    1714                    << "#CurrentPvs\n" << 0 << endl 
    1715                    << "#ExpectedCost\n" << expCost << endl 
    1716                    << "#AvgRenderCost\n" << avgRenderCost << endl 
    1717                    << "#Deviation\n" << dev << endl 
    1718                    << "#TotalPvs\n" << totalPvs << endl 
    1719                    << "#PvsSizeDecrease\n0" << endl 
    1720                    << "#Volume\n0" << endl 
    1721                    //<< "#Siblings\n" << mergeStats.siblings << endl 
    1722                    << endl; 
    1723          
    1724  
    1725         while (!tQueue.empty()) 
    1726         { 
    1727                 TraversalData tData = tQueue.top(); 
    1728                 tQueue.pop(); 
    1729  
    1730                 if (tData.mNode->IsLeaf()) 
    1731                 { 
    1732                         ViewCell *viewCell = dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell(); 
    1733                         viewCell->SetMergeCost((float)tData.mNode->mTimeStamp); 
    1734  
    1735                         Debug << "leaf time stamp: " << tData.mNode->mTimeStamp << endl; 
    1736  
    1737                         if (tData.mParentViewCell) 
    1738                         { 
    1739                                 tData.mParentViewCell->SetupChildLink(viewCell); 
    1740                                 // propagate up pvs: could be redone as propagepvs, which propagates pvs up and down 
    1741                                 mViewCellsTree->PropagateUpPvs(viewCell); 
    1742                         } 
    1743                 } 
    1744                 else 
    1745                 { 
    1746                         BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
    1747                         ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
    1748  
    1749                         ++ merged; 
    1750                         -- numViewCells; 
    1751  
    1752                         avgRenderCost = totalPvs / numViewCells; 
    1753  
    1754                         Debug//mStats  
    1755                                 << "#Pass\n" << 0 << endl 
    1756                                 << "#Merged\n" << merged << endl  
    1757                                 << "#ViewCells\n" << numViewCells << endl  
    1758                 << "#RenderCostIncrease\n" << 0 << endl 
    1759                                 << "#TotalRenderCost\n" << totalRenderCost << endl 
    1760                                 << "#CurrentPvs\n" << 0 << endl 
    1761                 << "#ExpectedCost\n" << 0 << endl 
    1762                                 << "#AvgRenderCost\n" << avgRenderCost << endl 
    1763                                 << "#Deviation\n" << dev << endl 
    1764                                 << "#TotalPvs\n" << totalPvs << endl 
    1765                                 << "#PvsSizeDecrease\n" << 0 << endl 
    1766                                 << "#Volume\n" << 0 << endl 
    1767                                 << endl; 
    1768  
    1769                         Debug << "interior time stamp: " << tData.mNode->mTimeStamp << endl; 
    1770  
    1771                         viewCellInterior->SetMergeCost((float)tData.mNode->mTimeStamp); 
    1772  
    1773  
    1774                         tQueue.push(TraversalData(interior->GetBack(), viewCellInterior)); 
    1775                         tQueue.push(TraversalData(interior->GetFront(), viewCellInterior)); 
    1776  
    1777                         if (tData.mParentViewCell) 
    1778                                 tData.mParentViewCell->SetupChildLink(viewCellInterior); 
    1779                 } 
    1780         } 
    1781  
    1782         return merged; 
    1783 } 
     1684ViewCell *BspViewCellsManager::ConstructSpatialMergeTree(BspNode *root) 
     1685{ 
     1686        if (root->IsLeaf()) 
     1687        { 
     1688                ViewCell *viewCell = dynamic_cast<BspLeaf *>(root)->GetViewCell(); 
     1689 
     1690                viewCell->SetMergeCost(0.0f); 
     1691 
     1692                return viewCell; 
     1693        } 
     1694         
     1695        BspInterior *interior = dynamic_cast<BspInterior *>(root); 
     1696        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
     1697                 
     1698        float mergeCost = 1.0f / (float)root->mTimeStamp; 
     1699        //Debug << "timestamp: " << root->mTimeStamp; 
     1700        //Debug << "merge cost: " << mergeCost << endl; 
     1701 
     1702        viewCellInterior->SetMergeCost(mergeCost); 
     1703 
     1704        float volume = 0; 
     1705         
     1706        BspNode *front = interior->GetFront(); 
     1707        BspNode *back = interior->GetBack(); 
     1708 
     1709        // recursivly compute child hierarchies 
     1710        ViewCell *backVc = ConstructSpatialMergeTree(back); 
     1711        ViewCell *frontVc = ConstructSpatialMergeTree(front); 
     1712 
     1713        viewCellInterior->SetupChildLink(frontVc); 
     1714        viewCellInterior->SetupChildLink(backVc); 
     1715 
     1716 
     1717        viewCellInterior->GetPvs().Merge(backVc->GetPvs()); 
     1718        viewCellInterior->GetPvs().Merge(frontVc->GetPvs()); 
     1719 
     1720        volume += backVc->GetVolume(); 
     1721        volume += frontVc->GetVolume();  
     1722 
     1723        viewCellInterior->SetVolume(volume); 
     1724 
     1725        return viewCellInterior; 
     1726} 
     1727 
    17841728 
    17851729/************************************************************************/ 
     
    26352579    Debug << ss << endl; 
    26362580 
    2637         //-- merge or subdivide view cells 
    2638         int merged = 0; 
     2581        //-- merge view cells 
     2582         
     2583        cout << "starting merge using " << mPostProcessSamples << " samples ... " << endl; 
     2584        long startTime = GetTime(); 
     2585 
     2586 
    26392587        if (mMergeViewCells) 
    26402588        { 
    2641                 cout << "starting merge using " << mPostProcessSamples << " samples ... " << endl; 
    2642                 long startTime = GetTime(); 
    2643  
    2644          
     2589                Debug << "merging view cells" << endl; 
    26452590                // TODO: should be done BEFORE the ray casting 
    2646                 merged = mViewCellsTree->ConstructMergeTree(rays, objects); 
    2647  
    2648                 //-- stats and visualizations 
    2649                 cout << "finished merging" << endl; 
    2650                 cout << "merged " << merged << " view cells in " 
    2651                          << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
    2652  
    2653                 Debug << "Postprocessing: Merged " << merged << " view cells in " 
    2654                           << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 
    2655         } 
     2591                mViewCellsTree->ConstructMergeTree(rays, objects); 
     2592        } 
     2593        else 
     2594        { 
     2595                Debug << "spatial merge" << endl; 
     2596                mViewCellsTree->SetRoot(ConstructSpatialMergeTree(mVspBspTree->GetRoot())); 
     2597        } 
     2598 
     2599        mViewCellsTree->ExportStats(); 
     2600 
     2601        //-- stats and visualizations 
     2602        cout << "finished merging" << endl; 
     2603        cout << "merged view cells in " 
     2604                 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
     2605 
     2606        Debug << "Postprocessing: Merged view cells in " 
     2607                  << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 
     2608         
    26562609 
    26572610        int savedColorCode = mColorCode; 
     
    29082861 
    29092862 
    2910 int VspBspViewCellsManager::ConstructSpatialMergeTree() 
    2911 { 
    2912         TraversalQueue tQueue; 
    2913         tQueue.push(TraversalData(mVspBspTree->GetRoot(), NULL)); 
    2914  
    2915         int merged = 0; 
    2916  
    2917         while (!tQueue.empty()) 
    2918         { 
    2919                 TraversalData tData = tQueue.top(); 
    2920                 tQueue.pop(); 
    2921  
    2922                 if (tData.mNode->IsLeaf()) 
    2923                 { 
    2924                         ViewCell *viewCell = dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell(); 
    2925  
    2926                         if (tData.mParentViewCell) 
    2927                         { 
    2928                                 tData.mParentViewCell->SetupChildLink(viewCell); 
    2929                                 // probagate up pvs 
    2930                                 mViewCellsTree->PropagateUpPvs(viewCell); 
    2931                         } 
    2932                 } 
    2933                 else 
    2934                 { 
    2935                         BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
    2936                         ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
    2937                         ++ merged; 
    2938  
    2939                         tQueue.push(TraversalData(interior->GetBack(), viewCellInterior)); 
    2940                         tQueue.push(TraversalData(interior->GetFront(), viewCellInterior)); 
    2941  
    2942                         if (tData.mParentViewCell) 
    2943                                 tData.mParentViewCell->SetupChildLink(viewCellInterior); 
    2944                 } 
    2945         } 
    2946         return merged; 
     2863ViewCell *VspBspViewCellsManager::ConstructSpatialMergeTree(BspNode *root) 
     2864{ 
     2865        if (root->IsLeaf()) 
     2866        { 
     2867                ViewCell *viewCell = dynamic_cast<BspLeaf *>(root)->GetViewCell(); 
     2868 
     2869                viewCell->SetMergeCost(0.0f); 
     2870 
     2871                return viewCell; 
     2872        } 
     2873         
     2874        BspInterior *interior = dynamic_cast<BspInterior *>(root); 
     2875        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
     2876                 
     2877        float mergeCost = 1.0f / (float)root->mTimeStamp; 
     2878        //Debug << "timestamp: " << root->mTimeStamp; 
     2879        //Debug << "merge cost: " << mergeCost << endl; 
     2880 
     2881        viewCellInterior->SetMergeCost(mergeCost); 
     2882 
     2883        float volume = 0; 
     2884         
     2885        BspNode *front = interior->GetFront(); 
     2886        BspNode *back = interior->GetBack(); 
     2887 
     2888        // recursivly compute child hierarchies 
     2889        ViewCell *backVc = ConstructSpatialMergeTree(back); 
     2890        ViewCell *frontVc = ConstructSpatialMergeTree(front); 
     2891 
     2892        viewCellInterior->SetupChildLink(frontVc); 
     2893        viewCellInterior->SetupChildLink(backVc); 
     2894 
     2895 
     2896        viewCellInterior->GetPvs().Merge(backVc->GetPvs()); 
     2897        viewCellInterior->GetPvs().Merge(frontVc->GetPvs()); 
     2898 
     2899        volume += backVc->GetVolume(); 
     2900        volume += frontVc->GetVolume();  
     2901 
     2902        viewCellInterior->SetVolume(volume); 
     2903 
     2904        return viewCellInterior; 
    29472905} 
    29482906 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r649 r650  
    352352        void CollectViewCells(const int n); 
    353353 
    354  
    355         virtual int ConstructSpatialMergeTree() { return 0;}; 
    356          
    357354        virtual bool EqualToSpatialNode(ViewCell *viewCell) const { return false;} 
    358355 
     
    529526        bool ExportViewCells(const string filename); 
    530527 
    531         int ConstructSpatialMergeTree(); 
     528        ViewCell *ConstructSpatialMergeTree(BspNode *root); 
    532529 
    533530 
     
    815812        void PrepareLoadedViewCells(); 
    816813 
    817         int ConstructSpatialMergeTree(); 
     814        ViewCell *ConstructSpatialMergeTree(BspNode *root); 
    818815 
    819816        /// the view space partition BSP tree. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r648 r650  
    7171mRenderCostWeight(0.5), 
    7272mUseRandomAxis(false), 
    73 mTimeStamp(0) 
     73mTimeStamp(1) 
    7474{ 
    7575        bool randomize = false; 
     
    575575                                                << "#RenderCostDecrease\n" << -costDecr << endl  
    576576                                                << "#TotalRenderCost\n" << mTotalCost << endl 
    577                                                 << "#AvgRenderCost\n" << mTotalPvsSize / mBspStats.Leaves() << endl; 
     577                                                << "#AvgRenderCost\n" << (float)mTotalPvsSize / (float)mBspStats.Leaves() << endl; 
    578578                        } 
    579579 
     
    766766        backData.mNode = interior->GetBack(); 
    767767 
    768         frontData.mNode->mTimeStamp = mTimeStamp; 
    769         backData.mNode->mTimeStamp = mTimeStamp ++; 
     768        interior->mTimeStamp = mTimeStamp ++; 
     769        //frontData.mNode->mTimeStamp = ++ mTimeStamp; 
     770        //backData.mNode->mTimeStamp = mTimeStamp; 
    770771 
    771772        //DEL_PTR(leaf); 
     
    29662967                // the same leaves must not be part of two merge candidates 
    29672968                leaf->Mail(); 
     2969                 
    29682970                vector<BspLeaf *> neighbors; 
    2969                 FindNeighbors(leaf, neighbors, true); 
    2970                 //FindApproximateNeighbors(leaf, neighbors, true); 
     2971                if (0) 
     2972                        FindNeighbors(leaf, neighbors, true); 
     2973                else 
     2974                        FindApproximateNeighbors(leaf, neighbors, true); 
    29712975                vector<BspLeaf *>::const_iterator nit, nit_end = neighbors.end(); 
    29722976 
Note: See TracChangeset for help on using the changeset viewer.