Changeset 1161 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 07/27/06 02:07:26 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1159 r1161 2225 2225 optInt, 2226 2226 "vsp_max_tests=", 2227 " 2000");2227 "5000"); 2228 2228 2229 2229 -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
r1151 r1161 7 7 #include "Renderer.h" 8 8 #include "Beam.h" 9 #include "Pvs.h" 9 10 10 11 … … 67 68 // visible pixels 68 69 int mVisiblePixels; 70 71 ObjectPvs mPvs; 69 72 70 73 }; -
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) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1160 r1161 279 279 /// store pvs size, used for evaluation purpose when pvss are stored only in the leaves 280 280 int mPvsSize; 281 // stores number of entries in pvs 281 /** stores number of entries in pvs 282 this variable has the same value as mPvsSize for object pvs, 283 but usually not for kd cell based pvs 284 */ 282 285 int mEntriesInPvs; 283 286 284 /// if the pvs size scalar is up to date and corresponding to the real pvs size 287 /// if the pvs size scalar (+ entries into pvs) 288 /// is up to date and corresponding to the real pvs size 285 289 bool mPvsSizeValid; 286 290 … … 440 444 void GetPvs(ViewCell *vc, ObjectPvs &pvs) const; 441 445 442 /** Returns pvs size (i.e. the number of entries weighted by their "importance".446 /** Returns pvs size (i.e. the number of stored objects 443 447 */ 444 448 int GetPvsSize(ViewCell *vc) const; 445 449 446 /** Returns actual number of object in this pvs and the children. 447 */ 448 int GetNumPvsEntries(ViewCell *vc) const; 450 /** Returns number of entries associated with this view cell. 451 This returns the same value as the GetPvsSize function for object pvs, 452 but most likely different values for kd node based pvs. 453 */ 454 int GetPvsEntries(ViewCell *vc) const; 455 456 /** Returns the actual number of stored entries in the view cells sub tree. 457 */ 458 int GetStoredPvsEntriesNum(ViewCell *root) const; 449 459 450 460 /** Returns memory cost of this view cell. -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1160 r1161 3985 3985 if (ViewCellsTreeConstructed() && mCompressViewCells) 3986 3986 { 3987 int pvsEntries = mViewCellsTree->Get NumPvsEntries(mViewCellsTree->GetRoot());3987 int pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 3988 3988 Debug << "number of entries before compress: " << pvsEntries << endl; 3989 3989 3990 3990 mViewCellsTree->SetViewCellsStorage(ViewCellsTree::COMPRESSED); 3991 3991 3992 pvsEntries = mViewCellsTree->Get NumPvsEntries(mViewCellsTree->GetRoot());3992 pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 3993 3993 Debug << "number of entries after compress: " << pvsEntries << endl; 3994 3994 } … … 4589 4589 { 4590 4590 int numSamples; 4591 4591 4592 4592 Environment::GetSingleton()->GetIntValue("RenderSampler.samples", numSamples); 4593 4593 cout << "samples" << numSamples << endl; … … 4607 4607 4608 4608 4609 // counting the pvss 4609 // for each sample: 4610 // find view cells associated with the samples 4611 // store the sample pvs with the pvs associated with the view cell 4612 // for each view cell: 4613 // compute difference point sampled pvs - view cell pvs 4614 // export geometry with color coded pvs difference 4615 4616 std::map<ViewCell *, ObjectPvs> sampleMap; 4617 4610 4618 vector<RenderCostSample>::const_iterator rit, rit_end = samples.end(); 4611 4619 4612 //std::map<ViewCell *, ObjectPvs> sampleMap; 4613 4620 for (rit = samples.begin(); rit != rit_end; ++ rit) 4621 { 4622 RenderCostSample sample = *rit; 4623 4624 ViewCell *vc = GetViewCell(sample.mPosition); 4625 4626 std::map<ViewCell *, ObjectPvs>::iterator it = sampleMap.find(vc); 4627 4628 if (it == sampleMap.end()) 4629 { 4630 sampleMap[vc] = sample.mPvs; 4631 } 4632 else 4633 { 4634 (*it).second.Merge(sample.mPvs); 4635 } 4636 } 4637 4638 // visualize the view cells 4639 std::map<ViewCell *, ObjectPvs>::const_iterator vit, vit_end = sampleMap.end(); 4640 4641 Material m;//= RandomMaterial(); 4642 4643 for (vit = sampleMap.begin(); vit != vit_end; ++ vit) 4644 { 4645 ViewCell *vc = (*vit).first; 4646 4647 const int pvsVc = mViewCellsTree->GetPvsEntries(vc); 4648 const int pvs2 = (*vit).second.GetSize(); 4649 4650 m.mDiffuseColor.r = (float) (pvsVc - pvs2); 4651 m.mDiffuseColor.b = 1.0f; 4652 //exporter->SetForcedMaterial(m); 4653 4654 // ExportViewCellGeometry(exporter, vc, mClipPlane); 4655 4656 /* // counting the pvss 4614 4657 for (rit = samples.begin(); rit != rit_end; ++ rit) 4615 4658 { … … 4622 4665 4623 4666 DEL_PTR(hMesh); 4624 #if 0 4625 if (!sampleMap.find(vc)) 4626 sampleMap.insert(vc, sample.mVisibleObjects); 4627 else 4628 sampleMap[vc].Merge(Merge(sample.mVisibleObjects); 4629 #endif 4667 4668 */ 4630 4669 } 4631 4670 } … … 5044 5083 if (ViewCellsTreeConstructed() && mCompressViewCells) 5045 5084 { 5046 int pvsEntries = mViewCellsTree->Get NumPvsEntries(mViewCellsTree->GetRoot());5085 int pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 5047 5086 Debug << "number of entries before compress: " << pvsEntries << endl; 5048 5087 5049 5088 mViewCellsTree->SetViewCellsStorage(ViewCellsTree::COMPRESSED); 5050 5089 5051 pvsEntries = mViewCellsTree->Get NumPvsEntries(mViewCellsTree->GetRoot());5090 pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 5052 5091 Debug << "number of entries after compress: " << pvsEntries << endl; 5053 5092 } -
GTP/trunk/Lib/Vis/Preprocessing/src/common.h
r1145 r1161 484 484 485 485 // if the view cells should be exported and inported as gzstream 486 #define ZIPPED_VIEWCELLS 0487 488 #endif 489 490 491 492 493 494 495 496 497 498 499 486 #define ZIPPED_VIEWCELLS 1 487 488 #endif 489 490 491 492 493 494 495 496 497 498 499
Note: See TracChangeset
for help on using the changeset viewer.