Changeset 1545 for GTP/trunk/Lib
- Timestamp:
- 09/29/06 22:42:25 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BoundingBoxConverter.h
r1006 r1545 13 13 14 14 IndexedBoundingBox(int idx, const AxisAlignedBox3 &box): IndexedBoundingBoxParent(idx, box) 15 { 16 17 } 15 {} 18 16 }; 19 17 -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1522 r1545 236 236 bool 237 237 Environment::GetParam(const char name, 238 239 238 const int index, 239 char *value) const 240 240 { 241 241 int column; … … 1522 1522 "0"); 1523 1523 1524 1524 RegisterOption("ViewCells.loadGeometry", 1525 optBool, 1526 "view_cells_load_geometry=", 1527 "false"); 1528 1529 RegisterOption("ViewCells.geometryFilename", 1530 optString, 1531 "view_cells_geometry_filename=", 1532 "viewCellsGeometry.x3d"); 1533 1534 RegisterOption("ViewCells.useBaseTrianglesAsGeometry", 1535 optBool, 1536 "view_cells_use_base_triangles_as_geometry=", 1537 "false"); 1538 1539 1540 1525 1541 /****************************************************************************/ 1526 1542 /* Render simulation related options */ … … 1667 1683 RegisterOption("BspTree.Visualization.exportSplits", 1668 1684 optBool, 1669 "bsp_visualization.export_splits ",1685 "bsp_visualization.export_splits=", 1670 1686 "false"); 1671 1687 … … 2495 2511 "-1"); 2496 2512 2497 RegisterOption("Hierarchy.Construction.useMultiLevel Construction",2498 optBool, 2499 "hierarchy_construction_ use_multilevel_construction=",2513 RegisterOption("Hierarchy.Construction.useMultiLevel", 2514 optBool, 2515 "hierarchy_construction_multilevel=", 2500 2516 "false"); 2501 2517 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1533 r1545 9 9 #include "RayCaster.h" 10 10 #include "Exporter.h" 11 #include "SamplingStrategy.h" 11 12 12 13 … … 24 25 25 26 GvsPreprocessor::GvsPreprocessor(): 26 Preprocessor(), mSamplingType(0), mSampleContriPerPass(0), mTotalSampleContri(0), 27 mReverseSamples(0), mBorderSamples(0) 27 Preprocessor(), 28 //mSamplingType(SamplingStrategy::DIRECTION_BASED_DISTRIBUTION), 29 mSamplingType(SamplingStrategy::DIRECTION_BOX_BASED_DISTRIBUTION), 30 mSampleContriPerPass(0), 31 mTotalSampleContri(0), 32 mReverseSamples(0), 33 mBorderSamples(0) 28 34 { 29 35 Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples); … … 53 59 #if 0 54 60 if ((dist - newDist) > mThresHold) 55 #else // rather take relative distance 61 #else 62 // rather take relative distance 56 63 if ((dist / newDist) > mThreshold) 57 64 #endif … … 62 69 delete newRay; 63 70 } 64 65 71 return true; 66 72 } … … 79 85 //cout << " h " << mSampleContriPerPass << " " << mSamplesPerPass << " " << mTotalSamples << endl; 80 86 mRayQueue.push(vssRay); 81 mVssRays.push_back(new VssRay(*vssRay)); 82 83 ++ mSampleContriPerPass; 87 //mVssRays.push_back(new VssRay(*vssRay)); 88 ++ mSampleContriPerPass; 84 89 85 90 return true; … … 179 184 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin); 180 185 181 VssRay *newRay = mRayCaster->Cast SingleRay(sray, mViewSpaceBox);182 186 VssRay *newRay = mRayCaster->CastRay(sray, mViewSpaceBox, false); 187 //cout << "\np1: " << p1 << "\np : " << p << "\np2: " << p2 << endl; 183 188 if (!newRay) 184 189 return 0; 185 190 cout << "here42" << endl; 186 191 const bool enqueued = HandleRay(newRay); 187 192 … … 230 235 simpleRays.AddRay(sr); 231 236 } 232 237 #if 0 233 238 VizStruct dummy; 234 239 dummy.enlargedTriangle = new Polygon3(enlargedTriangle); … … 236 241 //dummy.ray = new VssRay(currentRay); 237 242 vizContainer.push_back(dummy); 243 #endif 238 244 239 245 // cast rays to triangle vertices and determine visibility … … 260 266 #endif 261 267 262 mBorderSamples = castRays;268 mBorderSamples += castRays; 263 269 return castRays; 264 270 } … … 322 328 VssRayContainer samples; 323 329 CastRays(simpleRays, samples, true); 324 325 330 // add to ray queue 326 331 EnqueueRays(samples); 327 332 328 Debug << "generated " << numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;333 //Debug << "generated " << numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 329 334 330 335 return (int)samples.size(); … … 346 351 int GvsPreprocessor::Pass() 347 352 { 348 const int mSampleType = 0;349 353 // reset samples 350 354 int castSamples = 0; 351 355 mSampleContriPerPass = 0; 352 356 353 357 while (castSamples < mSamplesPerPass) 354 358 { 355 359 // Ray queue empty => 356 // cast a number of uniform samples to fill ray Queue357 castSamples += CastInitialSamples(mInitialSamples, mSampl eType);360 // cast a number of uniform samples to fill ray queue 361 castSamples += CastInitialSamples(mInitialSamples, mSamplingType); 358 362 castSamples += ProcessQueue(); 359 cout << "\ncast " << castSamples << " samples in a processing pass" << endl;363 //cout << "\ncast " << castSamples << " samples in a processing pass" << endl; 360 364 } 361 365 … … 369 373 { 370 374 int castSamples = 0; 375 ++ mGvsPass; 371 376 372 377 while (!mRayQueue.empty()) … … 375 380 VssRay *ray = mRayQueue.top(); 376 381 mRayQueue.pop(); 377 382 378 383 castSamples += AdaptiveBorderSampling(*ray); 379 380 384 delete ray; 381 385 } … … 388 392 { 389 393 cout << "Gvs Preprocessor started\n" << flush; 390 394 const long startTime = GetTime(); 395 396 mViewSpaceBox = mKdTree->GetBox(); 391 397 Randomize(0); 392 const long startTime = GetTime(); 398 399 mPass = 0; 400 mGvsPass = 0; 401 mSampleContriPerPass = 0; 402 mTotalSampleContri = 0; 403 mReverseSamples = 0; 404 mBorderSamples = 0; 405 393 406 int castSamples = 0; 394 mViewSpaceBox = mKdTree->GetBox(); 395 407 396 408 if (!mLoadViewCells) 397 409 { /// construct the view cells from the scratch … … 406 418 //////// 407 419 //-- stats 408 //cout << "+"; 409 cout << "\nsamples cast: " << castSamples << " of " << mTotalSamples << endl; 420 cout << "\nPass " << mPass << " #samples: " << castSamples << " of " << mTotalSamples << endl; 410 421 411 422 //mVssRays.PrintStatistics(mStats); 412 mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl 413 << "#TotalSamples\n" << castSamples << endl 414 << "#ContributingSamples\n" << mTotalSampleContri << endl 415 << "#Reverse samples\n" << mReverseSamples << endl 416 << "#Border samples\n" << mBorderSamples << endl; 417 423 mStats 424 << "#Pass\n" << mPass << endl 425 << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl 426 << "#TotalSamples\n" << castSamples << endl 427 << "#ScDiff\n" << mSampleContriPerPass << endl 428 << "#SamplesContri\n" << mTotalSampleContri << endl 429 << "#ReverseSamples\n" << mReverseSamples << endl 430 << "#BorderSamples\n" << mBorderSamples << endl 431 << "#GvsRuns\n" << mGvsPass << endl; 432 418 433 419 434 mViewCellsManager->PrintPvsStatistics(mStats); 420 435 // ComputeRenderError(); 421 } 422 423 Visualize(); 436 ++ mPass; 437 } 438 439 cout << 2 * castSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl; 440 Visualize(); 441 424 442 return true; 425 443 } -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r1533 r1545 116 116 117 117 void Visualize(); 118 118 119 ////////////////////// 119 120 … … 121 122 122 123 int mSamplesPerPass; 124 int mTotalSamples; 125 int mInitialSamples; 126 123 127 RayQueue mRayQueue; 124 128 int mSamplingType; 125 int mTotalSamples; 126 int mInitialSamples; 129 127 130 AxisAlignedBox3 mViewSpaceBox; 128 131 float mEps; 129 132 float mThreshold; 130 133 VssRayContainer mVssRays; 134 135 /////////// 136 // stats 131 137 int mSampleContriPerPass; 132 138 int mTotalSampleContri; 133 139 int mReverseSamples; 134 140 int mBorderSamples; 141 int mGvsPass; 135 142 }; 136 143 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1528 r1545 396 396 Preprocessor::Export( const string filename, 397 397 const bool scene, 398 const bool kdtree, 399 const bool bsptree 398 const bool kdtree 400 399 ) 401 400 { … … 403 402 404 403 if (exporter) { 405 if ( 0&& scene)404 if (2 && scene) 406 405 exporter->ExportScene(mSceneGraph->GetRoot()); 407 406 408 if ( 0&& kdtree) {407 if (1 && kdtree) { 409 408 exporter->SetWireframe(); 410 409 exporter->ExportKdTree(*mKdTree); 411 410 } 412 413 if (0 && bsptree) {414 //exporter->SetWireframe();415 exporter->ExportBspTree(*mBspTree);416 }417 411 418 412 delete exporter; … … 447 441 // default view space is the extent of the scene 448 442 mViewCellsManager->SetViewSpaceBox(mSceneGraph->GetBox()); 443 444 bool loadVcGeometry; 445 Environment::GetSingleton()->GetBoolValue("ViewCells.loadGeometry", loadVcGeometry); 446 447 bool extrudeBaseTriangles; 448 Environment::GetSingleton()->GetBoolValue("ViewCells.useBaseTrianglesAsGeometry", extrudeBaseTriangles); 449 450 char vcGeomFilename[100]; 451 Environment::GetSingleton()->GetStringValue("ViewCells.geometryFilename", vcGeomFilename); 452 453 if (mViewCellsManager->GetType() == ViewCellsManager::BSP) 454 { 455 if (!mViewCellsManager->LoadViewCellsGeometry(vcGeomFilename, extrudeBaseTriangles)) 456 { 457 cerr << "loading view cells geometry failed" << endl; 458 } 459 } 460 else 461 { 462 cerr << "loading view cells geometry is not implemented for this manager" << endl; 463 } 449 464 } 450 465 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1528 r1545 98 98 SamplingStrategy *GenerateSamplingStrategy(const int strategyId) const; 99 99 100 /** Export preprocessor data. 101 */ 100 102 bool Export( 101 103 const string filename, 102 104 const bool scene, 103 const bool kdtree, 104 const bool bsptree); 105 const bool kdtree); 105 106 106 107 virtual void KdTreeStatistics(ostream &s); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r1521 r1545 748 748 RelativePath="..\src\X3dParser.h"> 749 749 </File> 750 <File751 RelativePath="..\src\X3dParserXerces.h">752 </File>753 750 </Filter> 754 751 <Filter … … 788 785 <File 789 786 RelativePath="..\include\ViewCell.h"> 787 </File> 788 <File 789 RelativePath="..\src\X3dParserXerces.h"> 790 790 </File> 791 791 </Filter> -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1528 r1545 22 22 23 23 24 VssRay *RayCaster::CastSingleRay(const SimpleRay &simpleRay, 25 const AxisAlignedBox3 &box) 24 VssRay *RayCaster::CastRay(const SimpleRay &simpleRay, 25 const AxisAlignedBox3 &box, 26 const bool castDoubleRay) 26 27 { 27 28 VssRayContainer rays; 28 CastRay(simpleRay, rays, box, false);29 CastRay(simpleRay, rays, box, castDoubleRay); 29 30 30 31 if (!rays.empty()) -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r1528 r1545 41 41 42 42 /** Wrapper for casting single ray. 43 @returns ray or NULL if invalid 43 44 */ 44 VssRay *Cast SingleRay(45 VssRay *CastRay( 45 46 const SimpleRay &simpleRay, 46 const AxisAlignedBox3 &box 47 const AxisAlignedBox3 &box, 48 const bool castDoubleRay 47 49 ); 48 50 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1489 r1545 273 273 274 274 for (it = mChildren.begin(); it != it_end; ++ it) 275 { 275 276 delete (*it); 277 } 276 278 } 277 279 … … 1856 1858 int pvsSize = 0; 1857 1859 1860 ///////////// 1858 1861 //-- compressed pvs 1859 1862 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1297 r1545 232 232 233 233 234 //////////////// ////////////////////////////234 //////////////// 235 235 //-- mailing stuff 236 236 … … 255 255 static int sMailId; 256 256 static int sReservedMailboxes; 257 //int mMailbox;258 257 258 259 259 protected: 260 260 261 261 /// parent view cell in the view cell hierarchy 262 262 ViewCellInterior *mParent; 263 263 264 /// the potentially visible objects 264 265 ObjectPvs mPvs; 266 265 267 /// the volume of this view cell 266 268 float mVolume; 267 269 270 /// the area of this view cell 268 271 float mArea; 272 269 273 /// the cost that were paid for merging this view cells from two others. 270 274 float mMergeCost; 275 271 276 /// if the view cell is valid view space 272 277 bool mValid; 278 273 279 /// color used for consistent visualization 274 280 RgbColor mColor; 281 275 282 /// store pvs size, used for evaluation purpose when pvss are stored only in the leaves 276 283 int mPvsSize; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r1418 r1545 17 17 namespace GtpVisibilityPreprocessor { 18 18 19 19 ////////////// 20 20 //-- static members 21 21 … … 168 168 mRoot(NULL), 169 169 mUseAreaForPvs(false), 170 mGenerateViewCells(true), 171 mTimeStamp(1) 170 mUsePredefinedViewCells(false), 171 mTimeStamp(1), 172 mViewCellsTree(NULL), 173 mOutOfBoundsCellPartOfTree(false) 172 174 { 173 175 Randomize(); // initialise random generator for heuristics 174 175 mOutOfBoundsCell = GetOrCreateOutOfBoundsCell(); 176 176 mOutOfBoundsCell = new BspViewCell(); 177 178 ///////// 177 179 //-- termination criteria for autopartition 180 178 181 Environment::GetSingleton()->GetIntValue("BspTree.Termination.maxDepth", mTermMaxDepth); 179 182 Environment::GetSingleton()->GetIntValue("BspTree.Termination.minPvs", mTermMinPvs); … … 184 187 Environment::GetSingleton()->GetFloatValue("BspTree.Termination.minAccRayLenght", mTermMinAccRayLength); 185 188 189 190 ///////// 186 191 //-- factors for bsp tree split plane heuristics 192 187 193 Environment::GetSingleton()->GetFloatValue("BspTree.Factor.verticalSplits", mVerticalSplitsFactor); 188 194 Environment::GetSingleton()->GetFloatValue("BspTree.Factor.largestPolyArea", mLargestPolyAreaFactor); … … 196 202 Environment::GetSingleton()->GetFloatValue("BspTree.Termination.ct_div_ci", mCtDivCi); 197 203 204 205 /////////// 198 206 //-- termination criteria for axis aligned split 207 199 208 Environment::GetSingleton()->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", mAxisAlignedCtDivCi); 200 209 Environment::GetSingleton()->GetFloatValue("BspTree.Termination.maxCostRatio", mMaxCostRatio); … … 205 214 Environment::GetSingleton()->GetIntValue("BspTree.Termination.AxisAligned.minObjects", 206 215 mTermMinObjectsForAxisAligned); 216 217 218 ////////////// 207 219 //-- partition criteria 220 208 221 Environment::GetSingleton()->GetIntValue("BspTree.maxPolyCandidates", mMaxPolyCandidates); 209 222 Environment::GetSingleton()->GetIntValue("BspTree.maxRayCandidates", mMaxRayCandidates); … … 219 232 mSubdivisionStats.open(subdivisionStatsLog); 220 233 234 /////////////////////7 235 236 Debug << "BSP options: " << endl; 221 237 Debug << "BSP max depth: " << mTermMaxDepth << endl; 222 238 Debug << "BSP min PVS: " << mTermMinPvs << endl; … … 401 417 { 402 418 DEL_PTR(mRoot); 403 404 // TODO must be deleted if used!! 405 //if (mGenerateViewCells) DEL_PTR(mOutOfBoundsCell); 406 } 407 408 BspViewCell *BspTree::GetOutOfBoundsCell() 409 { 410 return mOutOfBoundsCell; 419 420 if (!mOutOfBoundsCellPartOfTree) 421 { 422 // out of bounds cell not part of tree => 423 // delete manually 424 DEL_PTR(mOutOfBoundsCell); 425 } 411 426 } 412 427 … … 418 433 419 434 420 BspViewCell *BspTree::GetOrCreateOutOfBoundsCell() 421 { 422 if (!mOutOfBoundsCell) 423 { 424 mOutOfBoundsCell = new BspViewCell(); 425 mOutOfBoundsCell->SetId(-1); 426 mOutOfBoundsCell->SetValid(false); 427 } 428 429 return mOutOfBoundsCell; 435 void BspTree::SetViewCellsTree(ViewCellsTree *viewCellsTree) 436 { 437 mViewCellsTree = viewCellsTree; 430 438 } 431 439 … … 433 441 void BspTree::InsertViewCell(ViewCellLeaf *viewCell) 434 442 { 443 // don't generate new view cell, insert this view cell 444 mUsePredefinedViewCells = true; 435 445 PolygonContainer *polys = new PolygonContainer(); 436 446 437 // don't generate new view cell, insert this one438 mGenerateViewCells = false;439 447 // extract polygons that guide the split process 440 448 mStat.polys += AddMeshToPolygons(viewCell->GetMesh(), *polys, viewCell); 441 mB ox.Include(viewCell->GetBox()); // add to BSP aabb449 mBbox.Include(viewCell->GetBox()); // add to BSP aabb 442 450 443 451 InsertPolygons(polys); … … 459 467 new BoundedRayContainer(), 460 468 0, 461 mUseAreaForPvs ? mB ox.SurfaceArea() : mBox.GetVolume(),469 mUseAreaForPvs ? mBbox.SurfaceArea() : mBbox.GetVolume(), 462 470 new BspNodeGeometry())); 463 471 … … 472 480 BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 473 481 482 /////////////////// 474 483 //-- filter view cell polygons down the tree until a leaf is reached 475 484 if (!tData.mPolygons->empty()) … … 489 498 490 499 // extract view cells associated with the split polygons 491 ViewCellLeaf *frontViewCell = GetOrCreateOutOfBoundsCell();492 ViewCellLeaf *backViewCell = GetOrCreateOutOfBoundsCell();500 ViewCellLeaf *frontViewCell = mOutOfBoundsCell; 501 ViewCellLeaf *backViewCell = mOutOfBoundsCell; 493 502 494 503 BspTraversalData frontData(interior->GetFront(), … … 498 507 tData.mRays, 499 508 tData.mPvs, 500 mUseAreaForPvs ? mB ox.SurfaceArea() : mBox.GetVolume(),509 mUseAreaForPvs ? mBbox.SurfaceArea() : mBbox.GetVolume(), 501 510 new BspNodeGeometry()); 502 511 … … 507 516 tData.mRays, 508 517 tData.mPvs, 509 mUseAreaForPvs ? mB ox.SurfaceArea() : mBox.GetVolume(),518 mUseAreaForPvs ? mBbox.SurfaceArea() : mBbox.GetVolume(), 510 519 new BspNodeGeometry()); 511 520 512 if ( !mGenerateViewCells)521 if (mUsePredefinedViewCells) 513 522 { 514 523 ExtractViewCells(frontData, … … 558 567 } 559 568 else 569 { 560 570 DEL_PTR(poly); 571 } 561 572 } 562 573 return (int)mesh->mFaces.size(); … … 572 583 573 584 int polysSize = 0; 574 585 cout << "here55 " << mBbox << endl; 586 587 cout << "here99"; 575 588 for (int i = 0; i < limit; ++ i) 576 { 577 if (viewCells[i]->GetMesh()) // copy the mesh data to polygons 578 { 579 mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 580 polysSize += AddMeshToPolygons(viewCells[i]->GetMesh(), polys, viewCells[i]); 581 } 582 } 583 589 {cout << "q"; 590 Mesh *mesh = viewCells[i]->GetMesh(); 591 if (mesh) 592 {cout << "w"; 593 // copy the mesh into polygons and add to BSP tree aabb 594 mBbox.Include(viewCells[i]->GetBox()); 595 polysSize += AddMeshToPolygons(mesh, polys, viewCells[i]); 596 } 597 } 598 cout << "here155 " << mBbox << endl; 584 599 return polysSize; 585 600 } … … 593 608 int limit = (maxObjects > 0) ? 594 609 Min((int)objects.size(), maxObjects) : (int)objects.size(); 595 610 cout << "here88"; 596 611 for (int i = 0; i < limit; ++i) 597 { 612 {cout << "e"; 598 613 Intersectable *object = objects[i]; 599 600 614 Mesh *mesh = NULL; 601 615 … … 616 630 mesh = new Mesh(); 617 631 mi->GetTransformedMesh(*mesh); 618 619 632 break; 620 633 } … … 624 637 } 625 638 626 if (mesh) // copy the mesh data to polygons 627 { 628 if (addToBbox) 629 mBox.Include(object->GetBox()); // add to BSP tree aabb 630 631 AddMeshToPolygons(mesh, polys, mOutOfBoundsCell); 632 633 // cleanup 634 if (object->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 635 DEL_PTR(mesh); 639 if (!mesh) continue; 640 // copy the mesh data to polygons 641 if (addToBbox) 642 {cout << "b"; 643 mBbox.Include(object->GetBox()); // add to BSP tree aabb 644 } 645 646 AddMeshToPolygons(mesh, polys, mOutOfBoundsCell); 647 648 // cleanup 649 if (object->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 650 { 651 DEL_PTR(mesh); 636 652 } 637 653 } … … 640 656 } 641 657 642 658 643 659 void BspTree::Construct(const ViewCellContainer &viewCells) 644 660 { 661 cout << "here5500000000" << endl; 662 // construct hierarchy over the given view cells 663 mUsePredefinedViewCells = true; 664 645 665 mStat.nodes = 1; 646 mB ox.Initialize();// initialise bsp tree bounding box666 mBbox.Initialize(); // initialise bsp tree bounding box 647 667 648 668 // copy view cell meshes into one big polygon soup … … 650 670 mStat.polys = AddToPolygonSoup(viewCells, *polys); 651 671 652 // view cells are given 653 mGenerateViewCells = false; 672 Exporter *expo = Exporter::GetExporter("dummy2.wrl"); 673 expo->ExportPolygons(*polys); 674 delete expo; 654 675 // construct tree from the view cell polygons 655 676 Construct(polys, new BoundedRayContainer()); … … 659 680 void BspTree::Construct(const ObjectContainer &objects) 660 681 { 682 // generate new view cells for this type 683 mUsePredefinedViewCells = false; 684 661 685 mStat.nodes = 1; 662 mB ox.Initialize(); // initialise bsp tree bounding box686 mBbox.Initialize(); // initialise bsp tree bounding box 663 687 664 688 PolygonContainer *polys = new PolygonContainer(); 665 689 666 mGenerateViewCells = true;667 690 // copy mesh instance polygons into one big polygon soup 668 691 mStat.polys = AddToPolygonSoup(objects, *polys); … … 677 700 // preprocess: throw out polygons coincident to the view space box (not needed) 678 701 PolygonContainer boxPolys; 679 mB ox.ExtractPolys(boxPolys);702 mBbox.ExtractPolys(boxPolys); 680 703 vector<Plane3> boxPlanes; 681 704 … … 722 745 723 746 724 725 747 void BspTree::Construct(const RayContainer &sampleRays, 726 748 AxisAlignedBox3 *forcedBoundingBox) 727 749 { 750 // generate new view cells for this contruction type 751 mUsePredefinedViewCells = false; 752 728 753 mStat.nodes = 1; 729 mBox.Initialize(); // initialise BSP tree bounding box 730 754 731 755 if (forcedBoundingBox) 732 mBox = *forcedBoundingBox; 756 { 757 mBbox = *forcedBoundingBox; 758 } 759 else 760 { 761 mBbox.Initialize(); // initialise BSP tree bounding box 762 } 733 763 734 764 PolygonContainer *polys = new PolygonContainer(); … … 737 767 RayContainer::const_iterator rit, rit_end = sampleRays.end(); 738 768 739 // generate view cells740 mGenerateViewCells = true;741 742 769 long startTime = GetTime(); 743 744 770 Debug << "**** Extracting polygons from rays ****\n"; 745 771 746 772 std::map<Face *, Polygon3 *> facePolyMap; 747 773 748 //-- extract polygons intersected by the rays749 774 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 750 775 { 776 ////////////// 777 //-- extract polygons intersected by the rays 751 778 Ray *ray = *rit; 752 779 … … 803 830 // compute bounding box 804 831 if (!forcedBoundingBox) 805 mBox.Include(*polys); 806 832 { 833 mBbox.Include(*polys); 834 } 835 836 //////////// 807 837 //-- store rays 808 838 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) … … 812 842 813 843 float minT, maxT; 814 if (mB ox.GetRaySegment(*ray, minT, maxT))844 if (mBbox.GetRaySegment(*ray, minT, maxT)) 815 845 rays->push_back(new BoundedRay(ray, minT, maxT)); 816 846 } … … 833 863 AxisAlignedBox3 *forcedBoundingBox) 834 864 { 865 // generate new view cells for this construction type 866 mUsePredefinedViewCells = false; 867 835 868 mStat.nodes = 1; 836 mB ox.Initialize(); // initialise BSP tree bounding box869 mBbox.Initialize(); // initialise BSP tree bounding box 837 870 838 871 if (forcedBoundingBox) 839 mBox = *forcedBoundingBox; 872 { 873 mBbox = *forcedBoundingBox; 874 } 840 875 841 876 BoundedRayContainer *rays = new BoundedRayContainer(); 842 877 PolygonContainer *polys = new PolygonContainer(); 843 878 844 mGenerateViewCells = true;845 846 879 // copy mesh instance polygons into one big polygon soup 847 880 mStat.polys = AddToPolygonSoup(objects, *polys, 0, !forcedBoundingBox); 848 881 849 882 /////// 883 //-- store rays 850 884 RayContainer::const_iterator rit, rit_end = sampleRays.end(); 851 852 //-- store rays 885 853 886 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 854 887 { … … 857 890 858 891 float minT, maxT; 859 if (mB ox.GetRaySegment(*ray, minT, maxT))892 if (mBbox.GetRaySegment(*ray, minT, maxT)) 860 893 rays->push_back(new BoundedRay(ray, minT, maxT)); 861 894 } … … 870 903 { 871 904 BspTraversalStack tStack; 872 873 905 mRoot = new BspLeaf(); 874 906 … … 880 912 polys, 881 913 0, 882 GetOrCreateOutOfBoundsCell(),914 mOutOfBoundsCell, 883 915 rays, 884 916 ComputePvsSize(*rays), … … 886 918 geom); 887 919 888 mTotalCost = tData.mPvs * tData.mProbability / mB ox.GetVolume();920 mTotalCost = tData.mPvs * tData.mProbability / mBbox.GetVolume(); 889 921 mTotalPvsSize = tData.mPvs; 890 922 … … 950 982 BspNode *BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData) 951 983 { 952 //-- terminate traversal 984 //////// 985 //-- terminate traversal 986 953 987 if (TerminationCriteriaMet(tData)) 954 988 { … … 957 991 BspViewCell *viewCell; 958 992 959 // generate new view cell for each leaf 960 if (mGenerateViewCells) 961 { 993 if (!mUsePredefinedViewCells) 994 { // generate new view cell for each leaf 962 995 viewCell = new BspViewCell(); 963 996 } 964 997 else 965 998 { 966 // add view cell to leaf999 // add predefined view cell to leaf 967 1000 viewCell = dynamic_cast<BspViewCell *>(tData.mViewCell); 1001 1002 /// out of bounds cell can be handled as any other cell 1003 if (viewCell == mOutOfBoundsCell) 1004 mOutOfBoundsCellPartOfTree = true; 968 1005 } 969 1006 … … 979 1016 viewCell->SetVolume(probability); 980 1017 981 //-- add pvs 1018 1019 /////////// 1020 //-- add pvs contribution of rays 1021 982 1022 if (viewCell != mOutOfBoundsCell) 983 1023 { … … 989 1029 } 990 1030 991 if (1) 992 EvaluateLeafStats(tData); 993 1031 if (1)EvaluateLeafStats(tData); 1032 1033 1034 //////// 994 1035 //-- clean up 995 1036 996 1037 // discard polygons 997 1038 CLEAR_CONTAINER(*tData.mPolygons); … … 1006 1047 } 1007 1048 1049 /////////// 1008 1050 //-- continue subdivision 1051 1009 1052 PolygonContainer coincident; 1010 1053 … … 1019 1062 SubdivideNode(tData, tFrontData, tBackData, coincident); 1020 1063 1021 1022 1064 if (1) 1023 1065 { … … 1028 1070 float cBack = (float)tBackData.mPvs * tBackData.mProbability; 1029 1071 1030 float costDecr = (cFront + cBack - cData) / mB ox.GetVolume();1072 float costDecr = (cFront + cBack - cData) / mBbox.GetVolume(); 1031 1073 1032 1074 mTotalCost += costDecr; … … 1040 1082 } 1041 1083 1042 // extract view cells from coincident polygons according to plane normal 1043 // only if front or back polygons are empty 1044 if (!mGenerateViewCells) 1084 // extract view cells from coincident polygons 1085 // with respect to the orientation of their normal 1086 // note: if front or back polygons are empty, 1087 // we get the valid in - out classification for the view cell 1088 1089 if (mUsePredefinedViewCells) 1045 1090 { 1046 1091 ExtractViewCells(tFrontData, … … 1057 1102 tStack.push(tBackData); 1058 1103 1059 // cleanup 1104 //////// 1105 //-- cleanup 1106 1060 1107 DEL_PTR(tData.mNode); 1061 1062 1108 DEL_PTR(tData.mPolygons); 1063 1109 DEL_PTR(tData.mRays); … … 1080 1126 coincident.begin(), it_end = coincident.end(); 1081 1127 1128 ////////// 1082 1129 //-- find first view cells in front and back leafs 1130 1083 1131 for (; !(foundFront && foundBack) && (it != it_end); ++ it) 1084 1132 { … … 1108 1156 // select subdivision plane 1109 1157 BspInterior *interior = new BspInterior(SelectPlane(leaf, tData)); 1110 1111 1158 1112 1159 #ifdef _DEBUG … … 1135 1182 *backData.mGeometry, 1136 1183 interior->mPlane, 1137 mB ox,1184 mBbox, 1138 1185 //0.000000000001); 1139 1186 mEpsilon); … … 1274 1321 const float ratio = newCost / oldCost; 1275 1322 1276 1277 #if 0 1323 #ifdef _DEBUG 1278 1324 Debug << "====================" << endl; 1279 1325 Debug << "costRatio=" << ratio << " pos=" << position<<" t=" << (position - minBox)/(maxBox - minBox) … … 1430 1476 return Plane3(pt[0], pt[1], pt[2]); 1431 1477 } 1478 1432 1479 1433 1480 Plane3 BspTree::ChooseCandidatePlane3(const BoundedRayContainer &rays) const … … 1697 1744 geomBack, 1698 1745 candidatePlane, 1699 mB ox,1746 mBbox, 1700 1747 mEpsilon); 1701 1748 … … 1856 1903 if (mSplitPlaneStrategy & VERTICAL_AXIS) 1857 1904 { 1858 Vector3 tinyAxis(0,0,0); tinyAxis[mB ox.Size().TinyAxis()] = 1.0f;1905 Vector3 tinyAxis(0,0,0); tinyAxis[mBbox.Size().TinyAxis()] = 1.0f; 1859 1906 // we put a penalty on the dot product between the "tiny" vertical axis 1860 1907 // and the split plane axis … … 1915 1962 AxisAlignedBox3 BspTree::GetBoundingBox() const 1916 1963 { 1917 return mB ox;1964 return mBbox; 1918 1965 } 1919 1966 … … 1972 2019 float maxt, mint; 1973 2020 1974 if (!mB ox.GetRaySegment(ray, mint, maxt))2021 if (!mBbox.GetRaySegment(ray, mint, maxt)) 1975 2022 return 0; 1976 2023 … … 2194 2241 } 2195 2242 } 2243 2244 // also add out of bounds cell 2245 if (0 && !mOutOfBoundsCell->Mailed()) 2246 { 2247 mOutOfBoundsCell->Mail(); 2248 viewCells.push_back(mOutOfBoundsCell); 2249 } 2250 2251 cout << "here555 " << viewCells.size() << endl; 2252 2196 2253 } 2197 2254 … … 2247 2304 case Ray::COINCIDENT: // TODO: should really discard ray? 2248 2305 frontRays.push_back(bRay); 2249 //DEL_PTR(bRay);2250 2306 break; 2251 2307 case Ray::BACK: … … 2322 2378 BspNodeGeometry &vcGeom) const 2323 2379 { 2380 // if false, cannot construct geometry for interior leaf 2381 if (!mViewCellsTree) 2382 return; 2383 2324 2384 ViewCellContainer leaves; 2325 2385 mViewCellsTree->CollectLeaves(vc, leaves); … … 2364 2424 2365 2425 for (int j = 0; j < 4; ++ j) 2366 vertices.push_back(mB ox.GetFace(i).mVertices[j]);2426 vertices.push_back(mBbox.GetFace(i).mVertices[j]); 2367 2427 2368 2428 Polygon3 *poly = new Polygon3(vertices); … … 2533 2593 *bGeom, 2534 2594 interior->GetPlane(), 2535 mB ox,2595 mBbox, 2536 2596 //0.0000001f); 2537 2597 mEpsilon); … … 2807 2867 Debug << "leaves in queue: " << numLeaves << endl; 2808 2868 2809 2869 #if 0 2870 ////////// 2810 2871 //-- collect the leaves which haven't been found by ray casting 2811 #if 02812 2872 cout << "finding additional merge candidates using geometry" << endl; 2813 2873 vector<BspLeaf *> leaves; … … 2822 2882 2823 2883 2824 2825 2884 /***************************************************************/ 2826 2885 /* BspNodeGeometry Implementation */ … … 3050 3109 bool BspNodeGeometry::Valid() const 3051 3110 { 3111 // geometry is degenerated 3052 3112 if (mPolys.size() < 4) 3053 3113 return false; … … 3294 3354 int id = -1; 3295 3355 if (leaf->GetViewCell() != mOutOfBoundsCell) 3356 { 3296 3357 id = leaf->GetViewCell()->GetId(); 3358 } 3297 3359 3298 3360 stream << "<Leaf viewCellId=\"" << id << "\" />" << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
r1449 r1545 27 27 { 28 28 public: 29 /** Default constructor. 30 */ 29 31 BspNodeGeometry() 30 32 {}; … … 343 345 { 344 346 friend class BspTree; 347 345 348 public: 346 349 /** Standard contructor taking split plane as argument. … … 438 441 } 439 442 440 441 443 /// Rays piercing this leaf. 442 444 VssRayContainer mVssRays; … … 444 446 /// leaf pvs 445 447 ObjectPvs *mPvs; 446 448 447 449 /// Probability that the view point lies in this leaf 448 450 float mProbability; … … 607 609 BspNode *GetRoot() const; 608 610 609 610 //bool Export(const string filename);611 612 611 /** Collects the leaf view cells of the tree 613 612 @param viewCells returns the view cells … … 629 628 630 629 /// bsp tree construction types 631 enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES};630 //enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES}; 632 631 633 632 /** Returns statistics. … … 678 677 bool Export(ofstream &stream); 679 678 680 681 /** Returns view cell corresponding to 682 the invalid view space. If it does not exist, it is created. 683 */ 684 BspViewCell *GetOutOfBoundsCell(); 685 686 ViewCellsTree *mViewCellsTree; 687 679 /** Pointer to the view cells tree. 680 */ 681 void SetViewCellsTree(ViewCellsTree *vct); 682 688 683 protected: 689 690 // --------------------------------------------------------------691 // For sorting objects692 // --------------------------------------------------------------693 struct SortableEntry694 {695 enum {POLY_MIN, POLY_MAX};696 697 int type;698 float value;699 Polygon3 *poly;700 SortableEntry() {}701 SortableEntry(const int t, const float v, Polygon3 *poly):702 type(t), value(v), poly(poly) {}703 704 bool operator<(const SortableEntry &b) const705 {706 return value < b.value;707 }708 };709 710 void ExportNode(BspNode *node, ofstream &stream);711 712 /** Evaluates tree stats in the BSP tree leafs.713 */714 void EvaluateLeafStats(const BspTraversalData &data);715 716 /** Subdivides node with respect to the traversal data.717 @param tStack current traversal stack718 @param tData traversal data also holding node to be subdivided719 @returns new root of the subtree720 */721 BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData);722 723 /** Constructs the tree from the given list of polygons and rays.724 @param polys stores set of polygons on which subdivision may be based725 @param rays storesset of rays on which subdivision may be based726 */727 void Construct(PolygonContainer *polys, BoundedRayContainer *rays);728 729 /** Selects the best possible splitting plane.730 @param leaf the leaf to be split731 @param polys the polygon list on which the split decition is based732 @param rays ray container on which selection may be based733 @note the polygons can be reordered in the process734 @returns the split plane735 */736 Plane3 SelectPlane(BspLeaf *leaf,737 BspTraversalData &data);738 739 /** Evaluates the contribution of the candidate split plane.740 741 @param candidatePlane the candidate split plane742 @param polys the polygons the split can be based on743 @param rays the rays the split can be based on744 745 @returns the cost of the candidate split plane746 */747 float SplitPlaneCost(const Plane3 &candidatePlane,748 BspTraversalData &data) const;749 750 /** Strategies where the effect of the split plane is tested751 on all input rays.752 @returns the cost of the candidate split plane753 */754 float SplitPlaneCost(const Plane3 &candidatePlane,755 const PolygonContainer &polys) const;756 757 /** Strategies where the effect of the split plane is tested758 on all input rays.759 760 @returns the cost of the candidate split plane761 */762 float SplitPlaneCost(const Plane3 &candidatePlane,763 const BoundedRayContainer &rays,764 const int pvs,765 const float probability,766 const BspNodeGeometry &cell) const;767 768 /** Filters next view cell down the tree and inserts it into the appropriate leaves769 (i.e., possibly more than one leaf).770 */771 void InsertViewCell(ViewCellLeaf *viewCell);772 /** Inserts polygons down the tree. The polygons are filtered until a leaf is reached,773 then further subdivided.774 */775 void InsertPolygons(PolygonContainer *polys);776 777 /** Subdivide leaf.778 @param leaf the leaf to be subdivided779 780 @param polys the polygons to be split781 @param frontPolys returns the polygons in front of the split plane782 @param backPolys returns the polygons in the back of the split plane783 784 @param rays the polygons to be filtered785 @param frontRays returns the polygons in front of the split plane786 @param backRays returns the polygons in the back of the split plane787 788 @returns the root of the subdivision789 */790 791 BspInterior *SubdivideNode(BspTraversalData &tData,792 BspTraversalData &frontData,793 BspTraversalData &backData,794 PolygonContainer &coincident);795 796 /** Filters polygons down the tree.797 @param node the current BSP node798 @param polys the polygons to be filtered799 @param frontPolys returns the polygons in front of the split plane800 @param backPolys returns the polygons in the back of the split plane801 */802 void FilterPolygons(BspInterior *node,803 PolygonContainer *polys,804 PolygonContainer *frontPolys,805 PolygonContainer *backPolys);806 807 /** Take 3 ray endpoints, where two are minimum and one a maximum808 point or the other way round.809 */810 Plane3 ChooseCandidatePlane(const BoundedRayContainer &rays) const;811 812 /** Take plane normal as plane normal and the midpoint of the ray.813 PROBLEM: does not resemble any point where visibility is likely to change814 */815 Plane3 ChooseCandidatePlane2(const BoundedRayContainer &rays) const;816 817 /** Fit the plane between the two lines so that the plane has equal shortest818 distance to both lines.819 */820 Plane3 ChooseCandidatePlane3(const BoundedRayContainer &rays) const;821 822 /** Selects the split plane in order to construct a tree with823 certain characteristics (e.g., balanced tree, least splits,824 2.5d aligned)825 @param polygons container of polygons826 @param rays bundle of rays on which the split can be based827 */828 Plane3 SelectPlaneHeuristics(BspLeaf *leaf,829 BspTraversalData &data);830 831 /** Extracts the meshes of the objects and adds them to polygons.832 Adds object aabb to the aabb of the tree.833 @param maxPolys the maximal number of objects to be stored as polygons834 @returns the number of polygons835 */836 int AddToPolygonSoup(const ObjectContainer &objects,837 PolygonContainer &polys,838 int maxObjects = 0,839 bool addToBbox = true);840 841 /** Extracts the meshes of the view cells and and adds them to polygons.842 Adds view cell aabb to the aabb of the tree.843 @param maxPolys the maximal number of objects to be stored as polygons844 @returns the number of polygons845 */846 int AddToPolygonSoup(const ViewCellContainer &viewCells,847 PolygonContainer &polys,848 int maxObjects = 0);849 850 /** Extract polygons of this mesh and add to polygon container.851 @param mesh the mesh that drives the polygon construction852 @param parent the parent intersectable this polygon is constructed from853 @returns number of polygons854 */855 int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent);856 857 /** Helper function which extracts a view cell on the front and the back858 of the split plane.859 @param backViewCell returns view cell on the back of the split plane860 @param frontViewCell returns a view cell on the front of the split plane861 @param coincident container of polygons coincident to the split plane862 @param splitPlane the split plane which decides about back and front863 @param extractBack if a back view cell is extracted864 @param extractFront if a front view cell is extracted865 */866 void ExtractViewCells(BspTraversalData &frontData,867 BspTraversalData &backData,868 const PolygonContainer &coincident,869 const Plane3 &splitPlane) const;870 871 /** Computes best cost ratio for the suface area heuristics for axis aligned872 splits. This heuristics minimizes the cost for ray traversal.873 @param polys the polygons guiding the ratio computation874 @param box the bounding box of the leaf875 @param axis the current split axis876 @param position returns the split position877 @param objectsBack the number of objects in the back of the split plane878 @param objectsFront the number of objects in the front of the split plane879 */880 float BestCostRatio(const PolygonContainer &polys,881 const AxisAlignedBox3 &box,882 const int axis,883 float &position,884 int &objectsBack,885 int &objectsFront) const;886 887 /** Sorts split candidates for cost heuristics using axis aligned splits.888 @param polys the input for choosing split candidates889 @param axis the current split axis890 @param splitCandidates returns sorted list of split candidates891 */892 void SortSubdivisionCandidates(const PolygonContainer &polys,893 const int axis,894 vector<SortableEntry> &splitCandidates) const;895 896 /** Selects an axis aligned split plane.897 Returns true if split is valied898 */899 bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const;900 901 /** Subdivides the rays into front and back rays according to the split plane.902 903 @param plane the split plane904 @param rays contains the rays to be split. The rays are905 distributed into front and back rays.906 @param frontRays returns rays on the front side of the plane907 @param backRays returns rays on the back side of the plane908 909 @returns the number of splits910 */911 int SplitRays(const Plane3 &plane,912 BoundedRayContainer &rays,913 BoundedRayContainer &frontRays,914 BoundedRayContainer &backRays);915 916 917 /** Extracts the split planes representing the space bounded by node n.918 */919 void ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const;920 921 /** Adds the object to the pvs of the front and back leaf with a given classification.922 923 @param obj the object to be added924 @param cf the ray classification regarding the split plane925 @param frontPvs returns the PVS of the front partition926 @param backPvs returns the PVS of the back partition927 928 */929 void AddObjToPvs(Intersectable *obj, const int cf, int &frontPvs, int &backPvs) const;930 931 /** Computes PVS size induced by the rays.932 */933 int ComputePvsSize(const BoundedRayContainer &rays) const;934 935 /** Returns true if tree can be terminated.936 */937 inline bool TerminationCriteriaMet(const BspTraversalData &data) const;938 939 /** Computes accumulated ray lenght of this rays.940 */941 float AccumulatedRayLength(BoundedRayContainer &rays) const;942 943 /** Splits polygons with respect to the split plane.944 @param polys the polygons to be split. the polygons are consumed and945 distributed to the containers frontPolys, backPolys, coincident.946 @param frontPolys returns the polygons in the front of the split plane947 @param backPolys returns the polygons in the back of the split plane948 @param coincident returns the polygons coincident to the split plane949 950 @returns the number of splits951 */952 int SplitPolygons(const Plane3 &plane,953 PolygonContainer &polys,954 PolygonContainer &frontPolys,955 PolygonContainer &backPolys,956 PolygonContainer &coincident) const;957 958 /** Adds ray sample contributions to the PVS.959 @param sampleContributions the number contributions of the samples960 @param contributingSampels the number of contributing rays961 962 */963 void AddToPvs(BspLeaf *leaf,964 const BoundedRayContainer &rays,965 int &sampleContributions,966 int &contributingSamples);967 968 /** Preprocesses polygons and throws out all polygons which969 are coincident to the view space box faces:970 These polygons can can be problematic for bsp because they create971 bad view cells.972 */973 void PreprocessPolygons(PolygonContainer &polys);974 975 /** Returns view cell corresponding to the invalid view space.976 If it does not exist, it is created.977 */978 BspViewCell *GetOrCreateOutOfBoundsCell();979 980 /// Pointer to the root of the tree.981 BspNode *mRoot;982 983 /// Stores statistics during traversal.984 BspTreeStatistics mStat;985 684 986 685 /// Strategies for choosing next split plane. … … 999 698 }; 1000 699 700 /** 701 For sorting polygons 702 */ 703 struct SortableEntry 704 { 705 enum {POLY_MIN, POLY_MAX}; 706 707 int type; 708 float value; 709 Polygon3 *poly; 710 SortableEntry() {} 711 SortableEntry(const int t, const float v, Polygon3 *poly): 712 type(t), value(v), poly(poly) {} 713 714 bool operator<(const SortableEntry &b) const 715 { 716 return value < b.value; 717 } 718 }; 719 720 void ExportNode(BspNode *node, ofstream &stream); 721 722 /** Evaluates tree stats in the BSP tree leafs. 723 */ 724 void EvaluateLeafStats(const BspTraversalData &data); 725 726 /** Subdivides node with respect to the traversal data. 727 @param tStack current traversal stack 728 @param tData traversal data also holding node to be subdivided 729 @returns new root of the subtree 730 */ 731 BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData); 732 733 /** Constructs the tree from the given list of polygons and rays. 734 @param polys stores set of polygons on which subdivision may be based 735 @param rays storesset of rays on which subdivision may be based 736 */ 737 void Construct(PolygonContainer *polys, BoundedRayContainer *rays); 738 739 /** Selects the best possible splitting plane. 740 @param leaf the leaf to be split 741 @param polys the polygon list on which the split decition is based 742 @param rays ray container on which selection may be based 743 @note the polygons can be reordered in the process 744 @returns the split plane 745 */ 746 Plane3 SelectPlane(BspLeaf *leaf, 747 BspTraversalData &data); 748 749 /** Evaluates the contribution of the candidate split plane. 750 751 @param candidatePlane the candidate split plane 752 @param polys the polygons the split can be based on 753 @param rays the rays the split can be based on 754 755 @returns the cost of the candidate split plane 756 */ 757 float SplitPlaneCost(const Plane3 &candidatePlane, 758 BspTraversalData &data) const; 759 760 /** Strategies where the effect of the split plane is tested 761 on all input rays. 762 @returns the cost of the candidate split plane 763 */ 764 float SplitPlaneCost(const Plane3 &candidatePlane, 765 const PolygonContainer &polys) const; 766 767 /** Strategies where the effect of the split plane is tested 768 on all input rays. 769 770 @returns the cost of the candidate split plane 771 */ 772 float SplitPlaneCost(const Plane3 &candidatePlane, 773 const BoundedRayContainer &rays, 774 const int pvs, 775 const float probability, 776 const BspNodeGeometry &cell) const; 777 778 /** Filters next view cell down the tree and inserts it into the appropriate leaves 779 (i.e., possibly more than one leaf). 780 */ 781 void InsertViewCell(ViewCellLeaf *viewCell); 782 /** Inserts polygons down the tree. The polygons are filtered until a leaf is reached, 783 then further subdivided. 784 */ 785 void InsertPolygons(PolygonContainer *polys); 786 787 /** Subdivide leaf. 788 @param leaf the leaf to be subdivided 789 790 @param polys the polygons to be split 791 @param frontPolys returns the polygons in front of the split plane 792 @param backPolys returns the polygons in the back of the split plane 793 794 @param rays the polygons to be filtered 795 @param frontRays returns the polygons in front of the split plane 796 @param backRays returns the polygons in the back of the split plane 797 798 @returns the root of the subdivision 799 */ 800 801 BspInterior *SubdivideNode(BspTraversalData &tData, 802 BspTraversalData &frontData, 803 BspTraversalData &backData, 804 PolygonContainer &coincident); 805 806 /** Filters polygons down the tree. 807 @param node the current BSP node 808 @param polys the polygons to be filtered 809 @param frontPolys returns the polygons in front of the split plane 810 @param backPolys returns the polygons in the back of the split plane 811 */ 812 void FilterPolygons(BspInterior *node, 813 PolygonContainer *polys, 814 PolygonContainer *frontPolys, 815 PolygonContainer *backPolys); 816 817 /** Take 3 ray endpoints, where two are minimum and one a maximum 818 point or the other way round. 819 */ 820 Plane3 ChooseCandidatePlane(const BoundedRayContainer &rays) const; 821 822 /** Take plane normal as plane normal and the midpoint of the ray. 823 PROBLEM: does not resemble any point where visibility is likely to change 824 */ 825 Plane3 ChooseCandidatePlane2(const BoundedRayContainer &rays) const; 826 827 /** Fit the plane between the two lines so that the plane has equal shortest 828 distance to both lines. 829 */ 830 Plane3 ChooseCandidatePlane3(const BoundedRayContainer &rays) const; 831 832 /** Selects the split plane in order to construct a tree with 833 certain characteristics (e.g., balanced tree, least splits, 834 2.5d aligned) 835 @param polygons container of polygons 836 @param rays bundle of rays on which the split can be based 837 */ 838 Plane3 SelectPlaneHeuristics(BspLeaf *leaf, 839 BspTraversalData &data); 840 841 /** Extracts the meshes of the objects and adds them to polygons. 842 Adds object aabb to the aabb of the tree. 843 @param maxPolys the maximal number of objects to be stored as polygons 844 @returns the number of polygons 845 */ 846 int AddToPolygonSoup(const ObjectContainer &objects, 847 PolygonContainer &polys, 848 int maxObjects = 0, 849 bool addToBbox = true); 850 851 /** Extracts the meshes of the view cells and and adds them to polygons. 852 Adds view cell aabb to the aabb of the tree. 853 @param maxPolys the maximal number of objects to be stored as polygons 854 @returns the number of polygons 855 */ 856 int AddToPolygonSoup(const ViewCellContainer &viewCells, 857 PolygonContainer &polys, 858 int maxObjects = 0); 859 860 /** Extract polygons of this mesh and add to polygon container. 861 @param mesh the mesh that drives the polygon construction 862 @param parent the parent intersectable this polygon is constructed from 863 @returns number of polygons 864 */ 865 int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 866 867 /** Helper function which extracts a view cell on the front and the back 868 of the split plane. 869 @param backViewCell returns view cell on the back of the split plane 870 @param frontViewCell returns a view cell on the front of the split plane 871 @param coincident container of polygons coincident to the split plane 872 @param splitPlane the split plane which decides about back and front 873 @param extractBack if a back view cell is extracted 874 @param extractFront if a front view cell is extracted 875 */ 876 void ExtractViewCells(BspTraversalData &frontData, 877 BspTraversalData &backData, 878 const PolygonContainer &coincident, 879 const Plane3 &splitPlane) const; 880 881 /** Computes best cost ratio for the suface area heuristics for axis aligned 882 splits. This heuristics minimizes the cost for ray traversal. 883 @param polys the polygons guiding the ratio computation 884 @param box the bounding box of the leaf 885 @param axis the current split axis 886 @param position returns the split position 887 @param objectsBack the number of objects in the back of the split plane 888 @param objectsFront the number of objects in the front of the split plane 889 */ 890 float BestCostRatio(const PolygonContainer &polys, 891 const AxisAlignedBox3 &box, 892 const int axis, 893 float &position, 894 int &objectsBack, 895 int &objectsFront) const; 896 897 /** Sorts split candidates for cost heuristics using axis aligned splits. 898 @param polys the input for choosing split candidates 899 @param axis the current split axis 900 @param splitCandidates returns sorted list of split candidates 901 */ 902 void SortSubdivisionCandidates(const PolygonContainer &polys, 903 const int axis, 904 vector<SortableEntry> &splitCandidates) const; 905 906 /** Selects an axis aligned split plane. 907 Returns true if split is valied 908 */ 909 bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const; 910 911 /** Subdivides the rays into front and back rays according to the split plane. 912 913 @param plane the split plane 914 @param rays contains the rays to be split. The rays are 915 distributed into front and back rays. 916 @param frontRays returns rays on the front side of the plane 917 @param backRays returns rays on the back side of the plane 918 919 @returns the number of splits 920 */ 921 int SplitRays(const Plane3 &plane, 922 BoundedRayContainer &rays, 923 BoundedRayContainer &frontRays, 924 BoundedRayContainer &backRays); 925 926 927 /** Extracts the split planes representing the space bounded by node n. 928 */ 929 void ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const; 930 931 /** Adds the object to the pvs of the front and back leaf with a given classification. 932 933 @param obj the object to be added 934 @param cf the ray classification regarding the split plane 935 @param frontPvs returns the PVS of the front partition 936 @param backPvs returns the PVS of the back partition 937 938 */ 939 void AddObjToPvs(Intersectable *obj, const int cf, int &frontPvs, int &backPvs) const; 940 941 /** Computes PVS size induced by the rays. 942 */ 943 int ComputePvsSize(const BoundedRayContainer &rays) const; 944 945 /** Returns true if tree can be terminated. 946 */ 947 inline bool TerminationCriteriaMet(const BspTraversalData &data) const; 948 949 /** Computes accumulated ray lenght of this rays. 950 */ 951 float AccumulatedRayLength(BoundedRayContainer &rays) const; 952 953 /** Splits polygons with respect to the split plane. 954 @param polys the polygons to be split. the polygons are consumed and 955 distributed to the containers frontPolys, backPolys, coincident. 956 @param frontPolys returns the polygons in the front of the split plane 957 @param backPolys returns the polygons in the back of the split plane 958 @param coincident returns the polygons coincident to the split plane 959 960 @returns the number of splits 961 */ 962 int SplitPolygons(const Plane3 &plane, 963 PolygonContainer &polys, 964 PolygonContainer &frontPolys, 965 PolygonContainer &backPolys, 966 PolygonContainer &coincident) const; 967 968 /** Adds ray sample contributions to the PVS. 969 @param sampleContributions the number contributions of the samples 970 @param contributingSampels the number of contributing rays 971 972 */ 973 void AddToPvs(BspLeaf *leaf, 974 const BoundedRayContainer &rays, 975 int &sampleContributions, 976 int &contributingSamples); 977 978 /** Preprocesses polygons and throws out all polygons which 979 are coincident to the view space box faces: 980 These polygons can can be problematic for bsp because they create 981 bad view cells. 982 */ 983 void PreprocessPolygons(PolygonContainer &polys); 984 985 986 /////////////////////////////////// 987 988 /// Pointer to the root of the tree. 989 BspNode *mRoot; 990 991 /// Stores statistics during traversal. 992 BspTreeStatistics mStat; 993 1001 994 /// box around the whole view domain 1002 AxisAlignedBox3 mB ox;995 AxisAlignedBox3 mBbox; 1003 996 1004 997 /// view cell corresponding to unbounded space … … 1006 999 1007 1000 /// if view cells should be generated or the given view cells should be used. 1008 bool m GenerateViewCells;1001 bool mUsePredefinedViewCells; 1009 1002 1010 1003 /// maximal number of polygons before subdivision termination … … 1076 1069 ofstream mSubdivisionStats; 1077 1070 1071 ViewCellsTree *mViewCellsTree; 1072 1073 bool mOutOfBoundsCellPartOfTree; 1078 1074 private: 1079 1075 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1528 r1545 23 23 #include "BvHierarchy.h" 24 24 #include "SamplingStrategy.h" 25 #include "SceneGraph.h" 25 26 26 27 27 28 // should not count origin object for sampling because it disturbs heuristics 28 29 #define SAMPLE_ORIGIN_OBJECTS 0 29 30 30 31 31 … … 63 63 mViewCellPvsIsUpdated(false), 64 64 mPreprocessor(NULL), 65 mViewCellsTree(viewCellsTree) 65 mViewCellsTree(viewCellsTree), 66 mUsePredefinedViewCells(false) 66 67 { 67 68 mViewSpaceBox.Initialize(); … … 649 650 { 650 651 if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 652 { 651 653 return false; 654 } 652 655 653 656 cout << "exporting view cells to xml ... "; … … 1044 1047 1045 1048 const int n = min(mMaxFilterSize, (int)neighborhood.size()); 1049 1050 ///////////////// 1046 1051 //-- use priority queue to merge leaf pairs 1047 1048 //cout << "neighborhood: " << neighborhood.size() << endl; 1049 //const float maxAvgCost = 350; 1052 1050 1053 for (int nMergedViewCells = 0; nMergedViewCells < n; ++ nMergedViewCells) 1051 1054 { … … 1058 1061 neighborhood.pop_back(); 1059 1062 1060 // cout << "vc idx: " << bestViewCellIdx << endl;1061 1063 if (!bestViewCell || !root) 1062 1064 cout << "warning!!" << endl; 1063 1065 1064 1066 // create new root of the hierarchy … … 1174 1176 const float filterWidth) 1175 1177 { 1176 1177 1178 1179 1180 ViewCell *currentViewCell = GetViewCell(viewPoint); 1181 1182 if (mMaxFilterSize < 1) { 1183 prvs.mViewCell = currentViewCell; 1184 return; 1185 } 1186 1187 const AxisAlignedBox3 box = GetFilterBBox(viewPoint, filterWidth); 1188 1189 if (currentViewCell) { 1190 ViewCellContainer viewCells; 1191 ComputeBoxIntersections(box, viewCells); 1192 1193 1194 ViewCell *root = ConstructLocalMergeTree2(currentViewCell, viewCells); 1195 prvs.mViewCell = root; 1196 1197 } else 1198 prvs.mViewCell = NULL; 1199 //prvs.mPvs = root->GetPvs(); 1178 ViewCell *currentViewCell = GetViewCell(viewPoint); 1179 1180 if (mMaxFilterSize < 1) { 1181 prvs.mViewCell = currentViewCell; 1182 return; 1183 } 1184 1185 const AxisAlignedBox3 box = GetFilterBBox(viewPoint, filterWidth); 1186 1187 if (currentViewCell) 1188 { 1189 ViewCellContainer viewCells; 1190 ComputeBoxIntersections(box, viewCells); 1191 1192 ViewCell *root = ConstructLocalMergeTree2(currentViewCell, viewCells); 1193 prvs.mViewCell = root; 1194 1195 } 1196 else 1197 { 1198 prvs.mViewCell = NULL; 1199 //prvs.mPvs = root->GetPvs(); 1200 } 1200 1201 } 1201 1202 … … 1262 1263 1263 1264 1264 bool ViewCellsManager::LoadViewCellsGeometry(const string filename) 1265 { 1265 bool ViewCellsManager::LoadViewCellsGeometry(const string filename, 1266 const bool extrudeBaseTriangles) 1267 { 1268 bool success; 1269 1270 /// we use predefined view cells from now on 1271 mUsePredefinedViewCells = true; 1266 1272 X3dParser parser; 1267 1268 Environment::GetSingleton()->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 1269 1270 bool success = parser.ParseFile(filename, *this); 1271 Debug << (int)mViewCells.size() << " view cells loaded" << endl; 1273 1274 if (extrudeBaseTriangles) 1275 { 1276 Environment::GetSingleton()->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 1277 success = parser.ParseFile(filename, *this); 1278 } 1279 else 1280 { 1281 // hack: use standard mesh loading 1282 // create temporary scene graph for loading the view cells geometry 1283 SceneGraphNode *root = new SceneGraphNode(); 1284 success = parser.ParseFile(filename, root, true); 1285 1286 if (success) 1287 { 1288 ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 1289 for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 1290 { 1291 if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 1292 { 1293 TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 1294 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 1295 mit->GetTransformedMesh(*mesh); 1296 mesh->ComputeBoundingBox(); 1297 mViewCells.push_back(GenerateViewCell(mesh)); 1298 } 1299 else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 1300 { 1301 MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 1302 mViewCells.push_back(GenerateViewCell(mit->GetMesh())); 1303 } 1304 } 1305 } 1306 DEL_PTR(root); 1307 } 1308 1309 if (success) 1310 { 1311 // set view space box to bounding box of the view cells 1312 /*AxisAlignedBox3 bbox; 1313 bbox.Initialize(); 1314 ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 1315 for (; it != it_end; ++ it) 1316 { 1317 bbox.Include(GetViewCellBox(*it)); 1318 } 1319 SetViewSpaceBox(bbox);*/ 1320 1321 cout << "generated " << (int)mViewCells.size() << " view cells using the geometry from file " << filename << endl; 1322 } 1272 1323 1273 1324 return success; … … 1396 1447 1397 1448 1398 1399 void ViewCellsManager::AddViewCell(ViewCell *viewCell)1400 {1401 mViewCells.push_back(viewCell);1402 }1403 1404 1405 1449 float ViewCellsManager::GetArea(ViewCell *viewCell) const 1406 1450 { … … 1412 1456 { 1413 1457 return viewCell->GetVolume(); 1414 }1415 1416 1417 void ViewCellsManager::DeriveViewCellsFromObjects(const ObjectContainer &objects,1418 ViewCellContainer &viewCells,1419 const int maxViewCells) const1420 {1421 // maximal max viewcells1422 int limit = maxViewCells > 0 ?1423 Min((int)objects.size(), maxViewCells) : (int)objects.size();1424 1425 for (int i = 0; i < limit; ++ i)1426 {1427 Intersectable *object = objects[i];1428 1429 // extract the mesh instances1430 if (object->Type() == Intersectable::MESH_INSTANCE)1431 {1432 MeshInstance *inst = dynamic_cast<MeshInstance *>(object);1433 1434 ViewCell *viewCell = GenerateViewCell(inst->GetMesh());1435 viewCells.push_back(viewCell);1436 }1437 else if (object->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)1438 {1439 TransformedMeshInstance *mi = dynamic_cast<TransformedMeshInstance *>(object);1440 1441 Mesh *mesh = MeshManager::GetSingleton()->CreateResource();1442 1443 // transform mesh1444 mi->GetTransformedMesh(*mesh);1445 1446 // create bb + kd tree1447 mesh->Preprocess();1448 1449 ViewCell *viewCell = GenerateViewCell(mi->GetMesh());1450 viewCells.push_back(viewCell);1451 1452 break;1453 }1454 }1455 1458 } 1456 1459 … … 1462 1465 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 1463 1466 1467 //////////// 1464 1468 //-- construct prism 1465 1469 … … 1473 1477 mesh->mFaces.push_back(new Face(3, 5, 2, 0)); 1474 1478 1475 //--- extrude new vertices for top of prism 1479 1480 ///////////// 1481 //-- extrude new vertices for top of prism 1482 1476 1483 Vector3 triNorm = baseTri.GetNormal(); 1477 1478 1484 Triangle3 topTri; 1479 1485 1480 1486 // add base vertices and calculate top vertices 1481 1487 for (int i = 0; i < 3; ++ i) 1488 { 1482 1489 mesh->mVertices.push_back(baseTri.mVertices[i]); 1490 } 1483 1491 1484 1492 // add top vertices 1485 1493 for (int i = 0; i < 3; ++ i) 1494 { 1486 1495 mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm); 1487 1488 mesh->Preprocess(); 1489 1496 } 1497 1498 // do we have to preprocess this mesh (we don't want to trace view cells!)? 1499 mesh->ComputeBoundingBox(); 1500 1490 1501 return GenerateViewCell(mesh); 1491 1502 } … … 1875 1886 // if view point is valid, add new object to the pvs 1876 1887 if (ray.mTerminationObject) 1877 { cout <<"here22" << endl;1888 { 1878 1889 viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf); 1879 1890 } … … 2007 2018 mNumActiveViewCells = n; 2008 2019 mViewCells.clear(); 2020 // implemented in subclasses 2009 2021 CollectViewCells(); 2010 2022 } … … 2497 2509 Environment::GetSingleton()->GetIntValue("BspTree.Construction.samples", mInitialSamples); 2498 2510 mBspTree->SetViewCellsManager(this); 2499 mBspTree-> mViewCellsTree = mViewCellsTree;2511 mBspTree->SetViewCellsTree(mViewCellsTree); 2500 2512 } 2501 2513 … … 2516 2528 const VssRayContainer &rays) 2517 2529 { 2518 // if view cells were already constructed 2530 // if view cells were already constructed, we can finish 2519 2531 if (ViewCellsConstructed()) 2520 2532 return 0; … … 2540 2552 } 2541 2553 2542 if ( mViewCells.empty())2554 if (!mUsePredefinedViewCells) 2543 2555 { 2544 2556 // no view cells loaded … … 2548 2560 } 2549 2561 else 2550 { 2562 { cout << "here222" << endl; 2563 // use predefined view cells geometry => 2564 // contruct bsp hierarchy over them 2551 2565 mBspTree->Construct(mViewCells); 2552 2566 } … … 2575 2589 2576 2590 void BspViewCellsManager::CollectViewCells() 2577 { 2578 // view cells tree constructed 2591 { 2579 2592 if (!ViewCellsTreeConstructed()) 2580 { 2593 { // view cells tree constructed 2581 2594 mBspTree->CollectViewCells(mViewCells); 2582 2595 } 2583 2596 else 2584 { 2585 // we can use the view cells tree hierarchy to get the right set 2586 mViewCellsTree->CollectBestViewCellSet(mViewCells, 2587 mNumActiveViewCells); 2597 { // we can use the view cells tree hierarchy to get the right set 2598 mViewCellsTree->CollectBestViewCellSet(mViewCells, mNumActiveViewCells); 2588 2599 } 2589 2600 } … … 2592 2603 float BspViewCellsManager::GetProbability(ViewCell *viewCell) 2593 2604 { 2594 // compute view cell area as subsititute for probability2595 2605 if (1) 2596 2606 return GetVolume(viewCell) / GetViewSpaceBox().GetVolume(); 2597 2607 else 2608 // compute view cell area as subsititute for probability 2598 2609 return GetArea(viewCell) / GetAccVcArea(); 2599 2610 } … … 2609 2620 2610 2621 2622 void BspViewCellsManager::ExportMergedViewCells(const ObjectContainer &objects) 2623 { 2624 // save color code 2625 const int savedColorCode = mColorCode; 2626 2627 // export merged view cells 2628 mColorCode = 0; // use random colors 2629 2630 Exporter *exporter = Exporter::GetExporter("merged_view_cells.wrl"); 2631 2632 cout << "exporting view cells after merge ... "; 2633 2634 if (exporter) 2635 { 2636 if (mExportGeometry) 2637 { 2638 exporter->ExportGeometry(objects); 2639 } 2640 2641 exporter->SetFilled(); 2642 ExportViewCellsForViz(exporter, NULL, GetClipPlane()); 2643 2644 delete exporter; 2645 } 2646 cout << "finished" << endl; 2647 2648 // export merged view cells using pvs color coding 2649 mColorCode = 1; 2650 2651 exporter = Exporter::GetExporter("merged_view_cells_pvs.wrl"); 2652 cout << "exporting view cells after merge (pvs size) ... "; 2653 2654 if (exporter) 2655 { 2656 if (mExportGeometry) 2657 { 2658 exporter->ExportGeometry(objects); 2659 } 2660 2661 exporter->SetFilled(); 2662 ExportViewCellsForViz(exporter, NULL, GetClipPlane()); 2663 2664 delete exporter; 2665 } 2666 cout << "finished" << endl; 2667 2668 mColorCode = savedColorCode; 2669 } 2670 2671 2611 2672 int BspViewCellsManager::PostProcess(const ObjectContainer &objects, 2612 2673 const VssRayContainer &rays) … … 2628 2689 } 2629 2690 2630 int vcSize = 0; 2631 int pvsSize = 0; 2632 2633 2691 if (mUsePredefinedViewCells) return 0; 2634 2692 ////////////////// 2635 2693 //-- merge leaves of the view cell hierarchy … … 2649 2707 { 2650 2708 cout << "constructing spatial merge tree" << endl; 2651 2652 // create spatial merge hierarchy 2653 ViewCell *root = ConstructSpatialMergeTree(mBspTree->GetRoot()); 2709 ViewCell *root; 2710 // the spatial merge tree is difficult to build for 2711 // this type of construction, as view cells cover several 2712 // leaves => create dummy tree which is only 2 levels deep 2713 if (mUsePredefinedViewCells) 2714 { 2715 root = ConstructDummyMergeTree(mBspTree->GetRoot()); 2716 } 2717 else 2718 { 2719 // create spatial merge hierarchy 2720 root = ConstructSpatialMergeTree(mBspTree->GetRoot()); 2721 } 2722 2654 2723 mViewCellsTree->SetRoot(root); 2655 2724 … … 2657 2726 ObjectPvs pvs; 2658 2727 UpdatePvsForEvaluation(root, pvs); 2728 2659 2729 } 2660 2730 … … 2680 2750 Debug << "\nView cells after merge:\n" << mCurrentViewCellsStats << endl; 2681 2751 2682 // save color code 2683 const int savedColorCode = mColorCode; 2684 2685 if (1) // export merged view cells 2686 { 2687 mColorCode = 0; // use random colors 2688 Exporter *exporter = Exporter::GetExporter("merged_view_cells.wrl"); 2752 if (1) ExportMergedViewCells(objects); 2753 2754 // only for debugging purpose: test if the subdivision is valid 2755 if (0) TestSubdivision(); 2756 2757 // compute final meshes and volume / area 2758 if (1) FinalizeViewCells(true); 2759 2760 // write view cells to disc 2761 if (1 && mExportViewCells) 2762 { 2763 char filename[100]; 2764 Environment::GetSingleton()->GetStringValue("ViewCells.filename", filename); 2765 ExportViewCells(filename, mExportPvs, objects); 2766 } 2767 2768 return 0; 2769 } 2770 2771 2772 BspViewCellsManager::~BspViewCellsManager() 2773 { 2774 } 2775 2776 2777 int BspViewCellsManager::GetType() const 2778 { 2779 return BSP; 2780 } 2781 2782 2783 void BspViewCellsManager::Visualize(const ObjectContainer &objects, 2784 const VssRayContainer &sampleRays) 2785 { 2786 if (!ViewCellsConstructed()) 2787 return; 2788 2789 int savedColorCode = mColorCode; 2689 2790 2690 cout << "exporting view cells after merge ... "; 2791 if (1) // export final view cells 2792 { 2793 mColorCode = 1; // hack color code 2794 Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl"); 2795 2796 cout << "exporting view cells after merge (pvs size) ... "; 2691 2797 2692 2798 if (exporter) … … 2697 2803 } 2698 2804 2699 exporter->SetFilled();2700 ExportViewCellsForViz(exporter, NULL, GetClipPlane());2701 2702 delete exporter;2703 }2704 cout << "finished" << endl;2705 }2706 2707 if (1)2708 {2709 // export merged view cells using pvs color coding2710 mColorCode = 1;2711 2712 Exporter *exporter = Exporter::GetExporter("merged_view_cells_pvs.wrl");2713 cout << "exporting view cells after merge (pvs size) ... ";2714 2715 if (exporter)2716 {2717 if (mExportGeometry)2718 {2719 exporter->ExportGeometry(objects);2720 }2721 2722 exporter->SetFilled();2723 ExportViewCellsForViz(exporter, NULL, GetClipPlane());2724 2725 delete exporter;2726 }2727 cout << "finished" << endl;2728 }2729 2730 // only for debugging purpose: test if the subdivision is valid2731 if (0) TestSubdivision();2732 2733 mColorCode = savedColorCode;2734 2735 // compute final meshes and volume / area2736 if (1) FinalizeViewCells(true);2737 2738 // write view cells to disc2739 if (1 && mExportViewCells)2740 {2741 char filename[100];2742 Environment::GetSingleton()->GetStringValue("ViewCells.filename", filename);2743 ExportViewCells(filename, mExportPvs, objects);2744 }2745 2746 return 0;2747 }2748 2749 2750 BspViewCellsManager::~BspViewCellsManager()2751 {2752 }2753 2754 2755 int BspViewCellsManager::GetType() const2756 {2757 return BSP;2758 }2759 2760 2761 void BspViewCellsManager::Visualize(const ObjectContainer &objects,2762 const VssRayContainer &sampleRays)2763 {2764 if (!ViewCellsConstructed())2765 return;2766 2767 int savedColorCode = mColorCode;2768 2769 2770 if (1) // export final view cells2771 {2772 mColorCode = 1; // hack color code2773 Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl");2774 2775 cout << "exporting view cells after merge (pvs size) ... ";2776 2777 if (exporter)2778 {2779 if (mExportGeometry)2780 {2781 exporter->ExportGeometry(objects);2782 }2783 2784 2805 ExportViewCellsForViz(exporter, NULL, GetClipPlane()); 2785 2806 delete exporter; … … 2787 2808 cout << "finished" << endl; 2788 2809 } 2789 2810 // reset color code 2790 2811 mColorCode = savedColorCode; 2791 2812 … … 2816 2837 { 2817 2838 //exporter->SetFilled(); 2818 2819 2839 if (mExportGeometry) 2840 { 2820 2841 exporter->ExportGeometry(objects); 2842 } 2821 2843 2822 2844 Material m; … … 2827 2849 exporter->ExportBspSplits(*mBspTree, true); 2828 2850 2829 // NOTE: take forced material, else big scenes cannot be viewed2851 // NOTE: take forced material, else big scenes cannot be viewed 2830 2852 m.mDiffuseColor = RgbColor(0, 1, 0); 2831 2853 exporter->SetForcedMaterial(m); … … 2840 2862 { 2841 2863 const int leafOut = 10; 2842 2843 2864 ViewCell::NewMail(); 2844 2865 2866 ////////// 2845 2867 //-- some rays for output 2846 2868 const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); … … 2861 2883 ViewCell *vc; 2862 2884 2863 if (0 )2885 if (0 || ((int)mViewCells.size() <= limit)) 2864 2886 vc = mViewCells[i]; 2865 2887 else … … 2878 2900 BspLeaf *leaf = ray->intersections[j].mLeaf; 2879 2901 if (vc == leaf->GetViewCell()) 2902 { 2880 2903 vcRays.push_back(ray->vssRay); 2904 } 2881 2905 } 2882 2906 } … … 3080 3104 { 3081 3105 if (!ViewCellsConstructed()) 3106 { 3082 3107 return NULL; 3108 } 3083 3109 3084 3110 if (!mViewSpaceBox.IsInside(point)) 3111 { 3085 3112 return NULL; 3086 3113 } 3114 3087 3115 return mBspTree->GetViewCell(point); 3088 3116 } … … 3154 3182 #endif 3155 3183 return true; 3184 } 3185 3186 3187 ViewCell *BspViewCellsManager::ConstructDummyMergeTree(BspNode *root) 3188 { 3189 ViewCellInterior *vcRoot = new ViewCellInterior(); 3190 3191 // evaluate merge cost for priority traversal 3192 const float mergeCost = 1.0f / (float)root->mTimeStamp; 3193 vcRoot->SetMergeCost(mergeCost); 3194 3195 float volume = 0; 3196 vector<BspLeaf *> leaves; 3197 mBspTree->CollectLeaves(leaves); 3198 vector<BspLeaf *>::const_iterator lit, lit_end = leaves.end(); 3199 3200 for (lit = leaves.begin(); lit != lit_end; ++ lit) 3201 { 3202 BspLeaf *leaf = *lit; 3203 ViewCell *vc = leaf->GetViewCell(); 3204 3205 vc->SetMergeCost(0.0f); 3206 vcRoot->SetupChildLink(vc); 3207 3208 volume += vc->GetVolume(); 3209 volume += vc->GetVolume(); 3210 3211 vcRoot->SetVolume(volume); 3212 } 3213 3214 return vcRoot; 3156 3215 } 3157 3216 … … 3180 3239 3181 3240 3241 //////////// 3182 3242 //-- recursivly compute child hierarchies 3243 3183 3244 ViewCell *backVc = ConstructSpatialMergeTree(back); 3184 3245 ViewCell *frontVc = ConstructSpatialMergeTree(front); 3185 3186 3246 3187 3247 viewCellInterior->SetupChildLink(backVc); … … 3528 3588 void VspBspViewCellsManager::CollectViewCells() 3529 3589 { 3530 // view cells tree constructed 3590 // view cells tree constructed? 3531 3591 if (!ViewCellsTreeConstructed()) 3532 3592 { … … 3581 3641 // if view cells were already constructed 3582 3642 if (ViewCellsConstructed()) 3643 { 3583 3644 return 0; 3645 } 3584 3646 3585 3647 int sampleContributions = 0; 3586 3587 3648 VssRayContainer sampleRays; 3588 3649 3589 int limit = min (mInitialSamples, (int)rays.size()); 3590 3591 VssRayContainer constructionRays; 3592 VssRayContainer savedRays; 3650 const int limit = min(mInitialSamples, (int)rays.size()); 3593 3651 3594 3652 Debug << "samples used for vsp bsp subdivision: " << mInitialSamples 3595 3653 << ", actual rays: " << (int)rays.size() << endl; 3596 3654 3597 GetRaySets(rays, mInitialSamples, constructionRays, &savedRays); 3598 3599 Debug << "initial rays: " << (int)constructionRays.size() << endl; 3600 Debug << "saved rays: " << (int)savedRays.size() << endl; 3601 3602 long startTime; 3603 3604 if (1) 3605 { 3655 VssRayContainer savedRays; 3656 3657 if (SAMPLE_AFTER_SUBDIVISION) 3658 { 3659 VssRayContainer constructionRays; 3660 3661 GetRaySets(rays, mInitialSamples, constructionRays, &savedRays); 3662 3663 Debug << "rays used for initial construction: " << (int)constructionRays.size() << endl; 3664 Debug << "rays saved for later use: " << (int)savedRays.size() << endl; 3665 3606 3666 mVspBspTree->Construct(constructionRays, &mViewSpaceBox); 3607 3667 } 3608 3668 else 3609 3669 { 3670 Debug << "rays used for initial construction: " << (int)rays.size() << endl; 3610 3671 mVspBspTree->Construct(rays, &mViewSpaceBox); 3611 3672 } … … 3613 3674 // collapse invalid regions 3614 3675 cout << "collapsing invalid tree regions ... "; 3615 startTime = GetTime(); 3676 long startTime = GetTime(); 3677 3616 3678 const int collapsedLeaves = mVspBspTree->CollapseTree(); 3617 3679 Debug << "collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 … … 3630 3692 3631 3693 ////////////////////// 3632 //-- recast rest ofrays3694 //-- recast the rest of the rays 3633 3695 startTime = GetTime(); 3634 3696 … … 3646 3708 3647 3709 if (0) 3648 { 3710 { //////// 3649 3711 //-- real meshes are contructed at this stage 3650 3712 cout << "finalizing view cells ... "; … … 4179 4241 // export rays 4180 4242 if (mExportRays) 4243 { 4181 4244 exporter->ExportRays(rays, RgbColor(1, 1, 0)); 4245 } 4182 4246 4183 4247 if (mExportGeometry) 4248 { 4184 4249 exporter->ExportGeometry(objects); 4250 } 4185 4251 4186 4252 delete exporter; … … 4783 4849 mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 4784 4850 4785 VssRayContainer::const_iterator vit, vit_end = constructionRays.end(); 4786 4787 for (vit = constructionRays.begin(); vit != vit_end; ++ vit) 4788 { 4789 storedRays.push_back(new VssRay(*(*vit))); 4790 } 4791 4792 //////////// 4851 4852 ///////////////////////// 4793 4853 //-- print satistics for subdivision and view cells 4794 4854 … … 4805 4865 4806 4866 4807 ////////// 4867 ////////////// 4808 4868 //-- recast rest of rays 4809 4869 … … 4818 4878 4819 4879 if (0) 4820 { 4821 // real meshes are constructed at this stage 4880 { // real meshes are constructed at this stage 4822 4881 cout << "finalizing view cells ... "; 4823 4882 FinalizeViewCells(true); … … 4961 5020 VspNode *back = interior->GetBack(); 4962 5021 4963 4964 5022 ObjectPvs frontPvs, backPvs; 4965 5023 5024 ///////// 4966 5025 //-- recursivly compute child hierarchies 5026 4967 5027 ViewCell *backVc = ConstructSpatialMergeTree(back); 4968 5028 ViewCell *frontVc = ConstructSpatialMergeTree(front); 4969 4970 5029 4971 5030 viewCellInterior->SetupChildLink(backVc); … … 5093 5152 AxisAlignedBox3 bbox = mHierarchyManager->GetViewSpaceBox(); 5094 5153 bbox.Scale(Vector3(0.5, 1, 0.5)); 5095 5096 5154 if (CLAMP_TO_BOX) 5097 5155 { … … 5101 5159 } 5102 5160 5103 ///////////////////5104 5105 5161 if (0 && mExportGeometry) 5106 5162 { 5107 5163 exporter->ExportGeometry(objects, true, CLAMP_TO_BOX ? &bbox : NULL); 5108 5164 } 5109 5110 // export rays 5165 5111 5166 if (0 && mExportRays) 5112 { 5167 { 5113 5168 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 5114 5169 } … … 5650 5705 } 5651 5706 5652 Debug << "\nrendercost hack: " << rc / mHierarchyManager->GetV spTree()->GetBoundingBox().GetVolume() << endl;5707 Debug << "\nrendercost hack: " << rc / mHierarchyManager->GetViewSpaceBox() << endl; 5653 5708 mViewCellsTree->ExportStats(fileName); 5654 5709 cout << "finished" << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1421 r1545 70 70 float avgPvs; 71 71 int viewcells; 72 72 }; 73 73 74 74 /// view cell container types … … 78 78 enum {PER_OBJECT, PER_TRIANGLE}; 79 79 80 friend class X3dViewCellsParseHandlers; 80 81 /** Default constructor. 81 82 */ … … 144 145 145 146 /** Load the input viewcells. The input viewcells should be given as a collection 146 of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of 147 the viewcell. The method then builds a BSP tree of these view cells. 147 of meshes. Each mesh is assume to form a bounded polyhedron 148 defining the interior of the viewcell. The view cells manager 149 is responsible for building a hierarchy over these view cells. 148 150 149 151 @param filename file to load 150 152 @return true on success 151 153 */ 152 virtual bool LoadViewCellsGeometry(const string filename); 153 154 virtual bool LoadViewCellsGeometry(const string filename, const bool extrudeBaseTriangle); 155 156 /** Merges two view cells. 157 @note the piercing rays of the front and back will be ordered 158 @returns new view cell based on the merging. 159 */ 160 ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const; 161 162 /** Merges a container of view cells. 163 @returns new view cell based on the merging. 164 */ 165 ViewCellInterior *MergeViewCells(ViewCellContainer &children) const; 166 167 /** Generates view cell of the type specified by this manager 168 */ 169 virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0; 170 154 171 /** Constructs view cell from base triangle. 155 172 The view cell is extruded along the normal vector. … … 158 175 */ 159 176 ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const; 160 161 /** Merges two view cells.162 @note the piercing rays of the front and back will be ordered163 @returns new view cell based on the merging.164 */165 ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const;166 167 /** Merges a container of view cells.168 @returns new view cell based on the merging.169 */170 ViewCellInterior *MergeViewCells(ViewCellContainer &children) const;171 172 /** Generates view cell of type specified by this manager173 */174 virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0;175 176 /** Adds a new view cell to the list of predefined view cells.177 */178 void AddViewCell(ViewCell *viewCell);179 180 /** Derive view cells from scene objects. The view ells are created by taking the object181 geometry into account.182 */183 void DeriveViewCellsFromObjects(const ObjectContainer &objects,184 ViewCellContainer &viewCells,185 const int maxViewCells) const;186 177 187 178 /** Sets maximal number of samples used for the … … 338 329 void SetValidityPercentage(const float minValid, const float maxValid); 339 330 331 /** Returns number of valid view cells. 332 */ 340 333 int CountValidViewcells() const; 341 334 … … 378 371 ViewCellsTree *GetViewCellsTree(); 379 372 373 /** Collect candidates for the view cell merge. 374 */ 380 375 virtual void CollectMergeCandidates(const VssRayContainer &rays, 381 376 vector<MergeCandidate> &candidates); … … 438 433 bool GetExportPvs() const; 439 434 435 ///////////////////////////// 436 // static members 437 440 438 /** Loads view cells from file. The view cells manager is created with 441 439 respect to the loaded view cells. … … 569 567 */ 570 568 virtual void ExportColor(Exporter *exporter, ViewCell *vc) const; 569 571 570 /** Creates meshes from the view cells. 572 571 */ 573 572 void CreateViewCellMeshes(); 574 /** Creates clip plane for visualization. 573 574 /** Creates clip plane for visualization. 575 575 */ 576 576 void CreateClipPlane(); 577 577 578 578 AxisAlignedPlane *GetClipPlane(); 579 579 580 /////////////////////// 580 581 … … 663 664 int mMaxFilterSize; 664 665 666 bool mStoreObjectPvs; 667 668 ////////////////// 665 669 //-- visualization options 666 670 667 671 /// color code for view cells visualization 672 bool mShowVisualization; 668 673 int mColorCode; 669 674 bool mExportGeometry; 670 675 bool mExportRays; 671 672 676 bool mViewCellsFinished; 673 674 677 bool mEvaluateViewCells; 675 676 bool mShowVisualization;677 678 678 int mRenderCostEvaluationType; 679 679 … … 681 681 bool mExportPvs; 682 682 683 bool mStoreObjectPvs; 684 685 VssRayContainer storedRays; 683 bool mUsePredefinedViewCells; 686 684 }; 687 685 688 686 689 /** 690 Manages different higher order operations on the view cells. 687 /** Manages different higher order operations on the view cells. 691 688 */ 692 689 class BspViewCellsManager: public ViewCellsManager … … 754 751 ViewCell *ConstructSpatialMergeTree(BspNode *root); 755 752 756 753 757 754 protected: 758 755 759 756 void CollectViewCells(); 760 761 757 762 758 /// the BSP tree. 763 759 BspTree *mBspTree; 764 765 760 vector<BspRay *> mBspRays; 766 761 767 762 private: 768 763 764 /** Constructs a spatial merge tree only 2 levels deep. 765 */ 766 ViewCell *ConstructDummyMergeTree(BspNode *root); 767 769 768 /** Exports visualization of the BSP splits. 770 769 */ … … 778 777 */ 779 778 void TestSubdivision(); 779 780 void ExportMergedViewCells(const ObjectContainer &objects); 780 781 }; 782 781 783 782 784 /** … … 1091 1093 1092 1094 1093 /*class ViewCellsManagerFactory1094 {1095 public:1096 ViewCellsManager *Create(const string mName);1097 };*/1098 1099 1095 } 1100 1096 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1449 r1545 265 265 266 266 int polysSize = 0; 267 267 268 268 for (int i = 0; i < limit; ++ i) 269 269 { 270 if (viewCells[i]->GetMesh()) // copy the mesh data to polygons271 {272 mBox.Include(viewCells[i]->GetBox()); //add to BSP tree aabb273 polysSize +=274 AddMeshToPolygons(viewCells[i]->GetMesh(),275 polys,276 viewCells[i]);277 } 278 } 279 270 Mesh *mesh = viewCells[i]->GetMesh(); 271 if (mesh) 272 { // // copy the mesh into polygons and add to BSP tree aabb 273 mBox.Include(viewCells[i]->GetBox()); 274 polysSize += AddMeshToPolygons(mesh, 275 polys, 276 viewCells[i]); 277 } 278 } 279 280 280 return polysSize; 281 281 } … … 2588 2588 { 2589 2589 ViewCell::NewMail(); 2590 2591 2590 CollectViewCells(mRoot, onlyValid, viewCells, true); 2592 2591 } 2593 2594 2595 void VspBspTree::CollapseViewCells()2596 {2597 // TODO2598 #if HAS_TO_BE_REDONE2599 stack<BspNode *> nodeStack;2600 2601 if (!mRoot)2602 return;2603 2604 nodeStack.push(mRoot);2605 2606 while (!nodeStack.empty())2607 {2608 BspNode *node = nodeStack.top();2609 nodeStack.pop();2610 2611 if (node->IsLeaf())2612 {2613 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell();2614 2615 if (!viewCell->GetValid())2616 {2617 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell();2618 2619 ViewCellContainer leaves;2620 mViewCellsTree->CollectLeaves(viewCell, leaves);2621 2622 ViewCellContainer::const_iterator it, it_end = leaves.end();2623 2624 for (it = leaves.begin(); it != it_end; ++ it)2625 {2626 BspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf;2627 l->SetViewCell(GetOrCreateOutOfBoundsCell());2628 ++ mBspStats.invalidLeaves;2629 }2630 2631 // add to unbounded view cell2632 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs());2633 DEL_PTR(viewCell);2634 }2635 }2636 else2637 {2638 BspInterior *interior = dynamic_cast<BspInterior *>(node);2639 2640 nodeStack.push(interior->GetFront());2641 nodeStack.push(interior->GetBack());2642 }2643 }2644 2645 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl;2646 #endif2647 }2648 2649 2650 void VspBspTree::CollectRays(VssRayContainer &rays)2651 {2652 vector<BspLeaf *> leaves;2653 2654 vector<BspLeaf *>::const_iterator lit, lit_end = leaves.end();2655 2656 for (lit = leaves.begin(); lit != lit_end; ++ lit)2657 {2658 BspLeaf *leaf = *lit;2659 VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end();2660 2661 for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit)2662 rays.push_back(*rit);2663 }2664 }2665 2666 2667 void VspBspTree::ValidateTree()2668 {2669 stack<BspNode *> nodeStack;2670 2671 if (!mRoot)2672 return;2673 2674 nodeStack.push(mRoot);2675 2676 mBspStats.invalidLeaves = 0;2677 while (!nodeStack.empty())2678 {2679 BspNode *node = nodeStack.top();2680 nodeStack.pop();2681 2682 if (node->IsLeaf())2683 {2684 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);2685 2686 if (!leaf->GetViewCell()->GetValid())2687 ++ mBspStats.invalidLeaves;2688 2689 // validity flags don't match => repair2690 if (leaf->GetViewCell()->GetValid() != leaf->TreeValid())2691 {2692 leaf->SetTreeValid(leaf->GetViewCell()->GetValid());2693 PropagateUpValidity(leaf);2694 }2695 }2696 else2697 {2698 BspInterior *interior = dynamic_cast<BspInterior *>(node);2699 2700 nodeStack.push(interior->GetFront());2701 nodeStack.push(interior->GetBack());2702 }2703 }2704 2705 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl;2706 }2707 2708 2592 2709 2593 … … 2748 2632 } 2749 2633 } 2750 2634 } 2635 2636 2637 void VspBspTree::CollapseViewCells() 2638 { 2639 // TODO 2640 #if HAS_TO_BE_REDONE 2641 stack<BspNode *> nodeStack; 2642 2643 if (!mRoot) 2644 return; 2645 2646 nodeStack.push(mRoot); 2647 2648 while (!nodeStack.empty()) 2649 { 2650 BspNode *node = nodeStack.top(); 2651 nodeStack.pop(); 2652 2653 if (node->IsLeaf()) 2654 { 2655 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 2656 2657 if (!viewCell->GetValid()) 2658 { 2659 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 2660 2661 ViewCellContainer leaves; 2662 mViewCellsTree->CollectLeaves(viewCell, leaves); 2663 2664 ViewCellContainer::const_iterator it, it_end = leaves.end(); 2665 2666 for (it = leaves.begin(); it != it_end; ++ it) 2667 { 2668 BspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf; 2669 l->SetViewCell(GetOrCreateOutOfBoundsCell()); 2670 ++ mBspStats.invalidLeaves; 2671 } 2672 2673 // add to unbounded view cell 2674 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 2675 DEL_PTR(viewCell); 2676 } 2677 } 2678 else 2679 { 2680 BspInterior *interior = dynamic_cast<BspInterior *>(node); 2681 2682 nodeStack.push(interior->GetFront()); 2683 nodeStack.push(interior->GetBack()); 2684 } 2685 } 2686 2687 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 2688 #endif 2689 } 2690 2691 2692 void VspBspTree::CollectRays(VssRayContainer &rays) 2693 { 2694 vector<BspLeaf *> leaves; 2695 2696 vector<BspLeaf *>::const_iterator lit, lit_end = leaves.end(); 2697 2698 for (lit = leaves.begin(); lit != lit_end; ++ lit) 2699 { 2700 BspLeaf *leaf = *lit; 2701 VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end(); 2702 2703 for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit) 2704 rays.push_back(*rit); 2705 } 2706 } 2707 2708 2709 void VspBspTree::ValidateTree() 2710 { 2711 stack<BspNode *> nodeStack; 2712 2713 if (!mRoot) 2714 return; 2715 2716 nodeStack.push(mRoot); 2717 2718 mBspStats.invalidLeaves = 0; 2719 while (!nodeStack.empty()) 2720 { 2721 BspNode *node = nodeStack.top(); 2722 nodeStack.pop(); 2723 2724 if (node->IsLeaf()) 2725 { 2726 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 2727 2728 if (!leaf->GetViewCell()->GetValid()) 2729 ++ mBspStats.invalidLeaves; 2730 2731 // validity flags don't match => repair 2732 if (leaf->GetViewCell()->GetValid() != leaf->TreeValid()) 2733 { 2734 leaf->SetTreeValid(leaf->GetViewCell()->GetValid()); 2735 PropagateUpValidity(leaf); 2736 } 2737 } 2738 else 2739 { 2740 BspInterior *interior = dynamic_cast<BspInterior *>(node); 2741 2742 nodeStack.push(interior->GetFront()); 2743 nodeStack.push(interior->GetBack()); 2744 } 2745 } 2746 2747 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 2751 2748 } 2752 2749 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
r1449 r1545 151 151 } 152 152 }; 153 154 153 155 154 typedef std::priority_queue<VspBspTraversalData> VspBspTraversalQueue; 156 157 155 158 156 class VspBspSubdivisionCandidate -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1522 r1545 1856 1856 1857 1857 // add to unbounded view cell 1858 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 1858 ViewCell *outOfBounds = GetOrCreateOutOfBoundsCell(); 1859 outOfBounds->GetPvs().AddPvs(viewCell->GetPvs()); 1859 1860 DEL_PTR(viewCell); 1860 1861 } … … 1900 1901 void VspTree::ValidateTree() 1901 1902 { 1902 mVspStats.invalidLeaves = 0;1903 1904 stack<VspNode *> nodeStack;1905 1906 1903 if (!mRoot) 1907 1904 return; 1905 1906 mVspStats.invalidLeaves = 0; 1907 stack<VspNode *> nodeStack; 1908 1908 1909 1909 nodeStack.push(mRoot); … … 1947 1947 bool onlyUnmailed) const 1948 1948 { 1949 stack<VspNode *> nodeStack;1950 1951 1949 if (!root) 1952 1950 return; 1953 1951 1952 stack<VspNode *> nodeStack; 1954 1953 nodeStack.push(root); 1955 1954 -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp
r1486 r1545 998 998 } 999 999 1000 1000 1001 void X3dExporter::ExportBspSplits(const BspTree &tree, 1001 1002 const bool exportDepth) … … 1007 1008 } 1008 1009 1010 1009 1011 void X3dExporter::ExportBspSplits(const VspBspTree &tree, 1010 1012 const bool exportDepth) … … 1015 1017 tree.GetEpsilon()); 1016 1018 } 1019 1017 1020 1018 1021 void X3dExporter::ExportBspSplitPlanes(const BspTree &tree) -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
r1421 r1545 918 918 919 919 // create view cell from base triangle 920 mViewCellsManager->AddViewCell( 921 mViewCellsManager->ExtrudeViewCell(baseTri, 922 mViewCellHeight)); 920 ViewCell *vc = mViewCellsManager->ExtrudeViewCell(baseTri, mViewCellHeight); 921 mViewCellsManager->mViewCells.push_back(vc); 923 922 } 924 923 } -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1522 r1545 172 172 if (0) 173 173 { 174 preprocessor->Export(filename + "-out.x3d", true, false , false);175 preprocessor->Export(filename + "-kdtree.x3d", false, true , false);174 preprocessor->Export(filename + "-out.x3d", true, false); 175 preprocessor->Export(filename + "-kdtree.x3d", false, true); 176 176 } 177 177
Note: See TracChangeset
for help on using the changeset viewer.