Changeset 1027 for GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
- Timestamp:
- 06/21/06 09:44:39 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1023 r1027 53 53 void VspTreeStatistics::Print(ostream &app) const 54 54 { 55 #if TODO 56 app << "===== BspTree statistics ===============\n"; 55 app << "===== VspTree statistics ===============\n"; 57 56 58 57 app << setprecision(4); … … 65 64 66 65 app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n"; 67 68 app << "#N_POLYSPLITS ( Number of polygon splits )\n" << polySplits << "\n";69 66 70 67 app << "#AXIS_ALIGNED_SPLITS (number of axis aligned splits)\n" << splits[0] + splits[1] + splits[2] << endl; … … 100 97 app << "#AVGDEPTH ( average depth )\n" << AvgDepth() << endl; 101 98 102 app << "#N_INPUTPOLYGONS (number of input polygons )\n" << polys << endl;103 104 99 app << "#N_INVALIDLEAVES (number of invalid leaves )\n" << invalidLeaves << endl; 105 100 … … 107 102 //app << "#N_PVS: " << pvs << endl; 108 103 109 app << "#N_ROUTPUT_INPUT_POLYGONS ( ratio polygons after subdivision / input polygons )\n" << 110 (polys + polySplits) / (double)polys << endl; 111 112 app << "===== END OF BspTree statistics ==========\n"; 113 #endif 104 app << "===== END OF VspTree statistics ==========\n"; 114 105 } 115 106 … … 267 258 return Interior; 268 259 } 260 261 269 262 270 263 /****************************************************************/ … … 449 442 { 450 443 mVspStats.nodes = 1; 451 mBoundingBox.Initialize(); // initialise vsp tree bounding box 452 444 453 445 if (forcedBoundingBox) 446 { 454 447 mBoundingBox = *forcedBoundingBox; 455 456 VssRayContainer::const_iterator rit, rit_end = sampleRays.end();457 458 Intersectable::NewMail();459 460 //-- compute bounding box461 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 462 {463 VssRay *ray = *rit; 464 465 // compute bounding box of view space466 if (!forcedBoundingBox) 467 {448 } 449 else // compute vsp tree bounding box 450 { 451 mBoundingBox.Initialize(); 452 453 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 454 455 //-- compute bounding box 456 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 457 { 458 VssRay *ray = *rit; 459 460 // compute bounding box of view space 468 461 mBoundingBox.Include(ray->GetTermination()); 469 462 mBoundingBox.Include(ray->GetOrigin()); 470 463 } 471 } 472 473 mTermMinProbability *= mBoundingBox.GetVolume();474 mGlobalCostMisses = 0;464 465 mTermMinProbability *= mBoundingBox.GetVolume(); 466 mGlobalCostMisses = 0; 467 } 475 468 } 476 469 … … 480 473 const float splitCandidateCost, 481 474 const float totalRenderCost, 482 475 const float avgRenderCost) 483 476 { 484 477 mSubdivisionStats … … 507 500 { 508 501 return 502 #if TODO 509 503 (((int)data.mRays->size() <= mTermMinRays) || 510 504 (data.mPvs <= mTermMinPvs) || … … 512 506 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 513 507 (data.mDepth >= mTermMaxDepth)); 508 #else 509 false; 510 #endif 514 511 } 515 512 … … 518 515 { 519 516 return 517 #if TODO 520 518 (mOutOfMemory || 521 519 (mVspStats.Leaves() >= mMaxViewCells) || 522 520 (mGlobalCostMisses >= mTermGlobalCostMissTolerance)); 521 #else 522 (mVspStats.Leaves() >= mMaxViewCells) ; 523 #endif 523 524 } 524 525 … … 633 634 634 635 void VspTree::EvalSplitCandidate(VspTraversalData &tData, 635 VspSplitCandidate &split Data)636 VspSplitCandidate &splitCandidate) 636 637 { 637 638 float frontProb; 638 float back tProb;639 float backProb; 639 640 640 641 VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode); … … 642 643 // compute locally best split plane 643 644 const bool success = 644 SelectPlane(tData, splitData.mSplitPlane, 645 frontProb, backtProb); 646 647 //TODO 645 SelectSplitPlane(tData, splitCandidate.mSplitPlane, frontProb, backProb); 646 648 647 // compute global decrease in render cost 649 splitData.mPriority = EvalRenderCostDecrease(splitData.mSplitPlane, tData); 650 splitData.mParentData = tData; 651 splitData.mMaxCostMisses = success ? tData.mMaxCostMisses : tData.mMaxCostMisses + 1; 648 splitCandidate.mPriority = EvalRenderCostDecrease(splitCandidate.mSplitPlane, tData); 649 splitCandidate.mParentData = tData; 650 splitCandidate.mMaxCostMisses = success ? tData.mMaxCostMisses : tData.mMaxCostMisses + 1; 651 652 Debug << "p: " << tData.mNode << " depth: " << tData.mDepth << endl; 652 653 } 653 654 … … 673 674 *backData.mRays); 674 675 676 Debug << "f: " << frontData.mRays->size() << " b: " << backData.mRays->size() << "d: " << tData.mRays->size() << endl; 675 677 //-- compute pvs 676 678 frontData.mPvs = ComputePvsSize(*frontData.mRays); … … 831 833 832 834 833 float VspTree:: BestCostRatioHeuristics(const RayInfoContainer &rays,834 835 836 837 835 float VspTree::EvalLocalCostHeuristics(const RayInfoContainer &rays, 836 const AxisAlignedBox3 &box, 837 const int pvsSize, 838 const int axis, 839 float &position) 838 840 { 839 841 const float minBox = box.Min(axis); … … 1003 1005 1004 1006 1005 float VspTree::Select Plane(const VspTraversalData &tData,1006 1007 1008 1007 float VspTree::SelectSplitPlane(const VspTraversalData &tData, 1008 AxisAlignedPlane &plane, 1009 float &pFront, 1010 float &pBack) 1009 1011 { 1010 1012 float nPosition[3]; … … 1019 1021 int bestAxis = -1; 1020 1022 1021 1022 1023 // if we use some kind of specialised fixed axis 1023 1024 const bool useSpecialAxis = 1024 1025 mOnlyDrivingAxis || mCirculatingAxis; 1025 1026 1027 int parentAxis = 0; 1028 VspNode *parent = tData.mNode->GetParent(); 1029 1030 if (parent) 1031 parentAxis = dynamic_cast<VspInterior *>(parent)->GetAxis(); 1032 1026 1033 if (mCirculatingAxis) 1027 sAxis = ( tData.mAxis + 1) % 3;1034 sAxis = (parentAxis + 1) % 3; 1028 1035 else if (mOnlyDrivingAxis) 1029 1036 sAxis = box.Size().DrivingAxis(); … … 1039 1046 { 1040 1047 nCostRatio[axis] = 1041 BestCostRatioHeuristics(*tData.mRays,1042 1048 EvalLocalCostHeuristics(*tData.mRays, 1049 box, 1043 1050 tData.mPvs, 1044 1051 axis, … … 1049 1056 nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 1050 1057 1051 nCostRatio[axis] = Eval SplitCost(tData,1052 box,1053 axis,1054 nPosition[axis],1055 nProbFront[axis],1056 nProbBack[axis]);1058 nCostRatio[axis] = EvalLocalSplitCost(tData, 1059 box, 1060 axis, 1061 nPosition[axis], 1062 nProbFront[axis], 1063 nProbBack[axis]); 1057 1064 } 1058 1065 … … 1091 1098 const VspTraversalData &data) const 1092 1099 { 1100 #if 1 1101 return -data.mDepth; 1102 #endif 1093 1103 float pvsFront = 0; 1094 1104 float pvsBack = 0; … … 1112 1122 float t; 1113 1123 VssRay *ray = rayInf.mRay; 1124 1114 1125 const int cf = 1115 1126 rayInf.ComputeRayIntersection(candidatePlane.mAxis, … … 1120 1131 AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 1121 1132 } 1133 1122 1134 1123 1135 AxisAlignedBox3 frontBox; … … 1145 1157 const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBoundingBox.GetVolume(); 1146 1158 1147 1148 #if 11149 1159 // take render cost of node into account 1150 1160 // otherwise danger of being stuck in a local minimum!! 1161 const float factor = 0.99f; 1162 1151 1163 const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 1152 return 0.99f * renderCostDecrease + 0.01f * normalizedOldRenderCost; 1153 #else 1154 return renderCostDecrease; 1155 #endif 1156 } 1157 1158 1159 float VspTree::EvalSplitCost(const VspTraversalData &data, 1160 const AxisAlignedBox3 &box, 1161 const int axis, 1162 const float &position, 1163 float &pFront, 1164 float &pBack) const 1164 return factor * renderCostDecrease + (1.0f - factor) * normalizedOldRenderCost; 1165 } 1166 1167 1168 float VspTree::EvalLocalSplitCost(const VspTraversalData &data, 1169 const AxisAlignedBox3 &box, 1170 const int axis, 1171 const float &position, 1172 float &pFront, 1173 float &pBack) const 1165 1174 { 1166 1175 float pvsTotal = 0; … … 1190 1199 1191 1200 //-- compute heurstics 1192 //-- we take simplified computation for mid split 1193 1201 1194 1202 pOverall = data.mProbability; 1203 // we take simplified computation for mid split 1195 1204 pBack = pFront = pOverall * 0.5f; 1196 1205 … … 1210 1219 1211 1220 void VspTree::AddObjToPvs(Intersectable *obj, 1212 1213 1214 1215 1221 const int cf, 1222 float &frontPvs, 1223 float &backPvs, 1224 float &totalPvs) const 1216 1225 { 1217 1226 if (!obj) … … 1352 1361 ++ mCreatedViewCells; 1353 1362 1354 #ifdef _DEBUG1363 //#ifdef _DEBUG 1355 1364 Debug << "BSP stats: " 1356 1365 << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " 1357 1366 << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 1358 // << "Area: " << data.mProbability << " (min: " << mTermMinProbability << "), "1359 1367 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 1360 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << " =, "1368 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 1361 1369 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 1362 #endif1370 //#endif 1363 1371 } 1364 1372 … … 1605 1613 1606 1614 if (GetBBox(interior->GetBack()).Side(plane) < 0) 1615 { 1607 1616 next = interior->GetFront(); 1617 } 1608 1618 else 1619 { 1609 1620 if (GetBBox(interior->GetFront()).Side(plane) < 0) 1621 { 1610 1622 next = interior->GetBack(); 1623 } 1611 1624 else 1612 1625 { … … 1618 1631 mask = mask >> 1; 1619 1632 } 1620 1621 nodeStack.push(next); 1633 } 1634 1635 nodeStack.push(next); 1622 1636 } 1623 1637 } … … 1704 1718 1705 1719 int VspTree::CastLineSegment(const Vector3 &origin, 1706 1707 1720 const Vector3 &termination, 1721 ViewCellContainer &viewcells) 1708 1722 { 1709 1723 int hits = 0; … … 1722 1736 VspNode *node = mRoot; 1723 1737 VspNode *farChild; 1738 1739 float position; 1740 int axis; 1741 1742 while (1) 1743 { 1744 if (!node->IsLeaf()) 1745 { 1746 VspInterior *in = dynamic_cast<VspInterior *>(node); 1747 position = in->GetPosition(); 1748 axis = in->GetAxis(); 1749 1750 if (entp[axis] <= position) 1751 { 1752 if (extp[axis] <= position) 1753 { 1754 node = in->GetFront(); 1755 // cases N1,N2,N3,P5,Z2,Z3 1756 continue; 1757 } else 1758 { 1759 // case N4 1760 node = in->GetFront(); 1761 farChild = in->GetBack(); 1762 } 1763 } 1764 else 1765 { 1766 if (position <= extp[axis]) 1767 { 1768 node = in->GetBack(); 1769 // cases P1,P2,P3,N5,Z1 1770 continue; 1771 } 1772 else 1773 { 1774 node = in->GetBack(); 1775 farChild = in->GetFront(); 1776 // case P4 1777 } 1778 } 1779 1780 // $$ modification 3.5.2004 - hints from Kamil Ghais 1781 // case N4 or P4 1782 const float tdist = (position - origin[axis]) / dir[axis]; 1783 tStack.push(LineTraversalData(farChild, extp, maxt)); //TODO 1784 1785 extp = origin + dir * tdist; 1786 maxt = tdist; 1787 } 1788 else 1789 { 1790 // compute intersection with all objects in this leaf 1791 VspLeaf *leaf = dynamic_cast<VspLeaf *>(node); 1792 ViewCell *vc = leaf->GetViewCell(); 1793 1794 if (!vc->Mailed()) 1795 { 1796 vc->Mail(); 1797 viewcells.push_back(vc); 1798 ++ hits; 1799 } 1800 #if 0 1801 leaf->mRays.push_back(RayInfo(new VssRay(origin, termination, NULL, NULL, 0))); 1802 #endif 1803 // get the next node from the stack 1804 if (tStack.empty()) 1805 break; 1806 1807 entp = extp; 1808 mint = maxt; 1809 1810 LineTraversalData &s = tStack.top(); 1811 node = s.mNode; 1812 extp = s.mExitPoint; 1813 maxt = s.mMaxT; 1814 tStack.pop(); 1815 } 1816 } 1817 1818 return hits; 1819 } 1820 1821 1822 int VspTree::CastRay(Ray &ray) 1823 { 1824 int hits = 0; 1825 1826 stack<LineTraversalData> tStack; 1827 const Vector3 dir = ray.GetDir(); 1828 1829 float maxt, mint; 1830 1831 if (!mBoundingBox.GetRaySegment(ray, mint, maxt)) 1832 return 0; 1833 1834 Intersectable::NewMail(); 1835 ViewCell::NewMail(); 1836 1837 Vector3 entp = ray.Extrap(mint); 1838 Vector3 extp = ray.Extrap(maxt); 1839 1840 const Vector3 origin = entp; 1841 1842 VspNode *node = mRoot; 1843 VspNode *farChild = NULL; 1724 1844 1725 1845 float position; … … 1741 1861 // cases N1,N2,N3,P5,Z2,Z3 1742 1862 continue; 1743 } else 1863 } 1864 else 1744 1865 { 1745 1866 // case N4 … … 1768 1889 const float tdist = (position - origin[axis]) / dir[axis]; 1769 1890 tStack.push(LineTraversalData(farChild, extp, maxt)); //TODO 1770 1771 1891 extp = origin + dir * tdist; 1772 1892 maxt = tdist; … … 1781 1901 { 1782 1902 vc->Mail(); 1783 viewcells.push_back(vc);1903 // todo: add view cells to ray 1784 1904 ++ hits; 1785 1905 } … … 1804 1924 return hits; 1805 1925 } 1806 1807 1808 int VspTree::CastRay(Ray &ray)1809 {1810 int hits = 0;1811 1812 stack<LineTraversalData> tStack;1813 const Vector3 dir = ray.GetDir();1814 1815 float maxt, mint;1816 1817 if (!mBoundingBox.GetRaySegment(ray, mint, maxt))1818 return 0;1819 1820 Intersectable::NewMail();1821 ViewCell::NewMail();1822 1823 Vector3 entp = ray.Extrap(mint);1824 Vector3 extp = ray.Extrap(maxt);1825 1826 const Vector3 origin = entp;1827 1828 VspNode *node = mRoot;1829 VspNode *farChild = NULL;1830 1831 float position;1832 int axis;1833 1834 while (1)1835 {1836 if (!node->IsLeaf())1837 {1838 VspInterior *in = dynamic_cast<VspInterior *>(node);1839 position = in->GetPosition();1840 axis = in->GetAxis();1841 1842 if (entp[axis] <= position)1843 {1844 if (extp[axis] <= position)1845 {1846 node = in->GetBack();1847 // cases N1,N2,N3,P5,Z2,Z31848 continue;1849 }1850 else1851 {1852 // case N41853 node = in->GetBack();1854 farChild = in->GetFront();1855 }1856 }1857 else1858 {1859 if (position <= extp[axis])1860 {1861 node = in->GetFront();1862 // cases P1,P2,P3,N5,Z11863 continue;1864 }1865 else1866 {1867 node = in->GetFront();1868 farChild = in->GetBack();1869 // case P41870 }1871 }1872 1873 // $$ modification 3.5.2004 - hints from Kamil Ghais1874 // case N4 or P41875 const float tdist = (position - origin[axis]) / dir[axis];1876 tStack.push(LineTraversalData(farChild, extp, maxt)); //TODO1877 extp = origin + dir * tdist;1878 maxt = tdist;1879 }1880 else1881 {1882 // compute intersection with all objects in this leaf1883 VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);1884 ViewCell *vc = leaf->GetViewCell();1885 1886 if (!vc->Mailed())1887 {1888 vc->Mail();1889 // todo: add view cells to ray1890 ++ hits;1891 }1892 #if 01893 leaf->mRays.push_back(RayInfo(new VssRay(origin, termination, NULL, NULL, 0)));1894 #endif1895 // get the next node from the stack1896 if (tStack.empty())1897 break;1898 1899 entp = extp;1900 mint = maxt;1901 1902 LineTraversalData &s = tStack.top();1903 node = s.mNode;1904 extp = s.mExitPoint;1905 maxt = s.mMaxT;1906 tStack.pop();1907 }1908 }1909 1910 return hits;1911 }1912 1913 1914 VspNode *VspTree::CollapseTree(VspNode *node, int &collapsed)1915 {1916 // TODO1917 #if HAS_TO_BE_REDONE1918 if (node->IsLeaf())1919 return node;1920 1921 VspInterior *interior = dynamic_cast<VspInterior *>(node);1922 1923 VspNode *front = CollapseTree(interior->GetFront(), collapsed);1924 VspNode *back = CollapseTree(interior->GetBack(), collapsed);1925 1926 if (front->IsLeaf() && back->IsLeaf())1927 {1928 VspLeaf *frontLeaf = dynamic_cast<VspLeaf *>(front);1929 VspLeaf *backLeaf = dynamic_cast<VspLeaf *>(back);1930 1931 //-- collapse tree1932 if (frontLeaf->GetViewCell() == backLeaf->GetViewCell())1933 {1934 BspViewCell *vc = frontLeaf->GetViewCell();1935 1936 VspLeaf *leaf = new VspLeaf(interior->GetParent(), vc);1937 leaf->SetTreeValid(frontLeaf->TreeValid());1938 1939 // replace a link from node's parent1940 if (leaf->GetParent())1941 leaf->GetParent()->ReplaceChildLink(node, leaf);1942 else1943 mRoot = leaf;1944 1945 ++ collapsed;1946 delete interior;1947 1948 return leaf;1949 }1950 }1951 #endif1952 return node;1953 }1954 1955 1956 int VspTree::CollapseTree()1957 {1958 int collapsed = 0;1959 1960 (void)CollapseTree(mRoot, collapsed);1961 // revalidate leaves1962 RepairViewCellsLeafLists();1963 1964 return collapsed;1965 }1966 1967 1968 void VspTree::RepairViewCellsLeafLists()1969 {1970 // TODO1971 #if HAS_TO_BE_REDONE1972 // list not valid anymore => clear1973 stack<VspNode *> nodeStack;1974 nodeStack.push(mRoot);1975 1976 ViewCell::NewMail();1977 1978 while (!nodeStack.empty())1979 {1980 VspNode *node = nodeStack.top();1981 nodeStack.pop();1982 1983 if (node->IsLeaf())1984 {1985 VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);1986 1987 BspViewCell *viewCell = leaf->GetViewCell();1988 1989 if (!viewCell->Mailed())1990 {1991 viewCell->mLeaves.clear();1992 viewCell->Mail();1993 }1994 1995 viewCell->mLeaves.push_back(leaf);1996 1997 }1998 else1999 {2000 VspInterior *interior = dynamic_cast<VspInterior *>(node);2001 2002 nodeStack.push(interior->GetFront());2003 nodeStack.push(interior->GetBack());2004 }2005 }2006 // TODO2007 #endif2008 }2009 2010 1926 2011 1927 … … 2171 2087 //-- test if start point behind or in front of plane 2172 2088 const int side = plane.ComputeRayIntersection(bRay, t); 2173 2089 #if 1 2174 2090 if (side == 0) 2175 2091 { … … 2195 2111 backRays.push_back(bRay); 2196 2112 } 2197 2113 #else 2114 if (side == 0) 2115 { 2116 ++ splits; 2117 2118 if (ray->HasPosDir(plane.mAxis)) 2119 { 2120 backRays.push_back(RayInfo(ray, bRay.GetMaxT(), t)); 2121 frontRays.push_back(RayInfo(ray, t, bRay.GetMinT())); 2122 } 2123 else 2124 { 2125 frontRays.push_back(RayInfo(ray, bRay.GetMaxT(), t)); 2126 backRays.push_back(RayInfo(ray, t, bRay.GetMinT())); 2127 } 2128 } 2129 else if (side == 1) 2130 { 2131 backRays.push_back(bRay); 2132 } 2133 else 2134 { 2135 frontRays.push_back(bRay); 2136 2137 } 2138 #endif 2198 2139 } 2199 2140 … … 2216 2157 AxisAlignedBox3 box(parent->GetBoundingBox()); 2217 2158 2218 if (parent->Get Front() == node)2159 if (parent->GetBack() == node) 2219 2160 box.SetMin(parent->GetAxis(), parent->GetPosition()); 2220 2161 else … … 2230 2171 ViewCellContainer &viewCells) const 2231 2172 { 2232 #if TODO 2233 stack<bspNodePair> nodeStack; 2234 BspNodeGeometry *rgeom = new BspNodeGeometry(); 2235 2236 ConstructGeometry(mRoot, *rgeom); 2237 2238 nodeStack.push(bspNodePair(mRoot, rgeom)); 2239 2173 stack<VspNode *> nodeStack; 2174 2240 2175 ViewCell::NewMail(); 2241 2176 2242 2177 while (!nodeStack.empty()) 2243 2178 { 2244 BspNode *node = nodeStack.top().first; 2245 BspNodeGeometry *geom = nodeStack.top().second; 2179 VspNode *node = nodeStack.top(); 2246 2180 nodeStack.pop(); 2247 2181 2248 const int side = geom->ComputeIntersection(box); 2249 2250 switch (side) 2251 { 2252 case -1: 2182 const AxisAlignedBox3 bbox = GetBBox(node); 2183 2184 if (bbox.Includes(box)) 2185 { 2253 2186 // node geometry is contained in box 2254 2187 CollectViewCells(node, true, viewCells, true); 2255 break;2256 2257 case 0:2188 } 2189 else if (Overlap(bbox, box)) 2190 { 2258 2191 if (node->IsLeaf()) 2259 2192 { … … 2268 2201 else 2269 2202 { 2270 BspInterior *interior = dynamic_cast<BspInterior *>(node);2203 VspInterior *interior = dynamic_cast<VspInterior *>(node); 2271 2204 2272 BspNode *first = interior->GetFront();2273 BspNode *second = interior->GetBack();2205 VspNode *first = interior->GetFront(); 2206 VspNode *second = interior->GetBack(); 2274 2207 2275 BspNodeGeometry *firstGeom = new BspNodeGeometry(); 2276 BspNodeGeometry *secondGeom = new BspNodeGeometry(); 2277 2278 geom->SplitGeometry(*firstGeom, 2279 *secondGeom, 2280 interior->GetPlane(), 2281 mBox, 2282 //0.0000001f); 2283 mEpsilon); 2284 2285 nodeStack.push(bspNodePair(first, firstGeom)); 2286 nodeStack.push(bspNodePair(second, secondGeom)); 2287 } 2288 2289 break; 2290 default: 2291 // default: cull 2292 break; 2293 } 2294 DEL_PTR(geom); 2295 } 2296 2297 #endif 2208 nodeStack.push(first); 2209 nodeStack.push(second); 2210 } 2211 } 2212 // default: cull 2213 } 2214 2298 2215 return (int)viewCells.size(); 2299 2216 } … … 2304 2221 /* class OspTree implementation */ 2305 2222 /*****************************************************************/ 2223 2306 2224 2307 2225 OspTree::OspTree(): … … 2499 2417 // create new interior node and two leaf node 2500 2418 const AxisAlignedPlane splitPlane = splitCandidate.mSplitPlane; 2419 2501 2420 newNode = SubdivideNode(dynamic_cast<KdLeaf *>(newNode), 2502 2421 splitPlane, … … 2635 2554 // << "Area: " << data.mProbability << " (min: " << mTermMinProbability << "), " 2636 2555 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 2637 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << " =, "2556 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 2638 2557 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 2639 2558 #endif … … 2647 2566 /*********************************************************************/ 2648 2567 2649 HierarchyManager::HierarchyManager() 2568 HierarchyManager::HierarchyManager(VspTree &vspTree, OspTree &ospTree): 2569 mVspTree(vspTree), mOspTree(ospTree) 2650 2570 { 2651 2571 } … … 2655 2575 { 2656 2576 SplitCandidate *splitCandidate = mTQueue.top(); 2577 Debug << "priority: " << splitCandidate->GetPriority() << endl; 2657 2578 mTQueue.pop(); 2658 2579 … … 2662 2583 2663 2584 void HierarchyManager::PrepareConstruction(const VssRayContainer &sampleRays, 2585 const ObjectContainer &objects, 2664 2586 AxisAlignedBox3 *forcedViewSpace, 2665 2587 RayInfoContainer &rays) 2666 2588 { 2589 mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 2590 2591 long startTime = GetTime(); 2592 2593 cout << "storing rays ... "; 2594 2595 Intersectable::NewMail(); 2596 2667 2597 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 2668 2669 long startTime = GetTime();2670 2671 cout << "storing rays ... ";2672 2673 Intersectable::NewMail();2674 2675 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace);2676 2598 2677 2599 //-- store rays … … 2684 2606 static Ray hray; 2685 2607 hray.Init(*ray); 2686 2608 2687 2609 // TODO: not very efficient to implictly cast between rays types 2688 if (m BoundingBox.GetRaySegment(hray, minT, maxT))2610 if (mVspTree.GetBoundingBox().GetRaySegment(hray, minT, maxT)) 2689 2611 { 2690 2612 float len = ray->Length(); … … 2697 2619 } 2698 2620 2699 cout << "finished" << endl; 2621 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 2622 2623 /// add first candidate for view space partition 2624 mVspTree.mRoot = new VspLeaf(); 2625 const float prop = mVspTree.mBoundingBox.GetVolume(); 2626 2627 /// first traversal data 2628 VspTree::VspTraversalData tData(mVspTree.mRoot, 2629 0, 2630 &rays, 2631 (int)objects.size(), 2632 //mVspTree.ComputePvsSize(rays), 2633 prop, 2634 mVspTree.mBoundingBox); 2635 2636 // compute first split candidate 2637 VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(); 2638 mVspTree.EvalSplitCandidate(tData, *splitCandidate); 2639 2640 mTQueue.push(splitCandidate); 2700 2641 2701 2642 //mOspTree->PrepareConstruction(sampleRays, forcedViewSpace, rays); … … 2710 2651 dynamic_cast<VspTree::VspSplitCandidate *>(candidate); 2711 2652 2712 return mVspTree ->GlobalTerminationCriteriaMet(sc->mParentData);2653 return mVspTree.GlobalTerminationCriteriaMet(sc->mParentData); 2713 2654 } 2714 2655 … … 2724 2665 2725 2666 // prepare vsp and osp trees for traversal 2726 PrepareConstruction(sampleRays, forcedViewSpace, *rays); 2727 2728 mVspTree->mVspStats.Start(); 2667 PrepareConstruction(sampleRays, objects, forcedViewSpace, *rays); 2668 2669 mVspTree.mVspStats.Reset(); 2670 mVspTree.mVspStats.Start(); 2729 2671 2730 2672 cout << "Constructing view space / object space tree ... \n"; … … 2738 2680 GlobalTerminationCriteriaMet(splitCandidate); 2739 2681 2682 Debug << "cost: " << splitCandidate->GetPriority(); 2683 2740 2684 // cost ratio of cost decrease / totalCost 2741 2685 const float costRatio = splitCandidate->GetPriority() / mTotalCost; … … 2744 2688 if (costRatio < mTermMinGlobalCostRatio) 2745 2689 ++ mGlobalCostMisses; 2746 2690 2747 2691 //-- subdivide leaf node 2748 2692 //-- either a object space or view space split … … 2752 2696 dynamic_cast<VspTree::VspSplitCandidate *>(splitCandidate); 2753 2697 2754 VspNode *r = mVspTree ->Subdivide(mTQueue, *sc, globalTerminationCriteriaMet);2698 VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 2755 2699 } 2756 2700 else // object space split 2757 2701 { 2758 2702 #if TODO 2759 KdNode *r = mKdtree ->Subdivide(tOspQueue, dynamic_cast<OspSplitCandidate<(splitCandidate));2703 KdNode *r = mKdtree.Subdivide(tOspQueue, dynamic_cast<OspSplitCandidate<(splitCandidate)); 2760 2704 #endif 2761 2705 } … … 2766 2710 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << "secs" << endl; 2767 2711 2768 mVspTree ->mVspStats.Stop();2712 mVspTree.mVspStats.Stop(); 2769 2713 } 2770 2714
Note: See TracChangeset
for help on using the changeset viewer.