Changeset 704


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

implemented first version of the visibility filter

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
7 edited

Legend:

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

    r697 r704  
    17901790                                                                        float &maxT) const 
    17911791{ 
    1792         maxT = 1e15; 
     1792        maxT = 1e15f; 
    17931793        minT = 0; 
    17941794         
  • GTP/trunk/Lib/Vis/Preprocessing/src/Beam.cpp

    r542 r704  
    119119        left = -right; 
    120120 
    121         top = yDirRange * 0.5; 
     121        top = yDirRange * 0.5f; 
    122122        bottom = -top; 
    123123} 
     
    165165 
    166166        // box should not never remove part of beam polygons 
    167         Vector3 bmin = mBox.Min() - Vector3(zfar * 2.0); 
    168         Vector3 bmax = mBox.Max() + Vector3(zfar * 2.0); 
     167        Vector3 bmin = mBox.Min() - Vector3(zfar * 2.0f); 
     168        Vector3 bmax = mBox.Max() + Vector3(zfar * 2.0f); 
    169169 
    170170        AxisAlignedBox3 bbox(bmin, bmax); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r695 r704  
    109109 
    110110  /** Compute continuous PVS difference */ 
    111   void ComputeContinuousPvsDifference(const Pvs<T> &pvs, 
     111  void ComputeContinuousPvsDifference(Pvs<T> &pvs, 
    112112                                                                          float &pvsReduction, 
    113113                                                                          float &pvsEnlargement); 
     
    115115 
    116116  /** Compute continuous PVS difference */ 
    117   float GetPvsHomogenity(const Pvs<T> &pvs) { 
     117  float GetPvsHomogenity(Pvs<T> &pvs) { 
    118118        float  
    119119          pvsReduction, 
     
    142142template <typename T> 
    143143void 
    144 Pvs<T>::ComputeContinuousPvsDifference(const Pvs<T> &b, 
     144Pvs<T>::ComputeContinuousPvsDifference(Pvs<T> &b, 
    145145                                                                           float &pvsReduction, 
    146146                                                                           float &pvsEnlargement) 
    147147{ 
    148148  // Uses sum of log differences, which corresponds to entropy 
    149   std::map<T, PvsData<T>, LtSample<T> >::const_iterator it; 
    150    
    151   for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) { 
     149  std::map<T, PvsData<T>, LtSample<T> >::iterator it; 
     150   
     151  for (it = b.mEntries.begin();  
     152          it != b.mEntries.end(); ++ it) { 
    152153        float bSumPdf = (*it).second.mSumPdf; 
    153154        float aSumPdf = 0.0f; 
    154155        PvsData<T> *data = Find((*it).first);            
    155156        if (data) { 
    156           aSumPdf = data->second.mSumPdf; 
     157          aSumPdf = data->mSumPdf; 
    157158          // mark this entry as processed to avoid double counting 
    158           data->second.mSumPdf = -aSumPdf; 
     159          data->mSumPdf = -aSumPdf; 
    159160        } 
    160161        float diff = bSumPdf - aSumPdf; 
     
    177178          PvsData<T> *data = b.Find((*it).first); 
    178179          if (data) { 
    179                 bSumPdf = data->second.mSumPdf; 
     180                bSumPdf = data->mSumPdf; 
    180181          } 
    181182          float diff = bSumPdf - aSumPdf; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp

    r697 r704  
    1414 
    1515 
    16 #define ROTATE_SCENE 1 
     16#define ROTATE_SCENE 0 
    1717// HACK 
    1818static void RotateMesh(Mesh *mesh) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r697 r704  
    29512951int BspNodeGeometry::ComputeIntersection(const AxisAlignedBox3 &box) const 
    29522952{ 
    2953         AxisAlignedBox3 boundingBox; 
    2954         GetBoundingBox(boundingBox); 
    2955  
    2956         const bool overlap = Overlap(boundingBox, box); 
    2957  
    2958         // no intersections with bounding box 
    2959         if (!overlap) 
    2960         { 
    2961                 return 1; 
    2962         } 
    2963         int result = -1; 
    2964  
    29652953        // 1: box does not intersect geometry 
    29662954        // 0: box intersects geometry 
    29672955        // -1: box contains geometry 
    2968         for (int i = 0; i < 6; ++ i)  
     2956 
     2957        AxisAlignedBox3 boundingBox; 
     2958        GetBoundingBox(boundingBox); 
     2959 
     2960        // no intersections with bounding box 
     2961        if (!Overlap(box, boundingBox)) 
     2962        { 
     2963                return 1; 
     2964        } 
     2965 
     2966        // box cotains bounding box of geometry >=> contains geometry 
     2967        if (box.Includes(boundingBox)) 
     2968                return -1; 
     2969 
     2970        int result = 0; 
     2971 
     2972        // test geometry planes for intersections 
     2973        vector<Plane3>::const_iterator it, it_end = mPlanes.end(); 
     2974 
     2975        for (it = mPlanes.begin(); it != it_end; ++ it) 
    29692976        {                
    2970                 const int side = Side(box.GetPlane(i)); 
     2977                const int side = box.Side(*it); 
    29712978                 
    29722979                // box does not intersects geometry 
    29732980                if (side == 1) 
     2981                { 
    29742982                        return 1; 
    2975  
    2976                 if (side == 0) 
    2977             result = 0; 
     2983                } 
     2984                //if (side == 0) result = 0; 
    29782985  } 
    29792986 
  • 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 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r703 r704  
    3838{ 
    3939public: 
    40   /// viewcells 
    41   ViewCellContainer mViewCells; 
     40  /// root of view cells tree 
     41  ViewCell *mViewCell; 
     42 
     43  //ViewCellContainer mViewCells; 
    4244  /// aggregated pvs 
    43   ObjectPvs mPvs; 
     45  //ObjectPvs mPvs; 
    4446 
    4547  // input parameter is the render budget for the PrVS 
     
    488490        virtual void PrepareLoadedViewCells() {}; 
    489491 
     492        /** Constructs local view cell merge hierarchy. 
     493        */ 
     494        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,  
     495                                                                          const ViewCellContainer &viewCells); 
     496 
    490497        /** Creates clip plane for visualization. 
    491498        */ 
Note: See TracChangeset for help on using the changeset viewer.