Changeset 1761 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 11/16/06 15:41:44 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1760 r1761 32 32 33 33 // $$JB HACK 34 #define USE_KD_PVS 035 #define KD_PVS_AREA ( 5*1e-4f)34 #define USE_KD_PVS 1 35 #define KD_PVS_AREA (1e-4f) 36 36 37 37 … … 87 87 { 88 88 // visualization stuff 89 Environment::GetSingleton()->GetBoolValue("ViewCells.Visualization.exportRays", mExportRays);89 Environment::GetSingleton()->GetBoolValue("ViewCells.Visualization.exportRays", mExportRays); 90 90 Environment::GetSingleton()->GetBoolValue("ViewCells.Visualization.exportGeometry", mExportGeometry); 91 91 Environment::GetSingleton()->GetFloatValue("ViewCells.maxPvsRatio", mMaxPvsRatio); … … 317 317 ViewCellsManager::GetIntersectable(const VssRay &ray, const bool isTermination) const 318 318 { 319 #if USE_KD_PVS 320 float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 321 KdNode *node = GetPreprocessor()->mKdTree->GetNode(isTermination ? 322 ray.mTermination : ray.mOrigin, 323 area); 324 return 325 GetPreprocessor()->mKdTree-> 326 GetOrCreateKdIntersectable(node); 327 #else 319 328 return isTermination ? ray.mTerminationObject : ray.mOriginObject; 329 #endif 320 330 } 321 331 … … 794 804 stream << "<BoundingBoxes>" << endl; 795 805 #if USE_KD_PVS 796 KdIntersectableMap::const_iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end();806 vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end(); 797 807 798 808 int id = 0; 799 809 for (kit = GetPreprocessor()->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 800 810 { 801 Intersectable *obj = (*kit).second;802 803 804 805 806 807 808 811 Intersectable *obj = *kit; 812 const AxisAlignedBox3 box = obj->GetBox(); 813 814 obj->SetId(id); 815 816 stream << "<BoundingBox" << " id=\"" << id << "\"" 817 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 818 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 809 819 } 810 820 #else 811 ObjectContainer::const_iterator oit, oit_end = objects.end();812 821 ObjectContainer::const_iterator oit, oit_end = objects.end(); 822 813 823 for (oit = objects.begin(); oit != oit_end; ++ oit) 814 824 { … … 955 965 float &contribution) const 956 966 { 957 if (!obj) return false; 958 967 if (!obj) 968 return false; 969 959 970 // potentially visible objects 960 971 return vc->AddPvsSample(obj, pdf, contribution); … … 1401 1412 ) 1402 1413 { 1403 sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 1404 1405 int start = (int)(mViewCells.size() * minValid); 1406 int end = (int)(mViewCells.size() * maxValid); 1407 1408 for (int i = 0; i < (int)mViewCells.size(); ++ i) 1409 { 1410 mViewCells[i]->SetValid(i >= start && i <= end); 1414 ObjectPvs dummyPvs; 1415 // update pvs sizes 1416 for (int i = 0; i < (int)mViewCells.size(); ++ i) { 1417 UpdatePvsForEvaluation(mViewCells[i], dummyPvs); 1418 } 1419 1420 sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 1421 1422 int start = (int)(mViewCells.size() * minValid); 1423 int end = (int)(mViewCells.size() * maxValid); 1424 1425 for (int i = 0; i < (int)mViewCells.size(); ++ i) 1426 { 1427 // cout<<"pvs:"<<mViewCells[i]->GetCachedPvsCost()<<endl; 1428 mViewCells[i]->SetValid(i >= start && i <= end); 1411 1429 } 1412 1430 } … … 1821 1839 stat.avgFilteredPvs = 0.0f; 1822 1840 stat.avgFilterContribution = 0.0f; 1841 stat.avgFilterRadius = 0; 1842 stat.avgFilterRatio = 0; 1823 1843 1824 1844 for (; it != mViewCells.end(); ++ it) 1825 1845 { 1826 1846 ViewCell *viewcell = *it; 1827 1828 const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 1829 1830 if (pvsCost < stat.minPvs) 1831 stat.minPvs = pvsCost; 1832 if (pvsCost > stat.maxPvs) 1833 stat.maxPvs = pvsCost; 1834 1835 stat.avgPvs += pvsCost; 1836 1837 const bool evaluateFilter = true; 1838 1839 if (evaluateFilter) { 1840 ObjectPvs filteredPvs = viewcell->GetPvs(); 1841 ApplyFilter2(viewcell, false, 1.0f, filteredPvs); 1842 float filteredCost = filteredPvs.EvalPvsCost(); 1843 stat.avgFilteredPvs += filteredCost; 1844 stat.avgFilterContribution += filteredCost - pvsCost; 1845 } else { 1846 stat.avgFilteredPvs += pvsCost; 1847 stat.avgFilterContribution += 0; 1847 if (viewcell->GetValid()) { 1848 const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 1849 1850 if (pvsCost < stat.minPvs) 1851 stat.minPvs = pvsCost; 1852 if (pvsCost > stat.maxPvs) 1853 stat.maxPvs = pvsCost; 1854 1855 stat.avgPvs += pvsCost; 1856 1857 const bool evaluateFilter = true; 1858 1859 if (evaluateFilter) { 1860 ObjectPvs filteredPvs = viewcell->GetPvs(); 1861 PvsFilterStatistics fstat = ApplyFilter2(viewcell, false, 1.0f, filteredPvs); 1862 1863 float filteredCost = filteredPvs.EvalPvsCost(); 1864 stat.avgFilteredPvs += filteredCost; 1865 stat.avgFilterContribution += filteredCost - pvsCost; 1866 1867 stat.avgFilterRadius += fstat.mAvgFilterRadius; 1868 stat.avgFilterRatio += fstat.mLocalFilterCount / (float) fstat.mGlobalFilterCount; 1869 1870 1871 } else { 1872 stat.avgFilteredPvs += pvsCost; 1873 stat.avgFilterContribution += 0; 1874 } 1875 1876 ++ stat.viewcells; 1848 1877 } 1849 1850 ++ stat.viewcells;1851 1878 } 1852 1879 … … 1855 1882 stat.avgFilteredPvs/=stat.viewcells; 1856 1883 stat.avgFilterContribution/=stat.viewcells; 1884 stat.avgFilterRadius/=stat.viewcells; 1885 stat.avgFilterRatio/=stat.viewcells; 1857 1886 } 1858 1887 } … … 1867 1896 s<<"#AVG_FILTERED_PVS\n"<<pvsStat.avgFilteredPvs<<endl; 1868 1897 s<<"#AVG_FILTER_CONTRIBUTION\n"<<pvsStat.avgFilterContribution<<endl; 1898 s<<"#AVG_FILTER_RADIUS\n"<<pvsStat.avgFilterRadius<<endl; 1899 s<<"#AVG_FILTER_RATIO\n"<<pvsStat.avgFilterRatio<<endl; 1869 1900 s<<"#MAX_PVS\n"<<pvsStat.maxPvs<<endl; 1870 1901 s<<"#MIN_PVS\n"<<pvsStat.minPvs<<endl; … … 1985 2016 return; 1986 2017 1987 #if USE_KD_PVS 1988 float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 1989 KdNode *node = GetPreprocessor()->mKdTree->GetNode(ray.mTermination, area); 1990 Intersectable *obj = 1991 GetPreprocessor()->mKdTree-> 1992 GetOrCreateKdIntersectable(node); 1993 #else 1994 Intersectable *obj = ray.mTerminationObject; 1995 #endif 2018 Intersectable *obj = GetIntersectable(ray, true); 1996 2019 1997 2020 for (it = viewcells->begin(); it != viewcells->end(); ++it) { … … 2037 2060 ray.mViewCells = viewcells; 2038 2061 } 2039 2040 #if USE_KD_PVS 2041 float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 2042 KdNode *node = GetPreprocessor()->mKdTree->GetNode(ray.mTermination, area); 2043 Intersectable *obj = 2044 GetPreprocessor()->mKdTree-> 2045 GetOrCreateKdIntersectable(node); 2046 #else 2047 Intersectable *obj = ray.mTerminationObject; 2048 #endif 2062 2063 Intersectable *obj = GetIntersectable(ray, true); 2049 2064 2050 2065 … … 2590 2605 2591 2606 2592 void 2607 PvsFilterStatistics 2593 2608 ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 2594 2609 const bool useViewSpaceFilter, … … 2597 2612 ) 2598 2613 { 2614 PvsFilterStatistics stats; 2615 2599 2616 AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 2600 2617 Vector3 center = vbox.Center(); 2601 2602 2618 // COpy the PVS 2603 2619 ObjectPvs basePvs = viewCell->GetPvs(); … … 2606 2622 ObjectPvsIterator pit = basePvs.GetIterator(); 2607 2623 2624 #if !USE_KD_PVS 2608 2625 // first mark all object from this pvs 2609 2626 while (pit.HasMoreEntries()) { … … 2613 2630 object->Mail(); 2614 2631 } 2615 2632 #endif 2616 2633 2617 2634 int pvsSize = 0; 2618 2635 int nPvsSize = 0; 2619 float samples = (float)pvs.GetSamples(); 2620 2621 // cout<<"#s"<<samples<<endl; 2622 // cout<<"pvs size = "<<pvs.GetSize() <<endl; 2636 float samples = (float)basePvs.GetSamples(); 2637 2638 cout<<"f #s="<<samples<<"pvs size = "<<basePvs.GetSize(); 2623 2639 // cout<<"Filter size = "<<filterSize<<endl; 2624 2640 // cout<<"vbox = "<<vbox<<endl; … … 2635 2651 #define MIN_LOCAL_SAMPLES 5 2636 2652 2637 float globalC = 2.0f*filterSize/sqrt(samples);2638 2653 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 2639 2654 … … 2659 2674 // update samples and globalC 2660 2675 samples = (float)pvs.GetSamples(); 2661 globalC = 2.0f*filterSize/sqrt(samples);2662 2676 // cout<<"neighboring viewcells = "<<i-1<<endl; 2663 2677 // cout<<"Samples' = "<<samples<<endl; 2664 2678 } 2679 2680 // Minimal number of samples so that filtering takes place 2681 #define MIN_SAMPLES 100 2682 if (samples > MIN_SAMPLES) { 2683 float globalC = 2.0f*filterSize/sqrt(samples); 2684 2685 pit = basePvs.GetIterator(); 2686 2687 ObjectContainer objects; 2688 2689 while (pit.HasMoreEntries()) 2690 { 2691 ObjectPvsEntry entry = pit.Next(); 2692 2693 Intersectable *object = entry.mObject; 2694 // compute filter size based on the distance and the numebr of samples 2695 AxisAlignedBox3 box = object->GetBox(); 2696 2697 float distance = Distance(center, box.Center()); 2698 float globalRadius = distance*globalC; 2699 2700 int objectSamples = (int)entry.mData.mSumPdf; 2701 float localRadius = MAX_FLOAT; 2702 if (objectSamples > MIN_LOCAL_SAMPLES) 2703 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 2704 sqrt((float)objectSamples); 2705 2706 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 2707 2708 // now compute the filter size 2709 float radius; 2710 2711 if (localRadius < globalRadius) { 2712 radius = localRadius; 2713 stats.mLocalFilterCount++; 2714 } else { 2715 radius = globalRadius; 2716 stats.mGlobalFilterCount++; 2717 } 2718 2719 stats.mAvgFilterRadius += radius; 2720 2721 // cout<<"box = "<<box<<endl; 2722 // cout<<"distance = "<<distance<<endl; 2723 // cout<<"radiues = "<<radius<<endl; 2724 2725 box.Enlarge(Vector3(radius)); 2726 2727 objects.clear(); 2728 // $$ warning collect objects takes only unmailed ones! 2729 CollectObjects(box, objects); 2730 // cout<<"collected objects="<<objects.size()<<endl; 2731 ObjectContainer::const_iterator noi = objects.begin(); 2732 for (; noi != objects.end(); ++ noi) { 2733 Intersectable *o = *noi; 2734 // $$ JB warning: pdfs are not correct at this point! 2735 pvs.AddSampleDirty(o, Limits::Small); 2736 } 2737 } 2738 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 2739 } 2665 2740 2666 pit = basePvs.GetIterator(); 2667 2668 ObjectContainer objects; 2669 2670 while (pit.HasMoreEntries()) 2671 { 2672 ObjectPvsEntry entry = pit.Next(); 2673 2674 Intersectable *object = entry.mObject; 2675 // compute filter size based on the distance and the numebr of samples 2676 AxisAlignedBox3 box = object->GetBox(); 2677 2678 float distance = Distance(center, box.Center()); 2679 float globalRadius = distance*globalC; 2680 2681 int objectSamples = (int)entry.mData.mSumPdf; 2682 float localRadius = MAX_FLOAT; 2683 if (objectSamples > MIN_LOCAL_SAMPLES) 2684 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 2685 sqrt((float)objectSamples); 2686 2687 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 2688 2689 // now compute the filter size 2690 float radius = Min(localRadius, globalRadius); 2691 2692 // cout<<"box = "<<box<<endl; 2693 // cout<<"distance = "<<distance<<endl; 2694 // cout<<"radiues = "<<radius<<endl; 2695 2696 box.Enlarge(Vector3(radius)); 2697 2698 objects.clear(); 2699 // $$ warning collect objects takes only unmailed ones! 2700 CollectObjects(box, objects); 2701 // cout<<"collected objects="<<objects.size()<<endl; 2702 ObjectContainer::const_iterator noi = objects.begin(); 2703 for (; noi != objects.end(); ++ noi) { 2704 Intersectable *o = *noi; 2705 // $$ JB warning: pdfs are not correct at this point! 2706 pvs.AddSampleDirty(o, Limits::Small); 2707 } 2708 } 2709 2710 // cout<<"nPvs size = "<<pvs.GetSize()<<endl; 2711 2741 cout<<" nPvs size = "<<pvs.GetSize()<<endl; 2742 2743 #if !USE_KD_PVS 2712 2744 // copy the base pvs to the new pvs 2713 2745 pit = basePvs.GetIterator(); … … 2716 2748 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 2717 2749 } 2750 #endif 2718 2751 2719 2752 Intersectable::NewMail(); 2753 return stats; 2720 2754 } 2721 2755 … … 5096 5130 VspOspViewCellsManager::GetIntersectable(const VssRay &ray, const bool isTermination) const 5097 5131 { 5132 #if USE_KD_PVS 5133 return ViewCellsManager::GetIntersectable(ray, isTermination); 5134 #else 5098 5135 return mHierarchyManager->GetIntersectable(ray, isTermination); 5136 #endif 5099 5137 } 5100 5138 … … 5853 5891 ViewCellContainer::const_iterator it = viewcells.begin(); 5854 5892 5893 Intersectable *terminationObj = GetIntersectable(ray, true); 5894 Intersectable *originObj = GetIntersectable(ray, false); 5895 5855 5896 for (; it != viewcells.end(); ++ it) 5856 5897 { … … 5861 5902 float contribution; 5862 5903 5863 if ( ray.mTerminationObject)5904 if (terminationObj) 5864 5905 { 5865 5906 // todo: maybe not correct for kd node pvs 5866 Intersectable *obj = mHierarchyManager->GetIntersectable(ray, true); 5867 5868 if (viewcell->GetPvs().GetSampleContribution(obj, 5869 ray.mPdf, 5870 contribution)) 5907 5908 if (viewcell->GetPvs().GetSampleContribution(terminationObj, 5909 ray.mPdf, 5910 contribution)) 5871 5911 { 5872 5912 ++ ray.mPvsContribution; 5873 5913 } 5874 5875 5914 5915 ray.mRelativePvsContribution += contribution; 5876 5916 } 5877 5917 5878 5918 //////////////// 5879 5919 //-- for directional sampling it is important to count only contributions … … 5881 5921 //-- the other contributions of this sample will be counted for the opposite ray! 5882 5922 #if SAMPLE_ORIGIN_OBJECTS 5883 if ( ray.mOriginObject&&5884 viewcell->GetPvs().GetSampleContribution( ray.mOriginObject,5885 ray.mPdf,5886 contribution))5887 {5923 if (originObj && 5924 viewcell->GetPvs().GetSampleContribution(originObj, 5925 ray.mPdf, 5926 contribution)) 5927 { 5888 5928 ++ ray.mPvsContribution; 5889 5929 ray.mRelativePvsContribution += contribution; 5890 }5930 } 5891 5931 #endif 5892 5932 } … … 5906 5946 break; 5907 5947 5948 //$$JB hack 5949 #if !USE_KD_PVS 5908 5950 AddSampleToPvs( 5909 ray.mTerminationObject, 5910 ray.mTermination, 5911 viewCell, 5912 ray.mPdf, 5913 ray.mRelativePvsContribution); 5914 5951 terminationObj, 5952 ray.mTermination, 5953 viewCell, 5954 ray.mPdf, 5955 ray.mRelativePvsContribution); 5956 #else 5957 viewCell->GetPvs().AddSample(terminationObj, ray.mPdf); 5958 #endif 5959 5915 5960 #if SAMPLE_ORIGIN_OBJECTS 5916 5917 5961 AddSampleToPvs( 5918 ray.mOriginObject,5919 ray.mOrigin,5920 viewCell,5921 ray.mPdf,5922 ray.mRelativePvsContribution);5962 originObj, 5963 ray.mOrigin, 5964 viewCell, 5965 ray.mPdf, 5966 ray.mRelativePvsContribution); 5923 5967 #endif 5924 5968 } 5925 5969 5926 5970 5927 5971 … … 5937 5981 float &contribution) const 5938 5982 { 5939 5940 5983 // The hierarchy manager decides about the type of sample cast 5984 return mHierarchyManager->AddSampleToPvs(obj, hitPoint, vc, pdf, contribution); 5941 5985 } 5942 5986
Note: See TracChangeset
for help on using the changeset viewer.