Changeset 441
- Timestamp:
- 12/01/05 18:50:06 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r437 r441 19 19 20 20 Preprocessor { 21 #type sampling22 type vss21 type sampling 22 # type vss 23 23 } 24 24 … … 99 99 100 100 ViewCells { 101 #hierarchy kdTree 102 #hierarchy vspTree 103 hierarchy bspTree 104 #hierarchy sceneDependent 101 loadFromFile false 102 #type kdTree 103 #type vspTree 104 type bspTree 105 #type sceneDependent 105 106 106 107 height 5.0 … … 123 124 BspTree { 124 125 Construction { 125 input fromSamples 126 # input fromViewCells 127 # input fromSceneGeometry 128 samples 50000 126 samples 200000 129 127 sideTolerance 0.005 130 128 } … … 169 167 maxRayCandidates 50 170 168 169 maxTests 500 170 171 171 # factors for evaluating split plane costs 172 172 Factor { … … 186 186 minRays 300 187 187 minPolygons -1 188 maxDepth 20189 minPvs 400188 maxDepth 40 189 minPvs 200 190 190 minArea 0.01 191 191 maxRayContribution 0.005 -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r438 r441 1175 1175 "true"); 1176 1176 1177 RegisterOption("ViewCells. hierarchy",1177 RegisterOption("ViewCells.type", 1178 1178 optString, 1179 "-view_cells_ hierarchy",1179 "-view_cells_type", 1180 1180 "bspTree"); 1181 1182 RegisterOption("ViewCells.loadFromFile", 1183 optBool, 1184 "-view_cells_load_from_file", 1185 "false"); 1181 1186 1182 1187 RegisterOption("ViewCells.maxViewCells", … … 1329 1334 "-bsp_max_plane_candidates=", 1330 1335 "20"); 1336 1337 RegisterOption("BspTree.maxTests", 1338 optInt, 1339 "-bsp_max_tests=", 1340 "5000"); 1331 1341 1332 1342 RegisterOption("BspTree.Visualization.samples", -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r440 r441 175 175 int bspConstructionSamples = 0; 176 176 177 mBspTree = new BspTree(); 178 177 179 environment->GetIntValue("BspTree.Construction.samples", bspConstructionSamples); 178 180 mViewCellsManager = new BspViewCellsManager(mBspTree, bspConstructionSamples); … … 212 214 213 215 bool loadViewCells = false; 214 environment->GetBoolValue("ViewCell .Construction.loadFromFile", loadViewCells);216 environment->GetBoolValue("ViewCells.loadFromFile", loadViewCells); 215 217 216 218 //-- load view cells from file if requested -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
r436 r441 229 229 dir = vssRay.GetDir() / dist; 230 230 231 intersections.push_back(Intersection(dist, vssRay.mTerminationObject, 0)); 231 if (vssRay.mTerminationObject) 232 intersections.push_back(Intersection(dist, vssRay.mTerminationObject, 0)); 232 233 233 234 Precompute(); -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h
r440 r441 37 37 return s; 38 38 } 39 40 SimulationStatistics() 41 { 42 Reset(); 43 } 39 44 }; 40 45 -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r440 r441 27 27 void 28 28 SamplingPreprocessor::SetupRay(Ray &ray, 29 30 29 const Vector3 &point, 30 const Vector3 &direction, 31 31 const int type, 32 32 const Ray::Intersection &origin) … … 57 57 58 58 59 int 59 void 60 60 SamplingPreprocessor::CastRays(const RayContainer &rays, 61 61 int &sampleContributions, 62 62 int &contributingSamples) 63 63 { 64 64 // cast ray to KD tree to find intersection with other objects 65 65 RayContainer::const_iterator it, it_end = rays.end(); 66 66 67 67 for (it = rays.begin(); it != it_end; ++it) 68 mKdTree->CastRay((*it)); 69 70 sampleContributions = mViewCellsManager->CastRays(rays); 68 mKdTree->CastRay(*(*it)); 69 70 // for KD tree, intersecting view cells are already known, so no 71 // additional ray must be cast to them 72 const bool castRaysToViewCells = 73 (mViewCellsManager->GetType() != ViewCellsManager::KD); 74 75 mViewCellsManager->ComputeSampleContributions(rays, 76 castRaysToViewCells, 77 sampleContributions, 78 contributingSamples); 71 79 } 72 80 73 81 int 74 SamplingPreprocessor::CastRay( constRay &ray)82 SamplingPreprocessor::CastRay(Ray &ray) 75 83 { 76 84 // cast ray to KD tree to find intersection with other objects 77 85 mKdTree->CastRay(ray); 78 86 79 return mViewCellsManager->CastRay(ray); 87 bool castRayToViewCells = mViewCellsManager->GetType() != ViewCellsManager::KD; 88 89 return mViewCellsManager->ComputeSampleContributions(ray, castRayToViewCells); 80 90 } 81 91 … … 134 144 int 135 145 SamplingPreprocessor::CastEdgeSamples( 136 137 138 139 140 146 Intersectable *object, 147 const Vector3 &point, 148 MeshInstance *mi, 149 const int samples 150 ) 141 151 { 142 152 Ray ray; … … 156 166 float t = RandomValue(0.0f,1.0f); 157 167 Vector3 target = t*poly.mVertices[edge] + (1.0f-t)*poly.mVertices[(edge + 1)% 158 168 poly.mVertices.size()]; 159 169 SetupRay(ray, point, target - point, Ray::LOCAL_RAY, Ray::Intersection(0, object, 0)); 160 170 if (!mesh->CastRay(ray, mi)) { … … 288 298 for (int k=0; k < mSamplesPerPass; k++) { 289 299 bool reverseSample = false; 290 291 300 292 301 if (nodeToSample) { 293 302 AxisAlignedBox3 box = mKdTree->GetBox(nodeToSample); … … 313 322 Ray::Intersection source = 314 323 Ray::Intersection(0, reverseSample ? NULL : object, faceIndex); 315 324 316 325 // construct a ray 317 326 SetupRay(*ray, point, direction, Ray::LOCAL_RAY, source); … … 323 332 passSampleContributions += sampleContributions; 324 333 }*/ 325 326 //-------------------327 ProcessViewCells(ray,328 objects,329 passContributingSamples,330 passSampleContributions);331 334 } 332 335 } else { … … 340 343 } 341 344 342 CastRays(passRays, passSampleContributions, passContributingSamples); 345 //------------------- 346 // cast rays for view cells construction 347 ProcessViewCells(passRays, 348 objects, 349 passSampleContributions, 350 passContributingSamples); 351 343 352 CLEAR_CONTAINER(passRays); 344 passRays.clear(); 345 353 346 354 totalSamples += passSamples; 347 355 … … 349 357 // HoleSamplingPass(); 350 358 351 mPass ++;359 mPass ++; 352 360 353 361 pvsSize += passSampleContributions; 354 362 355 363 float avgRayContrib = (passContributingSamples > 0) ? … … 393 401 cout << "\nevaluating bsp view cells render time before merge ... "; 394 402 395 SimulationStatistics ss = mViewCellsManager->SimulateRendering();403 const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 396 404 397 405 cout << " finished" << endl; … … 400 408 401 409 mViewCellsManager->Visualize(objects, mSampleRays); 402 403 404 } 405 406 void SamplingPreprocessor::ProcessViewCells(const Ray &ray,410 411 return true; 412 } 413 414 void SamplingPreprocessor::ProcessViewCells(const RayContainer &newRays, 407 415 const ObjectContainer &objects, 408 int &contributingSamples, 409 int &sampleContributions) 410 { 416 int &sampleContributions, 417 int &contributingSamples) 418 { 419 // cast rays to view cells 420 CastRays(newRays, sampleContributions, contributingSamples); 421 411 422 // save rays for view cells construction 412 423 if (!mViewCellsManager->ViewCellsConstructed()) 424 { 425 RayContainer::const_iterator it, it_end = newRays.end(); 426 427 if ((int)mVssSampleRays.size() < mViewCellsManager->GetConstructionSamples()) 413 428 { 414 if ((int)mSampleRays.size() < mViewCellsManager->GetConstructionSamples()) 415 mVssSampleRays.push_back(new VssRay(ray)); 429 for (it = newRays.begin(); it != it_end; ++ it) 430 mVssSampleRays.push_back(new VssRay(*(*it))); 431 } 416 432 else 417 433 { 418 434 mViewCellsManager->Construct(objects, mVssSampleRays); 435 419 436 // construct view cells using the collected samples 420 437 cout << "building view cells from " << (int)mSampleRays.size() << " samples " << endl; … … 432 449 ((int)mSampleRays.size() < mViewCellsManager->GetVisualizationSamples())) 433 450 { 434 mSampleRays.push_back(new Ray(ray)); 435 } 436 } 451 RayContainer::const_iterator it, it_end = newRays.end(); 452 453 for (it = newRays.begin(); it != it_end; ++ it) 454 mSampleRays.push_back(new Ray(*(*it))); 455 } 456 } -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r440 r441 37 37 38 38 /** Casts a bundle of sample rays into the scene. 39 @param sampleContributions the number of sample contributions 40 @param contributingSamples the number of samples contributing 39 41 */ 40 int CastRays(const RayContainer &rays, 41 int &sampleContribtion, 42 int &contributingSamples); 42 void 43 CastRays(const RayContainer &rays, 44 int &sampleContributions, 45 int &contributingSamples); 43 46 44 /** Casts a ray into the scene. 47 /** Casts a single ray into the scene. 48 @returns sample contributions 45 49 */ 46 int 47 CastRay(const Ray &ray); 50 int CastRay(Ray &ray); 48 51 49 52 /** Verify if the exact visibility for this object was established. … … 55 58 along the visibility skeleton. 56 59 */ 57 int CastEdgeSamples( 58 Intersectable *object, 59 const Vector3 &point, 60 MeshInstance *mi, 61 const int samples 62 ); 60 int 61 CastEdgeSamples( 62 Intersectable *object, 63 const Vector3 &point, 64 MeshInstance *mi, 65 const int samples 66 ); 63 67 64 68 /** Processes the view cells during a pass. 65 @param ray the current ray66 69 @param newRays the newly cast rays 70 @param sampleContributions returns the accumulated contribution of the samples 67 71 @param contributingSamples returns the samples contributing to pvs 68 @param sampleContributions returns the accumulated 69 contribution of the samples 70 */ 72 */ 71 73 72 void ProcessViewCells(const Ray &ray,74 void ProcessViewCells(const RayContainer &newRays, 73 75 const ObjectContainer &objects, 74 int & contributingSamples,75 int & sampleContributions);76 int &sampleContributions, 77 int &contributingSamples); 76 78 77 79 /** Adds objects samples to kd and bsp view cells. -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r440 r441 263 263 /****************************************************************/ 264 264 265 BspTree::BspTree(BspViewCell *viewCell): 266 mRootCell(viewCell), 265 BspTree::BspTree(): 267 266 mRoot(NULL), 268 267 mStoreLeavesWithRays(false), 269 mPvsUse Area(true),268 mPvsUseLen(false), 270 269 mGenerateViewCells(true) 271 270 { 272 271 Randomize(); // initialise random generator for heuristics 272 273 // the view cell corresponding to unbounded space 274 mRootCell = new BspViewCell(); 273 275 274 276 //-- termination criteria for autopartition … … 307 309 environment->GetIntValue("BspTree.splitPlaneStrategy", mSplitPlaneStrategy); 308 310 environment->GetFloatValue("BspTree.AxisAligned.splitBorder", mSplitBorder); 311 environment->GetIntValue("BspTree.maxTests", mMaxTests); 309 312 310 313 environment->GetFloatValue("BspTree.Construction.sideTolerance", Vector3::sDistTolerance); 311 314 Vector3::sDistToleranceSqrt = Vector3::sDistTolerance * Vector3::sDistTolerance; 312 315 313 // post processing stuff314 environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", mMinPvsDif);315 environment->GetIntValue("ViewCells.PostProcessing.minPvs", mMinPvs);316 environment->GetIntValue("ViewCells.PostProcessing.maxPvs", mMaxPvs);317 316 318 317 Debug << "BSP max depth: " << mTermMaxDepth << endl; … … 410 409 { 411 410 DEL_PTR(mRoot); 411 DEL_PTR(mRootCell); 412 } 413 414 BspViewCell *BspTree::GetRootCell() const 415 { 416 return mRootCell; 412 417 } 413 418 … … 433 438 mRoot = new BspLeaf(); 434 439 435 tStack.push(BspTraversalData(mRoot, polys, 0, mRootCell, new BoundedRayContainer(), 0,436 mBox.SurfaceArea(), new BspNodeGeometry()));440 tStack.push(BspTraversalData(mRoot, polys, 0, mRootCell, 441 new BoundedRayContainer(), 0)); 437 442 438 443 while (!tStack.empty()) … … 470 475 mRootCell, 471 476 tData.mRays, 472 tData.mPvs, 473 mBox.SurfaceArea(), 474 new BspNodeGeometry()); 477 tData.mPvs); 475 478 476 479 BspTraversalData backData(interior->GetBack(), … … 479 482 mRootCell, 480 483 tData.mRays, 481 tData.mPvs, 482 mBox.SurfaceArea(), 483 new BspNodeGeometry()); 484 tData.mPvs); 484 485 485 486 if (!mGenerateViewCells) … … 735 736 736 737 BspTraversalData tData(mRoot, polys, 0, mRootCell, rays, 737 ComputePvsSize(*rays) , cell->GetArea(), cell);738 ComputePvsSize(*rays)); 738 739 739 740 tStack.push(tData); … … 755 756 } 756 757 758 Debug << "here2" << endl; 757 759 cout << "finished\n"; 758 760 … … 766 768 ((int)data.mRays->size() <= mTermMinRays) || 767 769 (data.mPvs <= mTermMinPvs) || 768 (data.mArea <= mTermMinArea) ||769 770 (data.mDepth >= mTermMaxDepth) || 770 771 (data.GetAvgRayContribution() < mTermMaxRayContribution)); … … 815 816 DEL_PTR(tData.mPolygons); 816 817 DEL_PTR(tData.mRays); 817 DEL_PTR(tData.mGeometry); 818 818 819 819 return leaf; 820 820 } … … 824 824 825 825 BspTraversalData tFrontData(NULL, new PolygonContainer(), tData.mDepth + 1, mRootCell, 826 new BoundedRayContainer(), 0 , 0, new BspNodeGeometry());826 new BoundedRayContainer(), 0); 827 827 BspTraversalData tBackData(NULL, new PolygonContainer(), tData.mDepth + 1, mRootCell, 828 new BoundedRayContainer(), 0 , 0, new BspNodeGeometry());828 new BoundedRayContainer(), 0); 829 829 830 830 // create new interior node and two leaf nodes … … 860 860 DEL_PTR(tData.mPolygons); 861 861 DEL_PTR(tData.mRays); 862 DEL_PTR(tData.mGeometry); 863 862 864 863 return interior; 865 864 } … … 901 900 902 901 BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 902 903 Debug << "*********************" << endl; 904 long startTime = GetTime(); 905 903 906 // select subdivision plane 904 907 BspInterior *interior = 905 908 new BspInterior(SelectPlane(leaf, tData)); 906 909 Debug << "time used for split plane selection: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 907 910 #ifdef _DEBUG 908 911 Debug << interior << endl; 909 912 #endif 910 913 914 915 Debug << "number of rays: " << tData.mRays->size() << endl; 916 Debug << "number of polys: " << tData.mPolygons->size() << endl; 917 918 startTime = GetTime(); 919 911 920 // subdivide rays into front and back rays 912 921 SplitRays(interior->mPlane, *tData.mRays, *frontData.mRays, *backData.mRays); 913 922 923 Debug << "time used for rays splitting: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 924 925 startTime = GetTime(); 914 926 // subdivide polygons with plane 915 927 mStat.splits += interior->SplitPolygons(*tData.mPolygons, … … 918 930 coincident); 919 931 932 Debug << "time used for polygon splitting: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 933 920 934 // compute pvs 921 935 frontData.mPvs = ComputePvsSize(*frontData.mRays); 922 936 backData.mPvs = ComputePvsSize(*backData.mRays); 923 924 // split geometry and compute area925 if (1)926 {927 tData.mGeometry->SplitGeometry(*frontData.mGeometry,928 *backData.mGeometry,929 *this,930 interior->mPlane);931 932 933 frontData.mArea = frontData.mGeometry->GetArea();934 backData.mArea = backData.mGeometry->GetArea();935 }936 937 937 938 // compute accumulated ray length … … 1308 1309 const int frontAndBackId = ViewCell::sMailId; 1309 1310 1310 PolygonContainer::const_iterator it, it_end = polys.end(); 1311 1312 for (it = polys.begin(); it != it_end; ++ it) 1313 { 1314 const int classification = (*it)->ClassifyPlane(candidatePlane); 1311 bool useRand;; 1312 int limit; 1313 1314 // choose test polyongs randomly if over threshold 1315 if ((int)polys.size() > mMaxTests) 1316 { 1317 useRand = true; 1318 limit = mMaxTests; 1319 } 1320 else 1321 { 1322 useRand = false; 1323 limit = (int)polys.size(); 1324 } 1325 1326 1327 for (int i = 0; i < limit; ++ i) 1328 { 1329 const int testIdx = useRand ? Random(limit) : i; 1330 1331 Polygon3 *poly = polys[testIdx]; 1332 1333 const int classification = poly->ClassifyPlane(candidatePlane); 1315 1334 1316 1335 if (mSplitPlaneStrategy & BALANCED_POLYS) … … 1323 1342 { 1324 1343 if (classification == Polygon3::COINCIDENT) 1325 sumPolyArea += (*it)->GetArea();1344 sumPolyArea += poly->GetArea(); 1326 1345 //totalArea += area; 1327 1346 } … … 1329 1348 if (mSplitPlaneStrategy & BLOCKED_RAYS) 1330 1349 { 1331 const float blockedRays = (float) (*it)->mPiercingRays.size();1350 const float blockedRays = (float)poly->mPiercingRays.size(); 1332 1351 1333 1352 if (classification == Polygon3::COINCIDENT) … … 1340 1359 if (mSplitPlaneStrategy & BALANCED_VIEW_CELLS) 1341 1360 { 1342 MeshInstance *viewCell = (*it)->mParent;1361 MeshInstance *viewCell = poly->mParent; 1343 1362 1344 1363 // assure that we only count a view cell … … 1434 1453 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane, 1435 1454 const BoundedRayContainer &rays, 1436 const int pvs, 1437 const float area, 1438 const BspNodeGeometry &cell) const 1455 const int pvs) const 1439 1456 { 1440 1457 float val = 0; … … 1442 1459 float sumBalancedRays = 0; 1443 1460 float sumRaySplits = 0; 1444 1445 int backId = 0;1446 int frontId = 0;1447 int frontAndBackId = 0;1448 1461 1449 1462 int frontPvs = 0; … … 1451 1464 1452 1465 // probability that view point lies in child 1453 float pOverall = 0;1454 float pFront = 0 ;1455 float pBack = 0 ;1466 float pOverall = 1; 1467 float pFront = 0.5; 1468 float pBack = 0.5; 1456 1469 1457 1470 if (mSplitPlaneStrategy & PVS) … … 1459 1472 // create unique ids for pvs heuristics 1460 1473 GenerateUniqueIdsForPvs(); 1461 1462 if (mPvsUseArea) // use front and back cell areas to approximate volume1463 {1464 // construct child geometry with regard to the candidate split plane1465 BspNodeGeometry frontCell;1466 BspNodeGeometry backCell;1467 1468 cell.SplitGeometry(frontCell, backCell, *this, candidatePlane);1469 1470 pFront = frontCell.GetArea();1471 pBack = backCell.GetArea();1472 1473 pOverall = area;1474 }1475 1474 } 1476 1475 1477 BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 1478 1479 for (rit = rays.begin(); rit != rays.end(); ++ rit) 1480 { 1481 Ray *ray = (*rit)->mRay; 1482 const float minT = (*rit)->mMinT; 1483 const float maxT = (*rit)->mMaxT; 1476 bool useRand;; 1477 int limit; 1478 1479 // choose test polyongs randomly if over threshold 1480 if ((int)rays.size() > mMaxTests) 1481 { 1482 useRand = true; 1483 limit = mMaxTests; 1484 } 1485 else 1486 { 1487 useRand = false; 1488 limit = (int)rays.size(); 1489 } 1490 1491 for (int i = 0; i < limit; ++ i) 1492 { 1493 const int testIdx = useRand ? Random(limit) : i; 1494 1495 BoundedRay *bRay = rays[testIdx]; 1496 1497 Ray *ray = bRay->mRay; 1498 const float minT = bRay->mMinT; 1499 const float maxT = bRay->mMaxT; 1484 1500 1485 1501 Vector3 entP, extP; … … 1511 1527 AddObjToPvs(ray->sourceObject.mObject, cf, frontPvs, backPvs); 1512 1528 1513 if (!mPvsUseArea) // use front and back cell areas to approximate volume 1514 { 1515 float len = Distance(entP, extP); 1516 pOverall += len; 1517 1518 // use length of rays to approximate volume 1519 switch (cf) 1529 float len = 1; 1530 if (0){ 1531 if (mPvsUseLen) 1532 len = SqrDistance(entP, extP); 1533 1534 // use length of rays to approximate volume 1535 if (Ray::BACK && Ray::COINCIDENT) 1536 pBack += len; 1537 if (Ray::FRONT && Ray::COINCIDENT) 1538 pFront += len; 1539 if (Ray::FRONT_BACK || Ray::BACK_FRONT) 1540 { 1541 if (mPvsUseLen) 1520 1542 { 1521 case Ray::COINCIDENT: 1522 pBack += len; 1523 pFront += len; 1524 break; 1525 case Ray::BACK: 1526 pBack += len; 1527 break; 1528 case Ray::FRONT: 1529 pFront += len; 1530 break; 1531 case Ray::FRONT_BACK: 1532 { 1533 // find intersection of ray segment with plane 1534 const Vector3 extp = ray->Extrap(maxT); 1535 const float t = candidatePlane.FindT(ray->GetLoc(), extp); 1536 1537 const float newT = t * maxT; 1538 float newLen = Distance(ray->Extrap(newT), extp); 1539 1540 pFront += len - newLen; 1541 pBack += newLen; 1542 } 1543 break; 1544 case Ray::BACK_FRONT: 1545 { 1546 // find intersection of ray segment with plane 1547 const Vector3 extp = ray->Extrap(maxT); 1548 const float t = candidatePlane.FindT(ray->GetLoc(), extp); 1549 1550 const float newT = t * maxT; 1551 float newLen = Distance(ray->Extrap(newT), extp); 1552 1553 pFront += len; 1554 pBack += len - newLen; 1555 } 1556 break; 1557 default: 1558 Debug << "Should not come here 2" << endl; 1559 break; 1543 const Vector3 extp = ray->Extrap(maxT); 1544 const float t = candidatePlane.FindT(ray->GetLoc(), extp); 1545 1546 const float newT = t * maxT; 1547 const float newLen = SqrDistance(ray->Extrap(newT), extp); 1548 1549 if (Ray::FRONT_BACK) 1550 { 1551 pFront += len - newLen; 1552 pBack += newLen; 1553 } 1554 else 1555 { 1556 pBack += len - newLen; 1557 pFront += newLen; 1558 } 1560 1559 } 1561 } 1560 else 1561 { 1562 ++ pFront; 1563 ++ pBack; 1564 } 1565 }} 1562 1566 } 1563 1567 } … … 1572 1576 1573 1577 float denom = pOverall * (float)pvs * 2.0f + Limits::Small; 1574 if ((mSplitPlaneStrategy & PVS) && area && pvs) 1578 1579 if (mSplitPlaneStrategy & PVS) 1575 1580 { 1576 1581 val += mPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / denom; 1577 1582 1578 1583 // give penalty to unbalanced split 1579 if ( 0)1584 if (1) 1580 1585 if (((pFront * 0.2 + Limits::Small) > pBack) || (pFront < (pBack * 0.2 + Limits::Small))) 1581 1586 val += 0.5; 1582 1587 } 1583 1588 1589 1584 1590 #ifdef _DEBUG 1585 1591 Debug << "totalpvs: " << pvs << " ptotal: " << pOverall … … 1664 1670 (mSplitPlaneStrategy & PVS)) 1665 1671 { 1666 val += SplitPlaneCost(candidatePlane, *data.mRays, data.mPvs, 1667 data.mArea, *data.mGeometry); 1672 val += SplitPlaneCost(candidatePlane, *data.mRays, data.mPvs); 1668 1673 } 1669 1674 … … 1736 1741 ++ mStat.maxRayContribNodes; 1737 1742 1738 if (data.mGeometry->GetArea() <= mTermMinArea)1739 ++ mStat.minAreaNodes;1743 //if (data.mGeometry->GetArea() <= mTermMinArea) 1744 // ++ mStat.minAreaNodes; 1740 1745 1741 1746 #ifdef _DEBUG … … 1950 1955 } 1951 1956 } 1952 1953 bool BspTree::MergeViewCells(BspLeaf *front, BspLeaf *back) const1954 {1955 BspViewCell *viewCell =1956 NULL;//todo dynamic_cast<BspViewCell *>(ViewCell::Merge(*front->mViewCell, *back->mViewCell));1957 1958 if (!viewCell)1959 return false;1960 1961 // change view cells of all leaves associated with the1962 // previous view cells1963 1964 BspViewCell *fVc = front->mViewCell;1965 BspViewCell *bVc = back->mViewCell;1966 1967 vector<BspLeaf *> fLeaves = fVc->mBspLeaves;1968 vector<BspLeaf *> bLeaves = bVc->mBspLeaves;1969 1970 vector<BspLeaf *>::const_iterator it;1971 1972 for (it = fLeaves.begin(); it != fLeaves.end(); ++ it)1973 {1974 (*it)->SetViewCell(viewCell);1975 viewCell->mBspLeaves.push_back(*it);1976 }1977 for (it = bLeaves.begin(); it != bLeaves.end(); ++ it)1978 {1979 (*it)->SetViewCell(viewCell);1980 viewCell->mBspLeaves.push_back(*it);1981 }1982 1983 DEL_PTR(fVc);1984 DEL_PTR(bVc);1985 1986 return true;1987 }1988 1989 bool BspTree::ShouldMerge(BspLeaf *front, BspLeaf *back) const1990 {1991 ViewCell *fvc = front->mViewCell;1992 ViewCell *bvc = back->mViewCell;1993 1994 if ((fvc == mRootCell) || (bvc == mRootCell) || (fvc == bvc))1995 return false;1996 1997 int fdiff = fvc->GetPvs().Diff(bvc->GetPvs());1998 1999 if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs)2000 {2001 if ((fvc->GetPvs().GetSize() < mMinPvs) ||2002 (bvc->GetPvs().GetSize() < mMinPvs) ||2003 ((fdiff < mMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif)))2004 {2005 return true;2006 }2007 }2008 2009 return false;2010 }2011 2012 1957 2013 1958 BspTreeStatistics &BspTree::GetStat() … … 2457 2402 if (frontPoly->Valid()) 2458 2403 front.mPolys.push_back(frontPoly); 2404 else 2405 DEL_PTR(frontPoly); 2406 2459 2407 if (backPoly->Valid()) 2460 2408 back.mPolys.push_back(backPoly); 2409 else 2410 DEL_PTR(backPoly); 2461 2411 } 2462 2412 … … 2510 2460 2511 2461 planePoly->Split(plane, *frontPoly, *backPoly); 2462 2463 // don't need anymore 2512 2464 DEL_PTR(planePoly); 2513 2465 DEL_PTR(frontPoly); 2466 2467 // back polygon is belonging to geometry 2514 2468 if (backPoly->Valid()) 2515 2469 planePoly = backPoly; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r440 r441 364 364 /// rays piercing this node 365 365 BoundedRayContainer *mRays; 366 /// area of current node 367 float mArea; 368 BspNodeGeometry *mGeometry; 369 366 370 367 /// pvs size 371 368 int mPvs; … … 385 382 mViewCell(NULL), 386 383 mRays(NULL), 387 mPvs(0), 388 mArea(0.0), 389 mGeometry(NULL) 384 mPvs(0) 390 385 {} 391 386 … … 395 390 ViewCell *viewCell, 396 391 BoundedRayContainer *rays, 397 int pvs, 398 float area, 399 BspNodeGeometry *cell): 392 int pvs): 400 393 mNode(node), 401 394 mPolygons(polys), … … 403 396 mViewCell(viewCell), 404 397 mRays(rays), 405 mPvs(pvs), 406 mArea(area), 407 mGeometry(cell) 398 mPvs(pvs) 408 399 {} 409 400 }; … … 412 403 413 404 /** Default constructor creating an empty tree. 414 @param viewCell view cell corresponding to unbounded space415 405 */ 416 BspTree( BspViewCell *viewCell);417 406 BspTree(); 407 418 408 ~BspTree(); 419 409 410 420 411 const BspTreeStatistics &GetStatistics() const; 421 412 … … 506 497 BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 507 498 508 /** Returns true if merge criteria are reached.509 */510 bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;511 512 /** Merges view cells based on some criteria513 E.g., empty view cells can pe purged, view cells which have514 a very similar PVS can be merged to one larger view cell.515 516 @returns true if merge was successful.517 */518 bool MergeViewCells(BspLeaf *front, BspLeaf *back) const;519 520 499 /** Traverses tree and counts all view cells as well as their PVS size. 521 500 */ 522 501 void EvaluateViewCellsStats(BspViewCellsStatistics &stat) const; 502 503 /** Returns view cell corresponding to unbounded space. 504 */ 505 BspViewCell *GetRootCell() const; 523 506 524 507 /** Parses the environment and stores the global BSP tree parameters … … 601 584 float SplitPlaneCost(const Plane3 &candidatePlane, 602 585 const BoundedRayContainer &rays, 603 const int pvs, 604 const float area, 605 const BspNodeGeometry &cell) const; 586 const int pvs) const; 606 587 607 588 /** Filters next view cell down the tree and inserts it into the appropriate leaves … … 834 815 /// number of candidates for split planes evaluated using the rays 835 816 int mMaxRayCandidates; 836 817 /// maximum tests for split plane evaluation with a single candidate 818 int mMaxTests; 819 837 820 float mCtDivCi; 838 821 … … 856 839 float mBalancedViewCellsFactor; 857 840 858 //-- thresholds used for view cells merge859 int mMinPvsDif;860 int mMinPvs;861 int mMaxPvs;862 841 /// if area or accumulated ray lenght should be used for PVS heuristics 863 bool mPvsUse Area;842 bool mPvsUseLen; 864 843 865 844 private: -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r440 r441 13 13 14 14 15 16 15 ViewCellsManager::ViewCellsManager(): 17 16 mRenderSimulator(NULL), … … 20 19 mVisualizationSamples(0) 21 20 { 22 mUnbounded = GenerateViewCell(); 21 // post processing stuff 22 environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", mMinPvsDif); 23 environment->GetIntValue("ViewCells.PostProcessing.minPvs", mMinPvs); 24 environment->GetIntValue("ViewCells.PostProcessing.maxPvs", mMaxPvs); 23 25 } 24 26 … … 29 31 mVisualizationSamples(0) 30 32 { 31 mUnbounded = GenerateViewCell(); 33 // post processing stuff 34 environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", mMinPvsDif); 35 environment->GetIntValue("ViewCells.PostProcessing.minPvs", mMinPvs); 36 environment->GetIntValue("ViewCells.PostProcessing.maxPvs", mMaxPvs); 32 37 } 33 38 34 39 ViewCellsManager::~ViewCellsManager() 35 40 { 36 DEL_PTR(mUnbounded);37 41 DEL_PTR(mRenderSimulator); 38 42 } … … 63 67 } 64 68 65 int ViewCellsManager::CastRays(const RayContainer &rays) 66 { 67 int sampleContributions = 0; 69 void ViewCellsManager::ComputeSampleContributions(const RayContainer &rays, 70 const bool castRays, 71 int &sampleContributions, 72 int &contributingSamples) 73 { 74 // view cells not yet constructed 75 if (!ViewCellsConstructed()) 76 return; 68 77 69 78 RayContainer::const_iterator it, it_end = rays.end(); 70 79 71 80 for (it = rays.begin(); it != it_end; ++ it) 72 sampleContributions += CastRay(*(*it)); 73 74 return sampleContributions; 81 { 82 sampleContributions +=ComputeSampleContributions(*(*it), castRays); 83 contributingSamples += sampleContributions > 0; 84 } 75 85 } 76 86 … … 139 149 } 140 150 141 ViewCell *ViewCellsManager::Merge (ViewCell &front, ViewCell &back) const151 ViewCell *ViewCellsManager::MergeViewCells(ViewCell &front, ViewCell &back) const 142 152 { 143 153 ViewCell *vc = GenerateViewCell(); … … 158 168 SimulationStatistics ViewCellsManager::SimulateRendering() const 159 169 { 170 if (!ViewCellsConstructed()) 171 return SimulationStatistics(); 172 160 173 return mRenderSimulator->SimulateRendering(); 161 174 } … … 223 236 AxisAlignedBox3 *sceneBbox) 224 237 { 238 // if view cells were already constructed 225 239 if (ViewCellsConstructed()) 226 240 return 0; 227 241 242 Debug << "Constructing bsp view cells" << endl; 243 228 244 int sampleContributions = 0; 229 245 … … 235 251 sampleRays.push_back(new Ray(*rays[i])); 236 252 237 mBspTree->Construct(objects, sampleRays); 238 253 if (mViewCells.empty()) // no view cells loaded 254 mBspTree->Construct(objects, sampleRays); 255 else 256 mBspTree->Construct(mViewCells); 257 239 258 Debug << mBspTree->GetStatistics() << endl; 240 259 CLEAR_CONTAINER(sampleRays); … … 243 262 } 244 263 245 int BspViewCellsManager::CastRay(Ray &ray) 246 { 247 mBspTree->CastRay(ray); 264 int BspViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 265 { 266 // view cells not yet constructed 267 if (!ViewCellsConstructed()) 268 return 0; 269 270 int contributingSamples = 0; 271 272 if (castRay) 273 mBspTree->CastRay(ray); 248 274 249 275 //if (mBspTree->bspIntersections.empty()) return 0; 250 276 251 Intersectable *t erm=277 Intersectable *tObject = 252 278 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL; 253 279 254 return AddSampleContributions(ray, ray.sourceObject.mObject, term); 280 Intersectable *sObject = ray.sourceObject.mObject; 281 282 if (sObject || tObject) 283 { 284 // object can be seen from the view cell => add to view cell pvs 285 for (int j = 0; j < (int)ray.bspIntersections.size(); ++ j) 286 { 287 BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 288 289 // if ray not in unbounded space 290 if (leaf->GetViewCell() != mBspTree->GetRootCell()) 291 { 292 if (sObject) 293 { 294 contributingSamples += 295 leaf->GetViewCell()->GetPvs().AddSample(sObject); 296 } 297 298 if (tObject) 299 { 300 contributingSamples += 301 leaf->GetViewCell()->GetPvs().AddSample(tObject); 302 } 303 } 304 } 305 } 306 307 // rays passing through this viewcell 308 if (0) 309 for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j) 310 { 311 BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 312 313 if (leaf->GetViewCell() != mBspTree->GetRootCell()) 314 leaf->GetViewCell()-> 315 AddPassingRay(ray, contributingSamples ? 1 : 0); 316 } 317 318 return contributingSamples; 255 319 } 256 320 … … 258 322 const RayContainer &rays) 259 323 { 324 if (!ViewCellsConstructed()) 325 { 326 Debug << "view cells not constructed" << endl; 327 return 0; 328 } 329 330 260 331 //-- post processing of bsp view cells 261 332 int vcSize = 0; … … 277 348 //exporter->ExportBspViewCellPartition(*mBspTree, 0); 278 349 279 if ( 1)350 if (0) 280 351 { 281 352 Material m;//= RandomMaterial(); … … 323 394 BspLeaf *leaf = (*iit).mLeaf; 324 395 325 if ( mBspTree->ShouldMerge(leaf, previousLeaf))396 if (ShouldMerge(leaf, previousLeaf)) 326 397 { 327 mBspTree->MergeViewCells(leaf, previousLeaf);398 MergeBspLeafViewCells(leaf, previousLeaf); 328 399 329 400 ++ merged; … … 347 418 } 348 419 349 int BspViewCellsManager::AddSampleContributions(const Ray &ray,350 Intersectable *sObject,351 Intersectable *tObject)352 {353 int contributingSamples = 0;354 355 // rays passing through this viewcell356 if (0)357 for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j)358 {359 BspLeaf *leaf = ray.bspIntersections[j].mLeaf;360 361 if (leaf->GetViewCell() != mUnbounded)362 leaf->GetViewCell()->363 AddPassingRay(ray, contributingSamples ? 1 : 0);364 }365 366 if (!sObject && !tObject)367 return 0;368 369 // object can be seen from the view cell => add to view cell pvs370 for (int j = 0; j < (int)ray.bspIntersections.size(); ++ j)371 {372 BspLeaf *leaf = ray.bspIntersections[j].mLeaf;373 374 // if ray not in unbounded space375 if (leaf->GetViewCell() != mUnbounded)376 {377 if (sObject)378 {379 contributingSamples +=380 leaf->GetViewCell()->GetPvs().AddSample(sObject);381 }382 383 if (tObject)384 {385 contributingSamples +=386 leaf->GetViewCell()->GetPvs().AddSample(tObject);387 }388 }389 }390 391 return contributingSamples;392 }393 394 420 395 421 void BspViewCellsManager::Visualize(const ObjectContainer &objects, 396 422 const RayContainer &sampleRays) 397 423 { 424 if (!ViewCellsConstructed()) 425 return; 426 398 427 //-- recount pvs 399 428 BspViewCellsStatistics vcStats; … … 473 502 } 474 503 475 if ( 1)504 if (0) 476 505 exporter->ExportGeometry(objects); 477 506 … … 681 710 } 682 711 712 713 bool BspViewCellsManager::MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const 714 { 715 BspViewCell *viewCell = 716 dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(), *back->GetViewCell())); 717 718 if (!viewCell) 719 return false; 720 721 // change view cells of all leaves associated with the 722 // previous view cells 723 724 BspViewCell *fVc = front->GetViewCell(); 725 BspViewCell *bVc = back->GetViewCell(); 726 727 vector<BspLeaf *> fLeaves = fVc->mBspLeaves; 728 vector<BspLeaf *> bLeaves = bVc->mBspLeaves; 729 730 vector<BspLeaf *>::const_iterator it; 731 732 for (it = fLeaves.begin(); it != fLeaves.end(); ++ it) 733 { 734 (*it)->SetViewCell(viewCell); 735 viewCell->mBspLeaves.push_back(*it); 736 } 737 for (it = bLeaves.begin(); it != bLeaves.end(); ++ it) 738 { 739 (*it)->SetViewCell(viewCell); 740 viewCell->mBspLeaves.push_back(*it); 741 } 742 743 DEL_PTR(fVc); 744 DEL_PTR(bVc); 745 746 return true; 747 } 748 749 bool BspViewCellsManager::ShouldMerge(BspLeaf *front, BspLeaf *back) const 750 { 751 ViewCell *fvc = front->GetViewCell(); 752 ViewCell *bvc = back->GetViewCell(); 753 754 if ((fvc == mBspTree->GetRootCell()) || (bvc == mBspTree->GetRootCell()) || (fvc == bvc)) 755 return false; 756 757 int fdiff = fvc->GetPvs().Diff(bvc->GetPvs()); 758 759 if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs) 760 { 761 if ((fvc->GetPvs().GetSize() < mMinPvs) || 762 (bvc->GetPvs().GetSize() < mMinPvs) || 763 ((fdiff < mMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif))) 764 { 765 return true; 766 } 767 } 768 769 return false; 770 } 771 772 773 683 774 /**********************************************************************/ 684 775 /* KdViewCellsManager implementation */ … … 698 789 AxisAlignedBox3 *sceneBbox) 699 790 { 791 // if view cells already constructed 700 792 if (ViewCellsConstructed()) 701 793 return 0; 794 795 Debug << "Constructing bsp view cells" << endl; 702 796 703 797 mKdTree->Construct(); … … 720 814 const RayContainer &sampleRays) 721 815 { 816 if (!ViewCellsConstructed()) 817 return; 818 722 819 const int pvsOut = min((int)objects.size(), 10); 723 820 … … 801 898 } 802 899 803 int KdViewCellsManager::CastRay(const Ray &ray) 804 { 805 if (ray.kdLeaves.empty()) 900 int KdViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 901 { 902 // view cells not yet constructed 903 if (!ViewCellsConstructed()) 806 904 return 0; 807 905 808 Intersectable *terminator = 906 if (castRay) 907 mKdTree->CastRay(ray); 908 909 if (ray.kdLeaves.empty()) 910 return 0; 911 912 Intersectable *tObject = 809 913 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL; 810 914 811 return AddSampleContributions(ray, ray.sourceObject.mObject, terminator); 812 } 813 814 int KdViewCellsManager::AddSampleContributions(const Ray &ray, 815 Intersectable *sObject, 816 Intersectable *tObject) 817 { 915 Intersectable *sObject = 916 ray.sourceObject.mObject; 917 818 918 int contributingSamples = 0; 819 919 … … 843 943 contributingSamples += tObject->mKdPvs.AddSample(node); 844 944 } 845 945 846 946 return contributingSamples; 847 947 } 948 848 949 849 950 KdNode *KdViewCellsManager::GetNodeForPvs(KdLeaf *leaf) … … 874 975 AxisAlignedBox3 *sceneBbox) 875 976 { 977 // if view cells already constructed 876 978 if (ViewCellsConstructed()) 877 979 return 0; … … 886 988 } 887 989 888 int VspKdViewCellsManager::CastRay(const Ray &rays) 889 { 990 int VspKdViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 991 { 992 // view cells not yet constructed 993 if (!ViewCellsConstructed()) 994 return 0; 995 996 //if (castRay) // TODO 997 890 998 int sampleContributions = 0; 999 891 1000 /* 892 1001 for (int i = 0; i < (int)rays.size(); ++ i) … … 910 1019 const RayContainer &rays) 911 1020 { 1021 if (!ViewCellsConstructed()) 1022 return 0; 1023 912 1024 return 0; 913 1025 } … … 916 1028 const RayContainer &sampleRays) 917 1029 { 1030 if (!ViewCellsConstructed()) 1031 return; 1032 918 1033 if (1) 919 1034 { … … 1006 1121 return VSP_KD; 1007 1122 } 1008 1009 int VspKdViewCellsManager::AddSampleContributions(const Ray &ray,1010 Intersectable *sObject,1011 Intersectable *tObject)1012 {1013 int contributingSamples = 0;1014 /*1015 // rays passing through this viewcell1016 if (0)1017 for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j)1018 {1019 BspLeaf *leaf = ray.bspIntersections[j].mLeaf;1020 1021 if (leaf->GetViewCell() != mUnbounded)1022 leaf->GetViewCell()->1023 AddPassingRay(ray, contributingSamples ? 1 : 0);1024 }1025 1026 if (!sObject && !tObject)1027 return 0;1028 1029 // object can be seen from the view cell => add to view cell pvs1030 for (j=0; j < (int)ray.bspIntersections.size(); ++ j)1031 {1032 BspLeaf *leaf = ray.bspIntersections[j].mLeaf;1033 1034 // if ray not in unbounded space1035 if (leaf->GetViewCell() != mUnbounded)1036 {1037 if (sObject)1038 {1039 contributingSamples +=1040 leaf->GetViewCell()->GetPvs().AddSample(sObject);1041 }1042 1043 if (tObject)1044 {1045 contributingSamples +=1046 leaf->GetViewCell()->GetPvs().AddSample(tObject);1047 }1048 }1049 }1050 */1051 return contributingSamples;1052 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r440 r441 45 45 AxisAlignedBox3 *sceneBbox = NULL) = 0; 46 46 47 /** Casts bundle of rays to the view cells and stores contributions in PVS. 48 */ 49 int CastRays(const RayContainer &rays); 50 51 /** Casts ray to the view cells and stores contributions in PVS. 52 */ 53 virtual int CastRay(const Ray &ray) = 0; 47 /** Computes sample contributions of the rays to the view cells PVS. 48 49 @param rays bundle of rays used to find intersections with view cells and 50 adding the contribution 51 @param castRays true if ray should be cast to gain the information, false if rays 52 already hold the view cells intersection information and need not be recast. 53 @param sampleContributions returns the number of sample contributions 54 @param contributingSamples returns the number of contributingSamples 55 */ 56 void ComputeSampleContributions(const RayContainer &rays, 57 const bool castRays, 58 int &sampleContributions, 59 int &contributingSamples); 60 61 62 /** Computes sample contribution of a simgle ray to the view cells PVS. 63 @param ray finds intersections with view cells and holds the contribution 64 @param castRay true if ray should be cast to gain the information, false if ray 65 is already holding the information and need not be recast. 66 67 @returns number of sample contributions 68 */ 69 virtual int ComputeSampleContributions(Ray &ray, const bool castRay = true) = 0; 54 70 55 71 /** Post processes view cells givemŽa number of rays. … … 91 107 @returns new view cell based on the merging. 92 108 */ 93 ViewCell *Merge (ViewCell &front, ViewCell &back) const;109 ViewCell *MergeViewCells(ViewCell &front, ViewCell &back) const; 94 110 95 111 /** Generates view cell of type specified by this manager … … 136 152 virtual bool ViewCellsConstructed() const = 0; 137 153 154 155 138 156 protected: 139 /** Adds sample constributions to the view cell PVS. 140 @returns number of sample contributions 141 */ 142 virtual int AddSampleContributions(const Ray &ray, 143 Intersectable *sObject, 144 Intersectable *tObject) = 0; 157 158 145 159 146 160 /** Initialises the render time simulator. … … 163 177 int mPostProcessSamples; 164 178 int mVisualizationSamples; 179 180 //-- thresholds used for view cells merge 181 int mMinPvsDif; 182 int mMinPvs; 183 int mMaxPvs; 165 184 }; 185 186 166 187 167 188 /** … … 179 200 AxisAlignedBox3 *sceneBbox); 180 201 181 int C astRay(const Ray &rays);202 int ComputeSampleContributions(Ray &ray, const bool castRay = false); 182 203 183 204 int PostProcess(const ObjectContainer &objects, … … 189 210 int GetType() const; 190 211 191 /** Generates view cell of type specified by this manager192 */193 212 ViewCell *GenerateViewCell(Mesh *mesh = NULL) const; 194 213 … … 197 216 protected: 198 217 199 int AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject); 218 /** Merges view cells front and back leaf view cell. 219 */ 220 bool MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const; 221 222 /** Returns true if front and back leaf should be merged. 223 */ 224 bool ShouldMerge(BspLeaf *front, BspLeaf *back) const; 200 225 201 226 /// the BSP tree. … … 247 272 KdNode *GetNodeForPvs(KdLeaf *leaf); 248 273 249 int AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject);250 251 /// the BSP tree.252 KdTree *mKdTree;253 254 /// depth of the KD tree nodes with represent the view cells255 int mKdPvsDepth;274 int ComputeSampleContributions(Ray &ray, const bool castRay = true); 275 276 /// the BSP tree. 277 KdTree *mKdTree; 278 279 /// depth of the KD tree nodes with represent the view cells 280 int mKdPvsDepth; 256 281 }; 257 282 … … 271 296 AxisAlignedBox3 *sceneBbox); 272 297 273 int C astRay(const Ray &rays);298 int ComputeSampleContributions(Ray &ray, const bool castRay = true); 274 299 275 300 int PostProcess(const ObjectContainer &objects, … … 285 310 286 311 protected: 287 288 int AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject);289 312 290 313 /// the BSP tree. -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r439 r441 222 222 mRoot(NULL), 223 223 mStoreLeavesWithRays(false), 224 mPvsUse Area(true)224 mPvsUseLen(true) 225 225 { 226 226 Randomize(); // initialise random generator for heuristics … … 485 485 486 486 VspBspTraversalData tData(mRoot, polys, 0, mRootCell, rays, 487 ComputePvsSize(*rays) , cell->GetArea(), cell);487 ComputePvsSize(*rays)); 488 488 489 489 tStack.push(tData); … … 515 515 (((int)data.mRays->size() <= mTermMinRays) || 516 516 (data.mPvs <= mTermMinPvs) || 517 (data.mArea <= mTermMinArea) ||518 517 (data.mDepth >= mTermMaxDepth) || 519 518 (data.GetAvgRayContribution() < mTermMaxRayContribution)); … … 548 547 DEL_PTR(tData.mPolygons); 549 548 DEL_PTR(tData.mRays); 550 DEL_PTR(tData.mGeometry);549 //DEL_PTR(tData.mGeometry); 551 550 552 551 return leaf; … … 557 556 558 557 VspBspTraversalData tFrontData(NULL, new PolygonContainer(), tData.mDepth + 1, mRootCell, 559 new RayInfoContainer(), 0 , 0, new VspBspNodeGeometry());558 new RayInfoContainer(), 0); 560 559 VspBspTraversalData tBackData(NULL, new PolygonContainer(), tData.mDepth + 1, mRootCell, 561 new RayInfoContainer(), 0 , 0, new VspBspNodeGeometry());560 new RayInfoContainer(), 0); 562 561 563 562 // create new interior node and two leaf nodes … … 583 582 DEL_PTR(tData.mPolygons); 584 583 DEL_PTR(tData.mRays); 585 DEL_PTR(tData.mGeometry);584 //DEL_PTR(tData.mGeometry); 586 585 587 586 return interior; … … 616 615 frontData.mPvs = ComputePvsSize(*frontData.mRays); 617 616 backData.mPvs = ComputePvsSize(*backData.mRays); 618 619 // split geometry and compute area620 if (1)621 {622 tData.mGeometry->SplitGeometry(*frontData.mGeometry,623 *backData.mGeometry,624 *this,625 interior->mPlane);626 627 628 frontData.mArea = frontData.mGeometry->GetArea();629 backData.mArea = backData.mGeometry->GetArea();630 }631 617 632 618 // compute accumulated ray length … … 1006 992 1007 993 if (mSplitPlaneStrategy & PVS) 1008 {1009 994 // create unique ids for pvs heuristics 1010 995 GenerateUniqueIdsForPvs(); 1011 1012 if (mPvsUseArea) // use front and back cell areas to approximate volume 1013 { 1014 // construct child geometry with regard to the candidate split plane 1015 VspBspNodeGeometry frontCell; 1016 VspBspNodeGeometry backCell; 1017 1018 data.mGeometry->SplitGeometry(frontCell, backCell, *this, candidatePlane); 1019 1020 pFront = frontCell.GetArea(); 1021 pBack = backCell.GetArea(); 1022 1023 pOverall = data.mArea; 1024 } 1025 } 996 1026 997 1027 998 RayInfoContainer::const_iterator rit, rit_end = data.mRays->end(); … … 1055 1026 AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 1056 1027 1057 if (!mPvsUseArea) // use front and back cell areas to approximate volume 1058 { 1059 const float len = (*rit).SegmentLength(); 1060 pOverall += len; 1061 1062 // use length of rays to approximate volume 1063 if (cf == 1) 1064 pFront += len; 1065 if (cf == -1) 1066 pBack += len; 1067 if (cf == 0) 1028 float len = 1; 1029 1030 if (mPvsUseLen) // use front and back cell areas to approximate volume 1031 len = (*rit).SqrSegmentLength(); 1032 1033 pOverall += len; 1034 1035 // use length of rays to approximate volume 1036 if (cf == 1) 1037 pFront += len; 1038 if (cf == -1) 1039 pBack += len; 1040 if (cf == 0) 1041 { 1042 if (mPvsUseLen) 1068 1043 { 1069 1044 float newLen = len * … … 1071 1046 ((*rit).GetMaxT() - (*rit).GetMinT()); 1072 1047 1048 1073 1049 if (candidatePlane.Side((*rit).ExtrapOrigin()) <= 0) 1074 1050 { … … 1081 1057 pBack += len - newLen; 1082 1058 } 1083 } 1059 } 1060 else 1061 { 1062 ++ pFront; 1063 ++ pBack; 1064 } 1084 1065 } 1085 1066 } … … 1094 1075 val += mBalancedRaysFactor * fabs(sumBalancedRays) / raysSize; 1095 1076 1096 float denom = pOverall * (float)data.mPvs * 2.0f + Limits::Small; 1097 if ((mSplitPlaneStrategy & PVS) && data.mArea && data.mPvs) 1077 const float denom = pOverall * (float)data.mPvs * 2.0f + Limits::Small; 1078 1079 if (mSplitPlaneStrategy & PVS) 1098 1080 { 1099 1081 val += mPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / denom; 1100 1082 1101 1083 // give penalty to unbalanced split 1102 if ( 1)1084 if (0) 1103 1085 if (((pFront * 0.2 + Limits::Small) > pBack) || (pFront < (pBack * 0.2 + Limits::Small))) 1104 1086 val += 0.5; … … 1217 1199 ++ mStat.maxRayContribNodes; 1218 1200 1219 if (data.mGeometry->GetArea() <= mTermMinArea)1220 ++ mStat.minAreaNodes;1221 1201 1222 1202 #ifdef _DEBUG -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r440 r441 349 349 /// rays piercing this node 350 350 RayInfoContainer *mRays; 351 /// area of current node352 float mArea;353 /// geometry of current node induced by split planes354 VspBspNodeGeometry *mGeometry;355 351 356 352 /// pvs size … … 371 367 mViewCell(NULL), 372 368 mRays(NULL), 373 mPvs(0), 374 mArea(0.0), 375 mGeometry(NULL) 369 mPvs(0) 376 370 {} 377 371 … … 381 375 ViewCell *viewCell, 382 376 RayInfoContainer *rays, 383 int pvs, 384 float area, 385 VspBspNodeGeometry *cell): 377 int pvs): 386 378 mNode(node), 387 379 mPolygons(polys), … … 389 381 mViewCell(viewCell), 390 382 mRays(rays), 391 mPvs(pvs), 392 mArea(area), 393 mGeometry(cell) 383 mPvs(pvs) 394 384 {} 395 385 }; … … 762 752 763 753 /// if area or accumulated ray lenght should be used for PVS heuristics 764 bool mPvsUse Area;754 bool mPvsUseLen; 765 755 766 756 private: -
trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
r438 r441 77 77 78 78 if (!ray.intersections.empty()) 79 79 { 80 80 mTermination = ray.Extrap(ray.intersections[0].mT); 81 81 mTerminationObject = ray.intersections[0].mObject; 82 82 } 83 83 else 84 84 { 85 85 mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity 86 86 mTerminationObject = NULL; 87 87 } 88 88 89 89 Precompute();
Note: See TracChangeset
for help on using the changeset viewer.