- Timestamp:
- 11/01/06 18:36:21 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1705 r1706 310 310 virtual void CollectObjects(ObjectContainer &objects); 311 311 312 /** returns level of the hierarchy that is "active" right now. 313 */ 314 BvhNode *GetActiveNode() 315 { 316 return mActiveNode; 317 } 318 312 319 public: 313 320 … … 323 330 /// pointer to a split plane candidate splitting this leaf 324 331 SubdivisionCandidate *mSubdivisionCandidate; 332 333 334 BvhNode *mActiveNode; 325 335 }; 326 336 -
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 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1686 r1706 450 450 void ExportStats(ofstream &stats, SplitQueue &tQueue, const ObjectContainer &objects); 451 451 452 void CollectBestSet(const int maxSplits, 453 const float maxMemoryCost, 454 vector<VspNode *> &vspNodes, 455 vector<BvhNode *> &bvhNodes); 456 457 void ExtractStatistics(const int maxSplits, 458 const float maxMemoryCost, 459 float &renderCost, 460 float &memory, 461 int &pvsEntries); 452 462 protected: 453 463 -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1694 r1706 29 29 class PvsData { 30 30 public: 31 32 33 34 35 31 /// sum of probability density of visible sample rays 32 float mSumPdf; 33 34 PvsData() {} 35 PvsData(const float sumPdf): 36 36 mSumPdf(sumPdf) {} 37 37 38 39 40 41 42 43 38 // $$JB in order to return meaningfull values 39 // it assumes that the sum pdf has been normalized somehow!!! 40 float GetVisibility() 41 { 42 return mSumPdf; 43 } 44 44 }; 45 45 … … 47 47 class MailablePvsData 48 48 { 49 ////////////////////////////50 // Mailing stuff49 //////////////////////////// 50 // Mailing stuff 51 51 protected: 52 52 int mMailbox; 53 53 54 54 public: 55 56 57 58 59 60 55 // last mail id -> warning not thread safe! 56 // both mailId and mailbox should be unique for each thread!!! 57 static int sMailId; 58 static int sReservedMailboxes; 59 60 61 61 static void NewMail(const int reserve = 1) { 62 62 sMailId += sReservedMailboxes; 63 63 sReservedMailboxes = reserve; 64 64 } 65 65 66 66 void Mail() { mMailbox = sMailId; } 67 67 bool Mailed() const { return mMailbox == sMailId; } … … 71 71 72 72 int IncMail() { return ++ mMailbox - sMailId; } 73 //////////////////////////////////////////74 75 76 77 78 79 80 73 ////////////////////////////////////////// 74 75 // sum of probability density of visible sample rays 76 float mSumPdf; 77 int mCounter; 78 79 MailablePvsData() {} 80 MailablePvsData(const float sumPdf): 81 81 mSumPdf(sumPdf) {} 82 82 83 84 85 86 87 88 83 // $$JB in order to return meaningfull values 84 // it assumes that the sum pdf has been normalized somehow!!! 85 float GetVisibility() 86 { 87 return mSumPdf; 88 } 89 89 }; 90 90 … … 97 97 { 98 98 public: 99 Pvs(): /*mSamples(0), */mEntries() {} 100 101 //virtual ~Pvs(); 102 103 /** Compresses PVS lossless or lossy. 104 */ 105 int Compress() {return 0;} 106 int GetSize() const {return (int)mEntries.size();} 107 bool Empty() const {return mEntries.empty();} 108 109 /** Normalize the visibility of entries in order to get comparable 110 results 111 */ 112 void NormalizeMaximum(); 113 114 /** Merges pvs of a into this pvs. 115 */ 116 void Merge(const Pvs<T, S> &a); 117 118 /** Difference of pvs to pvs b. 119 @returns number of different entries. 120 */ 121 int Diff(const Pvs<T, S> &b); 122 123 /** Finds sample in PVS. 124 @returns sample if found, NULL otherwise. 125 */ 126 S *Find(T sample); 127 128 bool GetSampleContribution(T sample, const float pdf, float &contribution); 129 130 /** Adds sample to PVS. 131 @contribution contribution of sample (0 or 1) 132 @returns true if sample was not already in PVS. 133 */ 134 bool AddSample(T sample, const float pdf, float &contribution); 135 136 /** Adds sample to PVS. 137 @returns contribution of sample (0 or 1) 138 */ 139 float AddSample(T sample, const float pdf); 140 141 /** Adds sample to PVS. 142 @returns PvsData 143 */ 144 S *AddSample2(T sample, const float pdf); 145 146 /** Adds one pvs to another one. 147 @returns new pvs size 148 */ 149 int AddPvs(const Pvs<T, S> &pvs); 150 151 /** Subtracts one pvs from another one. 152 WARNING: could contains bugs 153 @returns new pvs size 154 */ 155 int SubtractPvs(const Pvs<T, S> &pvs); 156 /** Returns PVS data, i.e., how often it was seen from the view cell, 157 and the object itsef. 158 */ 159 void GetData(const int index, T &entry, S &data); 160 161 /** Collects the PVS entries and returns them in the vector. 162 */ 163 void CollectEntries(std::vector<T> &entries); 164 165 /** Removes sample from PVS if reference count is zero. 166 @param visibleSamples number of references to be removed 167 */ 168 bool RemoveSample(T sample, const float pdf); 169 170 /** Compute continuous PVS difference */ 171 void ComputeContinuousPvsDifference(Pvs<T, S> &pvs, 172 float &pvsReduction, 173 float &pvsEnlargement); 174 175 176 /** Clears the pvs. 177 */ 178 void Clear(); 179 180 static int GetEntrySizeByte(); 181 static float GetEntrySize(); 182 183 /** Compute continuous PVS difference */ 184 float GetPvsHomogenity(Pvs<T, S> &pvs) { 185 float 186 pvsReduction, 187 pvsEnlargement; 188 189 ComputeContinuousPvsDifference(pvs, 190 pvsReduction, 191 pvsEnlargement); 192 193 return pvsReduction + pvsEnlargement; 194 } 195 196 int Size() { return mEntries.size(); } 197 198 /// Map of PVS entries 199 std::map<T, S, LtSample<T> > mEntries; 99 Pvs(): /*mSamples(0), */mEntries() {} 100 101 //virtual ~Pvs(); 102 103 /** Compresses PVS lossless or lossy. 104 */ 105 int Compress() {return 0;} 106 int GetSize() const {return (int)mEntries.size();} 107 bool Empty() const {return mEntries.empty();} 108 109 /** Normalize the visibility of entries in order to get comparable 110 results 111 */ 112 void NormalizeMaximum(); 113 114 /** Merges pvs of a into this pvs. 115 */ 116 void Merge(const Pvs<T, S> &a); 117 118 /** Difference of pvs to pvs b. 119 @returns number of different entries. 120 */ 121 int Diff(const Pvs<T, S> &b); 122 123 /** Finds sample in PVS. 124 @returns sample if found, NULL otherwise. 125 */ 126 S *Find(T sample); 127 128 bool GetSampleContribution(T sample, const float pdf, float &contribution); 129 130 /** Adds sample to PVS. 131 @contribution contribution of sample (0 or 1) 132 @returns true if sample was not already in PVS. 133 */ 134 bool AddSample(T sample, const float pdf, float &contribution); 135 136 /** Adds sample to PVS. 137 @returns contribution of sample (0 or 1) 138 */ 139 float AddSample(T sample, const float pdf); 140 141 /** Adds sample to PVS. 142 @returns PvsData 143 */ 144 S *AddSample2(T sample, const float pdf); 145 146 /** Adds one pvs to another one. 147 @returns new pvs size 148 */ 149 int AddPvs(const Pvs<T, S> &pvs); 150 151 /** Subtracts one pvs from another one. 152 WARNING: could contains bugs 153 @returns new pvs size 154 */ 155 int SubtractPvs(const Pvs<T, S> &pvs); 156 /** Returns PVS data, i.e., how often it was seen from the view cell, 157 and the object itsef. 158 */ 159 void GetData(const int index, T &entry, S &data); 160 161 /** Collects the PVS entries and returns them in the vector. 162 */ 163 void CollectEntries(std::vector<T> &entries); 164 165 /** Removes sample from PVS if reference count is zero. 166 @param visibleSamples number of references to be removed 167 */ 168 bool RemoveSample(T sample, const float pdf); 169 170 /** Compute continuous PVS difference 171 */ 172 void ComputeContinuousPvsDifference(Pvs<T, S> &pvs, 173 float &pvsReduction, 174 float &pvsEnlargement); 175 176 177 /** Clears the pvs. 178 */ 179 void Clear(); 180 181 static int GetEntrySizeByte(); 182 static float GetEntrySize(); 183 184 /** Compute continuous PVS difference */ 185 float GetPvsHomogenity(Pvs<T, S> &pvs) { 186 float 187 pvsReduction, 188 pvsEnlargement; 189 190 ComputeContinuousPvsDifference(pvs, 191 pvsReduction, 192 pvsEnlargement); 193 194 return pvsReduction + pvsEnlargement; 195 } 196 197 int Size() { return mEntries.size(); } 198 199 /// Map of PVS entries 200 std::map<T, S, LtSample<T> > mEntries; 200 201 }; 201 202 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1695 r1706 686 686 mergedVc->SetMergeCost(totalRenderCost); 687 687 688 // HACK689 //mergedVc->SetMergeCost(1.0f / (float)realNumActiveViewCells);690 691 688 // check if "siblings (back and front node of the same parent) 692 if (0) 693 ++ mergeStats.siblings; 694 // set the co Žst for rendering a view cell689 if (0) ++ mergeStats.siblings; 690 691 // set the cost for rendering a view cell 695 692 mergedVc->SetCost(realExpectedCost); 696 693 … … 763 760 } 764 761 765 // test if voluje is equal 766 Debug << "volume of the root view cell: " << mRoot->GetVolume() << " " << mViewCellsManager->GetViewSpaceBox().GetVolume() << endl; 767 768 //hack!! 769 //mRoot->GetPvs().Clear(); 762 // test if computed volumes are correct 763 Debug << "volume of the root view cell: " << mRoot->GetVolume() 764 << " " << mViewCellsManager->GetViewSpaceBox().GetVolume() << endl; 770 765 771 766 // TODO: delete because makes no sense here
Note: See TracChangeset
for help on using the changeset viewer.