Changeset 600 for trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
- Timestamp:
- 02/06/06 19:09:53 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r590 r600 86 86 //-- max cost ratio for early tree termination 87 87 environment->GetFloatValue("VspBspTree.Termination.maxCostRatio", mTermMaxCostRatio); 88 88 mTermMinPolygons = 25; 89 89 //-- factors for bsp tree split plane heuristics 90 90 environment->GetFloatValue("VspBspTree.Factor.balancedRays", mBalancedRaysFactor); … … 116 116 117 117 118 mSubdivisionStats.open("subdivisionStats.log"); 118 119 119 120 … … 387 388 388 389 // return memory usage in MB 389 float VspBspTree::GetMemUsage(/*const VspBspTraversal Stack&tstack*/) const390 float VspBspTree::GetMemUsage(/*const VspBspTraversalQueue &tstack*/) const 390 391 { 391 392 return … … 402 403 void VspBspTree::Construct(const PolygonContainer &polys, RayInfoContainer *rays) 403 404 { 404 VspBspTraversal Stack tStack;405 VspBspTraversalQueue tQueue; 405 406 406 407 mRoot = new BspLeaf(); … … 426 427 tData.mIsKdNode = false; 427 428 428 tStack.push(tData); 429 429 tQueue.push(tData); 430 431 mTotalCost = tData.GetCost() / mBox.GetVolume(); 432 433 Debug << "total cost: " << mTotalCost << endl; 434 mSplits = 0; 435 430 436 mBspStats.Start(); 431 437 cout << "Contructing vsp bsp tree ... \n"; … … 440 446 int nleaves = 500; 441 447 442 while (!t Stack.empty())443 { 444 tData = t Stack.top();445 t Stack.pop();448 while (!tQueue.empty()) 449 { 450 tData = tQueue.top(); 451 tQueue.pop(); 446 452 447 453 if (0 && !mOutOfMemory) … … 457 463 458 464 // subdivide leaf node 459 BspNode *r = Subdivide(t Stack, tData);465 BspNode *r = Subdivide(tQueue, tData); 460 466 461 467 if (r == mRoot) … … 489 495 (data.mProbability <= mTermMinProbability) || 490 496 (mBspStats.Leaves() >= mMaxViewCells) || 497 #if 0 498 (((int)data.mPolygons->size() <= mTermMinPolygons) && !data.mPolygons->empty())|| 499 #endif 491 500 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 492 501 (data.mDepth >= mTermMaxDepth)); … … 494 503 495 504 496 BspNode *VspBspTree::Subdivide(VspBspTraversal Stack &tStack,505 BspNode *VspBspTree::Subdivide(VspBspTraversalQueue &tQueue, 497 506 VspBspTraversalData &tData) 498 507 { … … 512 521 if (!newNode->IsLeaf()) //-- continue subdivision 513 522 { 523 if (1) 524 { 525 float costDecr = 526 (tFrontData.GetCost() + tBackData.GetCost() - tData.GetCost()) / mBox.GetVolume(); 527 mTotalCost += costDecr; 528 529 mSubdivisionStats 530 << "#Nodes\n" << ++ mSplits << endl 531 << "#RenderCostDecrease\n" << -costDecr << endl 532 << "#TotalRenderCost\n" << mTotalCost << endl; 533 } 534 514 535 // push the children on the stack 515 t Stack.push(tFrontData);516 t Stack.push(tBackData);536 tQueue.push(tFrontData); 537 tQueue.push(tBackData); 517 538 518 539 // delete old leaf node … … 1341 1362 float oldCost, newCost; 1342 1363 1364 // only render cost 1343 1365 if (1) 1344 1366 { … … 1346 1368 newCost = newRenderCost; 1347 1369 } 1348 else 1370 else // also considering standard deviation 1349 1371 { 1350 1372 // standard deviation is difference of back and front pvs … … 1361 1383 1362 1384 cost += mPvsFactor * newCost / oldCost; 1363 }1364 else1365 {1366 //-- compute weighted sum of expected render cost and standard deviation1367 1368 //-- first compute expected render cost1369 const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit);1370 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit);1371 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit);1372 1373 const float renderCostFront = penaltyFront * pFront;1374 const float renderCostBack = penaltyBack * pBack;1375 1376 const float oldRenderCost = pOverall * (float)penaltyOld + Limits::Small;1377 const float newRenderCost = renderCostFront + renderCostBack;1378 1379 1380 //-- compute standard deviation1381 const float expectedCost = 0.5f * (renderCostBack + renderCostFront);1382 1383 const float devFront = fabs(renderCostFront - expectedCost);1384 1385 const float devBack = fabs(renderCostBack - expectedCost);1386 1387 const float newDev = 0.5f * (devFront + devBack);1388 const float oldDev = oldRenderCost * oldRenderCost;1389 1390 const float newCost = newRenderCost * mRenderCostWeight + newDev * (1.0f - mRenderCostWeight);1391 const float oldCost = oldRenderCost * mRenderCostWeight + oldDev * (1.0f - mRenderCostWeight);1392 1393 cost += mPvsFactor * newCost / oldCost;1394 1395 // also try to equalize render differences between front and back pvs1396 //const float oldCost = pOverall + Limits::Small;1397 //float newCost = (float)abs(pvsFront - pvsBack);1398 1399 1385 } 1400 1386 } … … 1404 1390 << " frontpvs: " << pvsFront << " pFront: " << pFront 1405 1391 << " backpvs: " << pvsBack << " pBack: " << pBack << endl << endl; 1392 Debug << "cost: " << cost << endl; 1406 1393 #endif 1407 1394 1395 1408 1396 // normalize cost by sum of linear factors 1409 1397 if(0) … … 1638 1626 int hits = 0; 1639 1627 1640 stack<BspRayTraversalData> t Stack;1628 stack<BspRayTraversalData> tQueue; 1641 1629 1642 1630 float maxt, mint; … … 1646 1634 1647 1635 Intersectable::NewMail(); 1648 1636 ViewCell::NewMail(); 1649 1637 Vector3 entp = ray.Extrap(mint); 1650 1638 Vector3 extp = ray.Extrap(maxt); … … 1690 1678 1691 1679 // push data for far child 1692 t Stack.push(BspRayTraversalData(farChild, extp, maxt));1680 tQueue.push(BspRayTraversalData(farChild, extp, maxt)); 1693 1681 1694 1682 // find intersection of ray segment with plane … … 1709 1697 1710 1698 //-- fetch the next far child from the stack 1711 if (t Stack.empty())1699 if (tQueue.empty()) 1712 1700 break; 1713 1701 … … 1718 1706 break; 1719 1707 1720 BspRayTraversalData &s = t Stack.top();1708 BspRayTraversalData &s = tQueue.top(); 1721 1709 1722 1710 node = s.mNode; … … 1724 1712 maxt = s.mMaxT; 1725 1713 1726 t Stack.pop();1714 tQueue.pop(); 1727 1715 } 1728 1716 } … … 2204 2192 return (int)neighbors.size(); 2205 2193 } 2194 2195 2196 2197 int VspBspTree::FindApproximateNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 2198 const bool onlyUnmailed) const 2199 { 2200 stack<bspNodePair> nodeStack; 2201 2202 BspNodeGeometry nodeGeom; 2203 ConstructGeometry(n, nodeGeom); 2204 2205 // split planes from the root to this node 2206 // needed to verify that we found neighbor leaf 2207 // TODO: really needed? 2208 vector<Plane3> halfSpaces; 2209 ExtractHalfSpaces(n, halfSpaces); 2210 2211 2212 BspNodeGeometry *rgeom = new BspNodeGeometry(); 2213 ConstructGeometry(mRoot, *rgeom); 2214 2215 nodeStack.push(bspNodePair(mRoot, rgeom)); 2216 2217 while (!nodeStack.empty()) 2218 { 2219 BspNode *node = nodeStack.top().first; 2220 BspNodeGeometry *geom = nodeStack.top().second; 2221 2222 nodeStack.pop(); 2223 2224 if (node->IsLeaf()) 2225 { 2226 // test if this leaf is in valid view space 2227 if (node->TreeValid() && 2228 (node != n) && 2229 (!onlyUnmailed || !node->Mailed())) 2230 { 2231 bool isAdjacent = true; 2232 2233 // neighbor was found 2234 if (isAdjacent) 2235 { 2236 neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 2237 } 2238 } 2239 } 2240 else 2241 { 2242 BspInterior *interior = dynamic_cast<BspInterior *>(node); 2243 2244 const int cf = Polygon3::ClassifyPlane(nodeGeom.mPolys, 2245 interior->GetPlane(), 2246 mEpsilon); 2247 2248 BspNode *front = interior->GetFront(); 2249 BspNode *back = interior->GetBack(); 2250 2251 BspNodeGeometry *fGeom = new BspNodeGeometry(); 2252 BspNodeGeometry *bGeom = new BspNodeGeometry(); 2253 2254 geom->SplitGeometry(*fGeom, 2255 *bGeom, 2256 interior->GetPlane(), 2257 mBox, 2258 mEpsilon); 2259 2260 if (cf == Polygon3::FRONT_SIDE) 2261 { 2262 nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 2263 DEL_PTR(bGeom); 2264 } 2265 else 2266 { 2267 if (cf == Polygon3::BACK_SIDE) 2268 { 2269 nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 2270 DEL_PTR(fGeom); 2271 } 2272 else 2273 { // random decision 2274 nodeStack.push(bspNodePair(front, fGeom)); 2275 nodeStack.push(bspNodePair(back, bGeom)); 2276 } 2277 } 2278 } 2279 2280 DEL_PTR(geom); 2281 } 2282 2283 return (int)neighbors.size(); 2284 } 2285 2206 2286 2207 2287 … … 2378 2458 { 2379 2459 int hits = 0; 2380 stack<BspRayTraversalData> t Stack;2460 stack<BspRayTraversalData> tQueue; 2381 2461 2382 2462 float mint = 0.0f, maxt = 1.0f; 2383 2463 2384 2464 Intersectable::NewMail(); 2465 ViewCell::NewMail(); 2385 2466 2386 2467 Vector3 entp = origin; … … 2431 2512 2432 2513 // push data for far child 2433 t Stack.push(BspRayTraversalData(farChild, extp));2514 tQueue.push(BspRayTraversalData(farChild, extp)); 2434 2515 2435 2516 // find intersection of ray segment with plane … … 2450 2531 2451 2532 //-- fetch the next far child from the stack 2452 if (t Stack.empty())2533 if (tQueue.empty()) 2453 2534 break; 2454 2535 2455 2536 entp = extp; 2456 2537 2457 BspRayTraversalData &s = t Stack.top();2538 BspRayTraversalData &s = tQueue.top(); 2458 2539 2459 2540 node = s.mNode; 2460 2541 extp = s.mExitPoint; 2461 2542 2462 t Stack.pop();2543 tQueue.pop(); 2463 2544 } 2464 2545 } … … 2711 2792 vector<BspLeaf *> neighbors; 2712 2793 FindNeighbors(leaf, neighbors, true); 2713 2794 //FindApproximateNeighbors(leaf, neighbors, true); 2714 2795 vector<BspLeaf *>::const_iterator nit, nit_end = neighbors.end(); 2715 2796
Note: See TracChangeset
for help on using the changeset viewer.