Changeset 1563 for GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
- Timestamp:
- 10/03/06 22:03:58 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r1528 r1563 40 40 41 41 useViewspacePlane = mUseViewSpaceBox; //hack 42 43 mViewSpaceBox.Initialize();44 42 45 43 Debug << "*********** vss preprocessor options **************" << endl; … … 158 156 159 157 exporter->SetForcedMaterial(RgbColor(1,0,1)); 160 exporter->ExportBox(mView SpaceBox);158 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); 161 159 exporter->ResetForcedMaterial(); 162 160 … … 201 199 202 200 exporter->SetForcedMaterial(RgbColor(1,0,0)); 203 exporter->ExportBox(mView SpaceBox);201 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); 204 202 exporter->ResetForcedMaterial(); 205 203 … … 373 371 Debug << "type: vss" << endl; 374 372 375 long startTime = GetTime(); 376 377 int totalSamples = 0; 378 379 380 AxisAlignedBox3 box(mKdTree->GetBox()); 381 382 if (!useViewspacePlane) { 383 float size = 0.05f; 384 float s = 0.5f - size; 385 float olds = Magnitude(box.Size()); 386 box.Enlarge(box.Size()*Vector3(-s)); 387 Vector3 translation = Vector3(-olds*0.1f, 0, 0); 388 box.SetMin(box.Min() + translation); 389 box.SetMax(box.Max() + translation); 390 } else { 391 392 // sample city like heights 393 box.SetMin(1, box.Min(1) + box.Size(1)*0.2f); 394 box.SetMax(1, box.Min(1) + box.Size(1)*0.3f); 395 } 396 397 if (use2dSampling) 398 box.SetMax(1, box.Min(1)); 399 400 cout << "use view space box=" << mUseViewSpaceBox << endl; 401 402 403 if (mUseViewSpaceBox) 404 { 405 if (!mEnlargeViewSpace) 406 { 407 mViewSpaceBox = AxisAlignedBox3(box); 408 } 409 else 410 { 411 mViewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 412 413 if (0) 414 { 415 // HACK: enlarge in y directon 416 Vector3 size = mViewSpaceBox.Size(); 417 418 size[1] *= 1.25; 419 Vector3 enlarge(size[0] * 0.25f, size[1] * 0.0f, size[2] * 0.25f); 420 //Vector3 enlarge(size[0] * 4.0f, 0.0f, 0.0f); 421 422 mViewSpaceBox.Enlarge(enlarge); 423 mViewSpaceBox.SetMax(mViewSpaceBox.Max() + enlarge); 424 } 425 else 426 { 427 AxisAlignedBox3 tbox(mViewSpaceBox); 428 429 Vector3 size = mViewSpaceBox.Size(); 430 tbox.SetMax(0, mViewSpaceBox.Max(0) + size[0] * 0.5f); 431 tbox.SetMin(0, mViewSpaceBox.Min(0) + size[0]); 432 mViewSpaceBox = tbox; 433 } 434 } 435 } 436 else 437 { 438 mViewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 439 } 440 441 mSceneGraph->CollectObjects(&mObjects); 442 443 if (!mLoadViewCells) 444 { 445 //-- generate new view cells from the scratch 446 //-- for construction the manager uses it's own set of samples 447 ConstructViewCells(mViewSpaceBox); 448 } 373 const long startTime = GetTime(); 374 int totalSamples = 0; 375 376 if (mUseViewSpaceBox) 377 { 378 AxisAlignedBox3 viewSpaceBox; 379 viewSpaceBox.Initialize(); 380 381 viewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 382 AxisAlignedBox3 tbox(mViewCellsManager->GetViewSpaceBox()); 383 384 const Vector3 size = tbox.Size(); 385 viewSpaceBox.SetMax(0, tbox.Max(0) + size[0] * 0.5f); 386 viewSpaceBox.SetMin(0, tbox.Min(0) + size[0]); 387 388 // change the view space of the view cells manager 389 mViewCellsManager->SetViewSpaceBox(viewSpaceBox); 390 } 391 392 393 mSceneGraph->CollectObjects(&mObjects); 394 395 if (!mLoadViewCells) 396 { 397 //-- generate new view cells from the scratch 398 //-- for construction the manager uses it's own set of samples 399 ConstructViewCells(); 400 } 449 401 #if 0 450 451 452 453 454 455 456 457 402 else 403 { 404 //-- load view cells from file 405 //-- test successful view cells loading by exporting them again 406 VssRayContainer dummies; 407 mViewCellsManager->Visualize(mObjects, dummies); 408 mViewCellsManager->ExportViewCells("test.xml.zip", mViewCellsManager->GetExportPvs(), mObjects); 409 } 458 410 #endif 459 411 460 VssTree *vssTree = NULL; 461 const long initialTime = GetTime(); 462 463 if (mLoadInitialSamples) 464 { 465 cout << "Loading samples from file ... "; 466 LoadSamples(mVssRays, mObjects); 467 cout << "finished\n" << endl; 468 totalSamples = (int)mVssRays.size(); 469 } 470 else 471 { 472 while (totalSamples < mInitialSamples) { 473 int passContributingSamples = 0; 474 int passSampleContributions = 0; 475 int passSamples = 0; 476 477 int index = 0; 478 479 int sampleContributions; 480 481 int s = Min(mSamplesPerPass, mInitialSamples); 482 for (int k=0; k < s; k++) 412 VssTree *vssTree = NULL; 413 const long initialTime = GetTime(); 414 415 if (mLoadInitialSamples) 416 { 417 cout << "Loading samples from file ... "; 418 LoadSamples(mVssRays, mObjects); 419 cout << "finished\n" << endl; 420 totalSamples = (int)mVssRays.size(); 421 } 422 else 423 { 424 while (totalSamples < mInitialSamples) { 425 int passContributingSamples = 0; 426 int passSampleContributions = 0; 427 int passSamples = 0; 428 429 int index = 0; 430 431 int sampleContributions; 432 433 int s = Min(mSamplesPerPass, mInitialSamples); 434 for (int k=0; k < s; k++) 435 { 436 Vector3 viewpoint; 437 438 mViewCellsManager->GetViewPoint(viewpoint); 439 const Vector3 direction = GetDirection(viewpoint, &mViewCellsManager->GetViewSpaceBox()); 440 441 const SimpleRay sray(viewpoint, direction); 442 sampleContributions = mRayCaster->CastRay(sray, mVssRays, mViewCellsManager->GetViewSpaceBox(), true); 443 444 if (sampleContributions) { 445 passContributingSamples ++; 446 passSampleContributions += sampleContributions; 447 } 448 passSamples++; 449 totalSamples++; 450 } 451 452 mPass++; 453 int pvsSize = 0; 454 float avgRayContrib = (passContributingSamples > 0) ? 455 passSampleContributions/(float)passContributingSamples : 0; 456 457 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 458 cout << "#TotalSamples=" << totalSamples/1000 459 << "#SampleContributions=" << passSampleContributions << " (" 460 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 461 << pvsSize/(float)mObjects.size() << endl 462 << "avg ray contrib=" << avgRayContrib << endl; 463 464 mStats << 465 "#Pass\n" <<mPass<<endl<< 466 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 467 "#TotalSamples\n" << totalSamples<< endl<< 468 "#SampleContributions\n" << passSampleContributions << endl << 469 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 470 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 471 "#AvgRayContrib\n" << avgRayContrib << endl; 472 } 473 474 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 475 476 477 478 } 479 480 481 cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl << flush; 482 Debug << (int)mVssRays.size() << " rays generated in " 483 << TimeDiff(initialTime, GetTime()) * 1e-3 << " seconds" << endl; 484 485 if (mStoreInitialSamples) 486 { 487 cout << "Writing " << (int)mVssRays.size() << " samples to file ... "; 488 ExportSamples(mVssRays); 489 cout << "finished\n" << endl; 490 491 /*VssRayContainer dummyRays; 492 LoadSamples(dummyRays, mObjects); 493 Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl; 494 495 for (int i = 0; i < (int)mVssRays.size(); ++ i) 483 496 { 484 Vector3 viewpoint; 485 486 mViewCellsManager->GetViewPoint(viewpoint); 487 const Vector3 direction = GetDirection(viewpoint, &mViewSpaceBox); 488 489 const SimpleRay sray(viewpoint, direction); 490 sampleContributions = mRayCaster->CastRay(sray, mVssRays, mViewSpaceBox, true); 491 492 if (sampleContributions) { 493 passContributingSamples ++; 494 passSampleContributions += sampleContributions; 497 Debug << mVssRays[i]->GetOrigin() << " " << mVssRays[i]->GetTermination() << " " << mVssRays[i]->mOriginObject << " " << mVssRays[i]->mTerminationObject << endl; 498 Debug << dummyRays[i]->GetOrigin() << " " << dummyRays[i]->GetTermination() << " " << dummyRays[i]->mOriginObject << " " << dummyRays[i]->mTerminationObject << endl << endl; 499 }*/ 500 } 501 502 503 //int numExportRays = 2000; 504 int numExportRays = 0; 505 506 if (numExportRays) { 507 char filename[64]; 508 sprintf(filename, "vss-rays-initial.x3d"); 509 ExportRays(filename, mVssRays, numExportRays); 510 } 511 512 vssTree = new VssTree; 513 // viewcells = Construct(mVssRays); 514 515 vssTree->Construct(mVssRays, NULL); 516 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 517 518 if (0) ExportRays("kdtree.x3d", mVssRays, 10); 519 520 if (0) 521 { 522 ExportVssTree("vss-tree-100.x3d", vssTree, Vector3(1,0,0)); 523 ExportVssTree("vss-tree-001.x3d", vssTree, Vector3(0,0,1)); 524 ExportVssTree("vss-tree-101.x3d", vssTree, Vector3(1,0,1)); 525 ExportVssTree("vss-tree-101m.x3d", vssTree, Vector3(-1,0,-1)); 526 ExportVssTreeLeaves(vssTree, 10); 527 } 528 529 // viewcells->UpdatePVS(newVssRays); 530 // get viewcells as kd tree boxes 531 vector<AxisAlignedBox3> kdViewcells; 532 if (0) { 533 vector<KdLeaf *> leaves; 534 mKdTree->CollectLeaves(leaves); 535 vector<KdLeaf *>::const_iterator it; 536 int targetLeaves = 50; 537 float prob = targetLeaves/(float)leaves.size(); 538 for (it = leaves.begin(); it != leaves.end(); ++it) 539 if (RandomValue(0.0f,1.0f) < prob) 540 kdViewcells.push_back(mKdTree->GetBox(*it)); 541 542 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 543 cout<<"Initial average PVS size = "<<avgPvs<<endl; 544 } 545 546 547 int samples = 0; 548 int pass = 0; 549 550 551 // cast view cell samples 552 while (samples < mVssSamples) 553 { 554 555 int num = mVssSamplesPerPass; 556 SimpleRayContainer rays; 557 VssRayContainer vssRays; 558 559 if (!mUseImportanceSampling) { 560 for (int j=0; j < num; j++) { 561 Vector3 viewpoint; 562 mViewCellsManager->GetViewPoint(viewpoint); 563 Vector3 direction = GetDirection(viewpoint, NULL); 564 rays.push_back(SimpleRay(viewpoint, direction)); 495 565 } 496 passSamples++;497 totalSamples++;566 } else { 567 num = GenerateImportanceRays(vssTree, num, rays); 498 568 } 499 569 500 mPass++; 501 int pvsSize = 0; 502 float avgRayContrib = (passContributingSamples > 0) ? 503 passSampleContributions/(float)passContributingSamples : 0; 504 505 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 506 cout << "#TotalSamples=" << totalSamples/1000 507 << "#SampleContributions=" << passSampleContributions << " (" 508 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 509 << pvsSize/(float)mObjects.size() << endl 510 << "avg ray contrib=" << avgRayContrib << endl; 511 512 mStats << 513 "#Pass\n" <<mPass<<endl<< 514 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 515 "#TotalSamples\n" << totalSamples<< endl<< 516 "#SampleContributions\n" << passSampleContributions << endl << 517 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 518 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 519 "#AvgRayContrib\n" << avgRayContrib << endl; 520 } 521 522 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 523 524 525 526 } 527 528 529 cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl << flush; 530 Debug << (int)mVssRays.size() << " rays generated in " 531 << TimeDiff(initialTime, GetTime()) * 1e-3 << " seconds" << endl; 532 533 if (mStoreInitialSamples) 534 { 535 cout << "Writing " << (int)mVssRays.size() << " samples to file ... "; 536 ExportSamples(mVssRays); 537 cout << "finished\n" << endl; 538 539 /*VssRayContainer dummyRays; 540 LoadSamples(dummyRays, mObjects); 541 Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl; 542 543 for (int i = 0; i < (int)mVssRays.size(); ++ i) 544 { 545 Debug << mVssRays[i]->GetOrigin() << " " << mVssRays[i]->GetTermination() << " " << mVssRays[i]->mOriginObject << " " << mVssRays[i]->mTerminationObject << endl; 546 Debug << dummyRays[i]->GetOrigin() << " " << dummyRays[i]->GetTermination() << " " << dummyRays[i]->mOriginObject << " " << dummyRays[i]->mTerminationObject << endl << endl; 547 }*/ 548 } 549 550 551 //int numExportRays = 2000; 552 int numExportRays = 0; 553 554 if (numExportRays) { 555 char filename[64]; 556 sprintf(filename, "vss-rays-initial.x3d"); 557 ExportRays(filename, mVssRays, numExportRays); 558 } 559 560 vssTree = new VssTree; 561 // viewcells = Construct(mVssRays); 562 563 vssTree->Construct(mVssRays, NULL); 564 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 565 566 if (0) ExportRays("kdtree.x3d", mVssRays, 10); 567 568 if (0) 569 { 570 ExportVssTree("vss-tree-100.x3d", vssTree, Vector3(1,0,0)); 571 ExportVssTree("vss-tree-001.x3d", vssTree, Vector3(0,0,1)); 572 ExportVssTree("vss-tree-101.x3d", vssTree, Vector3(1,0,1)); 573 ExportVssTree("vss-tree-101m.x3d", vssTree, Vector3(-1,0,-1)); 574 ExportVssTreeLeaves(vssTree, 10); 575 } 576 577 // viewcells->UpdatePVS(newVssRays); 578 // get viewcells as kd tree boxes 579 vector<AxisAlignedBox3> kdViewcells; 580 if (0) { 581 vector<KdLeaf *> leaves; 582 mKdTree->CollectLeaves(leaves); 583 vector<KdLeaf *>::const_iterator it; 584 int targetLeaves = 50; 585 float prob = targetLeaves/(float)leaves.size(); 586 for (it = leaves.begin(); it != leaves.end(); ++it) 587 if (RandomValue(0.0f,1.0f) < prob) 588 kdViewcells.push_back(mKdTree->GetBox(*it)); 589 590 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 591 cout<<"Initial average PVS size = "<<avgPvs<<endl; 592 } 593 594 595 int samples = 0; 596 int pass = 0; 597 598 599 // cast view cell samples 600 while (samples < mVssSamples) 601 { 602 603 int num = mVssSamplesPerPass; 604 SimpleRayContainer rays; 605 VssRayContainer vssRays; 606 607 if (!mUseImportanceSampling) { 608 for (int j=0; j < num; j++) { 609 Vector3 viewpoint; 610 mViewCellsManager->GetViewPoint(viewpoint); 611 Vector3 direction = GetDirection(viewpoint, NULL); 612 rays.push_back(SimpleRay(viewpoint, direction)); 613 } 614 } else { 615 num = GenerateImportanceRays(vssTree, num, rays); 616 } 617 618 CastRays(rays, vssRays, true); 619 vssTree->AddRays(vssRays); 620 621 if (0) { 622 int subdivided = vssTree->UpdateSubdivision(); 623 cout<<"subdivided leafs = "<<subdivided<<endl; 624 } 625 626 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 627 cout<<"Average PVS size = "<<avgPvs<<endl; 628 629 /// compute view cell contribution of rays 630 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 631 632 if (numExportRays) { 633 char filename[64]; 634 if (mUseImportanceSampling) 635 sprintf(filename, "vss-rays-i%04d.x3d", pass); 636 else 637 sprintf(filename, "vss-rays-%04d.x3d", pass); 638 639 ExportRays(filename, vssRays, numExportRays); 640 } 641 642 samples+=num; 643 float pvs = vssTree->GetAvgPvsSize(); 644 cout<<"*****************************\n"; 645 cout<<samples<<" avgPVS ="<<pvs<<endl; 646 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 647 cout<<"*****************************\n"; 648 // if (samples >= mVssSamples) break; 649 pass ++; 650 } 651 652 if (mTestBeamSampling && mUseGlRenderer) 653 { 654 TestBeamCasting(vssTree, mViewCellsManager, mObjects); 655 } 656 657 if (0) Debug << vssTree->stat << endl; 658 659 if (0) 660 { 661 VssRayContainer viewCellRays; 662 // compute rays used for view cells construction 663 const int numRays = mViewCellsManager->GetVisualizationSamples(); 664 vssTree->CollectRays(viewCellRays, numRays); 665 } 666 667 668 //////////////////// 669 //-- render simulation after construction 670 671 mRenderSimulator->RenderScene(); 672 SimulationStatistics ss; 673 mRenderSimulator->GetStatistics(ss); 674 Debug << "\nFinal view cells partition render time\n" << ss << endl; 675 cout << "\nFinal view cells partition render time\n" << ss << endl; 676 677 delete vssTree; 678 679 return true; 680 } 681 682 } 570 CastRays(rays, vssRays, true); 571 vssTree->AddRays(vssRays); 572 573 if (0) { 574 int subdivided = vssTree->UpdateSubdivision(); 575 cout<<"subdivided leafs = "<<subdivided<<endl; 576 } 577 578 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 579 cout<<"Average PVS size = "<<avgPvs<<endl; 580 581 /// compute view cell contribution of rays 582 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 583 584 if (numExportRays) { 585 char filename[64]; 586 if (mUseImportanceSampling) 587 sprintf(filename, "vss-rays-i%04d.x3d", pass); 588 else 589 sprintf(filename, "vss-rays-%04d.x3d", pass); 590 591 ExportRays(filename, vssRays, numExportRays); 592 } 593 594 samples+=num; 595 float pvs = vssTree->GetAvgPvsSize(); 596 cout<<"*****************************\n"; 597 cout<<samples<<" avgPVS ="<<pvs<<endl; 598 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 599 cout<<"*****************************\n"; 600 // if (samples >= mVssSamples) break; 601 pass ++; 602 } 603 604 if (mTestBeamSampling && mUseGlRenderer) 605 { 606 TestBeamCasting(vssTree, mViewCellsManager, mObjects); 607 } 608 609 if (0) Debug << vssTree->stat << endl; 610 611 if (0) 612 { 613 VssRayContainer viewCellRays; 614 // compute rays used for view cells construction 615 const int numRays = mViewCellsManager->GetVisualizationSamples(); 616 vssTree->CollectRays(viewCellRays, numRays); 617 } 618 619 620 //////////////////// 621 //-- render simulation after construction 622 623 mRenderSimulator->RenderScene(); 624 SimulationStatistics ss; 625 mRenderSimulator->GetStatistics(ss); 626 Debug << "\nFinal view cells partition render time\n" << ss << endl; 627 cout << "\nFinal view cells partition render time\n" << ss << endl; 628 629 delete vssTree; 630 631 return true; 632 } 633 634 }
Note: See TracChangeset
for help on using the changeset viewer.