Changeset 1709 for GTP/trunk/Lib/Vis
- Timestamp:
- 11/02/06 19:09:30 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1707 r1709 52 52 mTimeStamp(0) 53 53 { 54 54 55 } 55 56 … … 103 104 104 105 BvhLeaf::BvhLeaf(const AxisAlignedBox3 &bbox): 105 BvhNode(bbox), mSubdivisionCandidate(NULL) 106 { 106 BvhNode(bbox), 107 mSubdivisionCandidate(NULL) 108 { 109 mActiveNode = this; 107 110 } 108 111 … … 111 114 BvhNode(bbox, parent) 112 115 { 116 mActiveNode = this; 113 117 } 114 118 … … 120 124 { 121 125 mObjects.reserve(numObjects); 126 mActiveNode = this; 122 127 } 123 128 … … 1399 1404 void BvHierarchy::PrintSubdivisionStats(const SubdivisionCandidate &sc) 1400 1405 { 1401 const float costDecr = 1402 sc.GetRenderCostDecrease();// / mHierarchyManager->GetViewSpaceBox().GetVolume(); 1406 const float costDecr = sc.GetRenderCostDecrease(); 1403 1407 1404 1408 mSubdivisionStats -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1707 r1709 1619 1619 1620 1620 1621 void HierarchyManager::EvaluateSubdivision(const VssRayContainer &sampleRays, 1622 const ObjectContainer &objects, 1623 const string &filename) 1624 { 1625 VspTree *oldVspTree = mVspTree; 1626 ViewCellsManager *vm = mVspTree->mViewCellsManager; 1627 BvHierarchy *oldHierarchy = mBvHierarchy; 1628 1629 mBvHierarchy = new BvHierarchy(); 1630 mBvHierarchy->mHierarchyManager = this; 1631 mBvHierarchy->mViewCellsManager = vm; 1632 1633 mVspTree = new VspTree(); 1634 mVspTree->mHierarchyManager = this; 1635 mVspTree->mViewCellsManager = vm; 1636 1637 // create first nodes 1638 mVspTree->Initialise(sampleRays, &oldVspTree->mBoundingBox); 1639 InitialiseObjectSpaceSubdivision(objects); 1640 1641 const long startTime = GetTime(); 1642 cout << "Constructing evaluation hierarchies ... \n"; 1643 1644 ofstream stats; 1645 stats.open(filename.c_str()); 1646 SplitQueue tQueue; 1647 1648 BvhNode *oldBvhRoot = oldHierarchy->GetRoot(); 1649 VspNode *oldVspRoot = oldVspTree->GetRoot(); 1650 1651 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 1652 1653 SubdivisionCandidate *firstVsp = mVspTree->PrepareConstruction(sampleRays, *viewSpaceRays); 1654 SubdivisionCandidate *firstBvh = mBvHierarchy->PrepareConstruction(sampleRays, objects); 1655 1656 firstVsp->mEvaluationHack = oldVspRoot; 1657 firstBvh->mEvaluationHack = oldBvhRoot; 1658 1659 firstVsp->SetPriority((float)-oldVspRoot->mTimeStamp); 1660 firstBvh->SetPriority((float)-oldBvhRoot->mTimeStamp); 1661 1662 tQueue.Push(firstVsp); 1663 tQueue.Push(firstBvh); 1664 1665 ExportStats(stats, tQueue, objects); 1666 1667 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 1668 RemoveRayRefs(objects); 1669 1670 // view cells needed only for evaluation 1621 class HierarchyNodeWrapper; 1622 1623 1624 template <typename T> class myless 1625 { 1626 public: 1627 bool operator() (T v1, T v2) const 1628 { 1629 return (v1->GetMergeCost() < v2->GetMergeCost()); 1630 } 1631 }; 1632 1633 1634 typedef priority_queue<HierarchyNodeWrapper *, vector<HierarchyNodeWrapper *>, 1635 myless<vector<HierarchyNodeWrapper *>::value_type> > HierarchyNodeQueue; 1636 1637 class HierarchyNodeWrapper 1638 { 1639 public: 1640 enum {VSP_NODE, BVH_NODE, VIEW_CELL}; 1641 1642 virtual float GetMergeCost() const = 0; 1643 virtual int Type() const = 0; 1644 virtual bool IsLeaf() const = 0; 1645 1646 virtual void PushChildren(HierarchyNodeQueue &tQueue) = 0; 1647 }; 1648 1649 1650 class VspNodeWrapper: public HierarchyNodeWrapper 1651 { 1652 public: 1653 VspNodeWrapper(VspNode *node): mNode(node) {} 1654 1655 int Type() const { return VSP_NODE; } 1656 1657 float GetMergeCost() const { return (float) -mNode->mTimeStamp; }; 1658 1659 bool IsLeaf() const { return mNode->IsLeaf(); } 1660 1661 void PushChildren(HierarchyNodeQueue &tQueue) 1662 { 1663 if (!mNode->IsLeaf()) 1664 { 1665 VspInterior *interior = dynamic_cast<VspInterior *>(mNode); 1666 1667 tQueue.push(new VspNodeWrapper(interior->GetFront())); 1668 tQueue.push(new VspNodeWrapper(interior->GetBack())); 1669 } 1670 } 1671 1672 VspNode *mNode; 1673 }; 1674 1675 1676 class BvhNodeWrapper: public HierarchyNodeWrapper 1677 { 1678 public: 1679 BvhNodeWrapper(BvhNode *node): mNode(node) {} 1680 1681 int Type() const { return BVH_NODE; } 1682 1683 float GetMergeCost() const { return (float)-mNode->mTimeStamp; }; 1684 1685 bool IsLeaf() const { return mNode->IsLeaf(); } 1686 1687 void PushChildren(HierarchyNodeQueue &tQueue) 1688 { 1689 if (!mNode->IsLeaf()) 1690 { 1691 BvhInterior *interior = dynamic_cast<BvhInterior *>(mNode); 1692 1693 tQueue.push(new BvhNodeWrapper(interior->GetFront())); 1694 tQueue.push(new BvhNodeWrapper(interior->GetBack())); 1695 } 1696 } 1697 1698 BvhNode *mNode; 1699 }; 1700 1701 1702 class ViewCellWrapper: public HierarchyNodeWrapper 1703 { 1704 public: 1705 1706 ViewCellWrapper(ViewCell *vc): mViewCell(vc) {} 1707 1708 int Type() const { return VIEW_CELL; } 1709 1710 float GetMergeCost() const { return mViewCell->GetMergeCost(); }; 1711 1712 bool IsLeaf() const { return mViewCell->IsLeaf(); } 1713 1714 void PushChildren(HierarchyNodeQueue &tQueue) 1715 { 1716 if (!mViewCell->IsLeaf()) 1717 { 1718 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(mViewCell); 1719 1720 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1721 1722 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1723 { 1724 tQueue.push(new ViewCellWrapper(*it)); 1725 } 1726 } 1727 } 1728 1729 ViewCell *mViewCell; 1730 }; 1731 1732 1733 void HierarchyManager::CollectBestSet(const int maxSplits, 1734 const float maxMemoryCost, 1735 ViewCellContainer &viewCells, 1736 vector<BvhNode *> &bvhNodes) 1737 { 1738 HierarchyNodeQueue tqueue; 1739 //tqueue.push(new VspNodeWrapper(mVspTree->GetRoot())); 1740 tqueue.push(new ViewCellWrapper(mVspTree->mViewCellsTree->GetRoot())); 1741 tqueue.push(new BvhNodeWrapper(mBvHierarchy->GetRoot())); 1742 1743 float memCost = 0; 1744 1745 while (!tqueue.empty()) 1746 { 1747 HierarchyNodeWrapper *nodeWrapper = tqueue.top(); 1748 tqueue.pop(); 1749 1750 // save the view cells if it is a leaf or if enough view cells have already been traversed 1751 // because of the priority queue, this will be the optimal set of v 1752 if (nodeWrapper->IsLeaf() || 1753 ((viewCells.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) || 1754 (memCost > maxMemoryCost) 1755 ) 1756 { 1757 if (nodeWrapper->Type() == HierarchyNodeWrapper::VSP_NODE) 1758 { 1759 ViewCellWrapper *viewCellWrapper = dynamic_cast<ViewCellWrapper *>(nodeWrapper); 1760 viewCells.push_back(viewCellWrapper->mViewCell); 1761 } 1762 else 1763 { 1764 BvhNodeWrapper *bvhNodeWrapper = dynamic_cast<BvhNodeWrapper *>(nodeWrapper); 1765 bvhNodes.push_back(bvhNodeWrapper->mNode); 1766 } 1767 } 1768 else 1769 { 1770 nodeWrapper->PushChildren(tqueue); 1771 } 1772 1773 delete nodeWrapper; 1774 } 1775 } 1776 1777 1778 bool HierarchyManager::ExtractStatistics(const int maxSplits, 1779 const float maxMemoryCost, 1780 float &renderCost, 1781 float &memory, 1782 int &pvsEntries) 1783 { 1671 1784 ViewCellContainer viewCells; 1672 mVspTree->CollectViewCells(viewCells, false); 1673 1674 // helper trees can be destroyed 1675 DEL_PTR(mVspTree); 1676 DEL_PTR(mBvHierarchy); 1677 1678 CLEAR_CONTAINER(viewCells); 1679 1680 // reset hierarchies 1681 mVspTree = oldVspTree; 1682 mBvHierarchy = oldHierarchy; 1683 1684 // reinstall old bv refs 1685 vector<BvhLeaf *> leaves; 1686 mBvHierarchy->CollectLeaves(mBvHierarchy->GetRoot(), leaves); 1687 vector<BvhLeaf *>::const_iterator bit, bit_end = leaves.end(); 1688 1689 for (bit = leaves.begin(); bit != bit_end; ++ bit) 1690 { 1691 mBvHierarchy->AssociateObjectsWithLeaf(*bit); 1692 } 1785 vector<BvhNode *> bvhNodes; 1786 1787 // collect best set of view cells for this #splits 1788 CollectBestSet(maxSplits, maxMemoryCost, viewCells, bvhNodes); 1789 1790 vector<BvhNode *>::const_iterator bit, bit_end = bvhNodes.end(); 1791 1792 for (bit = bvhNodes.begin(); bit != bit_end; ++ bit) 1793 { 1794 mBvHierarchy->SetActive(*bit); 1795 } 1796 1797 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1798 1799 int numEntries = 0; 1800 float pvsCost = 0.0f; 1801 1802 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 1803 { 1804 ViewCell *vc = *vit; 1805 ObjectPvs pvs; 1806 mVspTree->mViewCellsTree->GetPvs(vc, pvs); 1807 1808 BvhNode::NewMail(); 1809 1810 // hack: should not be done here 1811 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 1812 1813 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 1814 { 1815 BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>((*oit).first); 1816 BvhLeaf *leaf = intersect->GetItem(); 1817 BvhNode *activeNode = leaf->GetActiveNode(); 1818 1819 if (!activeNode->Mailed()) 1820 { 1821 activeNode->Mail(); 1822 1823 ++ numEntries; 1824 pvsCost += mBvHierarchy->EvalAbsCost(leaf->mObjects); 1825 } 1826 } 1827 } 1828 1829 return (viewCells.size() + bvhNodes.size() < mHierarchyStats.Leaves()); 1693 1830 } 1694 1831 … … 1707 1844 ///////////// 1708 1845 //-- first view cell 1846 1709 1847 UpdateStats(stats, 2, totalRenderCost, entriesInPvs, memoryCost, true); 1710 1848 … … 1770 1908 1771 1909 1772 1773 class HierarchyNodeWrapper; 1774 1775 1776 template <typename T> class myless 1777 { 1778 public: 1779 bool operator() (T v1, T v2) const 1780 { 1781 return (v1->GetMergeCost() < v2->GetMergeCost()); 1782 } 1783 }; 1784 1785 typedef priority_queue<HierarchyNodeWrapper *, vector<HierarchyNodeWrapper *>, 1786 myless<vector<HierarchyNodeWrapper *>::value_type> > HierarchyNodeQueue; 1787 1788 class HierarchyNodeWrapper 1789 { 1790 public: 1791 enum {VSP_NODE, BVH_NODE, VIEW_CELL}; 1792 1793 virtual float GetMergeCost() const = 0; 1794 virtual int Type() const = 0; 1795 virtual bool IsLeaf() const = 0; 1796 1797 virtual void PushChildren(HierarchyNodeQueue &tQueue) = 0; 1798 }; 1799 1800 1801 class VspNodeWrapper: public HierarchyNodeWrapper 1802 { 1803 public: 1804 VspNodeWrapper(VspNode *node): mNode(node) {} 1805 1806 int Type() const { return VSP_NODE; } 1807 1808 float GetMergeCost() const { return (float) -mNode->mTimeStamp; }; 1809 1810 bool IsLeaf() const { return mNode->IsLeaf(); } 1811 1812 void PushChildren(HierarchyNodeQueue &tQueue) 1813 { 1814 if (!mNode->IsLeaf()) 1815 { 1816 VspInterior *interior = dynamic_cast<VspInterior *>(mNode); 1817 1818 tQueue.push(new VspNodeWrapper(interior->GetFront())); 1819 tQueue.push(new VspNodeWrapper(interior->GetBack())); 1820 } 1821 } 1822 1823 VspNode *mNode; 1824 }; 1825 1826 1827 class BvhNodeWrapper: public HierarchyNodeWrapper 1828 { 1829 public: 1830 BvhNodeWrapper(BvhNode *node): mNode(node) {} 1831 1832 int Type() const { return BVH_NODE; } 1833 1834 float GetMergeCost() const { return (float)-mNode->mTimeStamp; }; 1835 1836 bool IsLeaf() const { return mNode->IsLeaf(); } 1837 1838 void PushChildren(HierarchyNodeQueue &tQueue) 1839 { 1840 if (!mNode->IsLeaf()) 1841 { 1842 BvhInterior *interior = dynamic_cast<BvhInterior *>(mNode); 1843 1844 tQueue.push(new BvhNodeWrapper(interior->GetFront())); 1845 tQueue.push(new BvhNodeWrapper(interior->GetBack())); 1846 } 1847 } 1848 1849 BvhNode *mNode; 1850 }; 1851 1852 1853 class ViewCellWrapper: public HierarchyNodeWrapper 1854 { 1855 public: 1856 1857 ViewCellWrapper(ViewCell *vc): mViewCell(vc) {} 1858 1859 int Type() const { return VIEW_CELL; } 1860 1861 float GetMergeCost() const { return mViewCell->GetMergeCost(); }; 1862 1863 bool IsLeaf() const { return mViewCell->IsLeaf(); } 1864 1865 void PushChildren(HierarchyNodeQueue &tQueue) 1866 { 1867 if (!mViewCell->IsLeaf()) 1868 { 1869 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(mViewCell); 1870 1871 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1872 1873 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1874 { 1875 tQueue.push(new ViewCellWrapper(*it)); 1876 } 1877 } 1878 } 1879 1880 ViewCell *mViewCell; 1881 }; 1882 1883 1884 void HierarchyManager::CollectBestSet(const int maxSplits, 1885 const float maxMemoryCost, 1886 // vector<VspNode *> &vspNodes, 1887 ViewCellContainer &viewCells, 1888 vector<BvhNode *> &bvhNodes) 1889 { 1890 HierarchyNodeQueue tqueue; 1891 //tqueue.push(new VspNodeWrapper(mVspTree->GetRoot())); 1892 tqueue.push(new ViewCellWrapper(mVspTree->mViewCellsTree->GetRoot())); 1893 tqueue.push(new BvhNodeWrapper(mBvHierarchy->GetRoot())); 1894 1895 float memCost = 0; 1896 1897 while (!tqueue.empty()) 1898 { 1899 HierarchyNodeWrapper *nodeWrapper = tqueue.top(); 1900 tqueue.pop(); 1901 1902 // save the view cells if it is a leaf or if enough view cells have already been traversed 1903 // because of the priority queue, this will be the optimal set of v 1904 if (nodeWrapper->IsLeaf() || 1905 ((viewCells.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) || 1906 (memCost > maxMemoryCost) 1907 ) 1908 { 1909 if (nodeWrapper->Type() == HierarchyNodeWrapper::VSP_NODE) 1910 { 1911 ViewCellWrapper *viewCellWrapper = dynamic_cast<ViewCellWrapper *>(nodeWrapper); 1912 viewCells.push_back(viewCellWrapper->mViewCell); 1913 } 1914 else 1915 { 1916 BvhNodeWrapper *bvhNodeWrapper = dynamic_cast<BvhNodeWrapper *>(nodeWrapper); 1917 bvhNodes.push_back(bvhNodeWrapper->mNode); 1918 } 1919 } 1920 else 1921 { 1922 nodeWrapper->PushChildren(tqueue); 1923 } 1924 1925 delete nodeWrapper; 1926 } 1927 } 1928 1929 1930 void HierarchyManager::ExtractStatistics(const int maxSplits, 1931 const float maxMemoryCost, 1932 float &renderCost, 1933 float &memory, 1934 int &pvsEntries) 1935 { 1936 //vector<VspNode *> vspNodes; 1910 void HierarchyManager::EvaluateSubdivision(const VssRayContainer &sampleRays, 1911 const ObjectContainer &objects, 1912 const string &filename) 1913 { 1914 VspTree *oldVspTree = mVspTree; 1915 ViewCellsManager *vm = mVspTree->mViewCellsManager; 1916 BvHierarchy *oldHierarchy = mBvHierarchy; 1917 1918 mBvHierarchy = new BvHierarchy(); 1919 mBvHierarchy->mHierarchyManager = this; 1920 mBvHierarchy->mViewCellsManager = vm; 1921 1922 mVspTree = new VspTree(); 1923 mVspTree->mHierarchyManager = this; 1924 mVspTree->mViewCellsManager = vm; 1925 1926 // create first nodes 1927 mVspTree->Initialise(sampleRays, &oldVspTree->mBoundingBox); 1928 InitialiseObjectSpaceSubdivision(objects); 1929 1930 const long startTime = GetTime(); 1931 cout << "Constructing evaluation hierarchies ... \n"; 1932 1933 ofstream stats; 1934 stats.open(filename.c_str()); 1935 SplitQueue tQueue; 1936 1937 BvhNode *oldBvhRoot = oldHierarchy->GetRoot(); 1938 VspNode *oldVspRoot = oldVspTree->GetRoot(); 1939 1940 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 1941 1942 SubdivisionCandidate *firstVsp = mVspTree->PrepareConstruction(sampleRays, *viewSpaceRays); 1943 SubdivisionCandidate *firstBvh = mBvHierarchy->PrepareConstruction(sampleRays, objects); 1944 1945 firstVsp->mEvaluationHack = oldVspRoot; 1946 firstBvh->mEvaluationHack = oldBvhRoot; 1947 1948 firstVsp->SetPriority((float)-oldVspRoot->mTimeStamp); 1949 firstBvh->SetPriority((float)-oldBvhRoot->mTimeStamp); 1950 1951 tQueue.Push(firstVsp); 1952 tQueue.Push(firstBvh); 1953 1954 ExportStats(stats, tQueue, objects); 1955 1956 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 1957 RemoveRayRefs(objects); 1958 1959 // view cells needed only for evaluation 1937 1960 ViewCellContainer viewCells; 1938 vector<BvhNode *> bvhNodes; 1939 1940 CollectBestSet(maxSplits, maxMemoryCost, viewCells, bvhNodes); 1941 1942 vector<BvhNode *>::const_iterator bit, bit_end = bvhNodes.end(); 1943 1944 for (bit = bvhNodes.begin(); bit != bit_end; ++ bit) 1945 { 1946 mBvHierarchy->SetActive(*bit); 1947 } 1948 1949 //vector<VspNode *>::const_iterator vit, vit_end = vspNodes.end(); 1950 1951 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1952 1953 int numEntries = 0; 1954 float pvsCost = 0.0f; 1955 1956 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 1957 { 1958 ViewCell *vc = *vit; 1959 ObjectPvs pvs; 1960 mVspTree->mViewCellsTree->GetPvs(vc, pvs); 1961 1962 BvhNode::NewMail(); 1963 1964 // hack: should not be done here 1965 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 1966 1967 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 1968 { 1969 BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>((*oit).first); 1970 BvhLeaf *leaf = intersect->GetItem(); 1971 BvhNode *activeNode = leaf->GetActiveNode(); 1972 1973 if (!activeNode->Mailed()) 1974 { 1975 activeNode->Mail(); 1976 1977 ++ numEntries; 1978 pvsCost += mBvHierarchy->EvalAbsCost(leaf->mObjects); 1979 } 1980 } 1981 } 1982 1983 /*TraversalQueue tqueue; 1984 tqueue.push(mRoot); 1985 1986 //cout << "exporting stats ... " << endl; 1987 int numViewCells = 1; 1988 1989 const AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 1990 const float vol = box.GetVolume(); 1991 1992 const int rootPvs = GetPvsSize(mRoot); 1993 const int rootEntries = GetPvsEntries(mRoot); 1994 float totalRenderCost, avgRenderCost, expectedCost; 1995 1996 float deviation = 0; 1997 int totalPvs = rootPvs; 1998 int entriesInPvs = rootEntries; 1999 2000 totalRenderCost = avgRenderCost = expectedCost = (float)rootPvs; 2001 2002 ofstream stats; 2003 stats.open(mergeStats.c_str()); 2004 2005 const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 2006 2007 ///////////// 2008 //-- first view cell 2009 2010 UpdateStats(stats, 2011 0, 2012 numViewCells, 2013 0, 2014 totalRenderCost, 2015 rootPvs, 2016 expectedCost, 2017 avgRenderCost, 2018 deviation, 2019 totalPvs, 2020 entriesInPvs, 2021 memoryCost, 2022 0, 2023 mRoot->GetVolume()); 2024 2025 2026 //-- go through tree in the order of render cost decrease 2027 //-- which is the same order as the view cells were merged 2028 //-- or the reverse order of subdivision for subdivision-only 2029 //-- view cell hierarchies. 2030 2031 while (!tqueue.empty()) 2032 { 2033 ViewCell *vc = tqueue.top(); 2034 tqueue.pop(); 2035 2036 if (!vc->IsLeaf()) 2037 { 2038 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 2039 2040 const int parentPvs = GetPvsSize(interior); 2041 const int parentPvsEntries = GetPvsEntries(interior); 2042 const float parentCost = (float)parentPvs * interior->GetVolume(); 2043 2044 float childCost = 0; 2045 int childPvs = 0; 2046 int childPvsEntries = 0; 2047 2048 -- numViewCells; 2049 2050 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 2051 2052 for (it = interior->mChildren.begin(); it != it_end; ++ it) 2053 { 2054 ViewCell *vc = *it; 2055 2056 const int pvsSize = GetPvsSize(vc); 2057 const int pvsEntries = GetPvsEntries(vc); 2058 2059 childCost += (float) pvsSize * vc->GetVolume(); 2060 childPvs += pvsSize; 2061 childPvsEntries += pvsEntries; 2062 2063 tqueue.push(vc); 2064 ++ numViewCells; 2065 } 2066 2067 // update stats for this view cell 2068 const float costDecr = (parentCost - childCost) / vol; 2069 2070 totalRenderCost -= costDecr; 2071 totalPvs += childPvs - parentPvs; 2072 entriesInPvs += childPvsEntries - parentPvsEntries; 2073 2074 expectedCost = totalRenderCost / (float)numViewCells; 2075 avgRenderCost = (float)totalPvs / (float)numViewCells; 2076 2077 const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 2078 2079 UpdateStats(stats, 2080 0, 2081 numViewCells, 2082 costDecr, 2083 totalRenderCost, 2084 parentPvs, 2085 expectedCost, 2086 avgRenderCost, 2087 deviation, 2088 totalPvs, 2089 entriesInPvs, 2090 memoryCost, 2091 childPvs - parentPvs, 2092 vc->GetVolume()); 2093 } 2094 } 2095 2096 stats.close(); 2097 */ 2098 } 2099 2100 } 1961 mVspTree->CollectViewCells(viewCells, false); 1962 1963 // helper trees can be destroyed 1964 DEL_PTR(mVspTree); 1965 DEL_PTR(mBvHierarchy); 1966 1967 CLEAR_CONTAINER(viewCells); 1968 1969 // reset hierarchies 1970 mVspTree = oldVspTree; 1971 mBvHierarchy = oldHierarchy; 1972 1973 // reinstall old bv refs 1974 vector<BvhLeaf *> leaves; 1975 mBvHierarchy->CollectLeaves(mBvHierarchy->GetRoot(), leaves); 1976 vector<BvhLeaf *>::const_iterator bit, bit_end = leaves.end(); 1977 1978 for (bit = leaves.begin(); bit != bit_end; ++ bit) 1979 { 1980 mBvHierarchy->AssociateObjectsWithLeaf(*bit); 1981 } 1982 } 1983 1984 1985 void HierarchyManager::EvaluateSubdivision2(ofstream &splitsStats, 1986 ofstream &memStats, 1987 const int splitsStepSize, 1988 const float memStepSize) 1989 { 1990 int splits = 0; 1991 float mem = 15; 1992 1993 float renderCost; 1994 float memory; 1995 int pvsEntries; 1996 1997 while (1) 1998 { 1999 if (!ExtractStatistics(i, 99999999, renderCost, memory, pvsEntries)) 2000 break; 2001 2002 UpdateStats(splitsStats, splits, renderCost, pvsEntries, memory, 0); 2003 2004 splits += splitsStepSize 2005 } 2006 2007 while (1) 2008 { 2009 if (!ExtractStatistics(99999999, mem, renderCost, memory, pvsEntries)) 2010 break; 2011 2012 UpdateStats(splitsStats, splits, renderCost, pvsEntries, memory, 0); 2013 2014 mem += memStepSize 2015 } 2016 2017 } 2018 2019 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1707 r1709 240 240 const string &filename); 241 241 242 void EvaluateSubdivision2(ofstream &stats); 243 244 242 245 float mInitialRenderCost; 243 246 … … 452 455 void CollectBestSet(const int maxSplits, 453 456 const float maxMemoryCost, 454 //vector<VspNode *> &vspNodes,455 457 ViewCellContainer &viewCells, 456 458 vector<BvhNode *> &bvhNodes); 457 459 458 voidExtractStatistics(const int maxSplits,460 bool ExtractStatistics(const int maxSplits, 459 461 const float maxMemoryCost, 460 462 float &renderCost, 461 463 float &memory, 462 464 int &pvsEntries); 465 466 463 467 protected: 464 468 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1707 r1709 42 42 43 43 // pvs penalty can be different from pvs size 44 inline static float EvalPvsPenalty(const int pvs,45 const int lower,46 const int upper)44 inline static float EvalPvsPenalty(const float pvs, 45 const float lower, 46 const float upper) 47 47 { 48 48 // clamp to minmax values … … 76 76 77 77 /// Fast computation of merged pvs size 78 static int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2)78 static float ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) 79 79 { 80 80 // add first pvs 81 int pvs =pvs1.GetSize();81 float pvs = (float)pvs1.GetSize(); 82 82 83 83 ObjectPvsMap::const_iterator it, it_end = pvs1.mEntries.end(); … … 112 112 mParent(NULL), 113 113 mMergeCost(0), 114 mPvs Size(0),114 mPvsCost(0), 115 115 mEntriesInPvs(0), 116 116 mPvsSizeValid(false) 117 //mMailbox(0)118 117 { 119 118 mId = -100; … … 127 126 mParent(NULL), 128 127 mMergeCost(0), 129 mPvs Size(0),128 mPvsCost(0), 130 129 mPvsSizeValid(false) 131 130 //mMailbox(0) … … 244 243 float ViewCell::GetRenderCost() const 245 244 { 246 //return (float)mPvs.GetSize() * GetVolume(); 247 return (float)mPvsSize * GetVolume(); 245 return mPvsCost * GetVolume(); 248 246 } 249 247 … … 352 350 //app << "#N_CTIME ( Construction time [s] )\n" << Time() << " \n"; 353 351 354 app << "#N_OVERALLPVS ( objects in PVS )\n" << pvsSize << endl; 352 app << "#N_OVERALLPVS ( cost of the PVS )\n" << pvsCost << endl; 353 354 //app << "#N_PVSENTRIES ( entries in the PVS)\n" << pvsEntries << endl; 355 355 356 356 app << "#N_PMAXPVS ( largest PVS )\n" << maxPvs << endl; … … 520 520 521 521 float variance = 0; 522 int totalPvs = 0;522 float totalPvs = 0; 523 523 float totalRenderCost = 0; 524 524 … … 669 669 670 670 //-- merge the view cells of leaf1 and leaf2 671 int pvsDiff;671 float pvsDiff; 672 672 ViewCellInterior *mergedVc = 673 MergeViewCells(mc.mLeftViewCell, mc.mRightViewCell, pvsDiff); 674 673 MergeViewCells(mc.mLeftViewCell, mc.mRightViewCell, pvsDiff); 675 674 676 675 // total render cost and deviation has changed … … 926 925 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 927 926 { 928 const int lower =mViewCellsManager->GetMinPvsSize();929 const int upper =mViewCellsManager->GetMaxPvsSize();927 const float lower = (float)mViewCellsManager->GetMinPvsSize(); 928 const float upper = (float)mViewCellsManager->GetMaxPvsSize(); 930 929 931 930 const float penalty = EvalPvsPenalty((*vit)->GetPvs().EvalPvsCost(), lower, upper); … … 992 991 ViewCellInterior *ViewCellsTree::MergeViewCells(ViewCell *left, 993 992 ViewCell *right, 994 int &pvsDiff) //const993 float &pvsDiff) //const 995 994 { 996 995 // create merged view cell … … 1183 1182 { 1184 1183 //const int pvs1 = SubtractedPvsSize(vc1, leaf, *leaf->mPvs); 1185 const int pvs1 =SubtractedPvsSize(vc1->GetPvs(), leaf->GetPvs());1186 const int pvs2 =AddedPvsSize(vc2->GetPvs(), leaf->GetPvs());1187 1188 const int lowerPvsLimit =mViewCellsManager->GetMinPvsSize();1189 const int upperPvsLimit =mViewCellsManager->GetMaxPvsSize();1184 const float pvs1 = (float)SubtractedPvsSize(vc1->GetPvs(), leaf->GetPvs()); 1185 const float pvs2 = (float)AddedPvsSize(vc2->GetPvs(), leaf->GetPvs()); 1186 1187 const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize(); 1188 const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize(); 1190 1189 1191 1190 const float pvsPenalty1 = … … 1311 1310 float ViewCellsTree::GetVariance(ViewCell *vc) const 1312 1311 { 1313 const int upper =mViewCellsManager->GetMaxPvsSize();1314 const int lower =mViewCellsManager->GetMinPvsSize();1312 const float upper = (float)mViewCellsManager->GetMaxPvsSize(); 1313 const float lower = (float)mViewCellsManager->GetMinPvsSize(); 1315 1314 1316 1315 if (1) 1317 1316 { 1318 1317 const float penalty = 1319 EvalPvsPenalty( vc->GetPvs().GetSize(), lower, upper);1318 EvalPvsPenalty(GetPvsCost(vc), lower, upper); 1320 1319 1321 1320 return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / … … 1330 1329 float ViewCellsTree::GetDeviation(ViewCell *vc) const 1331 1330 { 1332 const int upper =mViewCellsManager->GetMaxPvsSize();1333 const int lower =mViewCellsManager->GetMinPvsSize();1331 const float upper = (float)mViewCellsManager->GetMaxPvsSize(); 1332 const float lower = (float)mViewCellsManager->GetMinPvsSize(); 1334 1333 1335 1334 if (1) 1336 1335 { 1337 const float penalty = EvalPvsPenalty( vc->GetPvs().EvalPvsCost(), lower, upper);1336 const float penalty = EvalPvsPenalty(GetPvsCost(vc), lower, upper); 1338 1337 return fabs(mAvgRenderCost - penalty) / (float)mNumActiveViewCells; 1339 1338 } … … 1386 1385 //-- compute pvs difference 1387 1386 1388 int newPvs; 1389 1390 if (1) // not valid if not using const cost per object!! 1391 { 1392 newPvs = ComputeMergedPvsSize(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 1393 } 1394 else 1395 { 1396 newPvs = (int)ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 1397 } 1387 float newPvs; 1388 1389 // not valid if not using const cost per object!! 1390 newPvs = ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 1391 1398 1392 1399 1393 const float newPenalty = EvalPvsPenalty(newPvs, 1400 mViewCellsManager->GetMinPvsSize(),1401 mViewCellsManager->GetMaxPvsSize());1394 (float)mViewCellsManager->GetMinPvsSize(), 1395 (float)mViewCellsManager->GetMaxPvsSize()); 1402 1396 1403 1397 ViewCell *vc1 = mc.mLeftViewCell; … … 1485 1479 1486 1480 void ViewCellsTree::UpdateStats(ofstream &stats, 1487 const int pass, 1488 const int viewCells, 1489 const float renderCostDecrease, 1490 const float totalRenderCost, 1491 const int currentPvs, 1492 const float expectedCost, 1493 const float avgRenderCost, 1494 const float deviation, 1495 const int totalPvs, 1496 const int entriesInPvs, 1497 const float memoryCost, 1498 const int pvsSizeDecr, 1499 const float volume) 1500 { 1501 stats << "#Pass\n" << pass << endl 1502 << "#Splits\n" << viewCells << endl 1503 << "#RenderCostDecrease\n" << renderCostDecrease << endl // TODO 1504 << "#TotalRenderCost\n" << totalRenderCost << endl 1505 << "#CurrentPvs\n" << currentPvs << endl 1506 << "#ExpectedCost\n" << expectedCost << endl 1507 << "#AvgRenderCost\n" << avgRenderCost << endl 1508 << "#Deviation\n" << deviation << endl 1509 << "#TotalPvs\n" << totalPvs << endl 1510 << "#TotalEntriesInPvs\n" << entriesInPvs << endl 1511 << "#Memory\n" << memoryCost << endl 1512 << "#PvsSizeDecrease\n" << pvsSizeDecr << endl 1513 << "#Volume\n" << volume << endl 1481 const ViewCellsTreeStats &vcStats) 1482 { 1483 stats << "#Pass\n" << vcStats.mPass << endl 1484 << "#Splits\n" << vcStats.mNumViewCells << endl 1485 << "#RenderCostDecrease\n" << vcStats.mRenderCostDecrease << endl // TODO 1486 << "#TotalRenderCost\n" << vcStats.mTotalRenderCost << endl 1487 << "#CurrentPvs\n" << vcStats.mCurrentPvsCost << endl 1488 << "#ExpectedCost\n" << vcStats.mExpectedCost << endl 1489 << "#AvgRenderCost\n" << vcStats.mAvgRenderCost << endl 1490 << "#Deviation\n" << vcStats.mDeviation << endl 1491 << "#TotalPvs\n" << vcStats.mTotalPvsCost << endl 1492 << "#TotalEntriesInPvs\n" << vcStats.mEntriesInPvs << endl 1493 << "#Memory\n" << vcStats.mMemoryCost << endl 1494 << "#PvsSizeDecrease\n" << vcStats.mPvsSizeDecr << endl 1495 << "#Volume\n" << vcStats.mVolume << endl 1514 1496 << endl; 1515 1497 } … … 1521 1503 tqueue.push(mRoot); 1522 1504 1505 ViewCellsTreeStats vcStats; 1506 vcStats.Reset(); 1507 1523 1508 //cout << "exporting stats ... " << endl; 1524 int numViewCells = 1;1509 vcStats.mNumViewCells = 1; 1525 1510 1526 1511 const AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 1527 1512 const float vol = box.GetVolume(); 1528 1513 1529 const int rootPvs = GetPvsSize(mRoot);1514 const float rootPvs = GetPvsCost(mRoot); 1530 1515 const int rootEntries = GetPvsEntries(mRoot); 1531 float totalRenderCost, avgRenderCost, expectedCost;1532 1533 float deviation = 0;1534 int totalPvs= rootPvs;1535 int entriesInPvs = rootEntries;1536 1537 totalRenderCost = avgRenderCost = expectedCost = (float)rootPvs;1516 1517 vcStats.mTotalPvsCost = rootPvs; 1518 vcStats.mTotalRenderCost = rootPvs; 1519 vcStats.mAvgRenderCost = rootPvs; 1520 vcStats.mExpectedCost = rootPvs; 1521 1522 vcStats.mEntriesInPvs = rootEntries; 1538 1523 1539 1524 ofstream stats; 1540 1525 stats.open(mergeStats.c_str()); 1541 1526 1542 const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize();1527 vcStats.mMemoryCost = (float)vcStats.mEntriesInPvs * ObjectPvs::GetEntrySize(); 1543 1528 1544 1529 ///////////// 1545 1530 //-- first view cell 1546 1531 1547 UpdateStats(stats, 1548 0, 1549 numViewCells, 1550 0, 1551 totalRenderCost, 1552 rootPvs, 1553 expectedCost, 1554 avgRenderCost, 1555 deviation, 1556 totalPvs, 1557 entriesInPvs, 1558 memoryCost, 1559 0, 1560 mRoot->GetVolume()); 1532 UpdateStats(stats, vcStats); 1533 1561 1534 1562 1563 1535 //-- go through tree in the order of render cost decrease 1564 1536 //-- which is the same order as the view cells were merged … … 1575 1547 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1576 1548 1577 const int parentPvs = GetPvsSize(interior);1549 const float parentCost = GetPvsCost(interior); 1578 1550 const int parentPvsEntries = GetPvsEntries(interior); 1579 const float parentCost = (float)parentPvs * interior->GetVolume(); 1580 1551 const float parentExpCost = (float)parentCost * interior->GetVolume(); 1552 1553 float childExpCost = 0; 1581 1554 float childCost = 0; 1582 int childPvs = 0;1583 1555 int childPvsEntries = 0; 1584 1556 1585 -- numViewCells;1557 -- vcStats.mNumViewCells; 1586 1558 1587 1559 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); … … 1591 1563 ViewCell *vc = *it; 1592 1564 1593 const int pvsSize = GetPvsSize(vc);1565 const float pvsCost = GetPvsCost(vc); 1594 1566 const int pvsEntries = GetPvsEntries(vc); 1595 1567 1596 child Cost += (float) pvsSize* vc->GetVolume();1597 child Pvs += pvsSize;1568 childExpCost += childCost * vc->GetVolume(); 1569 childCost += pvsCost; 1598 1570 childPvsEntries += pvsEntries; 1599 1571 1600 1572 tqueue.push(vc); 1601 ++ numViewCells;1573 ++ vcStats.mNumViewCells; 1602 1574 } 1603 1575 1604 1576 // update stats for this view cell 1605 const float costDecr = (parentCost - childCost) / vol; 1606 1607 totalRenderCost -= costDecr; 1608 totalPvs += childPvs - parentPvs; 1609 entriesInPvs += childPvsEntries - parentPvsEntries; 1610 1611 expectedCost = totalRenderCost / (float)numViewCells; 1612 avgRenderCost = (float)totalPvs / (float)numViewCells; 1613 1614 const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 1615 1616 UpdateStats(stats, 1617 0, 1618 numViewCells, 1619 costDecr, 1620 totalRenderCost, 1621 parentPvs, 1622 expectedCost, 1623 avgRenderCost, 1624 deviation, 1625 totalPvs, 1626 entriesInPvs, 1627 memoryCost, 1628 childPvs - parentPvs, 1629 vc->GetVolume()); 1577 const float costDecr = (parentExpCost - childExpCost) / vol; 1578 1579 vcStats.mTotalRenderCost -= costDecr; 1580 vcStats.mTotalPvsCost += childCost - parentCost; 1581 vcStats.mEntriesInPvs += childPvsEntries - parentPvsEntries; 1582 1583 vcStats.mExpectedCost = vcStats.mTotalRenderCost / (float)vcStats.mNumViewCells; 1584 vcStats.mAvgRenderCost = vcStats.mTotalPvsCost / (float)vcStats.mNumViewCells; 1585 1586 vcStats.mMemoryCost = vcStats.mEntriesInPvs * ObjectPvs::GetEntrySize(); 1587 1588 UpdateStats(stats, vcStats); 1630 1589 } 1631 1590 } … … 1789 1748 1790 1749 1791 int ViewCellsTree::GetPvsSizeForLeafStorage(ViewCell *vc) const1750 float ViewCellsTree::GetPvsCostForLeafStorage(ViewCell *vc) const 1792 1751 { 1793 1752 // pvs is always stored directly in leaves … … 1802 1761 if (vc->mPvsSizeValid) 1803 1762 { 1804 return vc->mPvs Size;1763 return vc->mPvsCost; 1805 1764 } 1806 1765 … … 1886 1845 1887 1846 1888 int ViewCellsTree::GetPvsSizeForCompressedStorage(ViewCell *vc) const1889 { 1890 int pvsSize= 0;1847 float ViewCellsTree::GetPvsCostForCompressedStorage(ViewCell *vc) const 1848 { 1849 float pvsCost = 0; 1891 1850 1892 1851 ///////////// … … 1896 1855 if (vc->mPvsSizeValid) 1897 1856 { 1898 pvs Size = vc->mPvsSize;1857 pvsCost = vc->mPvsCost; 1899 1858 } 1900 1859 … … 1908 1867 1909 1868 // matt: bug! must evaluate kd pvss also 1910 pvs Size+= CountPvsContribution(root);1869 pvsCost += CountPvsContribution(root); 1911 1870 } 1912 1871 … … 1918 1877 vc = tstack.top(); 1919 1878 tstack.pop(); 1879 1920 1880 // matt: bug! must evaluate kd pvss also 1921 pvs Size+= CountPvsContribution(vc);1881 pvsCost += CountPvsContribution(vc); 1922 1882 1923 1883 if (!vc->IsLeaf()) 1924 1884 { 1925 1885 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1926 1927 1886 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1928 1887 … … 1934 1893 } 1935 1894 1936 return pvs Size;1895 return pvsCost; 1937 1896 } 1938 1897 … … 1990 1949 1991 1950 1992 int ViewCellsTree::GetPvsSize(ViewCell *vc) const1993 { 1994 int pvsSize= 0;1951 float ViewCellsTree::GetPvsCost(ViewCell *vc) const 1952 { 1953 float pvsCost = 0; 1995 1954 Intersectable::NewMail(); 1996 1955 … … 2003 1962 case PVS_IN_LEAVES: 2004 1963 // pvs is stored only in leaves 2005 pvs Size = GetPvsSizeForLeafStorage(vc);1964 pvsCost = GetPvsCostForLeafStorage(vc); 2006 1965 break; 2007 1966 case COMPRESSED: 2008 pvs Size = GetPvsSizeForCompressedStorage(vc);1967 pvsCost = GetPvsCostForCompressedStorage(vc); 2009 1968 break; 2010 1969 case PVS_IN_INTERIORS: … … 2012 1971 // pvs is stored consistently in the tree up to the root 2013 1972 // just return pvs size 2014 pvs Size= vc->GetPvs().EvalPvsCost();1973 pvsCost = vc->GetPvs().EvalPvsCost(); 2015 1974 break; 2016 1975 } 2017 1976 2018 return pvs Size;1977 return pvsCost; 2019 1978 } 2020 1979 … … 2194 2153 2195 2154 const float vol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 2196 const int rootPvs = GetPvsSize(mRoot);2155 const float rootPvs = GetPvsCost(mRoot); 2197 2156 2198 2157 float totalRenderCost; 2199 2158 2200 int totalPvs= rootPvs;2159 float totalPvsCost = rootPvs; 2201 2160 totalRenderCost = (float)rootPvs; 2202 2161 … … 2217 2176 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 2218 2177 2219 const int parentPvs = GetPvsSize(interior);2220 const float parent Cost = (float)parentPvs* interior->GetVolume();2178 const float parentCost = GetPvsCost(interior); 2179 const float parentExpCost = parentCost * interior->GetVolume(); 2221 2180 2222 2181 -- numViewCells; 2223 2182 2183 float childExpCost = 0; 2224 2184 float childCost = 0; 2225 int childPvs = 0;2226 2185 2227 2186 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); … … 2231 2190 ViewCell *vc = *it; 2232 2191 2233 const int pvsSize = GetPvsSize(vc);2192 const float pvsCost = GetPvsCost(vc); 2234 2193 2235 child Cost += (float) pvsSize* vc->GetVolume();2236 child Pvs += pvsSize;2194 childExpCost += (float) pvsCost * vc->GetVolume(); 2195 childCost += pvsCost; 2237 2196 2238 2197 tqueue.push(vc); … … 2241 2200 2242 2201 // update stats for this view cell 2243 const float costDecr = (parent Cost - childCost) / vol;2202 const float costDecr = (parentExpCost - childExpCost) / vol; 2244 2203 totalRenderCost -= costDecr; 2245 const float expectedCost = totalRenderCost ;/// (float)numViewCells; 2246 2247 costFunction.push_back(expectedCost); 2204 2205 costFunction.push_back(totalRenderCost); 2248 2206 } 2249 2207 } … … 2283 2241 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 2284 2242 2285 const int parentPvs = GetPvsSize(interior);2243 const float parentPvsCost = GetPvsCost(interior); 2286 2244 const int parentPvsEntries = GetPvsEntries(interior); 2287 const float parent Cost = (float)parentPvs* interior->GetVolume();2288 2289 float child Cost = 0;2245 const float parentExpCost = (float)parentPvsCost * interior->GetVolume(); 2246 2247 float childExpCost = 0; 2290 2248 int childPvs = 0; 2291 2249 int childPvsEntries = 0; … … 2299 2257 ViewCell *vc = *it; 2300 2258 2301 //const int pvsSize = GetPvsSize(vc);2302 2259 const int pvsEntries = GetPvsEntries(vc); 2303 2304 //childPvs += pvsSize;2305 2260 childPvsEntries += pvsEntries; 2306 2261 … … 2310 2265 2311 2266 // update stats for this view cell 2312 const float costDecr = (parentCost - childCost) / vol; 2313 2314 //totalPvs += childPvs - parentPvs; 2267 const float costDecr = (parentExpCost - childExpCost) / vol; 2268 2315 2269 entriesInPvs += childPvsEntries - parentPvsEntries; 2316 2270 … … 2328 2282 ++ vcStat.viewCells; 2329 2283 2330 const int pvsSize = GetPvsSize(vc);2331 2332 vcStat.pvs Size += pvsSize;2333 2334 if (pvs Size == 0)2284 const float pvsCost = GetPvsCost(vc); 2285 2286 vcStat.pvsCost += pvsCost; 2287 2288 if (pvsCost < Limits::Small) 2335 2289 ++ vcStat.emptyPvs; 2336 2290 2337 if (pvs Size> vcStat.maxPvs)2338 vcStat.maxPvs = pvs Size;2339 2340 if (pvs Size< vcStat.minPvs)2341 vcStat.minPvs = pvs Size;2291 if (pvsCost > vcStat.maxPvs) 2292 vcStat.maxPvs = pvsCost; 2293 2294 if (pvsCost < vcStat.minPvs) 2295 vcStat.minPvs = pvsCost; 2342 2296 2343 2297 if (!vc->GetValid()) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1707 r1709 35 35 /// number of view cells 36 36 int viewCells; 37 /// sizeof the PVS38 int pvsSize;37 /// cost of the PVS 38 float pvsCost; 39 39 /// largest PVS of all view cells 40 int maxPvs;40 float maxPvs; 41 41 /// smallest PVS of all view cells 42 int minPvs;42 float minPvs; 43 43 /// view cells with empty PVS 44 44 int emptyPvs; … … 57 57 58 58 double AvgLeaves() const {return (double)leaves / (double)viewCells;}; 59 double AvgPvs() const {return (double)pvs Size/ (double)viewCells;};59 double AvgPvs() const {return (double)pvsCost / (double)viewCells;}; 60 60 61 61 void Reset() 62 62 { 63 63 viewCells = 0; 64 pvs Size= 0;64 pvsCost = 0; 65 65 maxPvs = 0; 66 66 … … 75 75 76 76 friend ostream &operator<<(ostream &s, const ViewCellsStatistics &stat) 77 { 78 stat.Print(s); 79 return s; 80 } 81 }; 82 83 84 class ViewCellsTreeStats 85 { 86 public: 87 int mPass; 88 89 int mNumViewCells; 90 91 float mRenderCostDecrease; 92 93 float mTotalRenderCost; 94 95 float mCurrentPvsCost; 96 97 float mExpectedCost; 98 99 float mAvgRenderCost; 100 101 float mDeviation; 102 103 float mTotalPvsCost; 104 105 int mEntriesInPvs; 106 107 float mMemoryCost; 108 109 int mPvsSizeDecr; 110 111 float mVolume; 112 113 114 void Reset() 115 { 116 mPass = 0; 117 mNumViewCells = 0; 118 mRenderCostDecrease = 0; 119 mTotalRenderCost = 0; 120 mCurrentPvsCost = 0; 121 mExpectedCost = 0; 122 mAvgRenderCost = 0; 123 mDeviation = 0; 124 mTotalPvsCost = 0; 125 mEntriesInPvs = 0; 126 mMemoryCost = 0; 127 mPvsSizeDecr = 0; 128 mVolume = 0; 129 } 130 131 132 void Print(ostream &app) const; 133 134 friend ostream &operator<<(ostream &s, const ViewCellsTreeStats &stat) 77 135 { 78 136 stat.Print(s); … … 181 239 // HACK: take scalar value because pvs may not have been stored properly 182 240 #if 1 183 return a->mPvs Size < b->mPvsSize;241 return a->mPvsCost < b->mPvsCost; 184 242 #else 185 243 return a->GetPvs().EvalPvsCost() < b->GetPvs().EvalPvsCost(); … … 251 309 RgbColor mColor; 252 310 /// store pvs size, used for evaluation purpose when pvss are stored only in the leaves 253 int mPvsSize;311 float mPvsCost; 254 312 /** stores number of entries in pvs 255 313 this variable has the same value as mPvsSize for object pvs, … … 421 479 void GetPvs(ViewCell *vc, ObjectPvs &pvs) const; 422 480 423 /** Returns pvs size (i.e. the number ofstored objects)424 */ 425 int GetPvsSize(ViewCell *vc) const;481 /** Returns pvs size (i.e. the render cost of the stored objects) 482 */ 483 float GetPvsCost(ViewCell *vc) const; 426 484 427 485 /** Returns number of entries associated with this view cell. … … 538 596 @returns difference in pvs size 539 597 */ 540 ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, int &pvsDiff); //const;598 ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, float &pvsDiff); //const; 541 599 542 600 /** Shuffles, i.e. takes border leaf from view cell 1 and adds it … … 601 659 The pvs is assumed to be stored using lossless compression. 602 660 */ 603 int GetPvsSizeForCompressedStorage(ViewCell *vc) const;661 float GetPvsCostForCompressedStorage(ViewCell *vc) const; 604 662 605 663 /** Computes pvs size of this view cell. 606 664 The pvs is assumed to be stored in the leaves. 607 665 */ 608 int GetPvsSizeForLeafStorage(ViewCell *vc) const;666 float GetPvsCostForLeafStorage(ViewCell *vc) const; 609 667 610 668 /** Counts the logical number of entries in the pvs this view cell. … … 616 674 */ 617 675 void UpdateStats(ofstream &stats, 618 const int pass, 619 const int viewCells, 620 const float renderCostDecrease, 621 const float totalRenderCost, 622 const int currentPvs, 623 const float expectedCost, 624 const float avgRenderCost, 625 const float deviation, 626 const int totalPvs, 627 const int entriesInPvs, 628 const float memoryCost, 629 const int pvsSizeDecr, 630 const float volume); 676 const ViewCellsTreeStats &vcStats); 631 677 632 678 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1708 r1709 296 296 int stype; 297 297 298 const int numStrategies = 3; 299 298 300 stype = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 299 mPreprocessor->GenerateRays(samplesPerPass / 4, sampleType, simpleRays);301 mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays); 300 302 301 303 stype = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; 302 mPreprocessor->GenerateRays(samplesPerPass / 4, sampleType, simpleRays); 303 304 stype = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION; 305 mPreprocessor->GenerateRays(samplesPerPass / 4, sampleType, simpleRays); 304 mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays); 305 306 if (0) 307 { 308 stype = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION; 309 mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays); 310 } 306 311 307 312 stype = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION; 308 mPreprocessor->GenerateRays(samplesPerPass / 4, sampleType, simpleRays);313 mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays); 309 314 310 315 cout << "generated " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; … … 516 521 if (mEvaluateViewCells) 517 522 { 518 cout << "here42 ***********" << endl;519 523 EvalViewCellPartition(); 520 524 } … … 794 798 mViewCellsTree->CollectBestViewCellSet(viewCells, nViewCells); 795 799 796 int maxPvs, maxVal, minVal;800 float maxPvs, maxVal, minVal; 797 801 798 802 // sort by pvs size 799 803 sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs); 800 804 801 maxPvs = mViewCellsTree->GetPvs Size(viewCells.back());805 maxPvs = mViewCellsTree->GetPvsCost(viewCells.back()); 802 806 minVal = 0; 803 807 … … 805 809 int histoMaxVal; 806 810 Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal); 807 maxVal = max( histoMaxVal, maxPvs);811 maxVal = max((float)histoMaxVal, maxPvs); 808 812 809 813 Debug << "histogram minpvssize: " << minVal << " maxpvssize: " << maxVal … … 814 818 const int intervals = min(histoIntervals, (int)viewCells.size()); 815 819 816 const int range = maxVal - minVal;817 int stepSize = range / intervals;820 const float range = maxVal - minVal; 821 int stepSize = (int)(range / intervals); 818 822 819 823 // set step size to avoid endless loop … … 825 829 const float totalVol = GetViewSpaceBox().GetVolume(); 826 830 827 int currentPvs = minVal;//(int)ceil(minRenderCost);831 float currentPvs = minVal; 828 832 829 833 int i = 0; … … 840 844 841 845 while ((i < (int)viewCells.size()) && 842 (mViewCellsTree->GetPvs Size(viewCells[i]) < currentPvs))846 (mViewCellsTree->GetPvsCost(viewCells[i]) < currentPvs)) 843 847 { 844 848 volDif += viewCells[i]->GetVolume(); … … 851 855 852 856 if (0 && (i < (int)viewCells.size())) 853 Debug << "new pvs size increase: " << mViewCellsTree->GetPvsSize(viewCells[i])857 Debug << "new pvs cost increase: " << mViewCellsTree->GetPvsCost(viewCells[i]) 854 858 << " " << currentPvs << endl; 855 859 … … 864 868 outstream << "#VolumeSum\n" << volRatioSum << endl << endl; 865 869 866 //if ((i >= (int)viewCells.size()) || (currentPvs >= maxPvs)) break;867 868 870 //-- increase current pvs size to define next interval 869 871 currentPvs += stepSize; … … 1009 1011 ObjectPvs pvs; 1010 1012 1011 cout << "updating pvs for contribution ... " << endl;1013 cout << "updating pvs for evaluation ... " << endl; 1012 1014 1013 1015 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); … … 1499 1501 float &deviation, 1500 1502 float &variance, 1501 int &totalPvs,1503 float &totalCost, 1502 1504 float &avgRenderCost) 1503 1505 { … … 1506 1508 1507 1509 totalRenderCost = 0; 1508 total Pvs= 0;1510 totalCost = 0; 1509 1511 1510 1512 ViewCellContainer::const_iterator it, it_end = mViewCells.end(); … … 1514 1516 ViewCell *vc = *it; 1515 1517 totalRenderCost += vc->GetPvs().EvalPvsCost() * vc->GetVolume(); 1516 total Pvs+= (int)vc->GetPvs().EvalPvsCost();1518 totalCost += (int)vc->GetPvs().EvalPvsCost(); 1517 1519 } 1518 1520 … … 1520 1522 totalRenderCost /= mViewSpaceBox.GetVolume(); 1521 1523 expectedRenderCost = totalRenderCost / (float)mViewCells.size(); 1522 avgRenderCost = total Pvs/ (float)mViewCells.size();1524 avgRenderCost = totalCost / (float)mViewCells.size(); 1523 1525 1524 1526 … … 1744 1746 void ViewCellsManager::GetPvsStatistics(PvsStatistics &stat) 1745 1747 { 1746 // update pvs of view cells tree if necessary 1747 UpdatePvs(); 1748 1749 ViewCellContainer::const_iterator it = mViewCells.begin(); 1750 1751 stat.viewcells = 0; 1752 stat.minPvs = 100000000; 1753 stat.maxPvs = 0; 1754 stat.avgPvs = 0.0f; 1755 1756 for (; it != mViewCells.end(); ++ it) 1757 { 1758 ViewCell *viewcell = *it; 1759 1760 // bool mCountKdPvs = false; 1761 const int pvsSize = mViewCellsTree->GetPvsSize(viewcell); 1762 1763 1764 if (pvsSize < stat.minPvs) 1765 stat.minPvs = pvsSize; 1766 if (pvsSize > stat.maxPvs) 1767 stat.maxPvs = pvsSize; 1768 1769 stat.avgPvs += pvsSize; 1770 1771 ++ stat.viewcells; 1772 } 1773 1774 if (stat.viewcells) 1775 stat.avgPvs/=stat.viewcells; 1748 // update pvs of view cells tree if necessary 1749 UpdatePvs(); 1750 1751 ViewCellContainer::const_iterator it = mViewCells.begin(); 1752 1753 stat.viewcells = 0; 1754 stat.minPvs = 100000000; 1755 stat.maxPvs = 0; 1756 stat.avgPvs = 0.0f; 1757 1758 for (; it != mViewCells.end(); ++ it) 1759 { 1760 ViewCell *viewcell = *it; 1761 1762 const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 1763 1764 if (pvsCost < stat.minPvs) 1765 stat.minPvs = pvsCost; 1766 if (pvsCost > stat.maxPvs) 1767 stat.maxPvs = pvsCost; 1768 1769 stat.avgPvs += pvsCost; 1770 1771 ++ stat.viewcells; 1772 } 1773 1774 if (stat.viewcells) 1775 stat.avgPvs/=stat.viewcells; 1776 1776 } 1777 1777 … … 2053 2053 float ViewCellsManager::GetRendercost(ViewCell *viewCell) const 2054 2054 { 2055 return (float)mViewCellsTree->GetPvs Size(viewCell);2055 return (float)mViewCellsTree->GetPvsCost(viewCell); 2056 2056 } 2057 2057 … … 2327 2327 2328 2328 void ViewCellsManager::UpdateScalarPvsSize(ViewCell *vc, 2329 const int pvsSize,2329 const float pvsCost, 2330 2330 const int entriesInPvs) const 2331 2331 { 2332 vc->mPvs Size = pvsSize;2332 vc->mPvsCost = pvsCost; 2333 2333 vc->mEntriesInPvs = entriesInPvs; 2334 2334 … … 2525 2525 { 2526 2526 importance = 2527 (float)mViewCellsTree->GetPvs Size(vc) /2527 (float)mViewCellsTree->GetPvsCost(vc) / 2528 2528 (float)mCurrentViewCellsStats.maxPvs; 2529 2529 } … … 2578 2578 if (root->IsLeaf()) 2579 2579 { 2580 //cout << "updating leaf" << endl; 2580 2581 // we assume that pvs is explicitly stored in leaves 2581 2582 pvs = root->GetPvs(); 2582 2583 UpdateScalarPvsSize(root, pvs.EvalPvsCost(), pvs.GetSize()); 2583 2584 2584 return; 2585 2585 } 2586 2586 2587 //cout << "recursivly updating pvs" << endl; 2588 2587 2589 //////////////// 2588 2590 //-- interior node => propagate pvs up the tree … … 2597 2599 // pvss of child nodes 2598 2600 vector<ObjectPvs> pvsList; 2601 pvsList.resize((int)interior->mChildren.size()); 2599 2602 2600 2603 ViewCellContainer::const_iterator vit, vit_end = interior->mChildren.end(); 2601 pvsList.resize((int)interior->mChildren.size());2604 2602 2605 int i = 0; 2606 2603 2607 for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ i) 2604 2608 { 2605 //ObjectPvs objPvs;2606 2607 2609 ////////////////// 2608 2610 //-- recursivly compute child pvss 2609 2610 2611 UpdatePvsForEvaluation(*vit, pvsList[i]/*objPvs*/); 2611 2612 // store pvs in vector2613 //pvsList.push_back(objPvs);2614 2612 } 2615 2613 … … 3047 3045 Exporter *exporter = Exporter::GetExporter(s); 3048 3046 3049 cout << "view cell " << idx << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl;3047 cout << "view cell " << idx << ": pvs cost=" << (int)mViewCellsTree->GetPvsCost(vc) << endl; 3050 3048 3051 3049 if (exportRays) … … 4400 4398 Exporter *exporter = Exporter::GetExporter(s); 4401 4399 4402 const int pvsSize = (int)mViewCellsTree->GetPvsSize(vc);4403 cout << "view cell " << vc->GetId() << ": pvs size=" << pvsSize<< endl;4400 const float pvsCost = mViewCellsTree->GetPvsCost(vc); 4401 cout << "view cell " << vc->GetId() << ": pvs cost=" << pvsCost << endl; 4404 4402 4405 4403 if (exportRays) … … 5285 5283 Exporter *exporter = Exporter::GetExporter(s); 5286 5284 5287 cout << "view cell " << vc->GetId() << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl;5285 cout << "view cell " << vc->GetId() << ": pvs cost=" << mViewCellsTree->GetPvsCost(vc) << endl; 5288 5286 5289 5287 if (exportPvs) … … 5661 5659 5662 5660 5663 #if 05661 #if 1 5664 5662 #if TEST_EVALUATION 5665 5663 void VspOspViewCellsManager::EvalViewCellPartition() … … 5730 5728 { 5731 5729 ViewCell *vc = *vit; 5732 int pvs= vc->GetPvs().EvalPvsCost();5733 float vol = vc->GetVolume();5734 rc += pvs * vol;5730 const float pvsCost = vc->GetPvs().EvalPvsCost(); 5731 const float vol = vc->GetVolume(); 5732 rc += pvsCost * vol; 5735 5733 } 5736 5734 … … 5826 5824 sprintf(str, "-%09d-eval.log", castSamples); 5827 5825 string filename = string(statsPrefix) + string(str); 5828 5829 mHierarchyManager->EvaluateSubdivision (evaluationSamples, mPreprocessor->mObjects, filename);5826 ofstream ofstr(filename.c_str()); 5827 mHierarchyManager->EvaluateSubdivision2(ofstr); 5830 5828 5831 5829 timeDiff = TimeDiff(startTime, GetTime()); … … 5833 5831 Debug << "statistis compted in " << timeDiff * 1e-3 << " secs" << endl; 5834 5832 5835 //disposeRays(evaluationSamples, NULL); 5836 } 5837 5838 disposeRays(evaluationSamples, NULL); 5839 5833 disposeRays(evaluationSamples, NULL); 5834 } 5840 5835 } 5841 5836 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1707 r1709 64 64 struct PvsStatistics 65 65 { 66 int minPvs;67 int maxPvs;66 float minPvs; 67 float maxPvs; 68 68 float avgPvs; 69 69 int viewcells; … … 77 77 78 78 friend class X3dViewCellsParseHandlers; 79 79 80 /** Default constructor. 80 81 */ … … 90 91 /** Constructs view cell container with a given number of samples. 91 92 */ 92 virtual int ConstructSubdivision( 93 const ObjectContainer &objects, 94 const VssRayContainer &rays) = 0; 93 virtual int ConstructSubdivision(const ObjectContainer &objects, 94 const VssRayContainer &rays) = 0; 95 95 96 96 /** Computes sample contributions of the rays to the view cells PVS. … … 360 360 float &deviation, 361 361 float &variance, 362 int &totalPvs,362 float &totalPvs, 363 363 float &avgRenderCost); 364 364 … … 414 414 of the hierarchy. 415 415 */ 416 void UpdateScalarPvsSize(ViewCell *vc, const int pvsSize, const int entriesInPvs) const;416 void UpdateScalarPvsSize(ViewCell *vc, const float pvsCost, const int entriesInPvs) const; 417 417 418 418 /** Returns bounding box of a view cell. … … 1107 1107 protected: 1108 1108 1109 //#ifTEST_EVALUATION1110 //virtual void EvalViewCellPartition();1111 //#endif1109 #if 1//TEST_EVALUATION 1110 virtual void EvalViewCellPartition(); 1111 #endif 1112 1112 1113 1113 /** Exports view cell geometry.
Note: See TracChangeset
for help on using the changeset viewer.