Ignore:
Timestamp:
03/16/06 15:04:03 (19 years ago)
Author:
mattausch
Message:

implemented first version of the visibility filter

File:
1 edited

Legend:

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

    r703 r704  
    544544} 
    545545 
    546 /* 
    547 int ViewCellsManager::ConstructLocalMergeTree(vector<LocalMergeCandidate> candidates) 
    548                                                                                           
    549 { 
    550         while(!candidates.empty()) 
    551         { 
    552                 MergeCandidate mc = candidates.back(); 
    553                 candidates.pop_back(); 
    554                 EvalMergeCost(mc); 
    555                 mergeQueue.push(mc); 
    556         } 
    557  
    558         ViewCell::NewMail(); 
    559  
    560          
    561         long startTime = GetTime(); 
    562  
    563         mergeStats.candidates = (int)mMergeQueue.size(); 
    564  
    565         // passes are needed for statistics, because we don't want to record 
    566         // every merge 
    567         int pass = 0; 
    568         int mergedPerPass = 0; 
    569         float realExpectedCost = mExpectedCost; 
    570         float realAvgRenderCost = mAvgRenderCost; 
    571         int realNumActiveViewCells = mNumActiveViewCells; 
    572          
    573          reset. 
    574  
    575         int numMergedViewCells = 0; 
    576  
    577         environment->GetIntValue("ViewCells.PostProcess.maxMergesPerPass", maxMergesPerPass); 
    578         environment->GetFloatValue("ViewCells.PostProcess.avgCostMaxDeviation", avgCostMaxDeviation); 
    579  
    580         cout << "actual merge starts now ... " << endl; 
    581  
     546 
     547inline float EvalMergeCost(ViewCell *root, ViewCell *candidate) 
     548{ 
     549        return root->GetPvs().GetPvsHomogenity(candidate->GetPvs()); 
     550} 
     551 
     552 
     553int GetBestViewCellIdx(ViewCell *root, const ViewCellContainer &neighborhood) 
     554{ 
     555        int bestViewCellIdx = -1;; 
     556 
     557        float mergeCost = Limits::Infinity; 
     558        int i = 0; 
     559 
     560        ViewCellContainer::const_iterator it, it_end = neighborhood.end(); 
     561 
     562        for (it = neighborhood.begin(); it != it_end; ++ it, ++ i) 
     563        { 
     564                const float mc = EvalMergeCost(root, *it); 
     565 
     566                if (mc > mergeCost) 
     567                { 
     568                        mergeCost = mc; 
     569                        bestViewCellIdx = i; 
     570                } 
     571        } 
     572 
     573        return bestViewCellIdx; 
     574} 
     575 
     576 
     577ViewCell *ViewCellsManager::ConstructLocalMergeTree(ViewCell *currentViewCell,  
     578                                                                                                        const ViewCellContainer &viewCells) 
     579{ 
     580        ViewCell *root = currentViewCell; 
     581        ViewCellContainer neighborhood = viewCells; 
     582 
     583        ViewCellContainer::const_iterator it, it_end = neighborhood.end(); 
     584 
     585        const int n = min(mMaxFilterSize, (int)neighborhood.size()); 
    582586        //-- use priority queue to merge leaf pairs 
    583587 
     588 
    584589        //const float maxAvgCost = 350; 
    585         while (!mMergeQueue.empty())//NumActiveViewCells > mMergeMinViewCells)) 
    586         { 
    587                 //-- reset merge queue if the ratio of current expected cost / real expected cost 
    588                 //   too small or after a given number of merges 
    589                 if ((mergedPerPass > maxMergesPerPass) || 
    590                         (avgCostMaxDeviation > mAvgRenderCost / realAvgRenderCost)) 
    591                 { 
    592                         // adjust render cost 
    593                         ++ pass; 
    594  
    595                         mergedPerPass = 0; 
    596                         mExpectedCost = realExpectedCost; 
    597                                          
    598                          
     590        for (int nMergedViewCells = 0; nMergedViewCells < n; ++ nMergedViewCells) 
     591        { 
     592                const int bestViewCellIdx = GetBestViewCellIdx(root, neighborhood); 
    599593                 
    600                         // refines the view cells 
    601                         // then priorities are recomputed 
    602                         // and the candidates are put back into merge queue 
    603                         if (mRefineViewCells) 
    604                                 RefineViewCells(rays, objects); 
    605                         else 
    606                                 ResetMergeQueue(); 
    607  
    608                         Debug << "Values after reset: "   
    609                                   << " erc: " << mExpectedCost  
    610                                   << " avg: " << mAvgRenderCost  
    611                                   << " dev: " << mDeviation << endl; 
    612  
    613                         if (mExportMergedViewCells) 
    614                         { 
    615                                 ExportMergedViewCells(activeViewCells, objects, numMergedViewCells); 
    616                         } 
    617                 } 
    618  
    619  
    620                 MergeCandidate mc = mMergeQueue.top(); 
    621                 mMergeQueue.pop(); 
    622          
    623                 // both view cells equal 
    624                 // NOTE: do I really still need this? probably cannot happen!! 
    625                 if (mc.mLeftViewCell == mc.mRightViewCell) 
    626                         continue; 
    627  
    628                 if (mc.IsValid()) 
    629                 { 
    630                         ViewCell::NewMail(); 
    631  
    632                         //-- update statistical values 
    633                         -- realNumActiveViewCells; 
    634                         ++ mergeStats.merged; 
    635                         ++ mergedPerPass; 
    636  
    637                         const float renderCostIncr = mc.GetRenderCost(); 
    638                         const float mergeCostIncr = mc.GetMergeCost(); 
    639  
    640                         totalRenderCost += renderCostIncr; 
    641                         mDeviation += mc.GetDeviationIncr(); 
    642                          
    643                          
    644                         // merge the view cells of leaf1 and leaf2 
    645                         int pvsDiff; 
    646                         ViewCellInterior *mergedVc =  
    647                                 MergeViewCells(mc.mLeftViewCell, mc.mRightViewCell, pvsDiff); 
    648  
    649  
    650                         // total render cost and deviation has changed 
    651                         // real expected cost will be larger than expected cost used for the 
    652                         // cost heuristics, but cannot recompute costs on each increase of the  
    653                         // expected cost 
    654                         totalPvs += pvsDiff; 
    655                         realExpectedCost = totalRenderCost / (float)realNumActiveViewCells; 
    656                         realAvgRenderCost = (float)totalPvs / (float)realNumActiveViewCells; 
    657          
    658                         // set merge cost to this node 
    659                         mergedVc->SetMergeCost(totalRenderCost); 
    660  
    661                         //if (mViewCellsManager->EqualToSpatialNode(mergedVc)) 
    662                         //      ++ mergeStats.siblings; 
    663                         mergedVc->SetCost(realExpectedCost); 
    664  
    665                         if ((mergeStats.merged % statsOut) == 0) 
    666                                 cout << "merged " << mergeStats.merged << " view cells" << endl; 
    667  
    668                 } 
    669                 else 
    670                 {  
    671                         // merge candidate not valid, because one of the leaves was already 
    672                         // merged with another one => validate and reinsert into queue 
    673                         if (ValidateMergeCandidate(mc)) 
    674                         { 
    675                                 EvalMergeCost(mc); 
    676                                 mMergeQueue.push(mc); 
    677                         } 
    678                 } 
     594                ViewCell *bestViewCell = neighborhood[bestViewCellIdx]; 
    679595                 
    680         } 
    681  
    682          
    683         // adjust stats and reset queue one final time 
    684         mExpectedCost = realExpectedCost; 
    685         mAvgRenderCost = realAvgRenderCost; 
    686         mNumActiveViewCells = realNumActiveViewCells; 
    687  
    688         UpdateActiveViewCells(activeViewCells); 
    689  
    690          
    691         // refine view cells and reset costs 
    692         if (mRefineViewCells) 
    693                 RefineViewCells(rays, objects); 
    694         else 
    695                 ResetMergeQueue(); 
    696  
    697         // create a root node if the merge was not done till root level, 
    698         // else take the single node as new root 
    699         if ((int)activeViewCells.size() > 1) 
    700         { 
    701                 Debug << "creating root of view cell hierarchy for "  
    702                           << (int)activeViewCells.size() << " view cells" << endl; 
     596                // remove from vector 
     597                swap(neighborhood[bestViewCellIdx], neighborhood.back()); 
     598                neighborhood.pop_back(); 
    703599                 
    704                 ViewCellInterior *root = mViewCellsManager->MergeViewCells(activeViewCells); 
    705                 root->SetMergeCost(totalRenderCost); 
    706                 // $$JB keep this 0 temporarilly 
    707                 root->SetCost(0.0f); 
    708  
    709                 mRoot = root; 
    710         } 
    711         else if ((int)activeViewCells.size() == 1) 
    712         { 
    713                 Debug << "setting root of the merge history" << endl; 
    714                 mRoot = activeViewCells[0]; 
    715         } 
    716  
    717         //-- empty merge queue just in case 
    718         while (!mMergeQueue.empty()) 
    719         { 
    720                 mMergeQueue.pop(); 
    721         } 
    722  
    723         // TODO delete because makes no sense here 
    724         mergeStats.expectedRenderCost = realExpectedCost; 
    725         mergeStats.deviation = mDeviation; 
    726  
    727         // we want to optimize this heuristics 
    728         mergeStats.heuristics =  
    729                 mDeviation * (1.0f - mRenderCostWeight) +  
    730                 mExpectedCost * mRenderCostWeight; 
    731  
    732         mergeStats.mergeTime = TimeDiff(startTime, GetTime()); 
    733         mergeStats.Stop(); 
    734         Debug << mergeStats << endl << endl; 
    735  
    736         // assign colors for the view cells so that at least one is always consistent 
    737         AssignRandomColors(); 
    738          
    739         //TODO: should return sample contributions? 
    740         return mergeStats.merged; 
    741 } 
    742 */ 
     600                if (!bestViewCell || !root) 
     601                        cout << "warning!!" << endl; 
     602                // create new root of the hierarchy 
     603                root = MergeViewCells(root, bestViewCell); 
     604        } 
     605 
     606        return root;     
     607} 
     608 
    743609 
    744610bool ViewCellsManager::CheckValidity(ViewCell *vc, 
     
    771637        const AxisAlignedBox3 box = GetFilterBBox(viewPoint, mFilterWidth); 
    772638 
     639        ViewCell *currentViewCell = GetViewCell(viewPoint); 
     640 
    773641        ViewCellContainer viewCells; 
    774642        ComputeBoxIntersections(box, viewCells); 
    775643 
    776                  
     644        ViewCell *root = ConstructLocalMergeTree(currentViewCell, viewCells); 
     645 
     646        prvs.mViewCell = root; 
     647        //prvs.mPvs = root->GetPvs(); 
    777648} 
    778649 
     
    20501921                subdivVol += (*it)->GetVolume(); 
    20511922 
    2052                 float thres = 0.9; 
     1923                float thres = 0.9f; 
    20531924                if ((lVol < ((*it)->GetVolume() * thres)) || 
    20541925                        (lVol * thres > ((*it)->GetVolume()))) 
     
    41063977                subdivVol += (*it)->GetVolume(); 
    41073978                 
    4108                 float thres = 0.9; 
     3979                float thres = 0.9f; 
    41093980                if ((lVol < ((*it)->GetVolume() * thres)) || (lVol * thres > ((*it)->GetVolume()))) 
    41103981                        Debug << "warning: " << lVol << " " << (*it)->GetVolume() << endl; 
     
    41294000        Exporter *exporter = Exporter::GetExporter("filter.x3d"); 
    41304001 
     4002        Vector3 bsize = mViewSpaceBox.Size(); 
     4003        const Vector3 viewPoint(mViewSpaceBox.Center()); 
     4004        const Vector3 width = Vector3(mFilterWidth); 
     4005         
     4006        PrVs testPrVs; 
     4007         
    41314008        if (exporter) 
    41324009        { 
    4133                 AxisAlignedBox3 testBox = mViewSpaceBox; 
    4134                 Vector3 bsize = mViewSpaceBox.Size(); 
    4135  
    4136                 testBox.Enlarge(Vector3(-bsize[0] * 0.3, 0, -bsize[2] * 0.4)); 
    4137                  
    41384010                ViewCellContainer viewCells; 
    4139          
    4140                 mVspBspTree->ComputeBoxIntersections(testBox, viewCells); 
    4141                 cout << "view cells: " << viewCells.size() << endl; 
    4142                  
     4011         
     4012        const AxisAlignedBox3 tbox = GetFilterBBox(viewPoint, mFilterWidth); 
     4013 
     4014                GetPrVS(viewPoint, testPrVs); 
     4015 
    41434016                exporter->SetWireframe(); 
    41444017 
    41454018                exporter->SetForcedMaterial(RgbColor(1,1,1)); 
    4146                 exporter->ExportBox(testBox); 
     4019                exporter->ExportBox(tbox); 
    41474020                 
    41484021                exporter->SetFilled(); 
    41494022                exporter->ResetForcedMaterial(); 
    4150         for (int i = 0; i < viewCells.size(); ++ i) 
    4151                 { 
    4152                         BspNodeGeometry geom; 
    4153                                  
    4154                         mVspBspTree->ConstructGeometry(viewCells[i], geom); 
    4155                         exporter->ExportPolygons(geom.GetPolys()); 
    4156                 }                
    4157  
    4158                 exporter->SetForcedMaterial(RgbColor(1,0,0)); 
     4023 
     4024                ExportViewCellGeometry(exporter, testPrVs.mViewCell); 
     4025 
     4026        exporter->SetForcedMaterial(RgbColor(1,0,0)); 
    41594027                exporter->ExportGeometry(objects); 
    41604028 
Note: See TracChangeset for help on using the changeset viewer.