Changeset 1706 for GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
- Timestamp:
- 11/01/06 18:36:21 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1705 r1706 1600 1600 } 1601 1601 1602 /*typedef priority_queue<ViewCell *, vector<ViewCell *>, 1603 myless<vector<ViewCell *>::value_type> > ViewCellsQueue; 1604 1605 typedef priority_queue<BvhNode *, vector<BvhNode *>, 1606 myless<vector<BvhNode *>::value_type> > BvhQueue; 1607 1608 typedef priority_queue<VspNode *, vector<VspNode *>, 1609 myless<vector<VspNode *>::value_type> > VspQueue; 1610 */ 1602 1611 1603 static void UpdateStats(ofstream &stats, 1612 1604 const int splits, … … 1776 1768 } 1777 1769 1778 1779 } 1770 1771 1772 class HierarchyNodeWrapper; 1773 1774 1775 template <typename T> class myless 1776 { 1777 public: 1778 bool operator() (T v1, T v2) const 1779 { 1780 return (v1->GetMergeCost() < v2->GetMergeCost()); 1781 } 1782 }; 1783 1784 typedef priority_queue<HierarchyNodeWrapper *, vector<HierarchyNodeWrapper *>, 1785 myless<vector<HierarchyNodeWrapper *>::value_type> > HierarchyNodeQueue; 1786 1787 class HierarchyNodeWrapper 1788 { 1789 public: 1790 enum {VSP_NODE, BVH_NODE}; 1791 1792 virtual float GetMergeCost() const = 0; 1793 virtual int Type() const = 0; 1794 virtual bool IsLeaf() const = 0; 1795 1796 virtual void PushChildren(HierarchyNodeQueue &tQueue) = 0; 1797 }; 1798 1799 1800 class VspNodeWrapper: public HierarchyNodeWrapper 1801 { 1802 public: 1803 VspNodeWrapper(VspNode *node): mNode(node) {} 1804 1805 int Type() const { return VSP_NODE; } 1806 1807 float GetMergeCost() const { return (float) -mNode->mTimeStamp; }; 1808 1809 bool IsLeaf() const { return mNode->IsLeaf(); } 1810 1811 void PushChildren(HierarchyNodeQueue &tQueue) 1812 { 1813 if (!mNode->IsLeaf()) 1814 { 1815 VspInterior *interior = dynamic_cast<VspInterior *>(mNode); 1816 1817 tQueue.push(new VspNodeWrapper(interior->GetFront())); 1818 tQueue.push(new VspNodeWrapper(interior->GetBack())); 1819 } 1820 } 1821 1822 VspNode *mNode; 1823 }; 1824 1825 1826 class BvhNodeWrapper: public HierarchyNodeWrapper 1827 { 1828 public: 1829 BvhNodeWrapper(BvhNode *node): mNode(node) {} 1830 1831 int Type() const { return BVH_NODE; } 1832 1833 float GetMergeCost() const { return (float)-mNode->mTimeStamp; }; 1834 1835 bool IsLeaf() const { return mNode->IsLeaf(); } 1836 1837 void PushChildren(HierarchyNodeQueue &tQueue) 1838 { 1839 if (!mNode->IsLeaf()) 1840 { 1841 BvhInterior *interior = dynamic_cast<BvhInterior *>(mNode); 1842 1843 tQueue.push(new BvhNodeWrapper(interior->GetFront())); 1844 tQueue.push(new BvhNodeWrapper(interior->GetBack())); 1845 } 1846 } 1847 1848 BvhNode *mNode; 1849 }; 1850 1851 1852 void HierarchyManager::CollectBestSet(const int maxSplits, 1853 const float maxMemoryCost, 1854 vector<VspNode *> &vspNodes, 1855 vector<BvhNode *> &bvhNodes) 1856 { 1857 HierarchyNodeQueue tqueue; 1858 tqueue.push(new VspNodeWrapper(mVspTree->GetRoot())); 1859 tqueue.push(new BvhNodeWrapper(mBvHierarchy->GetRoot())); 1860 1861 float memCost = 0; 1862 1863 while (!tqueue.empty()) 1864 { 1865 HierarchyNodeWrapper *nodeWrapper = tqueue.top(); 1866 tqueue.pop(); 1867 1868 // save the view cells if it is a leaf or if enough view cells have already been traversed 1869 // because of the priority queue, this will be the optimal set of v 1870 if (nodeWrapper->IsLeaf() || 1871 ((vspNodes.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) || 1872 (memCost > maxMemoryCost) 1873 ) 1874 { 1875 if (nodeWrapper->Type() == HierarchyNodeWrapper::VSP_NODE) 1876 { 1877 VspNodeWrapper *vspNodeWrapper = dynamic_cast<VspNodeWrapper *>(nodeWrapper); 1878 vspNodes.push_back(vspNodeWrapper->mNode); 1879 } 1880 else 1881 { 1882 BvhNodeWrapper *bvhNodeWrapper = dynamic_cast<BvhNodeWrapper *>(nodeWrapper); 1883 bvhNodes.push_back(bvhNodeWrapper->mNode); 1884 } 1885 } 1886 else 1887 { 1888 nodeWrapper->PushChildren(tqueue); 1889 } 1890 1891 delete nodeWrapper; 1892 } 1893 } 1894 1895 1896 void HierarchyManager::ExtractStatistics(const int maxSplits, 1897 const float maxMemoryCost, 1898 float &renderCost, 1899 float &memory, 1900 int &pvsEntries) 1901 { 1902 /*TraversalQueue tqueue; 1903 tqueue.push(mRoot); 1904 1905 //cout << "exporting stats ... " << endl; 1906 int numViewCells = 1; 1907 1908 const AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 1909 const float vol = box.GetVolume(); 1910 1911 const int rootPvs = GetPvsSize(mRoot); 1912 const int rootEntries = GetPvsEntries(mRoot); 1913 float totalRenderCost, avgRenderCost, expectedCost; 1914 1915 float deviation = 0; 1916 int totalPvs = rootPvs; 1917 int entriesInPvs = rootEntries; 1918 1919 totalRenderCost = avgRenderCost = expectedCost = (float)rootPvs; 1920 1921 ofstream stats; 1922 stats.open(mergeStats.c_str()); 1923 1924 const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 1925 1926 ///////////// 1927 //-- first view cell 1928 1929 UpdateStats(stats, 1930 0, 1931 numViewCells, 1932 0, 1933 totalRenderCost, 1934 rootPvs, 1935 expectedCost, 1936 avgRenderCost, 1937 deviation, 1938 totalPvs, 1939 entriesInPvs, 1940 memoryCost, 1941 0, 1942 mRoot->GetVolume()); 1943 1944 1945 //-- go through tree in the order of render cost decrease 1946 //-- which is the same order as the view cells were merged 1947 //-- or the reverse order of subdivision for subdivision-only 1948 //-- view cell hierarchies. 1949 1950 while (!tqueue.empty()) 1951 { 1952 ViewCell *vc = tqueue.top(); 1953 tqueue.pop(); 1954 1955 if (!vc->IsLeaf()) 1956 { 1957 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1958 1959 const int parentPvs = GetPvsSize(interior); 1960 const int parentPvsEntries = GetPvsEntries(interior); 1961 const float parentCost = (float)parentPvs * interior->GetVolume(); 1962 1963 float childCost = 0; 1964 int childPvs = 0; 1965 int childPvsEntries = 0; 1966 1967 -- numViewCells; 1968 1969 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1970 1971 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1972 { 1973 ViewCell *vc = *it; 1974 1975 const int pvsSize = GetPvsSize(vc); 1976 const int pvsEntries = GetPvsEntries(vc); 1977 1978 childCost += (float) pvsSize * vc->GetVolume(); 1979 childPvs += pvsSize; 1980 childPvsEntries += pvsEntries; 1981 1982 tqueue.push(vc); 1983 ++ numViewCells; 1984 } 1985 1986 // update stats for this view cell 1987 const float costDecr = (parentCost - childCost) / vol; 1988 1989 totalRenderCost -= costDecr; 1990 totalPvs += childPvs - parentPvs; 1991 entriesInPvs += childPvsEntries - parentPvsEntries; 1992 1993 expectedCost = totalRenderCost / (float)numViewCells; 1994 avgRenderCost = (float)totalPvs / (float)numViewCells; 1995 1996 const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 1997 1998 UpdateStats(stats, 1999 0, 2000 numViewCells, 2001 costDecr, 2002 totalRenderCost, 2003 parentPvs, 2004 expectedCost, 2005 avgRenderCost, 2006 deviation, 2007 totalPvs, 2008 entriesInPvs, 2009 memoryCost, 2010 childPvs - parentPvs, 2011 vc->GetVolume()); 2012 } 2013 } 2014 2015 stats.close(); 2016 */ 2017 } 2018 2019 }
Note: See TracChangeset
for help on using the changeset viewer.