Changeset 1291 for GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
- Timestamp:
- 08/28/06 18:42:33 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
r1288 r1291 1264 1264 1265 1265 1266 #if 01267 1268 1266 float OspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 1269 1267 const OspTraversalData &tData, … … 1274 1272 1275 1273 // probability that view point lies in back / front node 1276 float pOverall = 0;//data.mProbability; // todo matt§: value ok? 1277 float pFront = 0; 1278 float pBack = 0; 1279 float pFrontAndBack = 0; 1280 1281 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 1282 1283 Intersectable::NewMail(3); 1284 1285 KdLeaf *leaf = tData.mNode; 1286 const int totalPvs = (int)leaf->mObjects.size(); 1287 1288 RayInfoContainer frontRays, backRays; 1289 ClassifyRays(*tData.mRays, leaf, candidatePlane, frontRays, backRays); 1290 1291 ViewCellContainer touchedViewCells; 1292 1293 // sum up volume seen from the objects of left and right children 1294 // => the volume is the weight for the render cost equation 1295 ViewCell::NewMail(3); 1296 1297 RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 1298 1299 for (rit = tData.mRays->begin(); rit < rit_end; ++ rit) 1300 { 1301 VssRay *ray = (*rit).mRay; 1302 1303 // add volume to volumes of left and / or right children 1304 // if one of the ray end points is inside 1305 const int classification = ClassifyRay(ray, leaf, candidatePlane); 1306 1307 ViewCellContainer viewCells; 1308 mVspTree->GetViewCells(*ray, viewCells); 1309 1310 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1311 1312 // traverse through view cells and classify them according 1313 // to them being seen from to back / front / front and back node 1314 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 1315 { 1316 ViewCell *vc = *vit; 1317 1318 // if not previously mailed 1319 if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 1320 { 1321 touchedViewCells.push_back(vc); 1322 } 1323 1324 // classify / mail the view cell 1325 MailViewCell(vc, classification); 1326 } 1327 } 1328 1329 // evaluate view cells volume contribution 1330 // with respect to the mail box classification 1331 ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 1332 1333 for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 1334 { 1335 AddViewCellVolumeContri(*vit, pFront, pBack, pFrontAndBack); 1336 } 1337 1338 ////////////////////////////////////////////// 1339 // 1340 // evaluate contribution of objects which are part of other kd nodes 1341 // which are seen by the same view cell 1342 // These contributions cannot be reduced by splitting, because 1343 // the object would still be part of the pvs 1344 1345 float additionalFrontRenderCost = 0; 1346 float additionalBackRenderCost = 0; 1347 1348 MailablePvsData::NewMail(); 1349 1350 for (rit = tData.mRays->begin(); rit != tData.mRays->end(); ++ rit) 1351 { 1352 VssRay *ray = (*rit).mRay; 1353 1354 ViewCellContainer viewCells; 1355 mVspTree->GetViewCells(*ray, viewCells); 1356 1357 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1358 1359 // traverse through view cells 1360 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 1361 { 1362 ViewCell *viewCell = *vit; 1363 1364 // for a view cell: 1365 // if object is also in the kd pvs entries from other kd leaves, 1366 // render cost cannot be reduced for this view cell 1367 // => the render cost was falsly reduced, add them again 1368 1369 if (ray->mTerminationObject) 1370 { 1371 Intersectable *obj = ray->mTerminationObject; 1372 1373 const bool renderCostWrong = 1374 ViewCellHasMultipleReferences(obj, viewCell, true); 1375 1376 // if there is already an entry of this object in the view cell pvs 1377 if (renderCostWrong) 1378 { 1379 // view cell was counted only for front or back => correct tjos 1380 if (viewCell->Mailed(1) && obj->Mailed()) 1381 { 1382 additionalFrontRenderCost += viewCell->GetVolume(); 1383 } 1384 else if (viewCell->Mailed() && obj->Mailed(1)) 1385 { 1386 additionalBackRenderCost += viewCell->GetVolume(); 1387 } 1388 } 1389 } 1390 1391 if (ray->mOriginObject) 1392 { 1393 Intersectable *obj = ray->mOriginObject; 1394 1395 const bool renderCostWrong = 1396 ViewCellHasMultipleReferences(obj, viewCell, true); 1397 // if there is already an entry of this object in the view cell pvs 1398 if (renderCostWrong) 1399 { 1400 if (viewCell->Mailed(1) && obj->Mailed()) 1401 { 1402 additionalFrontRenderCost += viewCell->GetVolume(); 1403 } 1404 else if (viewCell->Mailed() && obj->Mailed(1)) 1405 { 1406 additionalBackRenderCost += viewCell->GetVolume(); 1407 } 1408 } 1409 } 1410 } 1411 } 1412 1413 ///////////////////////////// 1414 1415 1416 // these are non-overlapping sets 1417 pOverall = pFront + pBack + pFrontAndBack; 1418 1419 1420 //-- pvs rendering heuristics 1421 1422 const float oldRenderCost = pOverall * totalPvs; 1423 1424 // sum up the terms: 1425 // the view cells seeing 1426 // a) the left node are weighted by the #left node objects 1427 // b) the right node are weighted by the #right node objects 1428 // c) both nodes are weighted by the #parent node objects 1429 const float newRenderCost = pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack 1430 + additionalFrontRenderCost + additionalBackRenderCost; 1431 1432 // normalize volume with view space volume 1433 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 1434 1435 Debug << "\n(((( eval render cost decrease ))))" << endl 1436 << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl 1437 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol 1438 << " front and back p " << pFrontAndBack / viewSpaceVol << " p: " << tData.mProbability / viewSpaceVol << endl 1439 << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 1440 << "render cost decrease: " << renderCostDecrease << endl 1441 << "additional front " << additionalFrontRenderCost / viewSpaceVol 1442 << " additional back " << additionalBackRenderCost / viewSpaceVol << endl; 1443 1444 if (oldRenderCost < newRenderCost * 0.99) 1445 Debug <<"error!!"<<endl; 1446 1447 //if ((((pOverall - tData.mProbability) / viewSpaceVol) > 0.00001)) 1448 // Debug << "ERROR!!"<<endl; 1449 1450 normalizedOldRenderCost = oldRenderCost / viewSpaceVol; 1451 1452 1453 return renderCostDecrease; 1454 } 1455 1456 #else 1457 1458 float OspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 1459 const OspTraversalData &tData, 1460 float &normalizedOldRenderCost) const 1461 { 1462 float pvsFront = 0; 1463 float pvsBack = 0; 1464 1465 // probability that view point lies in back / front node 1466 float pOverall = 0;//data.mProbability; // todo matt§: value ok? 1274 float pOverall = 0; 1467 1275 float pFront = 0; 1468 1276 float pBack = 0; … … 1504 1312 } 1505 1313 1506 1507 1314 ViewCellContainer touchedViewCells; 1508 1315 … … 1603 1410 1604 1411 ///////////////////////////// 1605 1606 1607 // these are non-overlapping sets1608 pOverall = pFront + pBack + pFrontAndBack;1609 1610 1611 1412 //-- pvs rendering heuristics 1612 1413 1613 const float oldRenderCost = rc; //pOverall * totalPvs;1414 const float oldRenderCost = rc; 1614 1415 1615 1416 // sum up the terms: … … 1618 1419 // b) the right node are weighted by the #right node objects 1619 1420 // c) both nodes are weighted by the #parent node objects 1620 const float newRenderCost = newRc //pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack1621 ;// + additionalFrontRenderCost + additionalBackRenderCost; 1421 const float newRenderCost = newRc; 1422 1622 1423 1623 1424 // normalize volume with view space volume 1624 1425 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 1625 1426 1626 Debug << "\n(((( eval render cost decrease ))))" << endl 1627 << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl 1628 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol 1629 << " front and back p " << pFrontAndBack / viewSpaceVol << " p: " << tData.mProbability / viewSpaceVol << endl 1427 Debug << "\nrender cost decrease: " << endl 1630 1428 << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 1631 1429 << "render cost decrease: " << renderCostDecrease << endl; 1632 //<< "additional front " << additionalFrontRenderCost / viewSpaceVol1633 //<< " additional back " << additionalBackRenderCost / viewSpaceVol << endl;1634 1635 if (oldRenderCost < newRenderCost * 0.99)1636 Debug <<"error!!"<<endl;1637 1638 //if ((((pOverall - tData.mProbability) / viewSpaceVol) > 0.00001))1639 // Debug << "ERROR!!"<<endl;1640 1430 1641 1431 normalizedOldRenderCost = oldRenderCost / viewSpaceVol; … … 1644 1434 return renderCostDecrease; 1645 1435 } 1646 #endif1647 1436 1648 1437 … … 2234 2023 MailablePvsData::NewMail(); 2235 2024 2236 /*RayInfoContainer::const_iterator rit, rit_end = rays.end();2237 2238 for (rit = rays.begin(); rit < rit_end; ++ rit)2239 {2240 VssRay *ray = (*rit).mRay;2241 2242 ViewCellContainer viewCells;2243 mVspTree->GetViewCells(*ray, viewCells);2244 2245 ViewCellContainer::const_iterator vit, vit_end = viewCells.end();2246 2247 // traverse through view cells and classify them according2248 // to them being seen from to back / front / front and back node2249 for (vit = viewCells.begin(); vit != vit_end; ++ vit)2250 {2251 ViewCell *vc = *vit;2252 2253 Intersectable *obj = ray->mTerminationObject;2254 if (obj)2255 {2256 float contri;2257 AddViewCellToObjectPvs(obj, vc, contri, true);2258 }2259 2260 obj = ray->mOriginObject;2261 if (obj)2262 {2263 float contri;2264 AddViewCellToObjectPvs(obj, vc, contri, true);2265 }2266 }2267 }*/2268 2269 2025 ViewCellContainer touchedViewCells; 2270 2026 CollectTouchedViewCells(rays, touchedViewCells); … … 2297 2053 { 2298 2054 MailablePvsData::NewMail(); 2299 2300 /*RayInfoContainer::const_iterator rit, rit_end = rays.end();2301 for (rit = rays.begin(); rit < rit_end; ++ rit)2302 {2303 VssRay *ray = (*rit).mRay;2304 2305 // test if intersection point with one of the objects is inside this node2306 ViewCellContainer viewCells;2307 mVspTree->GetViewCells(*ray, viewCells);2308 2309 ViewCellContainer::const_iterator vit, vit_end = viewCells.end();2310 2311 // traverse through view cells and classify them according2312 // to them being seen from to back / front / front and back node2313 for (vit = viewCells.begin(); vit != vit_end; ++ vit)2314 {2315 ViewCell *vc = *vit;2316 Intersectable *obj = ray->mTerminationObject;2317 2318 if (obj)2319 {2320 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc);2321 2322 if (vdata && !vdata->Mailed())2323 {2324 vdata->Mail();2325 obj->mViewCellPvs.RemoveSample(vc, 1);2326 }2327 }2328 2329 obj = ray->mOriginObject;2330 2331 if (obj)2332 {2333 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc);2334 2335 if (vdata && !vdata->Mailed())2336 {2337 vdata->Mail();2338 obj->mViewCellPvs.RemoveSample(vc, 1);2339 }2340 }2341 }2342 }*/2343 2055 2344 2056 ViewCellContainer touchedViewCells;
Note: See TracChangeset
for help on using the changeset viewer.