Changeset 1161 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
- Timestamp:
- 07/27/06 02:07:26 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1160 r1161 1437 1437 1438 1438 const int rootPvs = GetPvsSize(mRoot); 1439 1440 Debug << "vsb volume: " << vol << endl; 1439 const int rootEntries = GetPvsEntries(mRoot); 1440 1441 /*Debug << "vsb volume: " << vol << endl; 1441 1442 Debug << "root volume: " << mRoot->GetVolume() << endl; 1442 1443 Debug << "root pvs: " << rootPvs << endl; 1444 */ 1443 1445 1444 1446 int totalPvs; … … 1460 1462 << "#TotalRenderCost\n" << totalRenderCost << endl 1461 1463 << "#CurrentPvs\n" << rootPvs << endl 1464 << "#CurrentEntries\n" << rootEntries << endl 1462 1465 << "#ExpectedCost\n" << expectedCost << endl 1463 1466 << "#AvgRenderCost\n" << avgRenderCost << endl … … 1468 1471 << endl; 1469 1472 1473 //-- go through tree in the order of render cost decrease 1474 //-- which is the same order as the view cells were merged 1475 //-- or the reverse order of subdivision for subdivision-only 1476 //-- view cell hierarchies. 1470 1477 1471 1478 while (!tqueue.empty()) … … 1628 1635 } 1629 1636 1630 // TODO 1637 // TODO matt: implement for different storing methods 1631 1638 void ViewCellsTree::GetPvs(ViewCell *vc, ObjectPvs &pvs) const 1632 1639 { 1633 // pvs is stored in each cell 1640 // pvs is stored in each cell => just return pvs 1634 1641 if (mViewCellsStorage == PVS_IN_INTERIORS) 1635 1642 { … … 1638 1645 } 1639 1646 1647 1648 //-- pvs is not stored with the interiors => reconstruct 1640 1649 Intersectable::NewMail(); 1641 1642 1650 1643 1651 int pvsSize = 0; … … 1660 1668 tstack.pop(); 1661 1669 1662 // add new pvs1670 // add newly found pvs to merged pvs 1663 1671 pvs.AddPvs(vc->GetPvs()); 1664 1672 1665 if (!vc->IsLeaf()) 1673 if (!vc->IsLeaf()) // interior cells: go down to leaf level 1666 1674 { 1667 1675 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); … … 1685 1693 1686 1694 //////////////////////////////////////////////// 1687 // --for interiors, pvs can be stored using different methods1688 // /////////////////////////////////////////////1695 // for interiors, pvs can be stored using different methods 1696 // 1689 1697 1690 1698 switch (mViewCellsStorage) … … 1697 1705 pvsSize = vc->GetPvs().CountPvs(); 1698 1706 } 1699 1707 else // interior node 1708 { 1709 // interior nodes: pvs is either stored as a scalar or 1710 // has to be reconstructed from the leaves 1711 1712 // the stored pvs size is the valid pvs size => just return scalar 1713 if (vc->mPvsSizeValid) 1714 { 1715 pvsSize = vc->mPvsSize; 1716 break; 1717 } 1718 1719 //-- if no valid pvs size stored as a scalar => 1720 //-- compute current pvs size of interior from it's leaf nodes 1721 ViewCellContainer leaves; 1722 CollectLeaves(vc, leaves); 1723 1724 ViewCellContainer::const_iterator it, it_end = leaves.end(); 1725 1726 Intersectable::NewMail(); 1727 1728 // sum different intersectables 1729 for (it = leaves.begin(); it != it_end; ++ it) 1730 { 1731 ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 1732 1733 // mail all from first pvs 1734 for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 1735 { 1736 Intersectable *intersect = (*oit).first; 1737 1738 if (!intersect->Mailed()) 1739 { 1740 ++ pvsSize; 1741 intersect->Mail(); 1742 } 1743 } 1744 } 1745 1746 break; 1747 } 1748 } 1749 case COMPRESSED: 1750 { 1751 //////////////////////// 1752 //-- compressed pvs 1753 1700 1754 // the stored pvs size is the valid pvs size => just return scalar 1701 1755 if (vc->mPvsSizeValid) … … 1704 1758 break; 1705 1759 } 1706 1707 //-- if no valid pvs size stored as a scalar => compute new pvs size 1708 ViewCellContainer leaves; 1709 CollectLeaves(vc, leaves); 1710 1711 ViewCellContainer::const_iterator it, it_end = leaves.end(); 1712 1713 Intersectable::NewMail(); 1714 1715 // sum different intersectables 1716 for (it = leaves.begin(); it != it_end; ++ it) 1760 1761 // if no pvs size stored, compute new one 1762 int pvsSize = 0; 1763 ViewCell *root = vc; 1764 1765 // also add pvs from this view cell to root 1766 while (root->GetParent()) 1717 1767 { 1718 ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 1719 1720 // mail all from first pvs 1721 for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 1768 root = root->GetParent(); 1769 // matt: bug! must evaluate kd pvss also 1770 pvsSize += CountDiffPvs(root); 1771 } 1772 1773 stack<ViewCell *> tstack; 1774 tstack.push(vc); 1775 1776 while (!tstack.empty()) 1777 { 1778 vc = tstack.top(); 1779 tstack.pop(); 1780 1781 pvsSize += CountDiffPvs(vc); 1782 1783 if (!vc->IsLeaf()) 1722 1784 { 1723 Intersectable *intersect = (*oit).first; 1724 1725 if (!intersect->Mailed()) 1785 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1786 1787 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1788 1789 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1726 1790 { 1727 ++ pvsSize; 1728 intersect->Mail(); 1791 tstack.push(*it); 1792 } 1793 } 1794 } 1795 break; 1796 } 1797 case PVS_IN_INTERIORS: 1798 default: 1799 // pvs is stored consistently in the tree up to the root 1800 // just return pvs size 1801 pvsSize = vc->GetPvs().CountPvs(); 1802 break; 1803 } 1804 1805 return pvsSize; 1806 } 1807 1808 1809 int ViewCellsTree::GetPvsEntries(ViewCell *vc) const 1810 { 1811 int pvsSize = 0; 1812 1813 Intersectable::NewMail(); 1814 1815 //////////////////////////////////////////////// 1816 // for interiors, pvs can be stored using different methods 1817 1818 switch (mViewCellsStorage) 1819 { 1820 case PVS_IN_LEAVES: //-- store pvs only in leaves 1821 { 1822 // pvs is always stored directly in leaves 1823 if (vc->IsLeaf()) 1824 { 1825 pvsSize = vc->GetPvs().GetSize(); 1826 } 1827 else // interior node 1828 { 1829 // interior nodes: pvs is either stored as a scalar or 1830 // has to be reconstructed from the leaves 1831 1832 // the stored pvs size is the valid pvs size => just return scalar 1833 if (vc->mPvsSizeValid) 1834 { 1835 pvsSize = vc->mPvsSize; 1836 break; 1837 } 1838 1839 // if no valid pvs size stored as a scalar => 1840 // compute current pvs size of interior from it's leaf nodes 1841 ViewCellContainer leaves; 1842 CollectLeaves(vc, leaves); 1843 1844 ViewCellContainer::const_iterator it, it_end = leaves.end(); 1845 1846 Intersectable::NewMail(); 1847 1848 // sum different intersectables 1849 for (it = leaves.begin(); it != it_end; ++ it) 1850 { 1851 ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 1852 1853 // mail all from first pvs 1854 for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 1855 { 1856 Intersectable *intersect = (*oit).first; 1857 1858 if (!intersect->Mailed()) 1859 { 1860 ++ pvsSize; 1861 intersect->Mail(); 1862 } 1729 1863 } 1730 1864 } 1731 } 1732 1733 break;1865 1866 break; 1867 } 1734 1868 } 1735 1869 case COMPRESSED: … … 1738 1872 //-- compressed pvs 1739 1873 1874 // the stored pvs size is the valid pvs size => just return scalar 1740 1875 if (vc->mPvsSizeValid) 1741 1876 { 1742 return vc->mPvsSize; 1877 pvsSize = vc->mPvsSize; 1878 break; 1743 1879 } 1744 1880 … … 1780 1916 case PVS_IN_INTERIORS: 1781 1917 default: 1782 Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().CountPvs() << endl; 1783 pvsSize = vc->GetPvs().CountPvs(); 1918 // pvs is stored consistently in the tree up to the root 1919 // just return pvs size 1920 pvsSize = vc->GetPvs().GetSize(); 1921 break; 1784 1922 } 1785 1923 … … 1793 1931 sizeof(PvsData<Intersectable *>) + sizeof(Intersectable *); 1794 1932 1795 return (float)GetNumPvsEntries(vc) * entrySize; 1796 } 1797 1798 1799 int ViewCellsTree::GetNumPvsEntries(ViewCell *vc) const 1800 { 1801 int pvsSize = 0; 1802 // only count leaves for uncompressed method for fairness 1803 if ((mViewCellsStorage == PVS_IN_INTERIORS) || vc->IsLeaf()) 1804 { 1805 pvsSize = vc->GetPvs().CountPvs(); 1806 } 1807 1808 if (!vc->IsLeaf()) 1809 { 1810 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1933 return (float)GetStoredPvsEntriesNum(vc) * entrySize; 1934 } 1935 1936 1937 int ViewCellsTree::GetStoredPvsEntriesNum(ViewCell *root) const 1938 { 1939 int pvsSize = root->GetPvs().GetSize(); 1940 1941 // recursivly count leaves 1942 if (!root->IsLeaf()) 1943 { 1944 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root); 1811 1945 1812 1946 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); … … 1814 1948 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1815 1949 { 1816 pvsSize += Get NumPvsEntries(*it);1950 pvsSize += GetStoredPvsEntriesNum(*it); 1817 1951 } 1818 1952 } … … 1926 2060 1927 2061 1928 /** Get costs resulting from each merge step. */ 2062 /** Get costs resulting from each merge step. 2063 */ 1929 2064 void 1930 2065 ViewCellsTree::GetCostFunction(vector<float> &costFunction) 1931 2066 { 1932 TraversalQueue tqueue; 1933 tqueue.push(mRoot); 1934 while (!tqueue.empty()) { 1935 ViewCell *vc = tqueue.top(); 1936 tqueue.pop(); 1937 // save the view cells if it is a leaf or if enough view cells have already been traversed 1938 // because of the priority queue, this will be the optimal set of v 1939 if (!vc->IsLeaf()) { 1940 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1941 costFunction.push_back(interior->GetMergeCost()); 1942 1943 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1944 1945 for (it = interior->mChildren.begin(); it != it_end; ++ it) { 1946 tqueue.push(*it); 1947 } 1948 1949 } 1950 } 1951 } 1952 1953 1954 void ViewCellsTree::UpdateViewCellsStats(ViewCell *vc, ViewCellsStatistics &vcStat) 2067 TraversalQueue tqueue; 2068 tqueue.push(mRoot); 2069 2070 while (!tqueue.empty()) 2071 { 2072 ViewCell *vc = tqueue.top(); 2073 tqueue.pop(); 2074 // save the view cells if it is a leaf or if enough view cells have already been traversed 2075 // because of the priority queue, this will be the optimal set of v 2076 if (!vc->IsLeaf()) { 2077 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 2078 costFunction.push_back(interior->GetMergeCost()); 2079 2080 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 2081 2082 for (it = interior->mChildren.begin(); it != it_end; ++ it) { 2083 tqueue.push(*it); 2084 } 2085 2086 } 2087 } 2088 } 2089 2090 2091 void ViewCellsTree::UpdateViewCellsStats(ViewCell *vc, 2092 ViewCellsStatistics &vcStat) 1955 2093 { 1956 2094 ++ vcStat.viewCells; … … 1972 2110 ++ vcStat.invalid; 1973 2111 } 2112 1974 2113 1975 2114 #if ZIPPED_VIEWCELLS … … 2004 2143 { 2005 2144 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 2145 2006 2146 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 2007 2147 for (it = interior->mChildren.begin(); it != it_end; ++ it)
Note: See TracChangeset
for help on using the changeset viewer.