Changeset 563
- Timestamp:
- 01/21/06 18:32:30 (18 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r547 r563 1434 1434 "false"); 1435 1435 1436 RegisterOption("Preprocessor.pvsRenderErrorSamples", 1437 optInt, 1438 "pvsRenderErrorSamples=", 1439 "10000"); 1440 1436 1441 RegisterOption("Preprocessor.useGlDebugger", 1437 1442 optBool, … … 1675 1680 RegisterOption("RssPreprocessor.Export.numRays", optInt, "rss_export_num_rays=", "5000"); 1676 1681 RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells", "false"); 1677 RegisterOption("RssPreprocessor.updateSubdivision", optBool, "rss_update_subdivision", "false"); 1682 RegisterOption("RssPreprocessor.updateSubdivision", 1683 optBool, 1684 "rss_update_subdivision", 1685 "false"); 1678 1686 1679 1687 -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
r561 r563 7 7 #include "Beam.h" 8 8 #include "KdTree.h" 9 #include "Environment.h" 9 10 10 11 #include <GL/glext.h> … … 191 192 192 193 void 193 GlRenderer ::RandomViewPoint()194 GlRendererBuffer::RandomViewPoint() 194 195 { 195 196 Vector3 pVector = Vector3(halton.GetNumber(1), … … 201 202 0.0f); 202 203 203 mViewPoint = mSceneGraph->GetBox().GetPoint(pVector); 204 // viewcells->GetViewPoint(mViewPoint); 205 206 mViewPoint = mSceneGraph->GetBox().GetPoint(pVector); 204 207 205 208 mViewDirection = Normalize(Vector3(sin(dVector.x), … … 211 214 } 212 215 216 217 GlRendererBuffer::GlRendererBuffer(const int w, 218 const int h, 219 SceneGraph *sceneGraph, 220 ViewCellsManager *viewcells, 221 KdTree *tree): 222 QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells, tree) { 223 224 environment->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 225 mPvsErrorBuffer.resize(mPvsStatFrames); 226 ClearErrorBuffer(); 227 228 InitGL(); 229 230 } 213 231 214 232 float … … 947 965 makeCurrent(); 948 966 GlRenderer::InitGL(); 949 #if 0967 #if 1 950 968 // initialise dual depth buffer textures 951 969 glGenTextures(1, &frontDepthMap); -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h
r556 r563 90 90 void SetupMaterial(Material *m); 91 91 virtual void SetupCamera(); 92 void RandomViewPoint();93 92 94 93 bool … … 119 118 SceneGraph *sceneGraph, 120 119 ViewCellsManager *viewcells, 121 KdTree *tree): 122 QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells, tree) { 123 124 mPvsStatFrames = 5000; 125 mPvsErrorBuffer.resize(mPvsStatFrames); 126 ClearErrorBuffer(); 127 128 // makeCurrent(); 129 // InitGL(); 130 // doneCurrent(); 131 132 } 120 KdTree *tree); 121 133 122 134 123 void … … 143 132 144 133 134 void RandomViewPoint(); 145 135 void SampleBeamContributions( 146 136 Intersectable *sourceObject, -
trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
r556 r563 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.0) on: ?t 19. I 1 1:57:31 20063 # Generated by qmake (2.00a) (Qt 4.1.0) on: ?t 19. I 16:46:41 2006 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 7 7 ############################################################################# 8 8 9 first: debug10 install: debug-install11 uninstall: debug-uninstall9 first: release 10 install: release-install 11 uninstall: release-uninstall 12 12 MAKEFILE = Makefile 13 13 QMAKE = qmake … … 27 27 MKDIR = mkdir 28 28 SUBTARGETS = \ 29 debug\30 release29 release \ 30 debug 31 31 32 release: $(MAKEFILE).Release FORCE 33 $(MAKE) -f $(MAKEFILE).Release 34 release-make_default: $(MAKEFILE).Release FORCE 35 $(MAKE) -f $(MAKEFILE).Release 36 release-make_first: $(MAKEFILE).Release FORCE 37 $(MAKE) -f $(MAKEFILE).Release first 38 release-all: $(MAKEFILE).Release FORCE 39 $(MAKE) -f $(MAKEFILE).Release all 40 release-clean: $(MAKEFILE).Release FORCE 41 $(MAKE) -f $(MAKEFILE).Release clean 42 release-distclean: $(MAKEFILE).Release FORCE 43 $(MAKE) -f $(MAKEFILE).Release distclean 44 release-install: $(MAKEFILE).Release FORCE 45 $(MAKE) -f $(MAKEFILE).Release install 46 release-uninstall: $(MAKEFILE).Release FORCE 47 $(MAKE) -f $(MAKEFILE).Release uninstall 32 48 debug: $(MAKEFILE).Debug FORCE 33 49 $(MAKE) -f $(MAKEFILE).Debug … … 46 62 debug-uninstall: $(MAKEFILE).Debug FORCE 47 63 $(MAKE) -f $(MAKEFILE).Debug uninstall 48 release: $(MAKEFILE).Release FORCE49 $(MAKE) -f $(MAKEFILE).Release50 release-make_default: $(MAKEFILE).Release FORCE51 $(MAKE) -f $(MAKEFILE).Release52 release-make_first: $(MAKEFILE).Release FORCE53 $(MAKE) -f $(MAKEFILE).Release first54 release-all: $(MAKEFILE).Release FORCE55 $(MAKE) -f $(MAKEFILE).Release all56 release-clean: $(MAKEFILE).Release FORCE57 $(MAKE) -f $(MAKEFILE).Release clean58 release-distclean: $(MAKEFILE).Release FORCE59 $(MAKE) -f $(MAKEFILE).Release distclean60 release-install: $(MAKEFILE).Release FORCE61 $(MAKE) -f $(MAKEFILE).Release install62 release-uninstall: $(MAKEFILE).Release FORCE63 $(MAKE) -f $(MAKEFILE).Release uninstall64 64 65 65 Makefile: preprocessor.pro D:/Qt/4.1.0/mkspecs/win32-msvc.net\qmake.conf D:/Qt/4.1.0/mkspecs/qconfig.pri \ … … 68 68 D:\Qt\4.1.0\mkspecs\features\default_pre.prf \ 69 69 D:\Qt\4.1.0\mkspecs\features\win32\default_pre.prf \ 70 D:\Qt\4.1.0\mkspecs\features\ debug.prf \70 D:\Qt\4.1.0\mkspecs\features\release.prf \ 71 71 D:\Qt\4.1.0\mkspecs\features\debug_and_release.prf \ 72 72 D:\Qt\4.1.0\mkspecs\features\default_post.prf \ … … 89 89 D:\Qt\4.1.0\mkspecs\features\default_pre.prf: 90 90 D:\Qt\4.1.0\mkspecs\features\win32\default_pre.prf: 91 D:\Qt\4.1.0\mkspecs\features\ debug.prf:91 D:\Qt\4.1.0\mkspecs\features\release.prf: 92 92 D:\Qt\4.1.0\mkspecs\features\debug_and_release.prf: 93 93 D:\Qt\4.1.0\mkspecs\features\default_post.prf: … … 109 109 qmake_all: FORCE 110 110 111 make_default: debug-make_default release-make_default FORCE112 make_first: debug-make_first release-make_first FORCE113 all: debug-all release-all FORCE114 clean: debug-clean release-clean FORCE111 make_default: release-make_default debug-make_default FORCE 112 make_first: release-make_first debug-make_first FORCE 113 all: release-all debug-all FORCE 114 clean: release-clean debug-clean FORCE 115 115 -$(DEL_FILE) preprocessor.exp 116 -$(DEL_FILE) preprocessor.pdb 117 -$(DEL_FILE) preprocessor.ilk 118 -$(DEL_FILE) vc*.pdb 119 -$(DEL_FILE) vc*.idb 120 distclean: debug-distclean release-distclean FORCE 116 distclean: release-distclean debug-distclean FORCE 121 117 -$(DEL_FILE) Makefile 122 118 119 release-mocclean: $(MAKEFILE).Release 120 $(MAKE) -f $(MAKEFILE).Release mocclean 123 121 debug-mocclean: $(MAKEFILE).Debug 124 122 $(MAKE) -f $(MAKEFILE).Debug mocclean 125 release-mocclean: $(MAKEFILE).Release 126 $(MAKE) -f $(MAKEFILE).Release mocclean 127 mocclean: debug-mocclean release-mocclean 123 mocclean: release-mocclean debug-mocclean 128 124 125 release-mocables: $(MAKEFILE).Release 126 $(MAKE) -f $(MAKEFILE).Release mocables 129 127 debug-mocables: $(MAKEFILE).Debug 130 128 $(MAKE) -f $(MAKEFILE).Debug mocables 131 release-mocables: $(MAKEFILE).Release 132 $(MAKE) -f $(MAKEFILE).Release mocables 133 mocables: debug-mocables release-mocables 129 mocables: release-mocables debug-mocables 134 130 FORCE: 135 131 132 $(MAKEFILE).Release: Makefile 136 133 $(MAKEFILE).Debug: Makefile 137 $(MAKEFILE).Release: Makefile -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r556 r563 33 33 Preprocessor::~Preprocessor() 34 34 { 35 cerr<<"Deleting view cells manager...\n";35 Debug<<"Deleting view cells manager...\n"; 36 36 DEL_PTR(mViewCellsManager); 37 cerr<<"done.\n";38 cerr<<"Deleting bsp tree...\n";37 Debug<<"done.\n"; 38 Debug<<"Deleting bsp tree...\n"; 39 39 DEL_PTR(mBspTree); 40 cerr<<"done.\n";41 cerr<<"Deleting kd tree...\n";40 Debug<<"done.\n"; 41 Debug<<"Deleting kd tree...\n"; 42 42 DEL_PTR(mKdTree); 43 cerr<<"done.\n";44 cerr<<"Deleting vspkd tree...\n";43 Debug<<"done.\n"; 44 Debug<<"Deleting vspkd tree...\n"; 45 45 DEL_PTR(mVspKdTree); 46 cerr<<"done.\n";47 cerr<<"Deleting vspbsp tree...\n";46 Debug<<"done.\n"; 47 Debug<<"Deleting vspbsp tree...\n"; 48 48 DEL_PTR(mVspBspTree); 49 cerr<<"done.\n";49 Debug<<"done.\n"; 50 50 } 51 51 … … 429 429 return true; 430 430 } 431 432 433 434 bool 435 Preprocessor::GenerateRays( 436 const int number, 437 const int sampleType, 438 SimpleRayContainer &rays 439 ) 440 { 441 Vector3 origin, direction; 442 443 for (int i=0; rays.size() < number; i++) { 444 mViewCellsManager->GetViewPoint(origin); 445 446 447 // now get the direction 448 switch (sampleType) { 449 case OBJECT_BASED_DISTRIBUTION: { 450 Vector3 point; 451 Vector3 normal; 452 int i = RandomValue(0, mObjects.size() - 1); 453 Intersectable *object = mObjects[i]; 454 object->GetRandomSurfacePoint(point, normal); 455 direction = point - origin; 456 } 457 break; 458 case DIRECTION_BASED_DISTRIBUTION: 459 direction = UniformRandomVector(); 460 break; 461 case DIRECTION_BOX_BASED_DISTRIBUTION: { 462 float alpha = RandomValue(0.0f, 2*M_PI); 463 float beta = RandomValue(-M_PI/2, M_PI/2); 464 direction = VssRay::GetDirection(alpha, beta); 465 break; 466 } 467 case SPATIAL_BOX_BASED_DISTRIBUTION: 468 direction = mKdTree->GetBox().GetRandomPoint() - origin; 469 break; 470 default: 471 // unsuported distribution type 472 return false; 473 } 474 // $$ jb the pdf is yet not correct for all sampling methods! 475 float pdf = 1.0f; 476 float c = Magnitude(direction); 477 if (c > Limits::Small) { 478 direction*=1.0f/c; 479 rays.AddRay(SimpleRay(origin, direction, pdf)); 480 } 481 } 482 return true; 483 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r538 r563 98 98 bool ExportSamples(const VssRayContainer &samples) const; 99 99 100 /** Get Sample rays of particular type, returns false if this 101 type of rays is not supported by the preprocessor 102 */ 103 enum { 104 OBJECT_BASED_DISTRIBUTION, 105 DIRECTION_BASED_DISTRIBUTION, 106 DIRECTION_BOX_BASED_DISTRIBUTION, 107 SPATIAL_BOX_BASED_DISTRIBUTION, 108 RSS_BASED_DISTRIBUTION, 109 RSS_SILHOUETTE_BASED_DISTRIBUTION, 110 VSS_BASED_DISTRIBUTION 111 }; 112 113 virtual bool 114 GenerateRays( 115 const int number, 116 const int raysType, 117 SimpleRayContainer &rays 118 ); 119 100 120 /// scene graph loaded from file 101 121 SceneGraph *mSceneGraph; -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r556 r563 325 325 (*it).mPdf*=c; 326 326 } 327 327 328 void AddRay(const SimpleRay &ray) { 329 push_back(ray); 330 mSumPdf += ray.mPdf; 331 } 328 332 }; 329 333 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
r556 r563 42 42 environment->GetBoolValue("RssPreprocessor.loadInitialSamples", mLoadInitialSamples); 43 43 environment->GetBoolValue("RssPreprocessor.storeInitialSamples", mStoreInitialSamples); 44 environment->GetBoolValue("RssPreprocessor.updateSubdivision", mUpdateSubdivision); 44 45 45 46 mStats.open("stats.log"); 46 47 } 47 mRssTree = NULL; 48 } 49 50 51 bool 52 RssPreprocessor::GenerateRays( 53 const int number, 54 const int sampleType, 55 SimpleRayContainer &rays 56 ) 57 { 58 bool result = false; 59 60 switch (sampleType) { 61 case RSS_BASED_DISTRIBUTION: 62 case RSS_SILHOUETTE_BASED_DISTRIBUTION: 63 if (mRssTree) { 64 GenerateImportanceRays(mRssTree, number, rays); 65 result = true; 66 rays.NormalizePdf(); 67 } 68 break; 69 default: 70 result = Preprocessor::GenerateRays(number, sampleType, rays); 71 } 72 73 return result; 74 } 75 76 void 77 RssPreprocessor::CastRays( 78 SimpleRayContainer &rays, 79 VssRayContainer &vssRays 80 ) 81 { 82 for (int i=0; i < rays.size(); i++) 83 CastRay(rays[i].mOrigin, rays[i].mDirection, rays[i].mPdf, vssRays); 84 } 85 48 86 49 87 RssPreprocessor::~RssPreprocessor() … … 190 228 } 191 229 192 Vector3193 RssPreprocessor::GetDirection(const Vector3 &viewpoint,194 AxisAlignedBox3 *viewSpaceBox195 )196 {197 Vector3 point;198 if (!use2dSampling) {199 if (mObjectBasedSampling) {200 Vector3 normal;201 int i = RandomValue(0, mObjects.size()-1);202 Intersectable *object = mObjects[i];203 object->GetRandomSurfacePoint(point, normal);204 } else {205 // select206 if (mDirectionalSampling) {207 point = viewpoint + UniformRandomVector();208 } else {209 // select the other point uniformly distruted in the whole viewspace210 AxisAlignedBox3 box;211 212 if (viewSpaceBox)213 box =*viewSpaceBox;214 else215 box = mKdTree->GetBox();216 217 point = box.GetRandomPoint();218 }219 }220 } else {221 AxisAlignedBox3 box;222 223 if (viewSpaceBox)224 box =*viewSpaceBox;225 else226 box = mKdTree->GetBox();227 228 point = box.GetRandomPoint();229 point.y = viewpoint.y;230 }231 232 return point - viewpoint;233 }234 235 Vector3236 RssPreprocessor::InitialGetDirection(const Vector3 &viewpoint,237 AxisAlignedBox3 *viewSpaceBox238 )239 {240 Vector3 point;241 if (!use2dSampling) {242 if (1 || mObjectBasedSampling) {243 Vector3 normal;244 int i = RandomValue(0, mObjects.size()-1);245 Intersectable *object = mObjects[i];246 object->GetRandomSurfacePoint(point, normal);247 } else {248 // select249 if (1 || mDirectionalSampling) {250 point = viewpoint + UniformRandomVector();251 } else {252 // select the other point uniformly distruted in the whole viewspace253 AxisAlignedBox3 box;254 255 if (viewSpaceBox)256 box =*viewSpaceBox;257 else258 box = mKdTree->GetBox();259 260 point = box.GetRandomPoint();261 }262 }263 } else {264 AxisAlignedBox3 box;265 266 if (viewSpaceBox)267 box =*viewSpaceBox;268 else269 box = mKdTree->GetBox();270 271 point = box.GetRandomPoint();272 point.y = viewpoint.y;273 }274 275 return point - viewpoint;276 }277 230 278 231 int … … 302 255 } 303 256 304 cout<<"Generated "<<num<<" rays."<<endl;305 257 306 258 return num; … … 322 274 exporter->SetFilled(); 323 275 // $$JB temporarily do not export the scene 324 if ( 1)276 if (0) 325 277 exporter->ExportScene(mSceneGraph->mRoot); 326 278 exporter->SetWireframe(); … … 474 426 } 475 427 428 429 476 430 bool 477 431 RssPreprocessor::ComputeVisibility() 478 432 { 479 433 480 if (renderer)481 renderer->InitGL();482 483 434 // connect(this, SIGNAL(EvalPvsStat()), renderer, SLOT(EvalPvsStat()) ); 484 435 … … 493 444 int totalSamples = 0; 494 445 495 AxisAlignedBox3 *box = new AxisAlignedBox3(mKdTree->GetBox()); 496 497 if (fromBoxVisibility) { 498 float m = box->Min(1); 499 float bsize = box->Size(1); 500 501 float size = 0.02f; 502 float s = 0.5f - size; 503 float olds = Magnitude(box->Size()); 504 box->Enlarge(box->Size()*Vector3(-s)); 505 // Vector3 translation = Vector3(-olds*0.2f, 0, 0); 506 Vector3 translation = Vector3(-0.05f*olds, 0, 0); 507 box->SetMin(box->Min() + translation); 508 box->SetMax(box->Max() + translation); 509 510 box->SetMin(1, m + bsize*0.1f); 511 box->SetMax(1, m + bsize*0.6f); 512 513 514 } else { 515 516 // sample city like heights 517 float m = box->Min(1); 518 float bsize = box->Size(1); 519 box->SetMin(1, m + bsize*0.2f); 520 box->SetMax(1, m + bsize*0.3f); 521 } 522 523 if (use2dSampling) 524 box->SetMax(1, box->Min(1)); 525 526 if (useViewSpaceBox) 527 { 528 mViewSpaceBox = box; 529 mViewCellsManager->SetViewSpaceBox(*box); 530 } 531 else 532 { 533 mViewSpaceBox = NULL; 534 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 535 } 446 mViewSpaceBox = NULL; 447 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 448 536 449 537 450 //-- load view cells from file if requested 538 if (mLoadViewCells) 539 { 540 // load now because otherwise bounding box not correct 541 mViewCellsManager->LoadViewCells(mViewCellsFilename, &mObjects); 542 } 543 544 RssTree *rssTree = NULL; 451 if (mLoadViewCells) { 452 // load now because otherwise bounding box not correct 453 mViewCellsManager->LoadViewCells(mViewCellsFilename, &mObjects); 454 } 455 545 456 int rssPass = 0; 546 457 int rssSamples = 0; 547 548 #if 0 458 549 459 if (mLoadInitialSamples) { 550 460 cout << "Loading samples from file ... "; … … 552 462 cout << "finished\n" << endl; 553 463 } else { 554 #endif555 while (totalSamples < mInitialSamples) {556 int passContributingSamples = 0;557 int passSampleContributions = 0;558 int passSamples = 0;559 int index = 0;560 561 int sampleContributions;562 563 //int s = Min(mSamplesPerPass, mInitialSamples);564 int s = mInitialSamples;565 566 float probability = 1.0f/mInitialSamples;567 for (int k=0; k < s; k++) {568 569 570 //Vector3 viewpoint = GetViewpoint(mViewSpaceBox);571 Vector3 viewpoint;572 mViewCellsManager->GetViewPoint(viewpoint);573 // viewpoint = GetViewpoint(mViewSpaceBox);574 Vector3 direction = InitialGetDirection(viewpoint, mViewSpaceBox);575 576 sampleContributions = CastRay(viewpoint, direction, probability, mVssRays);577 578 579 //-- CORR matt: put block inside loop580 if (sampleContributions) {581 passContributingSamples ++;582 passSampleContributions += sampleContributions;583 }584 passSamples++;585 totalSamples++;586 }587 588 589 float avgRayContrib = (passContributingSamples > 0) ?590 passSampleContributions/(float)passContributingSamples : 0;591 592 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;593 cout << "#TotalSamples=" << totalSamples/1000594 << "k #SampleContributions=" << passSampleContributions << " ("595 << 100*passContributingSamples/(float)passSamples<<"%)"596 << "avgcontrib=" << avgRayContrib << endl;597 598 mPass++;599 }600 601 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl;602 cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl <<flush;603 604 rssSamples += (int)mVssRays.size();605 606 607 if (mExportRays) {608 char filename[64];609 sprintf(filename, "rss-rays-initial.x3d");610 ExportRays(filename, mVssRays, mExportNumRays);611 }612 613 if (mStoreInitialSamples)614 {615 cout << "Writing samples to file ... ";616 ExportSamples(mVssRays);617 cout << "finished\n" << endl;618 }619 620 if (mUseViewcells) {621 // construct view cells622 if (!mLoadViewCells)623 mViewCellsManager->Construct(mObjects, mVssRays);624 // evaluate contributions of the intitial rays625 mViewCellsManager->ComputeSampleContributions(mVssRays);626 627 628 mStats <<629 "#Pass\n" <<mPass<<endl<<630 "#RssPass\n" <<rssPass<<endl<<631 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<<632 "#TotalSamples\n" <<totalSamples<<endl<<633 "#RssSamples\n" <<rssSamples<<endl;634 635 636 mVssRays.PrintStatistics(mStats);637 mViewCellsManager->PrintPvsStatistics(mStats);638 639 VssRayContainer selectedRays;640 int desired = Max(641 mViewCellsManager->GetPostProcessSamples(),642 mViewCellsManager->GetVisualizationSamples());643 644 mVssRays.SelectRays(desired, selectedRays);645 646 //-- post process view cells647 mViewCellsManager->PostProcess(mObjects, selectedRays);648 649 //-- several visualizations and statistics650 Debug << "view cells after post processing: " << endl;651 mViewCellsManager->PrintStatistics(Debug);652 653 if (1)654 mViewCellsManager->Visualize(mObjects, selectedRays);655 656 ComputeRenderError();657 658 }659 660 661 662 rssPass++;663 664 rssTree = new RssTree;665 rssTree->SetPass(mPass);666 667 /// compute view cell contribution of rays if view cells manager already constructed668 mViewCellsManager->ComputeSampleContributions(mVssRays);669 670 if (mUseImportanceSampling) {671 672 // if (fromBoxVisibility)673 // rssTree->Construct(mObjects, mVssRays, mViewSpaceBox);674 // else675 rssTree->Construct(mObjects, mVssRays);676 677 rssTree->stat.Print(mStats);678 cout<<"RssTree root PVS size = "<<rssTree->GetRootPvsSize()<<endl;679 680 if (mExportRssTree) {681 ExportRssTree("rss-tree-100.x3d", rssTree, Vector3(1,0,0));682 ExportRssTree("rss-tree-001.x3d", rssTree, Vector3(0,0,1));683 ExportRssTree("rss-tree-101.x3d", rssTree, Vector3(1,0,1));684 ExportRssTree("rss-tree-101m.x3d", rssTree, Vector3(-1,0,-1));685 ExportRssTreeLeaves(rssTree, 10);686 }687 688 if (mExportPvs) {689 ExportPvs("rss-pvs-initial.x3d", rssTree);690 }691 }692 693 // viewcells->UpdatePVS(newVssRays);694 695 696 while (1) {697 int num = mRssSamplesPerPass;698 464 SimpleRayContainer rays; 699 VssRayContainer vssRays; 700 701 702 if (!mUseImportanceSampling) { 703 for (int j=0; j < num; j++) { 704 //changed by matt 705 //Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 706 Vector3 viewpoint; 707 mViewCellsManager->GetViewPoint(viewpoint); 708 Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 709 rays.push_back(SimpleRay(viewpoint, direction, 1.0f)); 710 rays.mSumPdf += 1.0f; 711 } 712 } else { 713 num = GenerateImportanceRays(rssTree, num, rays); 714 } 715 716 rays.NormalizePdf(); 717 718 for (int i=0; i < rays.size(); i++) 719 CastRay(rays[i].mOrigin, rays[i].mDirection, rays[i].mPdf, vssRays); 720 721 722 totalSamples += (int)rays.size(); 723 rssSamples += (int)vssRays.size(); 724 465 466 GenerateRays(mInitialSamples, SPATIAL_BOX_BASED_DISTRIBUTION, rays); 467 468 CastRays(rays, mVssRays); 469 } 470 471 cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl <<flush; 472 473 rssSamples += (int)mVssRays.size(); 474 totalSamples += mInitialSamples; 475 mPass++; 476 477 if (mExportRays) { 478 char filename[64]; 479 sprintf(filename, "rss-rays-initial.x3d"); 480 ExportRays(filename, mVssRays, mExportNumRays); 481 } 482 483 if (mStoreInitialSamples) { 484 cout << "Writing samples to file ... "; 485 ExportSamples(mVssRays); 486 cout << "finished\n" << endl; 487 } 488 489 if (mUseViewcells) { 490 // construct view cells 491 if (!mLoadViewCells) 492 mViewCellsManager->Construct(mObjects, mVssRays); 493 494 495 496 // evaluate contributions of the intitial rays 497 mViewCellsManager->ComputeSampleContributions(mVssRays); 725 498 726 499 … … 731 504 "#TotalSamples\n" <<totalSamples<<endl<< 732 505 "#RssSamples\n" <<rssSamples<<endl; 506 507 508 mVssRays.PrintStatistics(mStats); 509 mViewCellsManager->PrintPvsStatistics(mStats); 510 511 VssRayContainer selectedRays; 512 int desired = Max( 513 mViewCellsManager->GetPostProcessSamples(), 514 mViewCellsManager->GetVisualizationSamples()); 515 516 mVssRays.SelectRays(desired, selectedRays); 517 518 //-- post process view cells 519 mViewCellsManager->PostProcess(mObjects, selectedRays); 520 521 //-- several visualizations and statistics 522 Debug << "view cells after post processing: " << endl; 523 mViewCellsManager->PrintStatistics(Debug); 524 525 if (1) 526 mViewCellsManager->Visualize(mObjects, selectedRays); 527 528 ComputeRenderError(); 529 } 530 531 rssPass++; 532 533 mRssTree = new RssTree; 534 mRssTree->SetPass(mPass); 535 536 /// compute view cell contribution of rays if view cells manager already constructed 537 mViewCellsManager->ComputeSampleContributions(mVssRays); 538 539 if (mUseImportanceSampling) { 540 541 mRssTree->Construct(mObjects, mVssRays); 542 543 mRssTree->stat.Print(mStats); 544 cout<<"RssTree root PVS size = "<<mRssTree->GetRootPvsSize()<<endl; 545 546 if (mExportRssTree) { 547 ExportRssTree("rss-tree-100.x3d", mRssTree, Vector3(1,0,0)); 548 ExportRssTree("rss-tree-001.x3d", mRssTree, Vector3(0,0,1)); 549 ExportRssTree("rss-tree-101.x3d", mRssTree, Vector3(1,0,1)); 550 ExportRssTree("rss-tree-101m.x3d", mRssTree, Vector3(-1,0,-1)); 551 ExportRssTreeLeaves(mRssTree, 10); 552 } 553 554 if (mExportPvs) { 555 ExportPvs("rss-pvs-initial.x3d", mRssTree); 556 } 557 } 558 559 // viewcells->UpdatePVS(newVssRays); 560 561 562 while (1) { 563 SimpleRayContainer rays; 564 VssRayContainer vssRays; 565 int castRays = 0; 566 if (mUseImportanceSampling) { 567 VssRayContainer tmpVssRays; 568 569 GenerateRays(mRssSamplesPerPass/2, RSS_BASED_DISTRIBUTION, rays); 570 CastRays(rays, tmpVssRays); 571 castRays += rays.size(); 572 float c1 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false); 573 mStats<<"#RssRelContrib"<<endl<<c1/rays.size()<<endl; 574 575 vssRays.insert(vssRays.end(), tmpVssRays.begin(), tmpVssRays.end() ); 576 rays.clear(); 577 tmpVssRays.clear(); 578 579 GenerateRays(mRssSamplesPerPass/4, SPATIAL_BOX_BASED_DISTRIBUTION, rays); 580 CastRays(rays, tmpVssRays); 581 castRays += rays.size(); 582 float c2 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false); 583 mStats<<"#SpatialRelContrib"<<endl<<c2/rays.size()<<endl; 584 585 vssRays.insert(vssRays.end(), tmpVssRays.begin(), tmpVssRays.end() ); 586 587 rays.clear(); 588 tmpVssRays.clear(); 589 590 591 GenerateRays(mRssSamplesPerPass/4, DIRECTION_BASED_DISTRIBUTION, rays); 592 CastRays(rays, tmpVssRays); 593 castRays += rays.size(); 594 float c3 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false); 595 mStats<<"#DirectionalRelContrib"<<endl<<c3/rays.size()<<endl; 596 597 vssRays.insert(vssRays.end(), tmpVssRays.begin(), tmpVssRays.end() ); 598 599 rays.clear(); 600 tmpVssRays.clear(); 601 602 // add contributions of all rays at once... 603 mViewCellsManager->AddSampleContributions(vssRays); 604 605 } 606 else { 607 int rayType = SPATIAL_BOX_BASED_DISTRIBUTION; 608 if (mObjectBasedSampling) 609 rayType = OBJECT_BASED_DISTRIBUTION; 610 else 611 if (mDirectionalSampling) 612 rayType = DIRECTION_BASED_DISTRIBUTION; 613 614 GenerateRays(mRssSamplesPerPass, rayType, rays); 615 CastRays(rays, vssRays); 616 castRays += rays.size(); 617 if (mUseViewcells) { 618 /// compute view cell contribution of rays 619 mViewCellsManager->ComputeSampleContributions(vssRays); 620 } 621 622 623 } 624 totalSamples += castRays; 625 rssSamples += (int)vssRays.size(); 626 627 cout<<"Generated "<<castRays<<" rays, progress "<<totalSamples/((float) mRssSamples + 628 mInitialSamples)<<"%\n"; 629 630 631 mStats << 632 "#Pass\n" <<mPass<<endl<< 633 "#RssPass\n" <<rssPass<<endl<< 634 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<< 635 "#TotalSamples\n" <<totalSamples<<endl<< 636 "#RssSamples\n" <<rssSamples<<endl; 733 637 734 638 735 639 if (mUseViewcells) { 736 737 /// compute view cell contribution of rays738 mViewCellsManager->ComputeSampleContributions(vssRays);739 740 640 vssRays.PrintStatistics(mStats); 741 641 mViewCellsManager->PrintPvsStatistics(mStats); … … 770 670 771 671 if (mUseImportanceSampling) { 772 rssTree->AddRays(vssRays); 773 774 if (0) { 775 cout<<"############# Rss PVS STAT ##################\n"; 776 cout<<"#AVG_RSS_PVS\n"<<rssTree->GetAvgPvsSize()<<endl; 777 cout<<"#RSS_ROOT_PVS\n"<<rssTree->GetRootPvsSize()<<endl; 778 } 779 672 mRssTree->AddRays(vssRays); 780 673 781 674 if (mUpdateSubdivision) { 782 675 int updatePasses = 1; 783 676 if (mPass % updatePasses == 0) { 784 int subdivided = rssTree->UpdateSubdivision();677 int subdivided = mRssTree->UpdateSubdivision(); 785 678 cout<<"subdivided leafs = "<<subdivided<<endl; 786 cout<<"#total leaves = "<< rssTree->stat.Leaves()<<endl;679 cout<<"#total leaves = "<<mRssTree->stat.Leaves()<<endl; 787 680 } 788 681 } 789 682 } 790 791 792 683 793 684 if (mExportPvs) { 794 685 char filename[64]; 795 686 sprintf(filename, "rss-pvs-%04d.x3d", rssPass); 796 ExportPvs(filename, rssTree);797 } 798 687 ExportPvs(filename, mRssTree); 688 } 689 799 690 800 691 if (!mUseImportanceSampling) 801 692 CLEAR_CONTAINER(vssRays); 693 // otherwise the rays get deleted by the rss tree update according to RssTree.maxRays .... 802 694 803 695 if (totalSamples >= mRssSamples + mInitialSamples) … … 807 699 rssPass++; 808 700 mPass++; 809 rssTree->SetPass(mPass);701 mRssTree->SetPass(mPass); 810 702 } 811 703 … … 825 717 826 718 } 827 828 cerr<<"Deleting RSS tree...\n";829 delete rssTree;830 cerr<<"Done.\n";719 720 Debug<<"Deleting RSS tree...\n"; 721 delete mRssTree; 722 Debug<<"Done.\n"; 831 723 832 724 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h
r537 r563 38 38 39 39 ofstream mStats; 40 40 RssTree *mRssTree; 41 41 42 42 // rays cast during the processing … … 56 56 GetViewpoint(AxisAlignedBox3 *viewSpaceBox); 57 57 58 Vector359 GetDirection(const Vector3 &viewpoint,60 AxisAlignedBox3 *viewSpaceBox61 );62 63 Vector364 InitialGetDirection(const Vector3 &viewpoint,65 AxisAlignedBox3 *viewSpaceBox66 );67 58 68 59 void … … 86 77 87 78 virtual bool BuildBspTree() { return false; } 88 79 80 void 81 CastRays( 82 SimpleRayContainer &rays, 83 VssRayContainer &vssRays 84 ); 89 85 90 86 bool … … 132 128 ComputeRenderError(); 133 129 130 /** Redefininition of the get sample rays method from the preprocessor */ 131 bool 132 GenerateRays( 133 const int number, 134 const int sampleType, 135 SimpleRayContainer &rays 136 ); 137 134 138 }; 135 139 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp
r556 r563 2097 2097 2098 2098 float extendedConvexCombinationProb = 0.0f; //0.7f 2099 float silhouetteCheckPercentage = 0. 5f; //0.5f2099 float silhouetteCheckPercentage = 0.0f; //0.5f 2100 2100 for (int i=0; generated < numberOfRays && i < numberOfTries; i++) { 2101 2101 bool useExtendedConvexCombination = ((nrays >= 2) && (Random(1.0f) < … … 2204 2204 // cout<<"desired="<<numberOfRays<<" tries="<<i<<endl; 2205 2205 // assign pdfs to the generated rays 2206 float p = (box.GetVolume()*dirBox.GetVolume())/i; 2206 float p = 1.0f; //(box.GetVolume()*dirBox.GetVolume())/i; 2207 rays.mSumPdf = 0.0f; 2207 2208 for (i=startIndex; i < rays.size(); i++) { 2208 2209 rays[i].mPdf = p; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r492 r563 67 67 } 68 68 69 mViewCellsManager->ComputeSampleContributions(vssRays );69 mViewCellsManager->ComputeSampleContributions(vssRays, true); 70 70 CLEAR_CONTAINER(vssRays); 71 71 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r562 r563 171 171 172 172 173 void ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays) 174 { 175 // view cells not yet constructed 176 if (!ViewCellsConstructed()) 177 return; 178 179 VssRayContainer::const_iterator it, it_end = rays.end(); 180 181 for (it = rays.begin(); it != it_end; ++ it) 182 { 183 ComputeSampleContributions(*(*it)); 184 } 173 float 174 ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays, 175 const bool addRays 176 ) 177 { 178 // view cells not yet constructed 179 if (!ViewCellsConstructed()) 180 return 0.0f; 181 182 VssRayContainer::const_iterator it, it_end = rays.end(); 183 184 float sum = 0.0f; 185 for (it = rays.begin(); it != it_end; ++ it) { 186 sum += ComputeSampleContributions(*(*it), addRays); 187 } 188 return sum; 185 189 } 186 190 … … 440 444 } 441 445 446 void 447 ViewCellsManager::AddSampleContributions(const VssRayContainer &rays) 448 { 449 if (!ViewCellsConstructed()) 450 return; 451 452 VssRayContainer::const_iterator it, it_end = rays.end(); 453 454 for (it = rays.begin(); it != it_end; ++ it) { 455 AddSampleContributions(*(*it)); 456 } 457 } 442 458 443 459 int ViewCellsManager::GetMinPvsSize() const … … 454 470 455 471 456 void ViewCellsManager::ComputeSampleContributions(VssRay &ray)457 { 458 ViewCellContainer viewcells; 459 460 ray.mPvsContribution = 0;461 ray.mRelativePvsContribution = 0.0f;462 463 // matt TODO: remove this!!464 Ray hray(ray);465 //static Ray hray;466 //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 467 468 float tmin = 0, tmax = 1.0; 469 470 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 471 return;472 473 Vector3 origin = hray.Extrap(tmin); 474 Vector3 termination = hray.Extrap(tmax);475 476 CastLineSegment(origin, termination, viewcells);477 //Debug << "constribution: " << (int)viewcells.size() << endl;478 // copy viewcells memory efficiently 479 const bool storeViewcells = false; 480 if (storeViewcells) 481 { 482 ray.mViewCells.reserve(viewcells.size()); 483 ray.mViewCells = viewcells;484 } 485 486 ViewCellContainer::const_iterator it = viewcells.begin(); 487 488 bool addInPlace = false;489 490 if (addInPlace) 491 {492 for (; it != viewcells.end(); ++it) {493 ViewCell *viewcell = *it; 494 495 // if ray not outside of view space 496 float contribution; 497 bool added = 498 viewcell->GetPvs().AddSample(ray.mTerminationObject, 499 ray.mPdf, 500 contribution501 502 if (added)503 ray.mPvsContribution++;504 505 ray.mRelativePvsContribution += contribution;506 } 507 }508 else 509 {510 for (; it != viewcells.end(); ++it) {511 ViewCell *viewcell = *it;512 // if ray not outside of view space513 float contribution;514 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject,515 ray.mPdf,516 contribution517 ))518 ray.mPvsContribution++; 519 ray.mRelativePvsContribution += contribution; 520 } 521 522 for (it = viewcells.begin(); it != viewcells.end(); ++it) {523 ViewCell *viewcell = *it;524 // if ray not outside of view space525 viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf);526 } 527 } 472 void 473 ViewCellsManager::AddSampleContributions(VssRay &ray) 474 { 475 // assumes viewcells have been stored... 476 ViewCellContainer *viewcells = &ray.mViewCells; 477 ViewCellContainer::const_iterator it; 478 for (it = viewcells->begin(); it != viewcells->end(); ++it) { 479 ViewCell *viewcell = *it; 480 // if ray not outside of view space 481 viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf); 482 } 483 } 484 485 float 486 ViewCellsManager::ComputeSampleContributions(VssRay &ray, 487 const bool addRays 488 ) 489 { 490 ViewCellContainer viewcells; 491 492 ray.mPvsContribution = 0; 493 ray.mRelativePvsContribution = 0.0f; 494 495 // matt TODO: remove this!! 496 Ray hray(ray); 497 float tmin = 0, tmax = 1.0; 498 499 //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 500 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 501 return 0.0f; 502 503 Vector3 origin = hray.Extrap(tmin); 504 Vector3 termination = hray.Extrap(tmax); 505 506 CastLineSegment(origin, 507 termination, 508 viewcells); 509 510 //Debug << "constribution: " << (int)viewcells.size() << endl; 511 512 // copy viewcells memory efficiently 513 const bool storeViewcells = !addRays; 514 515 if (storeViewcells) 516 { 517 ray.mViewCells.reserve(viewcells.size()); 518 ray.mViewCells = viewcells; 519 } 520 521 ViewCellContainer::const_iterator it = viewcells.begin(); 522 523 524 for (; it != viewcells.end(); ++it) { 525 ViewCell *viewcell = *it; 526 // if ray not outside of view space 527 float contribution; 528 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 529 ray.mPdf, 530 contribution 531 )) 532 ray.mPvsContribution++; 533 ray.mRelativePvsContribution += contribution; 534 } 535 536 if (addRays) 537 for (it = viewcells.begin(); it != viewcells.end(); ++it) { 538 ViewCell *viewcell = *it; 539 // if ray not outside of view space 540 viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf); 541 } 542 543 return ray.mRelativePvsContribution; 528 544 } 529 545 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r562 r563 68 68 @param rays bundle of rays used to find intersections with view cells and 69 69 adding the contribution 70 @param castRays true if ray should be cast to gain the information, false if rays 71 already hold the view cells intersection information and need not be recast. 72 @param sampleContributions returns the number of sample contributions 73 @param contributingSamples returns the number of contributingSamples 74 */ 75 void ComputeSampleContributions(const VssRayContainer &rays); 76 70 @param addRays true if rays should be added to the PVSs of the viewcells they 71 intersect */ 72 float ComputeSampleContributions(const VssRayContainer &rays, 73 const bool addContributions = true); 74 75 /** Add sample contributions to the viewcells they intersect */ 76 void AddSampleContributions(const VssRayContainer &rays); 77 77 78 78 79 /** Computes sample contribution of a simgle ray to the view cells PVS. … … 83 84 @returns number of sample contributions 84 85 */ 85 virtual void ComputeSampleContributions(VssRay &ray); 86 86 virtual float ComputeSampleContributions(VssRay &ray, const bool addRays = true); 87 88 virtual void AddSampleContributions(VssRay &ray); 89 87 90 /** Prints out statistics of the view cells. 88 91 */ -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r556 r563 25 25 # type vss 26 26 type rss 27 detectEmptyViewSpace true 28 } 27 detectEmptyViewSpace false 28 pvsRenderErrorSamples 10000 29 30 } 31 29 32 30 33 VssPreprocessor { … … 53 56 maxStaticMemory 100 54 57 55 splitType regular58 # splitType regular 56 59 # splitType heuristic 57 #splitType hybrid60 splitType hybrid 58 61 splitUseOnlyDrivingAxis true 59 62 … … 69 72 70 73 RssPreprocessor { 71 samplesPerPass 10000072 initialSamples 100000 73 vssSamples 1 000074 vssSamplesPerPass 100000 74 samplesPerPass 500000 75 initialSamples 1000000 76 vssSamples 15000000 77 vssSamplesPerPass 1000000 75 78 useImportanceSampling true 76 79 … … 87 90 useViewcells true 88 91 updateSubdivision true 89 loadInitialSamples true92 loadInitialSamples false 90 93 storeInitialSamples false 91 94 } … … 102 105 maxCostRatio 1.0 103 106 maxRayContribution 0.5 104 maxRays 1000000107 maxRays 5000000 105 108 maxTotalMemory 200 106 109 maxStaticMemory 100 107 110 108 splitType regular111 # splitType regular 109 112 # splitType heuristic 110 #splitType hybrid111 splitUseOnlyDrivingAxis true113 splitType hybrid 114 splitUseOnlyDrivingAxis false 112 115 importanceBasedCost false 113 116 … … 166 169 } 167 170 171 168 172 ViewCells { 169 173 loadFromFile true 174 exportToFile false 170 175 #type kdTree 171 176 #type vspKdTree 172 # 177 #type bspTree 173 178 type vspBspTree 174 179 … … 176 181 177 182 height 5.0 178 maxViewCells 500179 maxPvs 200180 181 182 PostProcess { 183 minPvsDif 100184 minPvs 10185 maxPvs 150183 maxViewCells 100000 184 #percentage of total visible objects where pvs is considered invalid 185 maxPvsRatio 0.05 186 187 delayedConstruction true 188 189 190 PostProcess { 186 191 # how much samples are used for post processing 187 samples 100000188 } 189 190 192 samples 200000 193 } 194 195 Visualization { 191 196 # how much samples we use for visualization 192 197 samples 5000 … … 196 201 colorCode Random 197 202 exportRays false 198 exportGeometry true199 } 200 201 filename ../data/soda/viewcells_soda5-2.xml202 #filename ../data/atlanta/viewcells_atlanta2.xml203 exportGeometry false 204 } 205 206 # filename ../data/soda/viewcells_soda5-2.xml 207 filename ../data/atlanta/viewcells_atlanta2.xml 203 208 # filename ../data/atlanta/atlanta_viewcells_large.x3d 204 209 # filename ../data/vienna/viewcells-25-sel.x3d 205 210 # filename ../data/vienna/viewcells-25.x3d 206 211 # filename ../data/vienna/viewcells-large-sel.x3d 212 # filename ../scripts/viewcells_vienna.xml 213 214 207 215 } 208 216 … … 252 260 } 253 261 } 262 254 263 255 264 VspBspTree { … … 309 318 } 310 319 311 PostProcess { 312 maxCostRatio 0.1 313 minViewCells 500 314 maxPvsSize 1000 315 useRaysForMerge true 316 } 317 } 320 } -
trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
r556 r563 17 17 18 18 # debuc config 19 CONFIG += console warn_off thread debugqt19 CONFIG += console warn_off thread release qt 20 20 21 21 # RELEASE CONFIG
Note: See TracChangeset
for help on using the changeset viewer.