Changeset 1824 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 11/28/06 19:46:36 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1816 r1824 32 32 33 33 // $$JB HACK 34 #define USE_KD_PVS 034 #define USE_KD_PVS 1 35 35 #define KD_PVS_AREA (1e-5f) 36 36 … … 856 856 viewCells = mViewCells; 857 857 #endif 858 ViewCellContainer::iterator it = viewCells.begin(), it_end = viewCells.end(); 858 ViewCellContainer::iterator it = viewCells.begin(), 859 it_end = viewCells.end(); 859 860 for (; it != it_end; ++it) { 860 861 //(*it)->UpdatePvsCost(); … … 872 873 // hack: normalize pvs size 873 874 int histoMaxVal; 874 Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal); 875 Environment::GetSingleton()->GetIntValue( 876 "Preprocessor.histogram.maxValue", histoMaxVal); 875 877 maxVal = max((float)histoMaxVal, maxPvs); 876 878 … … 1831 1833 if (evaluateFilter) { 1832 1834 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); 1835 1839 1836 1840 float filteredCost = filteredPvs.EvalPvsCost(); … … 1970 1974 1971 1975 float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 1972 1973 1976 const bool addRays, 1977 const bool storeViewCells) 1974 1978 { 1975 1979 ViewCellContainer viewcells; … … 2026 2030 ++ ray.mPvsContribution; 2027 2031 ray.mRelativePvsContribution += contribution; 2032 // $$ test of different contribution measure 2033 // ray.mRelativePvsContribution += 1.0f/(viewcell->GetPvs().GetSize() + 10.0f); 2034 2028 2035 } 2029 2036 } … … 2037 2044 if (ray.mOriginObject && 2038 2045 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 } 2045 2052 #endif 2046 2053 } … … 2582 2589 PvsFilterStatistics 2583 2590 ViewCellsManager::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"; 2590 2598 PvsFilterStatistics stats; 2591 2599 … … 2601 2609 // first mark all object from this pvs 2602 2610 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(); 2607 2615 } 2608 2616 #endif … … 2625 2633 // and gobal estimate for the view cell 2626 2634 // (total #rays intersecting the viewcell) 2627 #define MIN_LOCAL_SAMPLES 5 2628 2635 int minLocalSamples = 2; 2636 2629 2637 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 2630 2638 … … 2632 2640 2633 2641 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 2643 int i = 0;2644 for (i=0; it != it_end; ++ it, ++ i)2645 2646 //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl;2647 basePvs.MergeInPlace((*it)->GetPvs());2648 2649 2650 // update samples and globalC2651 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; 2654 2662 } 2655 2663 2656 2664 // Minimal number of samples so that filtering takes place 2657 #define MIN_SAMPLES 100 2665 #define MIN_SAMPLES 50 2666 2658 2667 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); 2715 2736 } 2716 2737 … … 2721 2742 pit = basePvs.GetIterator(); 2722 2743 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); 2725 2746 } 2726 2747 #endif
Note: See TracChangeset
for help on using the changeset viewer.