Changeset 1737 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 11/09/06 19:41:31 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1736 r1737 261 261 262 262 263 void 264 ViewCellsManager::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 265 { 266 GetPreprocessor()->mKdTree->CollectObjects(box, objects); 267 } 263 268 264 269 AxisAlignedBox3 ViewCellsManager::GetViewCellBox(ViewCell *vc) … … 1731 1736 void ViewCellsManager::UpdatePvs() 1732 1737 { 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 { 1745 1738 if (mViewCellPvsIsUpdated || !ViewCellsTreeConstructed()) 1739 return; 1740 1741 mViewCellPvsIsUpdated = true; 1742 1743 ViewCellContainer leaves; 1744 mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves); 1745 1746 ViewCellContainer::const_iterator it, it_end = leaves.end(); 1747 1748 for (it = leaves.begin(); it != it_end; ++ it) 1749 { 1750 mViewCellsTree->PropagatePvs(*it); 1746 1751 } 1747 1752 } … … 1750 1755 void ViewCellsManager::GetPvsStatistics(PvsStatistics &stat) 1751 1756 { 1752 // update pvs of view cells tree if necessary 1753 UpdatePvs(); 1754 1755 ViewCellContainer::const_iterator it = mViewCells.begin(); 1756 1757 stat.viewcells = 0; 1758 stat.minPvs = 100000000; 1759 stat.maxPvs = 0; 1760 stat.avgPvs = 0.0f; 1761 1762 for (; it != mViewCells.end(); ++ it) 1763 { 1764 ViewCell *viewcell = *it; 1765 1766 const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 1767 1768 if (pvsCost < stat.minPvs) 1769 stat.minPvs = pvsCost; 1770 if (pvsCost > stat.maxPvs) 1771 stat.maxPvs = pvsCost; 1772 1773 stat.avgPvs += pvsCost; 1774 1775 ++ stat.viewcells; 1776 } 1777 1778 if (stat.viewcells) 1779 stat.avgPvs/=stat.viewcells; 1757 // update pvs of view cells tree if necessary 1758 UpdatePvs(); 1759 1760 ViewCellContainer::const_iterator it = mViewCells.begin(); 1761 1762 stat.viewcells = 0; 1763 stat.minPvs = 100000000; 1764 stat.maxPvs = 0; 1765 stat.avgPvs = 0.0f; 1766 stat.avgFilteredPvs = 0.0f; 1767 stat.avgFilterContribution = 0.0f; 1768 1769 for (; it != mViewCells.end(); ++ it) 1770 { 1771 ViewCell *viewcell = *it; 1772 1773 const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 1774 1775 if (pvsCost < stat.minPvs) 1776 stat.minPvs = pvsCost; 1777 if (pvsCost > stat.maxPvs) 1778 stat.maxPvs = pvsCost; 1779 1780 stat.avgPvs += pvsCost; 1781 1782 if (0) { 1783 ObjectPvs filteredPvs = viewcell->GetPvs(); 1784 ApplyFilter2(viewcell, false, 1.0f, filteredPvs); 1785 float filteredCost = filteredPvs.EvalPvsCost(); 1786 stat.avgFilteredPvs += filteredCost; 1787 stat.avgFilterContribution += filteredCost - pvsCost; 1788 } 1789 1790 ++ stat.viewcells; 1791 } 1792 1793 if (stat.viewcells) { 1794 stat.avgPvs/=stat.viewcells; 1795 stat.avgFilteredPvs/=stat.viewcells; 1796 stat.avgFilterContribution/=stat.viewcells; 1797 } 1780 1798 } 1781 1799 … … 1787 1805 GetPvsStatistics(pvsStat); 1788 1806 s<<"#AVG_PVS\n"<<pvsStat.avgPvs<<endl; 1807 s<<"#AVG_FILTERED_PVS\n"<<pvsStat.avgFilteredPvs<<endl; 1808 s<<"#AVG_FILTER_CONTRIBUTION\n"<<pvsStat.avgFilterContribution<<endl; 1789 1809 s<<"#MAX_PVS\n"<<pvsStat.maxPvs<<endl; 1790 1810 s<<"#MIN_PVS\n"<<pvsStat.minPvs<<endl; … … 2497 2517 void 2498 2518 ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 2499 KdTree *kdTree,2519 const bool useViewSpaceFilter, 2500 2520 const float filterSize, 2501 2521 ObjectPvs &pvs 2502 2522 ) 2503 2523 { 2504 Vector3 center = viewCell->GetBox().Center(); 2524 AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 2525 Vector3 center = vbox.Center(); 2505 2526 // first determine the average size of the filter 2506 2507 2508 2527 2509 2528 Intersectable::NewMail(); … … 2518 2537 int pvsSize = 0; 2519 2538 int nPvsSize = 0; 2520 int samples = pvs.mSamples; 2521 2522 2539 float samples = pvs.mSamples; 2540 cout<<"Samples = "<<samples<<endl; 2541 // cout<<"Filter size = "<<filterSize<<endl; 2542 // cout<<"vbox = "<<vbox<<endl; 2543 // cout<<"center = "<<center<<endl; 2544 2545 2546 #define MIN_LOCAL_SAMPLES 5 2547 2548 // compute the average filter radius 2549 float globalC = 2.0f*filterSize/sqrt(samples); 2550 2551 float sumRadius = 0.0f; 2523 2552 for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi, pvsSize++) { 2524 2553 Intersectable *object = (*oi).first; 2525 2554 // compute filter size based on the distance and the numebr of samples 2526 float distance = Distance(center, object->GetBox().Center()); 2527 2555 AxisAlignedBox3 box = object->GetBox(); 2556 2557 float distance = Distance(center, box.Center()); 2558 float globalRadius = distance*globalC; 2559 2560 int objectSamples = (int)(*oi).second.mSumPdf; 2561 float localRadius = MAX_FLOAT; 2562 2563 if (objectSamples > MIN_LOCAL_SAMPLES) 2564 localRadius = 0.5f*Magnitude(box.Diagonal())/sqrt((float)objectSamples); 2565 2528 2566 // now compute the filter size 2529 float radius = distance*(filterSize/(4*samples)); 2567 float radius = Min(localRadius, globalRadius); 2568 2569 sumRadius +=radius; 2570 } 2571 2572 float avgRadius = sumRadius/pvsSize; 2573 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 2574 cout<<"radius ratio = "<<avgRadius/viewCellRadius<<endl; 2575 2576 // now compute the filter box around the current viewCell 2577 2578 if (useViewSpaceFilter) { 2579 // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 2580 float radius = viewCellRadius/100.0f; 2581 vbox.Enlarge(radius); 2582 cout<<"vbox = "<<vbox<<endl; 2583 ViewCellContainer viewCells; 2584 ComputeBoxIntersections(vbox, viewCells); 2585 2586 // cout<<"box="<<box<<endl; 2587 ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end(); 2588 2589 int i; 2590 for (i=0; it != it_end; ++ it, ++ i) 2591 if ((*it) != viewCell) { 2592 //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 2593 pvs.Merge((*it)->GetPvs()); 2594 } 2595 2596 // update samples and globalC 2597 samples = pvs.mSamples; 2598 globalC = 2.0f*filterSize/sqrt(samples); 2599 cout<<"neighboring viewcells = "<<i-1<<endl; 2600 cout<<"Samples' = "<<samples<<endl; 2601 } 2602 2603 for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) { 2604 Intersectable *object = (*oi).first; 2605 // compute filter size based on the distance and the numebr of samples 2530 2606 AxisAlignedBox3 box = object->GetBox(); 2607 2608 float distance = Distance(center, box.Center()); 2609 float globalRadius = distance*globalC; 2610 2611 2612 int objectSamples = (int)(*oi).second.mSumPdf; 2613 float localRadius = MAX_FLOAT; 2614 if (objectSamples > MIN_LOCAL_SAMPLES) 2615 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/sqrt((float)objectSamples); 2616 2617 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 2618 2619 // now compute the filter size 2620 float radius = Min(localRadius, globalRadius); 2621 2622 // cout<<"box = "<<box<<endl; 2623 // cout<<"distance = "<<distance<<endl; 2624 // cout<<"radiues = "<<radius<<endl; 2625 2531 2626 box.Enlarge(Vector3(radius)); 2532 2627 2533 2628 ObjectContainer objects; 2534 2629 // $$ warning collect objects takes only unmailed ones! 2535 // should use VspOsp!! 2536 kdTree->CollectObjects(box, objects); 2630 CollectObjects(box, objects); 2537 2631 // cout<<"collected objects="<<objects.size()<<endl; 2538 2632 ObjectContainer::const_iterator noi = objects.begin(); … … 2544 2638 } 2545 2639 } 2546 //cout<<"nPvs size = "<<nPvsSize<<endl;2640 cout<<"nPvs size = "<<nPvsSize<<endl; 2547 2641 pvs.Merge(nPvs); 2642 Intersectable::NewMail(); 2548 2643 } 2549 2644 … … 5724 5819 } 5725 5820 5821 void 5822 VspOspViewCellsManager::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 5823 { 5824 mHierarchyManager->CollectObjects(box, objects); 5825 } 5826 5726 5827 5727 5828 #if 1
Note: See TracChangeset
for help on using the changeset viewer.