Ignore:
Timestamp:
11/28/06 19:46:36 (18 years ago)
Author:
bittner
Message:

global lines support

File:
1 edited

Legend:

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

    r1816 r1824  
    3232 
    3333// $$JB HACK 
    34 #define USE_KD_PVS 0 
     34#define USE_KD_PVS 1 
    3535#define KD_PVS_AREA (1e-5f) 
    3636 
     
    856856        viewCells = mViewCells; 
    857857#endif 
    858         ViewCellContainer::iterator it = viewCells.begin(), it_end = viewCells.end();            
     858        ViewCellContainer::iterator it = viewCells.begin(), 
     859          it_end = viewCells.end();              
    859860        for (; it != it_end; ++it) { 
    860861          //(*it)->UpdatePvsCost(); 
     
    872873        // hack: normalize pvs size 
    873874        int histoMaxVal; 
    874         Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal); 
     875        Environment::GetSingleton()->GetIntValue( 
     876                                                                                         "Preprocessor.histogram.maxValue", histoMaxVal); 
    875877        maxVal = max((float)histoMaxVal, maxPvs); 
    876878                 
     
    18311833                if (evaluateFilter) { 
    18321834                  ObjectPvs filteredPvs = viewcell->GetPvs(); 
    1833                   PvsFilterStatistics fstat = ApplyFilter2(viewcell, false, 
    1834                                                                                                    1.0f, filteredPvs); 
     1835                  PvsFilterStatistics fstat = ApplyFilter2(viewcell, 
     1836                                                                                                                                                                                         false, 
     1837                                                                                                                                                                                         2.0f, 
     1838                                                                                                                                                                                         filteredPvs); 
    18351839                   
    18361840                  float filteredCost = filteredPvs.EvalPvsCost(); 
     
    19701974 
    19711975float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 
    1972                                                                                                   const bool addRays, 
    1973                                                                                                   const bool storeViewCells) 
     1976                                                                                                                                                                                                        const bool addRays, 
     1977                                                                                                                                                                                                        const bool storeViewCells) 
    19741978{ 
    19751979        ViewCellContainer viewcells; 
     
    20262030                                        ++ ray.mPvsContribution; 
    20272031                                        ray.mRelativePvsContribution += contribution; 
     2032                                        // $$ test of different contribution measure 
     2033                                        //                                      ray.mRelativePvsContribution += 1.0f/(viewcell->GetPvs().GetSize() + 10.0f); 
     2034 
    20282035                                } 
    20292036                        } 
     
    20372044                        if (ray.mOriginObject &&  
    20382045                                viewcell->GetPvs().GetSampleContribution(ray.mOriginObject, 
    2039                                                                                                                 ray.mPdf, 
    2040                                                                                                                 contribution)) 
    2041                         { 
    2042                                 ++ ray.mPvsContribution; 
    2043                                 ray.mRelativePvsContribution += contribution; 
    2044                         } 
     2046                                                                                                                                                                                                ray.mPdf, 
     2047                                                                                                                                                                                                contribution)) 
     2048                                { 
     2049                                        ++ ray.mPvsContribution; 
     2050                                        ray.mRelativePvsContribution += contribution; 
     2051                                } 
    20452052#endif 
    20462053                } 
     
    25822589PvsFilterStatistics 
    25832590ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 
    2584                                                            const bool useViewSpaceFilter, 
    2585                                                            const float filterSize, 
    2586                                                            ObjectPvs &pvs 
    2587                                                            ) 
    2588 { 
    2589         cout<<"y"; 
     2591                                                                                                                         const bool useViewSpaceFilter, 
     2592                                                                                                                         const float filterSize, 
     2593                                                                                                                         ObjectPvs &pvs, 
     2594                                                                                                                         vector<AxisAlignedBox3> *filteredBoxes 
     2595                                                                                                                         ) 
     2596{ 
     2597        //cout<<"y"; 
    25902598  PvsFilterStatistics stats; 
    25912599 
     
    26012609  // first mark all object from this pvs 
    26022610  while (pit.HasMoreEntries()) {                 
    2603         ObjectPvsEntry entry = pit.Next(); 
    2604          
    2605         Intersectable *object = entry.mObject; 
    2606         object->Mail(); 
     2611                ObjectPvsEntry entry = pit.Next(); 
     2612                 
     2613                Intersectable *object = entry.mObject; 
     2614                object->Mail(); 
    26072615  } 
    26082616#endif 
     
    26252633   // and gobal estimate for the view cell 
    26262634   // (total #rays intersecting the viewcell) 
    2627 #define MIN_LOCAL_SAMPLES 5 
    2628  
     2635  int minLocalSamples = 2; 
     2636   
    26292637  float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 
    26302638   
     
    26322640   
    26332641  if (useViewSpaceFilter) { 
    2634         //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
    2635         float radius = viewCellRadius/100.0f; 
    2636         vbox.Enlarge(radius); 
    2637         cout<<"vbox = "<<vbox<<endl; 
    2638         ViewCellContainer viewCells; 
    2639         ComputeBoxIntersections(vbox, viewCells); 
    2640          
    2641         ViewCellContainer::const_iterator it = viewCells.begin(), 
    2642           it_end = viewCells.end(); 
    2643         int i = 0; 
    2644         for (i=0; it != it_end; ++ it, ++ i) 
    2645           if ((*it) != viewCell) { 
    2646                 //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
    2647                 basePvs.MergeInPlace((*it)->GetPvs()); 
    2648           } 
    2649          
    2650         // update samples and globalC 
    2651         samples = (float)pvs.GetSamples(); 
    2652         //      cout<<"neighboring viewcells = "<<i-1<<endl; 
    2653         //      cout<<"Samples' = "<<samples<<endl; 
     2642                //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
     2643                float radius = viewCellRadius/100.0f; 
     2644                vbox.Enlarge(radius); 
     2645                cout<<"vbox = "<<vbox<<endl; 
     2646                ViewCellContainer viewCells; 
     2647                ComputeBoxIntersections(vbox, viewCells); 
     2648                 
     2649                ViewCellContainer::const_iterator it = viewCells.begin(), 
     2650                        it_end = viewCells.end(); 
     2651                int i = 0; 
     2652                for (i=0; it != it_end; ++ it, ++ i) 
     2653                        if ((*it) != viewCell) { 
     2654                                //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
     2655                                basePvs.MergeInPlace((*it)->GetPvs()); 
     2656                        } 
     2657                 
     2658                // update samples and globalC 
     2659                samples = (float)pvs.GetSamples(); 
     2660                //      cout<<"neighboring viewcells = "<<i-1<<endl; 
     2661                //      cout<<"Samples' = "<<samples<<endl; 
    26542662  } 
    2655  
     2663         
    26562664  // Minimal number of samples so that filtering takes place 
    2657 #define MIN_SAMPLES  100 
     2665#define MIN_SAMPLES  50 
     2666 
    26582667  if (samples > MIN_SAMPLES) { 
    2659         float globalC = 2.0f*filterSize/sqrt(samples); 
    2660          
    2661         pit = basePvs.GetIterator(); 
    2662          
    2663         ObjectContainer objects; 
    2664          
    2665         while (pit.HasMoreEntries()) 
    2666           {              
    2667                 ObjectPvsEntry entry = pit.Next(); 
    2668                  
    2669                 Intersectable *object = entry.mObject; 
    2670                 // compute filter size based on the distance and the numebr of samples 
    2671                 AxisAlignedBox3 box = object->GetBox(); 
    2672                  
    2673                 float distance = Distance(center, box.Center()); 
    2674                 float globalRadius = distance*globalC; 
    2675                  
    2676                 int objectSamples = (int)entry.mData.mSumPdf; 
    2677                 float localRadius = MAX_FLOAT; 
    2678                 if (objectSamples > MIN_LOCAL_SAMPLES) 
    2679                   localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
    2680                         sqrt((float)objectSamples); 
    2681                  
    2682                 //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
    2683                  
    2684                 // now compute the filter size 
    2685                 float radius; 
    2686  
    2687                 if (localRadius < globalRadius) { 
    2688                   radius = localRadius; 
    2689                   stats.mLocalFilterCount++; 
    2690                 } else { 
    2691                   radius = globalRadius; 
    2692                   stats.mGlobalFilterCount++; 
    2693                 } 
    2694  
    2695                 stats.mAvgFilterRadius += radius; 
    2696                  
    2697                 // cout<<"box = "<<box<<endl; 
    2698                 //      cout<<"distance = "<<distance<<endl; 
    2699                 //      cout<<"radiues = "<<radius<<endl; 
    2700                  
    2701                 box.Enlarge(Vector3(radius)); 
    2702                  
    2703                 objects.clear(); 
    2704                 // $$ warning collect objects takes only unmailed ones! 
    2705                 CollectObjects(box, objects); 
    2706                 //      cout<<"collected objects="<<objects.size()<<endl; 
    2707                 ObjectContainer::const_iterator noi = objects.begin(); 
    2708                 for (; noi != objects.end(); ++ noi) { 
    2709                   Intersectable *o = *noi; 
    2710                   // $$ JB warning: pdfs are not correct at this point!    
    2711                   pvs.AddSampleDirty(o, Limits::Small); 
    2712                 } 
    2713           } 
    2714         stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
     2668                float globalC = 2.0f*filterSize/sqrt(samples); 
     2669                 
     2670                pit = basePvs.GetIterator(); 
     2671                 
     2672                ObjectContainer objects; 
     2673                 
     2674                while (pit.HasMoreEntries()) 
     2675                        {                
     2676                                ObjectPvsEntry entry = pit.Next(); 
     2677                                 
     2678                                Intersectable *object = entry.mObject; 
     2679                                // compute filter size based on the distance and the numebr of samples 
     2680                                AxisAlignedBox3 box = object->GetBox(); 
     2681                                 
     2682                                float distance = Distance(center, box.Center()); 
     2683                                float globalRadius = distance*globalC; 
     2684                                 
     2685                                int objectSamples = (int)entry.mData.mSumPdf; 
     2686                                float localRadius = MAX_FLOAT; 
     2687                                 
     2688                                localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 
     2689                                        sqrt((float)objectSamples); 
     2690                                 
     2691                                //      cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 
     2692                                 
     2693                                // now compute the filter size 
     2694                                float radius; 
     2695 
     2696#if 0 
     2697                                if (objectSamples <= 1) { 
     2698                                        if (localRadius > globalRadius) { 
     2699                                                radius = 0.5flRadius; 
     2700                                                stats.mLocalFilterCount++; 
     2701                                        } else { 
     2702                                                radius = globalRadius; 
     2703                                                stats.mGlobalFilterCount++; 
     2704                                        } 
     2705                                } else { 
     2706                                        radius = localRadius; 
     2707                                        stats.mLocalFilterCount++; 
     2708                                } 
     2709#else 
     2710                                radius = 0.5f*globalRadius + 0.5f*localRadius; 
     2711                                stats.mLocalFilterCount++; 
     2712                                stats.mGlobalFilterCount++; 
     2713#endif 
     2714                                 
     2715                                stats.mAvgFilterRadius += radius; 
     2716                                 
     2717                                // cout<<"box = "<<box<<endl; 
     2718                                //      cout<<"distance = "<<distance<<endl; 
     2719                                //      cout<<"radiues = "<<radius<<endl; 
     2720                                 
     2721                                box.Enlarge(Vector3(radius)); 
     2722                                if (filteredBoxes) 
     2723                                        filteredBoxes->push_back(box); 
     2724                                objects.clear(); 
     2725                                // $$ warning collect objects takes only unmailed ones! 
     2726                                CollectObjects(box, objects); 
     2727                                //      cout<<"collected objects="<<objects.size()<<endl; 
     2728                                ObjectContainer::const_iterator noi = objects.begin(); 
     2729                                for (; noi != objects.end(); ++ noi) { 
     2730                                        Intersectable *o = *noi; 
     2731                                        // $$ JB warning: pdfs are not correct at this point!      
     2732                                        pvs.AddSampleDirty(o, Limits::Small); 
     2733                                } 
     2734                        } 
     2735                stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
    27152736  } 
    27162737   
     
    27212742  pit = basePvs.GetIterator(); 
    27222743  while (pit.HasMoreEntries()) {                 
    2723         ObjectPvsEntry entry = pit.Next(); 
    2724         pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
     2744                ObjectPvsEntry entry = pit.Next(); 
     2745                pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 
    27252746  } 
    27262747#endif 
Note: See TracChangeset for help on using the changeset viewer.