Changeset 1765 for GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
- Timestamp:
- 11/18/06 23:15:55 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1764 r1765 40 40 41 41 // pvs penalty can be different from pvs size 42 inline static float EvalPvsPenalty(const int pvs,43 const int lower,44 const int upper)42 inline static float EvalPvsPenalty(const float pvs, 43 const float lower, 44 const float upper) 45 45 { 46 46 // clamp to minmax values … … 734 734 735 735 mTotalCost -= sc->GetRenderCostDecrease(); 736 mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs;736 mTotalPvsSize += (int)(tFrontData.mPvs + tBackData.mPvs - tData.mPvs); 737 737 mPvsEntries += sc->GetPvsEntriesIncr(); 738 738 … … 932 932 933 933 //-- compute pvs 934 frontData.mPvs = EvalPvs Size(*frontData.mRays);935 backData.mPvs = EvalPvs Size(*backData.mRays);934 frontData.mPvs = EvalPvsCost(*frontData.mRays); 935 backData.mPvs = EvalPvsCost(*backData.mRays); 936 936 937 937 //-- split front and back node geometry and compute area … … 1120 1120 1121 1121 1122 int VspTree::PrepareHeuristics(KdLeaf *leaf)1122 float VspTree::PrepareHeuristics(KdLeaf *leaf) 1123 1123 { 1124 int pvsSize = 0;1124 float pvsSize = 0; 1125 1125 1126 1126 if (!leaf->Mailed()) … … 1160 1160 1161 1161 1162 int VspTree::PrepareHeuristics(const RayInfoContainer &rays)1162 float VspTree::PrepareHeuristics(const RayInfoContainer &rays) 1163 1163 { 1164 1164 Intersectable::NewMail(); … … 1166 1166 BvhLeaf::NewMail(); 1167 1167 1168 int pvsSize = 0;1168 float pvsSize = 0; 1169 1169 1170 1170 RayInfoContainer::const_iterator ri, ri_end = rays.end(); … … 1243 1243 1244 1244 void VspTree::EvalHeuristics(const SortableEntry &ci, 1245 int &pvsLeft,1246 int &pvsRight) const1245 float &pvsLeft, 1246 float &pvsRight) const 1247 1247 { 1248 1248 VssRay *ray = ci.ray; … … 1251 1251 if (ci.type == SortableEntry::ERayMin) 1252 1252 { 1253 pvsLeft += EvalMinEventContribution(*ray, true); 1253 1254 #if COUNT_ORIGIN_OBJECTS 1254 pvsLeft += EvalMinEventContribution(*ray, true);1255 #else1256 1255 pvsLeft += EvalMinEventContribution(*ray, false); 1257 1256 #endif … … 1259 1258 else // eval changes in pvs causes by max event 1260 1259 { 1260 pvsRight -= EvalMaxEventContribution(*ray, true); 1261 1261 #if COUNT_ORIGIN_OBJECTS 1262 pvsRight -= EvalMaxEventContribution(*ray, true);1263 #else1264 1262 pvsRight -= EvalMaxEventContribution(*ray, false); 1265 1263 #endif … … 1271 1269 const AxisAlignedBox3 &box, 1272 1270 const int axis, 1273 float &position) 1274 { 1275 // get subset of rays 1276 RayInfoContainer randomRays; 1277 randomRays.reserve(mMaxTests); 1278 1279 RayInfoContainer *usedRays; 1280 1281 if (mMaxTests < (int)tData.mRays->size()) 1282 { 1283 GetRayInfoSets(*tData.mRays, mMaxTests, randomRays); 1284 usedRays = &randomRays; 1285 } 1286 else 1287 { 1288 usedRays = tData.mRays; 1289 } 1290 1271 float &position, 1272 const RayInfoContainer &usedRays) 1273 { 1291 1274 const float minBox = box.Min(axis); 1292 1275 const float maxBox = box.Max(axis); … … 1297 1280 const float maxBand = minBox + mMaxBand * sizeBox; 1298 1281 1299 SortSubdivisionCandidates( *usedRays, axis, minBand, maxBand);1282 SortSubdivisionCandidates(usedRays, axis, minBand, maxBand); 1300 1283 1301 1284 // prepare the sweep 1302 1285 // note: returns pvs size => no need t give pvs size as function parameter 1303 const int pvsSize = PrepareHeuristics(*usedRays);1286 const float pvsCost = PrepareHeuristics(usedRays); 1304 1287 1305 1288 // go through the lists, count the number of objects left and right … … 1307 1290 // C = ct_div_ci + (ql*rl + qr*rr)/queries 1308 1291 1309 int pvsl = 0;1310 int pvsr = pvsSize;1311 1312 int pvsBack = pvsl;1313 int pvsFront = pvsr;1314 1315 float sum = (float)pvsSize* sizeBox;1292 float pvsl = 0; 1293 float pvsr = pvsCost; 1294 1295 float pvsBack = pvsl; 1296 float pvsFront = pvsr; 1297 1298 float sum = pvsCost * sizeBox; 1316 1299 float minSum = 1e20f; 1317 1300 … … 1327 1310 BvhLeaf::NewMail(); 1328 1311 1329 //-- traverse through visibility events 1330 vector<SortableEntry>::const_iterator ci, ci_end = mLocalSubdivisionCandidates->end(); 1331 1332 #ifdef GTPGTP_DEBUG 1333 const float volRatio = tData.mBoundingBox.GetVolume() / (sizeBox * mBoundingBox.GetVolume()); 1312 const float volRatio = 1313 tData.mBoundingBox.GetVolume() / (sizeBox * mBoundingBox.GetVolume()); 1314 1315 //////// 1316 //-- iterate through visibility events 1317 1318 vector<SortableEntry>::const_iterator ci, 1319 ci_end = mLocalSubdivisionCandidates->end(); 1320 1321 #ifdef GTP_DEBUG 1334 1322 const int leaves = mVspStats.Leaves(); 1335 1323 const bool printStats = ((axis == 0) && (leaves > 0) && (leaves < 90)); … … 1370 1358 sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value); 1371 1359 1372 #ifdef GTP GTP_DEBUG1360 #ifdef GTP_DEBUG 1373 1361 if (printStats) 1374 1362 { … … 1404 1392 //-- compute cost 1405 1393 1406 const int lowerPvsLimit =mViewCellsManager->GetMinPvsSize();1407 const int upperPvsLimit =mViewCellsManager->GetMaxPvsSize();1394 const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize(); 1395 const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize(); 1408 1396 1409 1397 const float pOverall = sizeBox; … … 1411 1399 const float pFront = maxBox - position; 1412 1400 1413 const float penaltyOld = EvalPvsPenalty(pvs Size, lowerPvsLimit, upperPvsLimit);1401 const float penaltyOld = EvalPvsPenalty(pvsCost, lowerPvsLimit, upperPvsLimit); 1414 1402 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 1415 1403 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); … … 1423 1411 } 1424 1412 1425 #ifdef GTPGTP_DEBUG1426 Debug << "\n§§§§ eval local cost §§§§" << endl1413 //#ifdef GTP_DEBUG 1414 cout << "\n((((( eval local cost )))))" << endl 1427 1415 << "back pvs: " << penaltyBack << " front pvs: " << penaltyFront << " total pvs: " << penaltyOld << endl 1428 1416 << "back p: " << pBack * volRatio << " front p " << pFront * volRatio << " p: " << pOverall * volRatio << endl 1429 1417 << "old rc: " << oldRenderCost * volRatio << " new rc: " << newRenderCost * volRatio << endl 1430 1418 << "render cost decrease: " << oldRenderCost * volRatio - newRenderCost * volRatio << endl; 1431 #endif1419 //#endif 1432 1420 return ratio; 1433 1421 } … … 1454 1442 mOnlyDrivingAxis || mCirculatingAxis; 1455 1443 1444 // get subset of rays 1445 RayInfoContainer randomRays; 1446 randomRays.reserve(mMaxTests); 1447 1448 RayInfoContainer *usedRays; 1449 1450 if (mMaxTests < (int)tData.mRays->size()) 1451 { 1452 GetRayInfoSets(*tData.mRays, mMaxTests, randomRays); 1453 usedRays = &randomRays; 1454 } 1455 else 1456 { 1457 usedRays = tData.mRays; 1458 } 1459 1456 1460 if (mCirculatingAxis) 1457 1461 { … … 1460 1464 1461 1465 if (parent) 1466 { 1462 1467 parentAxis = dynamic_cast<VspInterior *>(parent)->GetAxis(); 1468 } 1463 1469 1464 1470 sAxis = (parentAxis + 1) % 3; … … 1476 1482 { 1477 1483 //-- place split plane using heuristics 1484 1478 1485 nCostRatio[axis] = 1479 1486 EvalLocalCostHeuristics(tData, 1480 1487 box, 1481 1488 axis, 1482 nPosition[axis]); 1489 nPosition[axis], 1490 *usedRays); 1483 1491 } 1484 1492 else 1485 1493 { 1486 1494 //-- split plane position is spatial median 1495 1487 1496 nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 1488 1497 nCostRatio[axis] = EvalLocalSplitCost(tData, … … 1505 1514 } 1506 1515 1507 ///////////////////////// ///////1516 ///////////////////////// 1508 1517 //-- assign values of best split 1509 1518 … … 1571 1580 1572 1581 1573 /////////////////// /////////////////1582 /////////////////// 1574 1583 //-- evaluate render cost heuristics 1575 1584 1576 const int lowerPvsLimit =mViewCellsManager->GetMinPvsSize();1577 const int upperPvsLimit =mViewCellsManager->GetMaxPvsSize();1578 1579 const float penaltyOld = EvalPvsPenalty( (int)totalPvs, lowerPvsLimit, upperPvsLimit);1580 const float penaltyFront = EvalPvsPenalty( (int)pvsFront, lowerPvsLimit, upperPvsLimit);1581 const float penaltyBack = EvalPvsPenalty( (int)pvsBack, lowerPvsLimit, upperPvsLimit);1585 const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize(); 1586 const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize(); 1587 1588 const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit); 1589 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 1590 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 1582 1591 1583 1592 const float oldRenderCost = pOverall * penaltyOld; … … 1590 1599 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 1591 1600 1592 #ifdef GTP GTP_DEBUG1601 #ifdef GTP_DEBUG 1593 1602 Debug << "\nvsp render cost decrease" << endl 1594 1603 << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl … … 1619 1628 KdLeaf::NewMail(3); 1620 1629 1621 const int pvsSize = data.mPvs;1630 const float pvsSize = data.mPvs; 1622 1631 RayInfoContainer::const_iterator rit, rit_end = data.mRays->end(); 1623 1632 … … 1863 1872 if (data.mPvs > mVspStats.maxPvs) 1864 1873 { 1865 mVspStats.maxPvs = data.mPvs;1866 } 1867 1868 mVspStats.pvs += data.mPvs;1874 mVspStats.maxPvs = (int)data.mPvs; 1875 } 1876 1877 mVspStats.pvs += (int)data.mPvs; 1869 1878 1870 1879 if (data.mDepth < mVspStats.minDepth) … … 2215 2224 2216 2225 2217 int VspTree::EvalPvsSize(const RayInfoContainer &rays) const2218 { 2219 int pvsSize= 0;2226 float VspTree::EvalPvsCost(const RayInfoContainer &rays) const 2227 { 2228 float pvsCost = 0; 2220 2229 2221 2230 Intersectable::NewMail(); … … 2228 2237 { 2229 2238 VssRay *ray = (*rit).mRay; 2239 2240 pvsCost += EvalContributionToPvs(*ray, true); 2241 2230 2242 #if COUNT_ORIGIN_OBJECTS 2231 pvsSize += EvalContributionToPvs(*ray, true); 2232 #else 2233 pvsSize += EvalContributionToPvs(*ray, false); 2243 pvsCost += EvalContributionToPvs(*ray, false); 2234 2244 #endif 2235 2245 } 2236 2246 2237 return pvs Size;2247 return pvsCost; 2238 2248 } 2239 2249 … … 2307 2317 { 2308 2318 VssRay *ray = (*rit).mRay; 2319 2320 pvsSize += EvalPvsEntriesContribution(*ray, true); 2321 2309 2322 #if COUNT_ORIGIN_OBJECTS 2310 pvsSize += EvalPvsEntriesContribution(*ray, true);2311 #else2312 2323 pvsSize += EvalPvsEntriesContribution(*ray, false); 2313 2324 #endif … … 2890 2901 2891 2902 /// collect pvs from rays 2892 const int pvsSize = EvalPvsSize(rays);2903 const float pvsCost = EvalPvsCost(rays); 2893 2904 2894 2905 // root and bounding box were already constructed … … 2901 2912 2902 2913 // first vsp traversal data 2903 VspTraversalData vData(leaf, 0, &rays, pvs Size, prop, mBoundingBox);2914 VspTraversalData vData(leaf, 0, &rays, pvsCost, prop, mBoundingBox); 2904 2915 2905 2916 … … 2923 2934 leaf->SetSubdivisionCandidate(splitCandidate); 2924 2935 2925 mTotalCost = (float)pvsSize;2936 mTotalCost = pvsCost; 2926 2937 mPvsEntries = EvalPvsEntriesSize(rays); 2927 2938 … … 3057 3068 3058 3069 3059 int VspTree::PrepareHeuristics(const VssRay &ray, const bool isTermination)3060 { 3061 int pvsSize = 0;3070 float VspTree::PrepareHeuristics(const VssRay &ray, const bool isTermination) 3071 { 3072 float pvsSize = 0; 3062 3073 3063 3074 Intersectable *obj;
Note: See TracChangeset
for help on using the changeset viewer.