Ignore:
Timestamp:
12/11/06 08:31:01 (18 years ago)
Author:
bittner
Message:

sampling updates

File:
1 edited

Legend:

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

    r1876 r1877  
    2727 
    2828 
    29 // warning: Should not count origin object for sampling  
    30 // because it disturbs heuristics 
    31 #define SAMPLE_ORIGIN_OBJECTS 0  // matt temp 
    3229 
    3330// $$JB HACK 
     
    18711868                 
    18721869                if (evaluateFilter) { 
    1873                   ObjectPvs filteredPvs = viewcell->GetPvs(); 
     1870                  ObjectPvs filteredPvs; 
    18741871                  PvsFilterStatistics fstat = ApplyFilter2(viewcell, 
    1875                                                                                                                                                                                         false, 
    1876                                                                                                                                                                                         2.0f, 
    1877                                                                                                                                                                                         filteredPvs); 
     1872                                                                                                  false, 
     1873                                                                                                  2.0f, 
     1874                                                                                                  filteredPvs); 
    18781875                   
    18791876                  float filteredCost = filteredPvs.EvalPvsCost(); 
    18801877                  stat.avgFilteredPvs += filteredCost; 
    18811878                  stat.avgFilterContribution += filteredCost - pvsCost; 
    1882  
     1879                   
    18831880                  stat.avgFilterRadius += fstat.mAvgFilterRadius; 
    18841881                  int sum = fstat.mGlobalFilterCount + fstat.mLocalFilterCount; 
     
    18871884                          (float) sum; 
    18881885                  } 
    1889                    
    18901886                   
    18911887                } else { 
     
    20122008 
    20132009 
    2014 float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 
     2010 
     2011#define PVS_ADD_DIRTY 1 
     2012 
     2013float 
     2014ViewCellsManager::ComputeSampleContribution(VssRay &ray, 
    20152015                                                                                                  const bool addRays, 
    20162016                                                                                                  const bool storeViewCells) 
     
    20182018  ray.mPvsContribution = 0; 
    20192019  ray.mRelativePvsContribution = 0.0f; 
    2020  
     2020   
    20212021  if (ray.mTerminationObject==NULL) 
    20222022        return 0.0f; 
     
    20262026  static Ray hray; 
    20272027  hray.Init(ray); 
    2028   //hray.mFlags |= Ray::CULL_BACKFACES; 
    2029   //Ray hray(ray); 
    2030    
     2028 
    20312029  float tmin = 0, tmax = 1.0; 
    20322030   
     
    20392037  ViewCell::NewMail(); 
    20402038   
    2041   //    if (ray.mPdf!=1.0f) 
    2042   //      cout<<ray.mPdf<<" "; 
    2043    
    2044    
    20452039  // traverse the view space subdivision 
    20462040  CastLineSegment(origin, termination, viewcells); 
    20472041   
    20482042  if (storeViewCells) 
    2049         {       // copy viewcells memory efficiently 
     2043        {        
     2044          // copy viewcells memory efficiently 
    20502045          ray.mViewCells.reserve(viewcells.size()); 
    20512046          ray.mViewCells = viewcells; 
    20522047        } 
    2053    
    2054   Intersectable *obj = GetIntersectable(ray, true); 
    20552048   
    20562049  ViewCellContainer::const_iterator it = viewcells.begin(); 
    20572050   
     2051  Intersectable *terminationObj = GetIntersectable(ray, true); 
     2052   
     2053   
    20582054  for (; it != viewcells.end(); ++ it)  
    20592055        { 
    20602056          ViewCell *viewcell = *it; 
    2061           // tests if view cell is in valid view space 
     2057           
    20622058          if (viewcell->GetValid()) 
    2063                 { 
     2059                {       // if ray not outside of view space 
    20642060                  float contribution; 
    20652061                   
    2066                   if (ray.mTerminationObject)  {                         
    2067                         if (viewcell->GetPvs().GetSampleContribution(obj, 
    2068                                                                                                                  ray.mPdf, 
    2069                                                                                                                  contribution)) { 
    2070                           ++ ray.mPvsContribution; 
     2062                  if (terminationObj)  
     2063                        { 
     2064                          // todo: maybe not correct for kd node pvs 
     2065                          if (viewcell->GetPvs().GetSampleContribution( 
     2066                                                                                                                   terminationObj, ray.mPdf, contribution)) 
     2067                                { 
     2068                                  ++ ray.mPvsContribution; 
     2069                                  if (addRays) { 
     2070#if PVS_ADD_DIRTY 
     2071                                        viewcell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
     2072                                        if (viewcell->GetPvs().RequiresResort()) { 
     2073                                          viewcell->GetPvs().SimpleSort(); 
     2074                                        } 
     2075#else 
     2076                                        viewcell->GetPvs().AddSample(terminationObj, ray.mPdf); 
     2077#endif 
     2078                                  } 
     2079                                } 
     2080                           
     2081                          ray.mRelativePvsContribution += contribution; 
    20712082                        } 
    2072                          
    2073                         ray.mRelativePvsContribution += contribution; 
    2074                         // $$ test of different contribution measure 
    2075                         //                                      ray.mRelativePvsContribution += 1.0f/(viewcell->GetPvs().GetSize() + 10.0f); 
    2076                          
    2077                   } 
    2078                    
    2079 #if SAMPLE_ORIGIN_OBJECTS 
    2080                    
    2081                   // for directional sampling it is important to count only contributions 
    2082                   // made in one direction!!! 
    2083                   // the other contributions of this sample will be counted for the oposite ray! 
    2084  
    2085                         if (ray.mOriginObject &&  
    2086                                 viewcell->GetPvs().GetSampleContribution(ray.mOriginObject, 
    2087                                                                                                                                                                                                  ray.mPdf, 
    2088                                                                                                                                                                                                  contribution)) 
    2089                                 { 
    2090                                         ++ ray.mPvsContribution; 
    2091                                         ray.mRelativePvsContribution += contribution; 
    2092                                 } 
    2093 #endif 
    2094                 } 
    2095         } 
    2096  
    2097         // if true, the sampled entities are stored in the pvs 
    2098         if (addRays) 
    2099         { 
    2100                 for (it = viewcells.begin(); it != viewcells.end(); ++ it)  
    2101                 { 
    2102                         ViewCell *viewcell = *it; 
    2103              
    2104                         if (viewcell->GetValid()) 
    2105                         { 
    2106                                 // if view point is valid, add new object to the pvs 
    2107                           if (ray.mTerminationObject) 
    2108                                 {  
    2109                                   viewcell->GetPvs().AddSample(obj, ray.mPdf); 
    2110                                 }                                
    2111 #if SAMPLE_ORIGIN_OBJECTS 
    2112                                  if (ray.mOriginObject) 
    2113                                  {  
    2114                                          viewcell->GetPvs().AddSample(ray.mOriginObject, ray.mPdf); 
    2115                                  } 
    2116 #endif 
    2117                         } 
    2118                 } 
    2119         } 
    2120  
    2121         return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
    2122           (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
    2123 } 
     2083                } 
     2084        } 
     2085   
     2086  return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
     2087        (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
     2088} 
     2089 
    21242090 
    21252091 
     
    26272593 
    26282594 
    2629 #if 1 
    26302595PvsFilterStatistics 
    26312596ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
    2632                                                                                                                         const bool useViewSpaceFilter, 
    2633                                                                                                                         const float filterSize, 
    2634                                                                                                                         ObjectPvs &pvs, 
    2635                                                                                                                         vector<AxisAlignedBox3> *filteredBoxes 
    2636                                                                                                                         ) 
    2637 { 
    2638         //cout<<"y"; 
     2597                                                          const bool useViewSpaceFilter, 
     2598                                                          const float filterSize, 
     2599                                                          ObjectPvs &pvs, 
     2600                                                          vector<AxisAlignedBox3> *filteredBoxes 
     2601                                                          ) 
     2602{ 
     2603  //cout<<"y"; 
    26392604  PvsFilterStatistics stats; 
    26402605 
     
    26422607  Vector3 center = vbox.Center(); 
    26432608  // copy the PVS 
     2609  Intersectable::NewMail(); 
    26442610  ObjectPvs basePvs = viewCell->GetPvs(); 
    2645   Intersectable::NewMail(); 
    2646  
    26472611  ObjectPvsIterator pit = basePvs.GetIterator(); 
    26482612 
     2613  pvs.Reserve(viewCell->GetFilteredPvsSize()); 
     2614 
    26492615#if !USE_KD_PVS 
    2650   // first mark all object from this pvs 
     2616  // first mark all objects from this pvs 
    26512617  while (pit.HasMoreEntries()) {                 
    2652                 ObjectPvsEntry entry = pit.Next(); 
    2653                  
    2654                 Intersectable *object = entry.mObject; 
    2655                 object->Mail(); 
     2618        ObjectPvsEntry entry = pit.Next(); 
     2619         
     2620        Intersectable *object = entry.mObject; 
     2621        object->Mail(); 
    26562622  } 
    26572623#endif 
    2658  
     2624   
    26592625  int pvsSize = 0; 
    26602626  int nPvsSize = 0; 
     
    26812647   
    26822648  if (useViewSpaceFilter) { 
    2683                 //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
    2684                 float radius = viewCellRadius/100.0f; 
    2685                 vbox.Enlarge(radius); 
    2686                 cout<<"vbox = "<<vbox<<endl; 
    2687                 ViewCellContainer viewCells; 
    2688                 ComputeBoxIntersections(vbox, viewCells); 
    2689                  
    2690                 ViewCellContainer::const_iterator it = viewCells.begin(), 
    2691                         it_end = viewCells.end(); 
    2692                 int i = 0; 
    2693                 for (i=0; it != it_end; ++ it, ++ i) 
    2694                         if ((*it) != viewCell) { 
    2695                                 //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
    2696                                 basePvs.MergeInPlace((*it)->GetPvs()); 
    2697                         } 
    2698                  
    2699                 // update samples and globalC 
    2700                 samples = (float)pvs.GetSamples(); 
    2701                 //      cout<<"neighboring viewcells = "<<i-1<<endl; 
    2702                 //      cout<<"Samples' = "<<samples<<endl; 
     2649        //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
     2650        float radius = viewCellRadius/100.0f; 
     2651        vbox.Enlarge(radius); 
     2652        cout<<"vbox = "<<vbox<<endl; 
     2653        ViewCellContainer viewCells; 
     2654        ComputeBoxIntersections(vbox, viewCells); 
     2655         
     2656        ViewCellContainer::const_iterator it = viewCells.begin(), 
     2657          it_end = viewCells.end(); 
     2658        int i = 0; 
     2659        for (i=0; it != it_end; ++ it, ++ i) 
     2660          if ((*it) != viewCell) { 
     2661                //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
     2662                basePvs.MergeInPlace((*it)->GetPvs()); 
     2663          } 
     2664         
     2665        // update samples and globalC 
     2666        samples = (float)pvs.GetSamples(); 
     2667        //      cout<<"neighboring viewcells = "<<i-1<<endl; 
     2668        //      cout<<"Samples' = "<<samples<<endl; 
    27032669  } 
    2704          
     2670   
    27052671  // Minimal number of samples so that filtering takes place 
    27062672#define MIN_SAMPLES  50 
    2707  
     2673   
    27082674  if (samples > MIN_SAMPLES) { 
    2709                 float globalC = 2.0f*filterSize/sqrt(samples); 
    2710                  
    2711                 pit = basePvs.GetIterator(); 
    2712                  
    2713                 ObjectContainer objects; 
    2714                  
    2715                 while (pit.HasMoreEntries()) 
    2716                         {                
    2717                                 ObjectPvsEntry entry = pit.Next(); 
    2718                                  
    2719                                 Intersectable *object = entry.mObject; 
    2720                                 // compute filter size based on the distance and the numebr of samples 
    2721                                 AxisAlignedBox3 box = object->GetBox(); 
    2722                                  
    2723                                 float distance = Distance(center, box.Center()); 
    2724                                 float globalRadius = distance*globalC; 
    2725                                  
    2726                                 int objectSamples = (int)entry.mData.mSumPdf; 
    2727                                 float localRadius = MAX_FLOAT; 
    2728                                  
    2729                                 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
    2730                                         sqrt((float)objectSamples); 
    2731                                  
    2732                                 //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
    2733                                  
    2734                                 // now compute the filter size 
    2735                                 float radius; 
    2736  
     2675        float globalC = 2.0f*filterSize/sqrt(samples); 
     2676         
     2677        pit = basePvs.GetIterator(); 
     2678         
     2679        ObjectContainer objects; 
     2680         
     2681        while (pit.HasMoreEntries()) {           
     2682          ObjectPvsEntry entry = pit.Next(); 
     2683           
     2684          Intersectable *object = entry.mObject; 
     2685          // compute filter size based on the distance and the numebr of samples 
     2686          AxisAlignedBox3 box = object->GetBox(); 
     2687           
     2688          float distance = Distance(center, box.Center()); 
     2689          float globalRadius = distance*globalC; 
     2690           
     2691          int objectSamples = (int)entry.mData.mSumPdf; 
     2692          float localRadius = MAX_FLOAT; 
     2693           
     2694          localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
     2695                sqrt((float)objectSamples); 
     2696           
     2697          //    cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
     2698           
     2699          // now compute the filter size 
     2700          float radius; 
     2701           
    27372702#if 0 
    2738                                 if (objectSamples <= 1) { 
    2739                                         if (localRadius > globalRadius) { 
    2740                                                 radius = 0.5flRadius; 
    2741                                                 stats.mLocalFilterCount++; 
    2742                                         } else { 
    2743                                                 radius = globalRadius; 
    2744                                                 stats.mGlobalFilterCount++; 
    2745                                         } 
    2746                                 } else { 
    2747                                         radius = localRadius; 
    2748                                         stats.mLocalFilterCount++; 
    2749                                 } 
     2703          if (objectSamples <= 1) { 
     2704                if (localRadius > globalRadius) { 
     2705                  radius = 0.5flRadius; 
     2706                  stats.mLocalFilterCount++; 
     2707                } else { 
     2708                  radius = globalRadius; 
     2709                  stats.mGlobalFilterCount++; 
     2710                } 
     2711          } else { 
     2712                radius = localRadius; 
     2713                stats.mLocalFilterCount++; 
     2714          } 
    27502715#else 
    2751                                 radius = 0.5f*globalRadius + 0.5f*localRadius; 
    2752                                 stats.mLocalFilterCount++; 
    2753                                 stats.mGlobalFilterCount++; 
     2716          radius = 0.5f*globalRadius + 0.5f*localRadius; 
     2717          stats.mLocalFilterCount++; 
     2718          stats.mGlobalFilterCount++; 
    27542719#endif 
    2755                                  
    2756                                 stats.mAvgFilterRadius += radius; 
    2757                                  
    2758                                 // cout<<"box = "<<box<<endl; 
    2759                                 //      cout<<"distance = "<<distance<<endl; 
    2760                                 //      cout<<"radiues = "<<radius<<endl; 
    2761                                  
    2762                                 box.Enlarge(Vector3(radius)); 
    2763                                 if (filteredBoxes) 
    2764                                         filteredBoxes->push_back(box); 
    2765                                 objects.clear(); 
    2766                                 // $$ warning collect objects takes only unmailed ones! 
    2767                                 CollectObjects(box, objects); 
    2768                                 //      cout<<"collected objects="<<objects.size()<<endl; 
    2769                                 ObjectContainer::const_iterator noi = objects.begin(); 
    2770                                 for (; noi != objects.end(); ++ noi) { 
    2771                                         Intersectable *o = *noi; 
    2772                                         // $$ JB warning: pdfs are not correct at this point!      
    2773                                         pvs.AddSampleDirty(o, Limits::Small); 
    2774                                 } 
    2775                         } 
    2776                 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
     2720           
     2721          stats.mAvgFilterRadius += radius; 
     2722           
     2723          // cout<<"box = "<<box<<endl; 
     2724          //    cout<<"distance = "<<distance<<endl; 
     2725          //    cout<<"radiues = "<<radius<<endl; 
     2726           
     2727          box.Enlarge(Vector3(radius)); 
     2728 
     2729          if (filteredBoxes) 
     2730                filteredBoxes->push_back(box); 
     2731 
     2732          objects.clear(); 
     2733          // $$ warning collect objects takes only unmailed ones! 
     2734          CollectObjects(box, objects); 
     2735          //    cout<<"collected objects="<<objects.size()<<endl; 
     2736          ObjectContainer::const_iterator noi = objects.begin(); 
     2737          for (; noi != objects.end(); ++ noi) { 
     2738                Intersectable *o = *noi; 
     2739                // $$ JB warning: pdfs are not correct at this point!      
     2740                pvs.AddSampleDirty(o, Limits::Small); 
     2741          } 
     2742        } 
     2743        stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
    27772744  } 
    27782745   
    27792746  Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 
    2780  
     2747   
    27812748#if !USE_KD_PVS 
    27822749  // copy the base pvs to the new pvs 
    27832750  pit = basePvs.GetIterator(); 
    27842751  while (pit.HasMoreEntries()) {                 
    2785                 ObjectPvsEntry entry = pit.Next(); 
    2786                 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
     2752        ObjectPvsEntry entry = pit.Next(); 
     2753        pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
    27872754  } 
    27882755#endif 
     2756   
     2757  pvs.SimpleSort(); 
    27892758  viewCell->SetFilteredPvsSize(pvs.GetSize()); 
    27902759   
     
    27922761  return stats; 
    27932762} 
    2794 #else 
    2795 PvsFilterStatistics 
    2796 ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
    2797                                                            const bool useViewSpaceFilter, 
    2798                                                            const float filterSize, 
    2799                                                            ObjectPvs &pvs 
    2800                                                            ) 
    2801 { 
    2802         cout << "x"; 
    2803         PvsFilterStatistics stats; 
    2804  
    2805         AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 
    2806         Vector3 center = vbox.Center(); 
    2807         // copy the PVS 
    2808         ObjectPvs basePvs;// = viewCell->GetPvs(); 
    2809         Intersectable::NewMail(); 
    2810  
    2811         ObjectPvsIterator pit = viewCell->GetPvs().GetIterator(); 
    2812  
    2813 #if !USE_KD_PVS 
    2814         // first mark all object from this pvs 
    2815         while (pit.HasMoreEntries())  
    2816         {                
    2817                 ObjectPvsEntry entry = pit.Next(); 
    2818  
    2819                 Intersectable *object = entry.mObject; 
    2820                 object->Mail(); 
    2821         } 
    2822 #endif 
    2823  
    2824         int pvsSize = 0; 
    2825         int nPvsSize = 0; 
    2826         float samples = (float)viewCell->GetPvs().GetSamples(); 
    2827  
    2828         Debug<<"f #s="<<samples<<"pvs size = "<<viewCell->GetPvs().GetSize(); 
    2829         //  cout<<"Filter size = "<<filterSize<<endl; 
    2830         //  cout<<"vbox = "<<vbox<<endl; 
    2831         //  cout<<"center = "<<center<<endl; 
    2832  
    2833  
    2834         // Minimal number of local samples to take into account 
    2835         // the local sampling density. 
    2836         // The size of the filter is a minimum of the conservative 
    2837         // local sampling density estimate (#rays intersecting teh viewcell and 
    2838         // the object) 
    2839         // and gobal estimate for the view cell 
    2840         // (total #rays intersecting the viewcell) 
    2841 #define MIN_LOCAL_SAMPLES 5 
    2842  
    2843         float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 
    2844  
    2845         // now compute the filter box around the current viewCell 
    2846  
    2847         if (useViewSpaceFilter)  
    2848         { 
    2849                 //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
    2850                 float radius = viewCellRadius/100.0f; 
    2851                 vbox.Enlarge(radius); 
    2852                 cout<<"vbox = "<<vbox<<endl; 
    2853                 ViewCellContainer viewCells; 
    2854                 ComputeBoxIntersections(vbox, viewCells); 
    2855                  
    2856                 MergeViewCellsEfficient(basePvs, viewCells); 
    2857                 cout << "basepvs size " << basePvs.GetSize() << endl; 
    2858                 // update samples and globalC 
    2859                 samples = (float)pvs.GetSamples(); 
    2860                 //      cout<<"neighboring viewcells = "<<i-1<<endl; 
    2861                 //      cout<<"Samples' = "<<samples<<endl; 
    2862         } 
    2863         else 
    2864         { 
    2865                 basePvs = viewCell->GetPvs(); 
    2866         } 
    2867  
    2868         // Minimal number of samples so that filtering takes place 
    2869 #define MIN_SAMPLES  100 
    2870         if (samples > MIN_SAMPLES)  
    2871         { 
    2872                 float globalC = 2.0f*filterSize/sqrt(samples); 
    2873  
    2874                 pit = basePvs.GetIterator(); 
    2875  
    2876                 ObjectContainer objects; 
    2877  
    2878                 while (pit.HasMoreEntries()) 
    2879                 {                
    2880                         ObjectPvsEntry entry = pit.Next(); 
    2881  
    2882                         Intersectable *object = entry.mObject; 
    2883                         // compute filter size based on the distance and the numebr of samples 
    2884                         AxisAlignedBox3 box = object->GetBox(); 
    2885  
    2886                         float distance = Distance(center, box.Center()); 
    2887                         float globalRadius = distance*globalC; 
    2888  
    2889                         int objectSamples = (int)entry.mData.mSumPdf; 
    2890                         float localRadius = MAX_FLOAT; 
    2891  
    2892                         if (objectSamples > MIN_LOCAL_SAMPLES) 
    2893                         { 
    2894                                 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
    2895                                                                 sqrt((float)objectSamples); 
    2896                         } 
    2897  
    2898                         //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
    2899  
    2900                         // now compute the filter size 
    2901                         float radius; 
    2902  
    2903                         if (localRadius < globalRadius)  
    2904                         { 
    2905                                 radius = localRadius; 
    2906                                 stats.mLocalFilterCount++; 
    2907                         }  
    2908                         else  
    2909                         { 
    2910                                 radius = globalRadius; 
    2911                                 stats.mGlobalFilterCount++; 
    2912                         } 
    2913  
    2914                         stats.mAvgFilterRadius += radius; 
    2915  
    2916                         // cout<<"box = "<<box<<endl; 
    2917                         //      cout<<"distance = "<<distance<<endl; 
    2918                         //      cout<<"radiues = "<<radius<<endl; 
    2919  
    2920                         box.Enlarge(Vector3(radius)); 
    2921                         objects.clear(); 
    2922  
    2923                         // $$ warning collect objects takes only unmailed ones! 
    2924                         CollectObjects(box, objects); 
    2925  
    2926                         //      cout<<"collected objects="<<objects.size()<<endl; 
    2927                         ObjectContainer::const_iterator noi = objects.begin(); 
    2928                         for (; noi != objects.end(); ++ noi)  
    2929                         { 
    2930                                 Intersectable *o = *noi; 
    2931                                 // $$ JB warning: pdfs are not correct at this point!      
    2932                                 pvs.AddSampleDirty(o, Limits::Small); 
    2933                         } 
    2934                 } 
    2935  
    2936                 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
    2937         } 
    2938  
    2939         Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 
    2940  
    2941 #if !USE_KD_PVS 
    2942         // copy the base pvs to the new pvs 
    2943         pit = basePvs.GetIterator(); 
    2944         while (pit.HasMoreEntries())  
    2945         {                
    2946                 ObjectPvsEntry entry = pit.Next(); 
    2947                 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
    2948         } 
    2949 #endif 
    2950         viewCell->SetFilteredPvsSize(pvs.GetSize()); 
    2951  
    2952         Intersectable::NewMail(); 
    2953          
    2954         return stats; 
    2955 } 
    2956 #endif 
    29572763 
    29582764 
     
    60435849         
    60445850 
    6045 #define PVS_ADD_DIRTY 1 
    6046  
    6047 float 
    6048 VspOspViewCellsManager::ComputeSampleContribution(VssRay &ray, 
    6049                                                                                                   const bool addRays, 
    6050                                                                                                   const bool storeViewCells) 
    6051 { 
    6052   ray.mPvsContribution = 0; 
    6053   ray.mRelativePvsContribution = 0.0f; 
    6054    
    6055   if (ray.mTerminationObject==NULL) 
    6056         return 0.0f; 
    6057    
    6058   ViewCellContainer viewcells; 
    6059    
    6060   static Ray hray; 
    6061   hray.Init(ray); 
    6062  
    6063   float tmin = 0, tmax = 1.0; 
    6064    
    6065   if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
    6066         return 0; 
    6067    
    6068   Vector3 origin = hray.Extrap(tmin); 
    6069   Vector3 termination = hray.Extrap(tmax); 
    6070    
    6071   ViewCell::NewMail(); 
    6072    
    6073   // traverse the view space subdivision 
    6074   CastLineSegment(origin, termination, viewcells); 
    6075    
    6076   if (storeViewCells) 
    6077         {        
    6078           // copy viewcells memory efficiently 
    6079           ray.mViewCells.reserve(viewcells.size()); 
    6080           ray.mViewCells = viewcells; 
    6081         } 
    6082    
    6083   ViewCellContainer::const_iterator it = viewcells.begin(); 
    6084    
    6085   Intersectable *terminationObj = GetIntersectable(ray, true); 
    6086    
    6087 #if SAMPLE_ORIGIN_OBJECTS 
    6088   Intersectable *originObj = GetIntersectable(ray, false); 
    6089 #endif 
    6090    
    6091   for (; it != viewcells.end(); ++ it)  
    6092         { 
    6093           ViewCell *viewcell = *it; 
    6094            
    6095           if (viewcell->GetValid()) 
    6096                 {       // if ray not outside of view space 
    6097                   float contribution; 
    6098                    
    6099                   if (terminationObj)  
    6100                         { 
    6101                           // todo: maybe not correct for kd node pvs 
    6102                           if (viewcell->GetPvs().GetSampleContribution( 
    6103                                                                                                                    terminationObj, ray.mPdf, contribution)) 
    6104                                 { 
    6105                                   ++ ray.mPvsContribution; 
    6106                                 } 
    6107                            
    6108                           ray.mRelativePvsContribution += contribution; 
    6109                         } 
    6110                    
    6111                   //////////////// 
    6112                   //-- for directional sampling it is important to count  
    6113                   //-- only contributions made in one direction! 
    6114                   //-- the other contributions of this sample will be counted for the opposite ray! 
    6115                    
    6116 #if SAMPLE_ORIGIN_OBJECTS 
    6117                    
    6118                   if (originObj &&  
    6119                           viewcell->GetPvs().GetSampleContribution(originObj, 
    6120                                                                                                            ray.mPdf, 
    6121                                                                                                            contribution)) 
    6122                         { 
    6123                           ++ ray.mPvsContribution; 
    6124                           ray.mRelativePvsContribution += contribution; 
    6125                         } 
    6126 #endif 
    6127                 } 
    6128         } 
    6129    
    6130   if (!addRays) { 
    6131         return ray.mRelativePvsContribution; 
    6132   } 
    6133    
    6134   // sampled objects are stored in the pvs 
    6135   for (it = viewcells.begin(); it != viewcells.end(); ++ it)  { 
    6136         ViewCell *viewCell = *it; 
    6137          
    6138         if (!viewCell->GetValid()) 
    6139           break; 
    6140          
    6141         //$$JB hack 
    6142          
    6143 #if PVS_ADD_DIRTY 
    6144         viewCell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
    6145 #else 
    6146         viewCell->GetPvs().AddSample(terminationObj, ray.mPdf); 
    6147 #endif 
    6148          
    6149 #if SAMPLE_ORIGIN_OBJECTS 
    6150 #if PVS_ADD_DIRTY 
    6151         viewCell->GetPvs().AddSampleDirtyCheck(originObj, ray.mPdf); 
    6152 #else 
    6153         viewCell->GetPvs().AddSample(originObj, ray.mPdf); 
    6154 #endif 
    6155 #endif 
    6156         if (viewCell->GetPvs().RequiresResort()) { 
    6157           viewCell->GetPvs().Sort();                     
    6158         } 
    6159   } 
    6160    
    6161   return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 
    6162         (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 
    6163 } 
    61645851 
    61655852 
Note: See TracChangeset for help on using the changeset viewer.