Changeset 1787 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 11/24/06 12:05:28 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1786 r1787 32 32 33 33 // $$JB HACK 34 #define USE_KD_PVS 134 #define USE_KD_PVS 0 35 35 #define KD_PVS_AREA (1e-5f) 36 36 … … 2591 2591 2592 2592 2593 void ViewCellsManager::MergeViewCellsEfficient(ObjectPvs &pvs, const ViewCellContainer &viewCells) const 2594 { 2595 LocalMergeTree mergeTree(viewCells); 2596 mergeTree.Merge(pvs); 2597 } 2593 void ViewCellsManager::MergeViewCellsRecursivly(ObjectPvs &pvs, 2594 const ViewCellContainer &viewCells) const 2595 { 2596 MergeViewCellsRecursivly(pvs, viewCells, 0, (int)viewCells.size() - 1); 2597 } 2598 2599 2600 void ViewCellsManager::MergeViewCellsRecursivly(ObjectPvs &pvs, 2601 const ViewCellContainer &viewCells, 2602 const int leftIdx, 2603 const int rightIdx) const 2604 { 2605 if (leftIdx == rightIdx) 2606 { 2607 pvs = viewCells[leftIdx]->GetPvs(); 2608 } 2609 else 2610 { 2611 const int midSplit = (leftIdx + rightIdx) / 2; 2612 2613 ObjectPvs leftPvs, rightPvs; 2614 MergeViewCellsRecursivly(leftPvs, viewCells, leftIdx, midSplit); 2615 MergeViewCellsRecursivly(rightPvs, viewCells, midSplit, rightIdx); 2616 2617 ObjectPvs::Merge(pvs, leftPvs, rightPvs); 2618 } 2619 } 2620 2598 2621 2599 2622 #if 1 … … 2605 2628 ) 2606 2629 { 2630 cout<<"y"; 2607 2631 PvsFilterStatistics stats; 2608 2632 … … 2629 2653 float samples = (float)basePvs.GetSamples(); 2630 2654 2631 Debug<<"f #s="<<samples<<" pvs size = "<<basePvs.GetSize();2655 Debug<<"f #s="<<samples<<" pvs size = "<<basePvs.GetSize(); 2632 2656 // cout<<"Filter size = "<<filterSize<<endl; 2633 2657 // cout<<"vbox = "<<vbox<<endl; … … 2754 2778 ObjectPvs &pvs 2755 2779 ) 2756 {cout << "x"; 2757 PvsFilterStatistics stats; 2758 2759 AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 2760 Vector3 center = vbox.Center(); 2761 // copy the PVS 2762 ObjectPvs basePvs = viewCell->GetPvs(); 2763 Intersectable::NewMail(); 2764 2765 ObjectPvsIterator pit = basePvs.GetIterator(); 2780 { 2781 cout << "x"; 2782 PvsFilterStatistics stats; 2783 2784 AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 2785 Vector3 center = vbox.Center(); 2786 // copy the PVS 2787 ObjectPvs basePvs;// = viewCell->GetPvs(); 2788 Intersectable::NewMail(); 2789 2790 ObjectPvsIterator pit = viewCell->GetPvs().GetIterator(); 2766 2791 2767 2792 #if !USE_KD_PVS 2768 // first mark all object from this pvs 2769 while (pit.HasMoreEntries()) { 2770 ObjectPvsEntry entry = pit.Next(); 2771 2772 Intersectable *object = entry.mObject; 2773 object->Mail(); 2774 } 2793 // first mark all object from this pvs 2794 while (pit.HasMoreEntries()) 2795 { 2796 ObjectPvsEntry entry = pit.Next(); 2797 2798 Intersectable *object = entry.mObject; 2799 object->Mail(); 2800 } 2775 2801 #endif 2776 2802 2777 2778 2779 float samples = (float)basePvs.GetSamples();2780 2781 Debug<<"f #s="<<samples<<"pvs size = "<<basePvs.GetSize();2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2803 int pvsSize = 0; 2804 int nPvsSize = 0; 2805 float samples = (float)viewCell->GetPvs().GetSamples(); 2806 2807 Debug<<"f #s="<<samples<<"pvs size = "<<viewCell->GetPvs().GetSize(); 2808 // cout<<"Filter size = "<<filterSize<<endl; 2809 // cout<<"vbox = "<<vbox<<endl; 2810 // cout<<"center = "<<center<<endl; 2811 2812 2813 // Minimal number of local samples to take into account 2814 // the local sampling density. 2815 // The size of the filter is a minimum of the conservative 2816 // local sampling density estimate (#rays intersecting teh viewcell and 2817 // the object) 2818 // and gobal estimate for the view cell 2819 // (total #rays intersecting the viewcell) 2794 2820 #define MIN_LOCAL_SAMPLES 5 2795 2821 2796 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 2797 2798 // now compute the filter box around the current viewCell 2799 2800 if (useViewSpaceFilter) { 2801 // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 2802 float radius = viewCellRadius/100.0f; 2803 vbox.Enlarge(radius); 2804 cout<<"vbox = "<<vbox<<endl; 2805 ViewCellContainer viewCells; 2806 ComputeBoxIntersections(vbox, viewCells); 2807 ObjectPvs pvs; 2808 MergeViewCellsEfficient(pvs, viewCells); 2809 basePvs = pvs; 2810 2811 // update samples and globalC 2812 samples = (float)pvs.GetSamples(); 2813 // cout<<"neighboring viewcells = "<<i-1<<endl; 2814 // cout<<"Samples' = "<<samples<<endl; 2815 } 2816 2817 // Minimal number of samples so that filtering takes place 2822 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 2823 2824 // now compute the filter box around the current viewCell 2825 2826 if (useViewSpaceFilter) 2827 { 2828 // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 2829 float radius = viewCellRadius/100.0f; 2830 vbox.Enlarge(radius); 2831 cout<<"vbox = "<<vbox<<endl; 2832 ViewCellContainer viewCells; 2833 ComputeBoxIntersections(vbox, viewCells); 2834 2835 MergeViewCellsEfficient(basePvs, viewCells); 2836 cout << "basepvs size " << basePvs.GetSize() << endl; 2837 // update samples and globalC 2838 samples = (float)pvs.GetSamples(); 2839 // cout<<"neighboring viewcells = "<<i-1<<endl; 2840 // cout<<"Samples' = "<<samples<<endl; 2841 } 2842 else 2843 { 2844 basePvs = viewCell->GetPvs(); 2845 } 2846 2847 // Minimal number of samples so that filtering takes place 2818 2848 #define MIN_SAMPLES 100 2819 if (samples > MIN_SAMPLES) { 2820 float globalC = 2.0f*filterSize/sqrt(samples); 2821 2849 if (samples > MIN_SAMPLES) 2850 { 2851 float globalC = 2.0f*filterSize/sqrt(samples); 2852 2853 pit = basePvs.GetIterator(); 2854 2855 ObjectContainer objects; 2856 2857 while (pit.HasMoreEntries()) 2858 { 2859 ObjectPvsEntry entry = pit.Next(); 2860 2861 Intersectable *object = entry.mObject; 2862 // compute filter size based on the distance and the numebr of samples 2863 AxisAlignedBox3 box = object->GetBox(); 2864 2865 float distance = Distance(center, box.Center()); 2866 float globalRadius = distance*globalC; 2867 2868 int objectSamples = (int)entry.mData.mSumPdf; 2869 float localRadius = MAX_FLOAT; 2870 2871 if (objectSamples > MIN_LOCAL_SAMPLES) 2872 { 2873 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 2874 sqrt((float)objectSamples); 2875 } 2876 2877 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 2878 2879 // now compute the filter size 2880 float radius; 2881 2882 if (localRadius < globalRadius) 2883 { 2884 radius = localRadius; 2885 stats.mLocalFilterCount++; 2886 } 2887 else 2888 { 2889 radius = globalRadius; 2890 stats.mGlobalFilterCount++; 2891 } 2892 2893 stats.mAvgFilterRadius += radius; 2894 2895 // cout<<"box = "<<box<<endl; 2896 // cout<<"distance = "<<distance<<endl; 2897 // cout<<"radiues = "<<radius<<endl; 2898 2899 box.Enlarge(Vector3(radius)); 2900 objects.clear(); 2901 2902 // $$ warning collect objects takes only unmailed ones! 2903 CollectObjects(box, objects); 2904 2905 // cout<<"collected objects="<<objects.size()<<endl; 2906 ObjectContainer::const_iterator noi = objects.begin(); 2907 for (; noi != objects.end(); ++ noi) 2908 { 2909 Intersectable *o = *noi; 2910 // $$ JB warning: pdfs are not correct at this point! 2911 pvs.AddSampleDirty(o, Limits::Small); 2912 } 2913 } 2914 2915 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 2916 } 2917 2918 Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 2919 2920 #if !USE_KD_PVS 2921 // copy the base pvs to the new pvs 2822 2922 pit = basePvs.GetIterator(); 2823 2824 ObjectContainer objects; 2825 2826 while (pit.HasMoreEntries()) 2827 { 2923 while (pit.HasMoreEntries()) 2924 { 2828 2925 ObjectPvsEntry entry = pit.Next(); 2829 2830 Intersectable *object = entry.mObject; 2831 // compute filter size based on the distance and the numebr of samples 2832 AxisAlignedBox3 box = object->GetBox(); 2833 2834 float distance = Distance(center, box.Center()); 2835 float globalRadius = distance*globalC; 2836 2837 int objectSamples = (int)entry.mData.mSumPdf; 2838 float localRadius = MAX_FLOAT; 2839 if (objectSamples > MIN_LOCAL_SAMPLES) 2840 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 2841 sqrt((float)objectSamples); 2842 2843 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 2844 2845 // now compute the filter size 2846 float radius; 2847 2848 if (localRadius < globalRadius) { 2849 radius = localRadius; 2850 stats.mLocalFilterCount++; 2851 } else { 2852 radius = globalRadius; 2853 stats.mGlobalFilterCount++; 2854 } 2855 2856 stats.mAvgFilterRadius += radius; 2857 2858 // cout<<"box = "<<box<<endl; 2859 // cout<<"distance = "<<distance<<endl; 2860 // cout<<"radiues = "<<radius<<endl; 2861 2862 box.Enlarge(Vector3(radius)); 2863 2864 objects.clear(); 2865 // $$ warning collect objects takes only unmailed ones! 2866 CollectObjects(box, objects); 2867 // cout<<"collected objects="<<objects.size()<<endl; 2868 ObjectContainer::const_iterator noi = objects.begin(); 2869 for (; noi != objects.end(); ++ noi) { 2870 Intersectable *o = *noi; 2871 // $$ JB warning: pdfs are not correct at this point! 2872 pvs.AddSampleDirty(o, Limits::Small); 2873 } 2874 } 2875 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 2876 } 2877 2878 Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 2879 2880 #if !USE_KD_PVS 2881 // copy the base pvs to the new pvs 2882 pit = basePvs.GetIterator(); 2883 while (pit.HasMoreEntries()) { 2884 ObjectPvsEntry entry = pit.Next(); 2885 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 2886 } 2926 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 2927 } 2887 2928 #endif 2888 viewCell->SetFilteredPvsSize(pvs.GetSize()); 2889 2890 Intersectable::NewMail(); 2891 return stats; 2929 viewCell->SetFilteredPvsSize(pvs.GetSize()); 2930 2931 Intersectable::NewMail(); 2932 2933 return stats; 2892 2934 } 2893 2935 #endif 2894 2936 2895 2937 2896 2938 2897 2939 void ViewCellsManager::ExportColor(Exporter *exporter, … … 6227 6269 6228 6270 #if 0 6229 ////////////// //////////////6271 ////////////// 6230 6272 // filtered stats 6231 6273 sprintf(suffix, "-%09d-eval-filter.log", castSamples); … … 6242 6284 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 6243 6285 cout << "*************************************" << endl; 6244 6245 Debug << "statistics computed in " << timeDiff * 1e-3 << " secs" << endl; 6286 Debug << "filtered statistics computed in " << timeDiff * 1e-3 << " secs" << endl; 6246 6287 #endif 6247 6288 … … 6260 6301 } 6261 6302 6262 cout << "debug entries: " << pvsSize << ", memcost: " << (float)pvsSize * ObjectPvs::GetEntrySize() << endl; 6303 cout << "debug entries: " << pvsSize << ", memcost: " 6304 << (float)pvsSize * ObjectPvs::GetEntrySize() << endl; 6263 6305 } 6264 6306 } … … 6271 6313 6272 6314 6273 LocalMergeTree::LocalMergeTree(const ViewCellContainer &viewCells): 6274 mViewCells(viewCells) 6275 { 6276 mRoot = Subdivide(0, (int)mViewCells.size()); 6277 } 6278 6279 6280 void LocalMergeTree::Merge(ObjectPvs &mergedPvs) 6281 { 6282 Merge(mRoot, mergedPvs); 6283 } 6284 6285 6286 void LocalMergeTree::Merge(LocalMergeNode *node, ObjectPvs &mergedPvs) 6287 { 6288 //////////////// 6289 //-- pvs is not stored with the interiors => reconstruct 6290 if (node->IsLeaf()) 6291 { 6292 LocalMergeLeaf *leaf = dynamic_cast<LocalMergeLeaf *>(node); 6293 mergedPvs = leaf->mViewCell->GetPvs(); 6294 } 6295 else 6296 { 6297 LocalMergeInterior *interior = dynamic_cast<LocalMergeInterior *>(node); 6298 6299 ObjectPvs leftPvs, rightPvs; 6300 6301 Merge(interior->mLeft, leftPvs); 6302 Merge(interior->mRight, rightPvs); 6303 6304 ObjectPvs::Merge(mergedPvs, leftPvs, rightPvs); 6305 } 6306 } 6307 6308 6309 LocalMergeNode *LocalMergeTree::Subdivide(const int leftIdx, const int rightIdx) 6310 { 6311 if (leftIdx == rightIdx) 6312 { 6313 return new LocalMergeLeaf(mViewCells[leftIdx]); 6314 } 6315 6316 LocalMergeInterior *interior = new LocalMergeInterior(); 6317 6318 const int midSplit = (leftIdx + rightIdx) / 2; 6319 6320 interior->mLeft = Subdivide(leftIdx, midSplit); 6321 interior->mRight = Subdivide(midSplit, rightIdx); 6322 6323 return interior; 6324 } 6325 6326 6327 6328 } 6315 6316 }
Note: See TracChangeset
for help on using the changeset viewer.