- Timestamp:
- 02/18/06 20:35:23 (19 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env
r651 r652 289 289 Construction { 290 290 samples 50000 291 epsilon 0.000 05291 epsilon 0.0005 292 292 randomize false 293 293 renderCostWeight 1.0 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r650 r652 643 643 644 644 645 void VspBspTree::EvalSplitCandidate(VspBspTraversalData &tData, 646 VspBspSplitCandidate &splitData) 647 { 648 VspBspTraversalData frontData; 649 VspBspTraversalData backData; 650 651 int splitAxis = 0; 652 653 BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 654 SelectPlane(splitData.mSplitPlane, leaf, tData, frontData, backData, splitAxis); 655 656 // TODO: reuse 657 DEL_PTR(frontData.mGeometry); 658 DEL_PTR(backData.mGeometry); 659 660 splitData.mRenderCost = EvalRenderCostDecrease(splitData.mSplitPlane, tData); 661 splitData.mParentData = tData; 662 } 663 664 645 665 BspNode *VspBspTree::SubdivideNode(VspBspTraversalData &tData, 646 666 VspBspTraversalData &frontData, … … 653 673 Plane3 splitPlane; 654 674 655 int maxCostMisses = tData.mMaxCostMisses;656 657 675 int splitAxis; 658 676 659 677 const bool success = 660 678 SelectPlane(splitPlane, leaf, tData, frontData, backData, splitAxis); 679 680 681 int maxCostMisses = tData.mMaxCostMisses; 661 682 662 683 if (!success) … … 672 693 } 673 694 674 //! error also computed if cost ratio is missed 695 //-- the front and back traversal data is filled with the new values 696 frontData.mDepth = tData.mDepth + 1; 697 frontData.mPolygons = new PolygonContainer(); 698 frontData.mRays = new RayInfoContainer(); 699 700 backData.mDepth = tData.mDepth + 1; 701 backData.mPolygons = new PolygonContainer(); 702 backData.mRays = new RayInfoContainer(); 703 704 // subdivide rays 705 SplitRays(splitPlane, 706 *tData.mRays, 707 *frontData.mRays, 708 *backData.mRays); 709 710 711 // how often was max cost ratio missed in this branch? 712 frontData.mMaxCostMisses = maxCostMisses; 713 backData.mMaxCostMisses = maxCostMisses; 714 715 // compute pvs 716 frontData.mPvs = ComputePvsSize(*frontData.mRays); 717 backData.mPvs = ComputePvsSize(*backData.mRays); 718 719 // split front and back node geometry and compute area 720 721 // if geometry was not already computed 722 if (!frontData.mGeometry && !backData.mGeometry) 723 { 724 frontData.mGeometry = new BspNodeGeometry(); 725 backData.mGeometry = new BspNodeGeometry(); 726 727 tData.mGeometry->SplitGeometry(*frontData.mGeometry, 728 *backData.mGeometry, 729 splitPlane, 730 mBox, 731 mEpsilon); 732 733 if (mUseAreaForPvs) 734 { 735 frontData.mProbability = frontData.mGeometry->GetArea(); 736 backData.mProbability = backData.mGeometry->GetArea(); 737 } 738 else 739 { 740 frontData.mProbability = frontData.mGeometry->GetVolume(); 741 backData.mProbability = tData.mProbability - frontData.mProbability; 742 } 743 } 744 745 746 // subdivide polygons 747 SplitPolygons(splitPlane, 748 *tData.mPolygons, 749 *frontData.mPolygons, 750 *backData.mPolygons, 751 coincident); 752 753 754 675 755 if (splitAxis < 3) 676 756 ++ mBspStats.splits[splitAxis]; … … 680 760 mBspStats.nodes += 2; 681 761 762 763 764 /////////////////////////////////////// 765 682 766 //-- subdivide further 683 767 BspInterior *interior = new BspInterior(splitPlane); … … 687 771 #endif 688 772 689 //-- the front and back traversal data is filled with the new values690 frontData.mDepth = tData.mDepth + 1;691 frontData.mPolygons = new PolygonContainer();692 frontData.mRays = new RayInfoContainer();693 694 backData.mDepth = tData.mDepth + 1;695 backData.mPolygons = new PolygonContainer();696 backData.mRays = new RayInfoContainer();697 698 // subdivide rays699 SplitRays(interior->GetPlane(),700 *tData.mRays,701 *frontData.mRays,702 *backData.mRays);703 704 // subdivide polygons705 SplitPolygons(interior->GetPlane(),706 *tData.mPolygons,707 *frontData.mPolygons,708 *backData.mPolygons,709 coincident);710 711 712 // how often was max cost ratio missed in this branch?713 frontData.mMaxCostMisses = maxCostMisses;714 backData.mMaxCostMisses = maxCostMisses;715 716 // compute pvs717 frontData.mPvs = ComputePvsSize(*frontData.mRays);718 backData.mPvs = ComputePvsSize(*backData.mRays);719 720 // split front and back node geometry and compute area721 722 // if geometry was not already computed723 if (!frontData.mGeometry && !backData.mGeometry)724 {725 frontData.mGeometry = new BspNodeGeometry();726 backData.mGeometry = new BspNodeGeometry();727 728 tData.mGeometry->SplitGeometry(*frontData.mGeometry,729 *backData.mGeometry,730 interior->GetPlane(),731 mBox,732 mEpsilon);733 734 if (mUseAreaForPvs)735 {736 frontData.mProbability = frontData.mGeometry->GetArea();737 backData.mProbability = backData.mGeometry->GetArea();738 }739 else740 {741 frontData.mProbability = frontData.mGeometry->GetVolume();742 backData.mProbability = tData.mProbability - frontData.mProbability;743 }744 }745 746 747 773 //-- create front and back leaf 748 774 … … 767 793 768 794 interior->mTimeStamp = mTimeStamp ++; 769 //frontData.mNode->mTimeStamp = ++ mTimeStamp; 770 //backData.mNode->mTimeStamp = mTimeStamp; 771 795 772 796 //DEL_PTR(leaf); 773 797 return interior; … … 1135 1159 bool VspBspTree::SelectPlane(Plane3 &bestPlane, 1136 1160 BspLeaf *leaf, 1137 VspBspTraversalData &data, 1161 VspBspTraversalData &data, 1138 1162 VspBspTraversalData &frontData, 1139 1163 VspBspTraversalData &backData, … … 1345 1369 1346 1370 1371 float VspBspTree::EvalRenderCostDecrease(const Plane3 &candidatePlane, 1372 const VspBspTraversalData &data) const 1373 { 1374 int pvsFront = 0; 1375 int pvsBack = 0; 1376 int totalPvs = data.mPvs; 1377 1378 // probability that view point lies in back / front node 1379 float pOverall = data.mProbability; 1380 float pFront = 0; 1381 float pBack = 0; 1382 1383 1384 // create unique ids for pvs heuristics 1385 GenerateUniqueIdsForPvs(); 1386 1387 for (int i = 0; i < data.mRays->size(); ++ i) 1388 { 1389 RayInfo rayInf = (*data.mRays)[i]; 1390 1391 float t; 1392 VssRay *ray = rayInf.mRay; 1393 const int cf = rayInf.ComputeRayIntersection(candidatePlane, t); 1394 1395 // find front and back pvs for origing and termination object 1396 AddObjToPvs(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 1397 AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 1398 } 1399 1400 1401 BspNodeGeometry geomFront; 1402 BspNodeGeometry geomBack; 1403 1404 // construct child geometry with regard to the candidate split plane 1405 data.mGeometry->SplitGeometry(geomFront, 1406 geomBack, 1407 candidatePlane, 1408 mBox, 1409 mEpsilon); 1410 1411 if (!mUseAreaForPvs) // use front and back cell areas to approximate volume 1412 { 1413 pFront = geomFront.GetVolume(); 1414 pBack = pOverall - pFront; 1415 } 1416 else 1417 { 1418 pFront = geomFront.GetArea(); 1419 pBack = geomBack.GetArea(); 1420 } 1421 1422 1423 // -- pvs rendering heuristics 1424 const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 1425 const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 1426 1427 // only render cost heuristics or combined with standard deviation 1428 const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit); 1429 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 1430 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 1431 1432 const float oldRenderCost = pOverall * penaltyOld; 1433 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 1434 1435 return oldRenderCost - newRenderCost; 1436 } 1437 1438 1347 1439 float VspBspTree::EvalSplitPlaneCost(const Plane3 &candidatePlane, 1348 1440 const VspBspTraversalData &data, … … 1354 1446 float cost = 0; 1355 1447 1356 float sumBalancedRays = 0; 1357 float sumRaySplits = 0; 1358 1448 int totalPvs = 0; 1359 1449 int pvsFront = 0; 1360 1450 int pvsBack = 0; 1361 1451 1362 1452 // probability that view point lies in back / front node 1363 1453 float pOverall = 0; … … 1365 1455 pBack = 0; 1366 1456 1367 int raysFront = 0;1368 int raysBack = 0;1369 int totalPvs = 0;1370 1457 1371 1458 int limit; 1372 1459 bool useRand; 1460 1461 // create unique ids for pvs heuristics 1462 GenerateUniqueIdsForPvs(); 1373 1463 1374 1464 // choose test rays randomly if too much … … 1394 1484 const int cf = rayInf.ComputeRayIntersection(candidatePlane, t); 1395 1485 1396 if (0) 1397 { 1398 if (cf >= 0) 1399 ++ raysFront; 1400 if (cf <= 0) 1401 ++ raysBack; 1402 } 1403 1404 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 1405 { 1406 sumBalancedRays += cf; 1407 } 1408 1409 if (mSplitPlaneStrategy & BALANCED_RAYS) 1410 { 1411 if (cf == 0) 1412 ++ sumRaySplits; 1413 } 1414 1415 if (mSplitPlaneStrategy & PVS) 1416 { 1417 // find front and back pvs for origing and termination object 1418 AddObjToPvs(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 1419 AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 1420 } 1421 } 1422 1423 const float raysSize = (float)data.mRays->size() + Limits::Small; 1424 1425 if (mSplitPlaneStrategy & PVS) 1426 { 1427 // create unique ids for pvs heuristics 1428 GenerateUniqueIdsForPvs(); 1429 1430 // construct child geometry with regard to the candidate split plane 1431 data.mGeometry->SplitGeometry(geomFront, 1432 geomBack, 1433 candidatePlane, 1434 mBox, 1435 mEpsilon); 1436 1437 pOverall = data.mProbability; 1438 1439 if (!mUseAreaForPvs) // use front and back cell areas to approximate volume 1440 { 1441 pFront = geomFront.GetVolume(); 1442 pBack = pOverall - pFront; 1443 } 1444 else 1445 { 1446 pFront = geomFront.GetArea(); 1447 pBack = geomBack.GetArea(); 1448 } 1449 } 1450 1451 1452 if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 1453 cost += mLeastRaySplitsFactor * sumRaySplits / raysSize; 1454 1455 if (mSplitPlaneStrategy & BALANCED_RAYS) 1456 cost += mBalancedRaysFactor * fabs(sumBalancedRays) / raysSize; 1486 // find front and back pvs for origing and termination object 1487 AddObjToPvs(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 1488 AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 1489 } 1490 1491 // construct child geometry with regard to the candidate split plane 1492 data.mGeometry->SplitGeometry(geomFront, 1493 geomBack, 1494 candidatePlane, 1495 mBox, 1496 mEpsilon); 1497 1498 pOverall = data.mProbability; 1499 1500 if (!mUseAreaForPvs) // use front and back cell areas to approximate volume 1501 { 1502 pFront = geomFront.GetVolume(); 1503 pBack = pOverall - pFront; 1504 } 1505 else 1506 { 1507 pFront = geomFront.GetArea(); 1508 pBack = geomBack.GetArea(); 1509 } 1510 1457 1511 1458 1512 // -- pvs rendering heuristics 1459 if (mSplitPlaneStrategy & PVS) 1460 { 1461 const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 1462 const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 1463 1464 // only render cost heuristics or combined with standard deviation 1465 const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit); 1466 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 1467 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 1513 const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 1514 const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 1515 1516 // only render cost heuristics or combined with standard deviation 1517 const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit); 1518 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 1519 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 1468 1520 1469 const float oldRenderCost = pOverall * penaltyOld; 1470 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 1471 1472 float oldCost, newCost; 1473 1474 // only render cost 1475 if (1) 1476 { 1477 oldCost = oldRenderCost; 1478 newCost = newRenderCost; 1479 } 1480 else // also considering standard deviation 1481 { 1482 // standard deviation is difference of back and front pvs 1483 const float expectedCost = 0.5f * (penaltyFront + penaltyBack); 1484 1485 const float newDeviation = 0.5f * 1486 fabs(penaltyFront - expectedCost) + fabs(penaltyBack - expectedCost); 1487 1488 const float oldDeviation = penaltyOld; 1489 1490 newCost = mRenderCostWeight * newRenderCost + (1.0f - mRenderCostWeight) * newDeviation; 1491 oldCost = mRenderCostWeight * oldRenderCost + (1.0f - mRenderCostWeight) * oldDeviation; 1492 } 1493 1494 cost += mPvsFactor * newCost / (oldCost + Limits::Small); 1495 1496 } 1521 const float oldRenderCost = pOverall * penaltyOld; 1522 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 1523 1524 float oldCost, newCost; 1525 1526 // only render cost 1527 if (1) 1528 { 1529 oldCost = oldRenderCost; 1530 newCost = newRenderCost; 1531 } 1532 else // also considering standard deviation 1533 { 1534 // standard deviation is difference of back and front pvs 1535 const float expectedCost = 0.5f * (penaltyFront + penaltyBack); 1536 1537 const float newDeviation = 0.5f * 1538 fabs(penaltyFront - expectedCost) + fabs(penaltyBack - expectedCost); 1539 1540 const float oldDeviation = penaltyOld; 1541 1542 newCost = mRenderCostWeight * newRenderCost + (1.0f - mRenderCostWeight) * newDeviation; 1543 oldCost = mRenderCostWeight * oldRenderCost + (1.0f - mRenderCostWeight) * oldDeviation; 1544 } 1545 1546 cost += mPvsFactor * newCost / (oldCost + Limits::Small); 1547 1497 1548 1498 1549 #ifdef _DEBUG … … 1503 1554 #endif 1504 1555 1505 1506 // normalize cost by sum of linear factors 1507 if(0) 1508 return cost / (float)mCostNormalizer; 1509 else 1510 return cost; 1556 return cost; 1511 1557 } 1512 1558 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
r648 r652 159 159 160 160 typedef std::priority_queue<VspBspTraversalData> VspBspTraversalQueue; 161 //typedef std::stack<VspBspTraversalData> VspBspTraversalQueue; 161 162 163 struct VspBspSplitCandidate 164 { 165 /// the current node 166 Plane3 mSplitPlane; 167 168 // parent data 169 VspBspTraversalData mParentData; 170 171 float mRenderCost; 172 173 VspBspSplitCandidate(const Plane3 &plane, const VspBspTraversalData &tData): 174 mSplitPlane(plane), mParentData(tData) 175 {} 176 177 /** Returns cost of the traversal data. 178 */ 179 float GetCost() const 180 { 181 #if 1 182 return mRenderCost; 183 #endif 184 #if 0 185 return (float) (-mDepth); // for kd tree 186 #endif 187 } 188 189 friend bool operator<(const VspBspSplitCandidate &a, const VspBspSplitCandidate &b) 190 { 191 return a.GetCost() < b.GetCost(); 192 } 193 }; 194 195 typedef std::priority_queue<VspBspSplitCandidate> VspBspSplitQueue; 162 196 163 197 /** Default constructor creating an empty tree. … … 355 389 float &pFront, 356 390 float &pBack) const; 391 392 void EvalSplitCandidate(VspBspTraversalData &tData, VspBspSplitCandidate &splitData); 393 394 float EvalRenderCostDecrease(const Plane3 &candidatePlane, 395 const VspBspTraversalData &data) const; 357 396 358 397 /** Returns view cell corresponding to
Note: See TracChangeset
for help on using the changeset viewer.