Changeset 1877
- Timestamp:
- 12/11/06 08:31:01 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h
r1867 r1877 184 184 Vector3 GetRandomPoint() const; 185 185 Vector3 GetRandomSurfacePoint() const; 186 186 Vector3 GetUniformRandomSurfacePoint() const; 187 187 188 188 Vector3 GetPoint(const Vector3 &p) const { -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1867 r1877 2504 2504 2505 2505 2506 void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 2506 void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, 2507 ObjectContainer &objects) 2507 2508 { 2508 2509 stack<BvhNode *> nodeStack; 2509 2510 2510 2511 nodeStack.push(mRoot); 2511 2512 2512 while (!nodeStack.empty()) 2513 { 2513 while (!nodeStack.empty()) { 2514 2514 BvhNode *node = nodeStack.top(); 2515 2515 2516 2516 nodeStack.pop(); 2517 2518 if (node->IsLeaf()) 2519 { 2520 BvhLeaf *leaf = (BvhLeaf *)node; 2521 if (Overlap(box, leaf->GetBoundingBox())) { 2522 Intersectable *object = leaf; 2523 if (!object->Mailed()) { 2524 object->Mail(); 2525 objects.push_back(object); 2526 } 2527 } 2528 } 2517 if (node->IsLeaf()) { 2518 BvhLeaf *leaf = (BvhLeaf *)node; 2519 if (Overlap(box, leaf->GetBoundingBox())) { 2520 Intersectable *object = leaf; 2521 if (!object->Mailed()) { 2522 object->Mail(); 2523 objects.push_back(object); 2524 } 2525 } 2526 } 2529 2527 else 2530 2528 { 2531 2529 BvhInterior *interior = (BvhInterior *)node; 2532 2533 if (Overlap(box, interior->GetBoundingBox())) 2534 nodeStack.push(interior->GetFront()); 2535 2536 if (Overlap(box, interior->GetBoundingBox())) 2537 nodeStack.push(interior->GetBack()); 2530 if (Overlap(box, interior->GetBoundingBox())) { 2531 bool pushed = false; 2532 if (!interior->GetFront()->Mailed()) { 2533 nodeStack.push(interior->GetFront()); 2534 pushed = true; 2535 } 2536 if (!interior->GetBack()->Mailed()) { 2537 nodeStack.push(interior->GetBack()); 2538 pushed = true; 2539 } 2540 // avoid traversal of this node in the next query 2541 if (!pushed) 2542 interior->Mail(); 2543 } 2538 2544 } 2539 2545 } 2540 2546 } 2541 2547 -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1844 r1877 221 221 int NumberOfFaces() const { return 6; }; 222 222 223 223 int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 224 224 GtpVisibilityPreprocessor::Vector3 &normal) 225 225 { -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1876 r1877 1915 1915 "false"); 1916 1916 1917 RegisterOption("RssPreprocessor.distributions", 1918 optString, 1919 "rss_distributions=", 1920 "rss+spatial+object"); 1921 1917 1922 RegisterOption("RssTree.hybridDepth", optInt, "hybrid_depth=", "10"); 1918 1923 RegisterOption("RssTree.maxDepth", optInt, "kd_depth=", "12"); -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1867 r1877 113 113 virtual float GetArea() const {return 0; } 114 114 virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 115 virtual int GetRandomSurfacePoint(const float u, 116 const float v, 117 Vector3 &point, 118 Vector3 &normal) { 119 cerr<<"GetRandomSurfacePoint(u,v...) not yet implemented"<<endl; 120 return 1; 121 } 115 122 116 123 virtual int GetRandomEdgePoint(Vector3 &point, -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp
r1867 r1877 87 87 88 88 89 int 90 TriangleIntersectable::GetRandomSurfacePoint(const float u, 91 const float v, 92 Vector3 &point, 93 Vector3 &normal) 94 { 95 // random barycentric coordinates 96 float a = u; 97 float b = v; 98 float c = 1.0f - u - v; 99 100 point = mItem.mVertices[0] * a + mItem.mVertices[1] * b + mItem.mVertices[2] * c; 101 normal = mItem.GetNormal(); 102 103 return 0; 104 } 105 106 107 89 108 int TriangleIntersectable::GetRandomVisibleSurfacePoint(Vector3 &point, 90 109 Vector3 &normal, -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
r1768 r1877 136 136 137 137 138 138 139 template<typename T> 139 140 int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point, … … 203 204 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 204 205 206 int GetRandomSurfacePoint(const float u, 207 const float v, 208 Vector3 &point, Vector3 &normal); 209 210 205 211 int GetRandomVisibleSurfacePoint(Vector3 &point, 206 212 Vector3 &normal, -
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r1876 r1877 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: pá 8. XII 21:21:57 20063 # Generated by qmake (2.00a) (Qt 4.1.2) on: ne 10. XII 21:55:07 2006 4 4 # Project: preprocessor.pro 5 5 # Template: app -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1867 r1877 184 184 int Compress() {return 0;} 185 185 int GetSize() const {return (int)mEntries.size();} 186 bool Empty() const {return mEntries.empty();} 187 186 bool Empty() const {return mEntries.empty();} 187 188 void Reserve(const int n) { mEntries.reserve(n); } 188 189 /** Normalize the visibility of entries in order to get 189 190 comparable results. … … 231 232 */ 232 233 void Sort(); 234 235 /** Sort pvs entries assume that the pvs contains unique entries 236 */ 237 void SimpleSort(); 233 238 234 239 /** Adds sample to PVS. Assumes that the pvs is sorted … … 307 312 // way we can achieve logarithmic behaviour for insertion and find 308 313 const int dirtySize = (int)mEntries.size() - mLastSorted; 309 return dirtySize > (int)(log((double)mEntries.size()) / log(2.0));314 return dirtySize > 4*(int)(log((double)mEntries.size()) / log(2.0)); 310 315 } 311 316 … … 362 367 mEntries = newPvs.mEntries; 363 368 mLastSorted = (int)mEntries.size(); 369 } 370 371 template <typename T, typename S> 372 void Pvs<T, S>::SimpleSort() 373 { 374 sort(mEntries.begin(), mEntries.end()); 375 mLastSorted = (int)mEntries.size(); 364 376 } 365 377 … … 587 599 const bool checkDirty) 588 600 { 589 bool found = false; 590 591 PvsEntry<T, S> dummy(sample, PvsData()); 592 593 // only check clean part 594 // $$ TMP JB 595 // mLastSorted = 0; 596 vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 597 598 // binary search 599 it = lower_bound(mEntries.begin(), sorted_end, dummy); 600 601 if ((it != mEntries.end()) && ((*it).mObject == sample)) 602 found = true; 603 604 // sample not found yet => search further in the unsorted part 605 if (!found && checkDirty) 606 { 607 vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 608 609 for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit) ; 610 611 if ((dit != mEntries.end()) && ((*dit).mObject == sample)) 612 found = true; 613 } 614 615 return found; 601 bool found = false; 602 603 PvsEntry<T, S> dummy(sample, PvsData()); 604 605 // only check clean part 606 vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 607 608 // binary search 609 it = lower_bound(mEntries.begin(), sorted_end, dummy); 610 611 if ((it != mEntries.end()) && ((*it).mObject == sample)) 612 found = true; 613 614 // sample not found yet => search further in the unsorted part 615 if (!found && checkDirty) { 616 vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 617 618 for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit) ; 619 620 if (dit != dit_end) 621 found = true; 622 } 623 624 return found; 616 625 } 617 626 … … 698 707 const bool entryFound = Find(sample, it); 699 708 700 if (entryFound) 701 { 702 S &data = (*it).mData; 703 704 data.mSumPdf += pdf; 705 //contribution = pdf / data.mSumPdf; 706 707 return false; 708 } 709 else 710 { 711 AddSampleDirty(sample, pdf); 712 //contribution = 1.0f; 713 714 return true; 709 if (entryFound) { 710 S &data = (*it).mData; 711 712 data.mSumPdf += pdf; 713 //contribution = pdf / data.mSumPdf; 714 715 return false; 716 } 717 else { 718 AddSampleDirty(sample, pdf); 719 //contribution = 1.0f; 720 return true; 715 721 } 716 722 } -
GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp
r1876 r1877 148 148 149 149 if (viewcell) { 150 151 152 153 154 155 156 157 158 150 mViewCellsManager->ApplyFilter2(viewcell, 151 false, 152 1.0f, 153 pvs); 154 155 pvsSize = 0; 156 SetupCamera(); 157 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 158 glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 159 159 160 160 -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
r1867 r1877 324 324 static int sSimpleRayId; 325 325 SimpleRay(): mType(Ray::LOCAL_RAY) { 326 mId = sSimpleRayId++;326 // mId = sSimpleRayId++; 327 327 } 328 328 329 329 SimpleRay(const Vector3 &o, const Vector3 &d, const float p=1.0f): 330 330 mOrigin(o), mDirection(d), mPdf(p), mType(Ray::LOCAL_RAY) { 331 mId = sSimpleRayId++;331 // mId = sSimpleRayId++; 332 332 } 333 333 -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r1876 r1877 68 68 case SamplingStrategy::RSS_BASED_DISTRIBUTION: 69 69 case SamplingStrategy::RSS_SILHOUETTE_BASED_DISTRIBUTION: 70 71 72 73 74 70 if (mRssTree) { 71 result = GenerateImportanceRays(mRssTree, number, rays); 72 } 73 break; 74 75 75 default: 76 76 result = Preprocessor::GenerateRays(number, strategy, rays); … … 411 411 for (int i=0; i < distributions.size(); i++) { 412 412 distributions[i]->mRatio = distributions[i]->mContribution/ 413 (TIME_WEIGHT*distributions[i]->mTime + 414 (1 - TIME_WEIGHT)*distributions[i]->mRays); 413 (Limits::Small + 414 (TIME_WEIGHT*distributions[i]->mTime + 415 (1 - TIME_WEIGHT)*distributions[i]->mRays) 416 ); 415 417 416 418 #if 1 … … 438 440 Halton<4> halton; 439 441 440 // for (int i=1; i < 7; i++)441 // cout<<i<<" prime= "<<FindPrime(i)<<endl;442 // for (int i=1; i < 7; i++) 443 // cout<<i<<" prime= "<<FindPrime(i)<<endl; 442 444 443 445 Material mA, mB; … … 467 469 468 470 // use ray buffer to export ray animation 469 const bool useRayBuffer = true;471 const bool useRayBuffer = false; 470 472 471 473 vector<VssRayContainer> rayBuffer(50); … … 492 494 int rssSamples = 0; 493 495 494 if (mUseRssTree) 495 mDistributions.push_back(new RssBasedDistribution(*this)); 496 497 498 if (1) { 499 // mDistributions.push_back(new SpatialBoxBasedDistribution(*this)); 500 // mDistributions.push_back(new DirectionBasedDistribution(*this)); 501 mDistributions.push_back(new ObjectDirectionBasedDistribution(*this)); 502 // mDistributions.push_back(new ReverseObjectBasedDistribution(*this)); 503 mDistributions.push_back(new ObjectBasedDistribution(*this)); 504 mDistributions.push_back(new ReverseViewSpaceBorderBasedDistribution(*this)); 505 } else { 506 mDistributions.push_back(new GlobalLinesDistribution(*this)); 507 mDistributions.push_back(new SpatialBoxBasedDistribution(*this)); 496 // now decode distribution string 497 char buff[1024]; 498 Environment::GetSingleton()->GetStringValue("RssPreprocessor.distributions", 499 buff); 500 501 char *curr = buff; 502 mUseRssTree = false; 503 while (1) { 504 char *e = strchr(curr,'+'); 505 if (e!=NULL) { 506 *e=0; 507 } 508 509 if (strcmp(curr, "rss")==0) { 510 mDistributions.push_back(new RssBasedDistribution(*this)); 511 mUseRssTree = true; 512 } else 513 if (strcmp(curr, "object")==0) { 514 mDistributions.push_back(new ObjectBasedDistribution(*this)); 515 } else 516 if (strcmp(curr, "spatial")==0) { 517 mDistributions.push_back(new SpatialBoxBasedDistribution(*this)); 518 } else 519 if (strcmp(curr, "global")==0) { 520 mDistributions.push_back(new GlobalLinesDistribution(*this)); 521 } else 522 if (strcmp(curr, "direction")==0) { 523 mDistributions.push_back(new DirectionBasedDistribution(*this)); 524 } else 525 if (strcmp(curr, "object_direction")==0) { 526 mDistributions.push_back(new ObjectDirectionBasedDistribution(*this)); 527 } else 528 if (strcmp(curr, "reverse_object")==0) { 529 mDistributions.push_back(new ReverseObjectBasedDistribution(*this)); 530 } else 531 if (strcmp(curr, "reverse_viewspace_border")==0) { 532 mDistributions.push_back(new ReverseViewSpaceBorderBasedDistribution(*this)); 533 } 534 535 if (e==NULL) 536 break; 537 curr = e+1; 508 538 } 509 539 … … 517 547 cout<<"Generating initial rays..."<<endl<<flush; 518 548 519 if (mUseImportanceSampling) { 520 int count = 0; 521 int i; 522 523 // Generate initial samples 524 for (i=0; i < mDistributions.size(); i++) 525 if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 526 count++; 527 528 for (i=0; i < mDistributions.size(); i++) 529 if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 530 GenerateRays(mInitialSamples/count, 531 *mDistributions[i], 532 rays); 533 534 } else { 535 int rayType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; 536 if (mObjectBasedSampling) 537 rayType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 538 else 539 if (mDirectionalSampling) 540 rayType = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION; 541 cout<<"Generating rays..."<<endl; 542 543 Preprocessor::GenerateRays(mRssSamplesPerPass, rayType, rays); 544 } 549 int count = 0; 550 int i; 551 552 // Generate initial samples 553 for (i=0; i < mDistributions.size(); i++) 554 if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 555 count++; 556 557 for (i=0; i < mDistributions.size(); i++) 558 if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 559 GenerateRays(mInitialSamples/count, 560 *mDistributions[i], 561 rays); 562 563 545 564 546 565 547 566 cout<<"Casting initial rays..."<<endl<<flush; 548 567 CastRays(rays, mVssRays, true, pruneInvalidRays); 549 568 550 569 ExportObjectRays(mVssRays, 1546); 551 570 } … … 574 593 } 575 594 576 if (mUseViewcells) { 577 578 cout<<"Computing sample contributions..."<<endl<<flush; 579 // evaluate contributions of the intitial rays 580 mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 581 cout<<"done.\n"<<flush; 582 583 long time = GetTime(); 584 totalTime = TimeDiff(startTime, time)*1e-3f; 585 lastTime = time; 586 587 mStats << 588 "#Pass\n" <<mPass<<endl<< 589 "#RssPass\n" <<rssPass<<endl<< 590 "#Time\n" << totalTime <<endl<< 591 "#TotalSamples\n" <<totalSamples<<endl<< 592 "#RssSamples\n" <<rssSamples<<endl; 593 594 { 595 VssRayContainer contributingRays; 596 mVssRays.GetContributingRays(contributingRays, 0); 597 mStats<<"#NUM_CONTRIBUTING_RAYS\n"<<(int)contributingRays.size()<<endl; 598 if (mExportRays) { 599 char filename[64]; 600 sprintf(filename, "rss-crays-%04d.x3d", 0); 601 ExportRays(filename, contributingRays, mExportNumRays); 602 } 603 } 604 605 606 // viewcells->UpdatePVS(newVssRays); 607 Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 608 // cull viewcells with PVS > median (0.5f) 609 //mViewCellsManager->SetValidityPercentage(0, 0.5f); 610 // mViewCellsManager->SetValidityPercentage(0, 1.0f); 611 Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 612 613 mVssRays.PrintStatistics(mStats); 614 mViewCellsManager->PrintPvsStatistics(mStats); 615 616 617 if (0) { 618 char str[64]; 619 sprintf(str, "tmp/v-"); 620 621 // visualization 622 const bool exportRays = true; 623 const bool exportPvs = true; 624 ObjectContainer objects; 625 mViewCellsManager->ExportSingleViewCells(objects, 626 1000, 627 false, 628 exportPvs, 629 exportRays, 630 10000, 631 str); 632 } 633 595 cout<<"Computing sample contributions..."<<endl<<flush; 596 // evaluate contributions of the intitial rays 597 mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 598 cout<<"done.\n"<<flush; 599 600 long time = GetTime(); 601 totalTime = TimeDiff(startTime, time)*1e-3f; 602 lastTime = time; 603 604 mStats << 605 "#Pass\n" <<mPass<<endl<< 606 "#RssPass\n" <<rssPass<<endl<< 607 "#Time\n" << totalTime <<endl<< 608 "#TotalSamples\n" <<totalSamples<<endl<< 609 "#RssSamples\n" <<rssSamples<<endl; 610 611 { 612 VssRayContainer contributingRays; 613 mVssRays.GetContributingRays(contributingRays, 0); 614 mStats<<"#NUM_CONTRIBUTING_RAYS\n"<<(int)contributingRays.size()<<endl; 615 if (mExportRays) { 616 char filename[64]; 617 sprintf(filename, "rss-crays-%04d.x3d", 0); 618 ExportRays(filename, contributingRays, mExportNumRays); 619 } 620 } 621 622 623 // viewcells->UpdatePVS(newVssRays); 624 Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 625 // cull viewcells with PVS > median (0.5f) 626 //mViewCellsManager->SetValidityPercentage(0, 0.5f); 627 // mViewCellsManager->SetValidityPercentage(0, 1.0f); 628 Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 629 630 mVssRays.PrintStatistics(mStats); 631 mViewCellsManager->PrintPvsStatistics(mStats); 632 633 634 if (0) { 635 char str[64]; 636 sprintf(str, "tmp/v-"); 637 638 // visualization 639 const bool exportRays = true; 640 const bool exportPvs = true; 641 ObjectContainer objects; 642 mViewCellsManager->ExportSingleViewCells(objects, 643 1000, 644 false, 645 exportPvs, 646 exportRays, 647 10000, 648 str); 649 } 650 651 if (renderer) { 634 652 ComputeRenderError(); 635 653 } 636 637 // return 1;638 654 639 655 rssPass++; … … 647 663 // mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 648 664 649 if (mUseImportanceSampling) { 650 651 if (mUseRssTree) { 652 mRssTree->Construct(mObjects, mVssRays); 653 654 mRssTree->stat.Print(mStats); 655 cout<<"RssTree root PVS size = "<<mRssTree->GetRootPvsSize()<<endl; 656 657 if (mExportRssTree) { 658 ExportRssTree("rss-tree-100.x3d", mRssTree, Vector3(1,0,0)); 659 ExportRssTree("rss-tree-001.x3d", mRssTree, Vector3(0,0,1)); 660 ExportRssTree("rss-tree-101.x3d", mRssTree, Vector3(1,0,1)); 661 ExportRssTree("rss-tree-101m.x3d", mRssTree, Vector3(-1,0,-1)); 662 ExportRssTreeLeaves(mRssTree, 10); 663 } 664 } 665 666 if (mExportPvs) { 667 ExportPvs("rss-pvs-initial.x3d", mRssTree); 668 } 669 } 670 665 if (mUseRssTree) { 666 mRssTree->Construct(mObjects, mVssRays); 667 668 mRssTree->stat.Print(mStats); 669 cout<<"RssTree root PVS size = "<<mRssTree->GetRootPvsSize()<<endl; 670 671 if (mExportRssTree) { 672 ExportRssTree("rss-tree-100.x3d", mRssTree, Vector3(1,0,0)); 673 ExportRssTree("rss-tree-001.x3d", mRssTree, Vector3(0,0,1)); 674 ExportRssTree("rss-tree-101.x3d", mRssTree, Vector3(1,0,1)); 675 ExportRssTree("rss-tree-101m.x3d", mRssTree, Vector3(-1,0,-1)); 676 ExportRssTreeLeaves(mRssTree, 10); 677 } 678 } 679 680 if (mExportPvs) { 681 ExportPvs("rss-pvs-initial.x3d", mRssTree); 682 } 683 684 671 685 // keep only rss 672 686 // mDistributions.resize(1); … … 678 692 static VssRayContainer tmpVssRays; 679 693 680 rays.reserve((int)(1.1f*mRssSamplesPerPass)); 694 cout<<"H1"<<endl<<flush; 695 696 //rays.reserve((int)(1.1f*mRssSamplesPerPass)); 697 698 cout<<"H10"<<endl<<flush; 681 699 682 700 rays.clear(); 683 701 vssRays.clear(); 684 702 tmpVssRays.clear(); 685 703 686 704 int castRays = 0; 687 if (mUseImportanceSampling) { 688 689 NormalizeRatios(mDistributions); 690 691 long t1; 692 693 for (int i=0; i < mDistributions.size(); i++) { 694 t1 = GetTime(); 695 rays.clear(); 696 tmpVssRays.clear(); 697 if (mDistributions[i]->mRatio != 0) { 698 GenerateRays(int(mRssSamplesPerPass*mDistributions[i]->mRatio), 699 *mDistributions[i], 700 rays); 701 702 rays.NormalizePdf((float)rays.size()); 703 704 CastRays(rays, tmpVssRays, true, pruneInvalidRays); 705 castRays += (int)rays.size(); 706 707 cout<<"Computing sample contributions..."<<endl<<flush; 708 705 706 cout<<"H11"<<endl<<flush; 707 708 NormalizeRatios(mDistributions); 709 710 long t1; 711 cout<<"H2"<<endl<<flush; 712 for (int i=0; i < mDistributions.size(); i++) { 713 t1 = GetTime(); 714 rays.clear(); 715 tmpVssRays.clear(); 716 if (mDistributions[i]->mRatio != 0) { 717 GenerateRays(int(mRssSamplesPerPass*mDistributions[i]->mRatio), 718 *mDistributions[i], 719 rays); 720 721 rays.NormalizePdf((float)rays.size()); 722 723 CastRays(rays, tmpVssRays, true, pruneInvalidRays); 724 castRays += (int)rays.size(); 725 726 cout<<"Computing sample contributions..."<<endl<<flush; 727 709 728 #if ADD_RAYS_IN_PLACE 710 mDistributions[i]->mContribution =711 729 float contribution = 730 mViewCellsManager->ComputeSampleContributions(tmpVssRays, true, false); 712 731 #else 713 mDistributions[i]->mContribution =714 732 float contribution = 733 mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 715 734 #endif 716 cout<<"done."<<endl; 717 } 718 719 mDistributions[i]->mTime = TimeDiff(t1, GetTime()); 720 // mDistributions[i]->mRays = (int)rays.size(); 721 mDistributions[i]->mRays = (int)tmpVssRays.size() + 1; 722 // mStats<<"#RssRelContrib"<<endl<<contributions[0]/nrays[0]<<endl; 723 vssRays.insert(vssRays.end(), tmpVssRays.begin(), tmpVssRays.end() ); 724 } 725 726 EvaluateRatios(mDistributions); 727 728 // add contributions of all rays at once... 729 #if !ADD_RAYS_IN_PLACE 730 mViewCellsManager->AddSampleContributions(vssRays); 731 #endif 732 } 733 else { 734 int rayType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; 735 if (mObjectBasedSampling) 736 rayType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 737 else 738 if (mDirectionalSampling) 739 rayType = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION; 740 741 cout<<"Generating rays..."<<endl; 742 743 Preprocessor::GenerateRays(mRssSamplesPerPass, rayType, rays); 744 cout<<"done."<<endl; 745 746 cout<<"Casting rays..."<<endl; CastRays(rays, vssRays, true); 747 cout<<"done."<<endl; 748 castRays += (int)rays.size(); 749 if (mUseViewcells) { 750 /// compute view cell contribution of rays 751 cout<<"Computing sample contributions..."<<endl; 752 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 735 mDistributions[i]->mContribution = contribution; 736 mDistributions[i]->mTotalContribution += contribution; 737 753 738 cout<<"done."<<endl; 754 739 } 755 756 740 757 } 741 mDistributions[i]->mTime = TimeDiff(t1, GetTime()); 742 // mDistributions[i]->mRays = (int)rays.size(); 743 mDistributions[i]->mRays = (int)tmpVssRays.size(); 744 mDistributions[i]->mTotalRays = (int)tmpVssRays.size(); 745 746 // mStats<<"#RssRelContrib"<<endl<<contributions[0]/nrays[0]<<endl; 747 vssRays.insert(vssRays.end(), tmpVssRays.begin(), tmpVssRays.end() ); 748 } 749 750 EvaluateRatios(mDistributions); 751 752 // add contributions of all rays at once... 753 #if !ADD_RAYS_IN_PLACE 754 mViewCellsManager->AddSampleContributions(vssRays); 755 #endif 756 757 758 758 totalSamples += castRays; 759 759 rssSamples += (int)vssRays.size(); 760 760 761 761 cout<<"Generated "<<castRays<<" rays, progress "<<100.0f*totalSamples/((float) mRssSamples + 762 762 mInitialSamples)<<"%\n"; 763 763 764 764 765 765 long time = GetTime(); 766 766 totalTime += TimeDiff(lastTime, time); … … 773 773 "#TotalSamples\n" <<totalSamples<<endl<< 774 774 "#RssSamples\n" <<rssSamples<<endl; 775 776 777 if (mUseViewcells) { 778 Debug<<"Print statistics...\n"<<flush; 779 vssRays.PrintStatistics(mStats); 780 mViewCellsManager->PrintPvsStatistics(mStats); 781 Debug<<"done.\n"<<flush; 782 } 783 784 775 776 777 Debug<<"Print statistics...\n"<<flush; 778 vssRays.PrintStatistics(mStats); 779 mViewCellsManager->PrintPvsStatistics(mStats); 780 Debug<<"done.\n"<<flush; 781 785 782 if (renderer && mPass > 0) { 783 Debug<<"Computing render errror..."<<endl<<flush; 786 784 char buf[100]; 787 if (mUseImportanceSampling) 788 { 789 sprintf(buf, "snap/i-%02d-", mPass); 790 791 renderer->SetSnapPrefix(buf); 792 } 793 else 794 { 795 sprintf(buf, "snap/r-%02d-", mPass); 796 797 renderer->SetSnapPrefix(buf); 798 } 785 sprintf(buf, "snap/i-%02d-", mPass); 786 787 renderer->SetSnapPrefix(buf); 799 788 800 789 renderer->SetSnapErrorFrames(true); 801 }802 803 ComputeRenderError();790 ComputeRenderError(); 791 Debug<<"done."<<endl<<flush; 792 } 804 793 805 794 // epxort rays before adding them to the tree -> some of them can be deleted 806 795 807 796 if (mExportRays) { 797 Debug<<"Exporting rays..."<<endl<<flush; 808 798 char filename[64]; 809 if (mUseImportanceSampling) 810 sprintf(filename, "rss-rays-i%04d.x3d", rssPass); 811 else 812 sprintf(filename, "rss-rays-%04d.x3d", rssPass); 799 sprintf(filename, "rss-rays-i%04d.x3d", rssPass); 813 800 814 815 816 801 if (useRayBuffer) 817 802 vssRays.SelectRays(mExportNumRays, rayBuffer[mPass], true); … … 825 810 sprintf(filename, "rss-crays-%04d.x3d", rssPass); 826 811 ExportRays(filename, contributingRays, mExportNumRays); 812 813 Debug<<"done."<<endl<<flush; 827 814 } 828 815 … … 831 818 // already when adding into the tree 832 819 // do not add those rays which have too low or no contribution.... 833 834 835 if (mUseRssTree && mUseImportanceSampling) { 820 if (mUseRssTree) { 836 821 Debug<<"Adding rays...\n"<<flush; 837 822 mRssTree->AddRays(vssRays); … … 856 841 857 842 858 if (!mUse ImportanceSampling || !mUseRssTree)843 if (!mUseRssTree) 859 844 CLEAR_CONTAINER(vssRays); 860 845 // otherwise the rays get deleted by the rss tree update according to RssTree.maxRays .... … … 869 854 } 870 855 871 if (mUseViewcells) { 872 873 if(0) { 874 VssRayContainer selectedRays; 875 int desired = mViewCellsManager->GetVisualizationSamples(); 876 877 mVssRays.SelectRays(desired, selectedRays); 878 879 mViewCellsManager->Visualize(mObjects, selectedRays); 880 } 881 882 // view cells after sampling 883 mViewCellsManager->PrintStatistics(Debug); 884 885 EvalViewCellHistogram(); 886 887 //-- render simulation after merge 888 cout << "\nevaluating bsp view cells render time after sampling ... "; 889 890 mRenderSimulator->RenderScene(); 891 SimulationStatistics ss; 892 mRenderSimulator->GetStatistics(ss); 893 894 cout << " finished" << endl; 895 cout << ss << endl; 896 Debug << ss << endl; 897 } 898 899 900 if (useRayBuffer && mExportRays && mUseImportanceSampling) { 856 if(0) { 857 VssRayContainer selectedRays; 858 int desired = mViewCellsManager->GetVisualizationSamples(); 859 860 mVssRays.SelectRays(desired, selectedRays); 861 862 mViewCellsManager->Visualize(mObjects, selectedRays); 863 } 864 865 // view cells after sampling 866 mViewCellsManager->PrintStatistics(Debug); 867 868 EvalViewCellHistogram(); 869 870 //-- render simulation after merge 871 cout << "\nEvaluating view cells render time after sampling ... "; 872 873 mRenderSimulator->RenderScene(); 874 SimulationStatistics ss; 875 mRenderSimulator->GetStatistics(ss); 876 877 cout << " finished" << endl; 878 cout << ss << endl; 879 Debug << ss << endl; 880 881 if (useRayBuffer && mExportRays) { 901 882 char filename[64]; 902 883 sprintf(filename, "rss-rays-i.x3d"); … … 905 886 ExportRayAnimation(filename, rayBuffer); 906 887 } 907 908 888 889 909 890 // do not delete rss tree now - can be used for visualization.. 910 891 #if 0 … … 914 895 #endif 915 896 916 //mViewCellsManager->ExportViewCells("visibility.xml",917 // true);918 919 897 920 898 return true; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1876 r1877 675 675 float oldCost = (float)leaf->rays.size()*pvsSize; 676 676 info.costRatio = newCost/oldCost; 677 break; 677 678 } 678 679 } … … 1416 1417 1417 1418 int inactive=0; 1419 Debug<<"Deleting rays..."<<endl<<flush; 1418 1420 1419 1421 for(VssRayContainer::const_iterator ri = remove.begin(); … … 1428 1430 } 1429 1431 1432 Debug<<"done."<<endl<<flush; 1430 1433 1431 1434 // cout<<"all/inactive"<<remove.size()<<"/"<<inactive<<endl; 1432 1435 Debug<<"Adding rays..."<<endl<<flush; 1436 1433 1437 for(VssRayContainer::const_iterator ri = add.begin(); 1434 1438 ri != add.end(); … … 1439 1443 } 1440 1444 1445 Debug<<"done."<<endl<<flush; 1446 1441 1447 stat.rayRefs += add.size() - remove.size(); 1442 1448 1449 Debug<<"Updating statistics..."<<endl<<flush; 1443 1450 UpdateTreeStatistics(); 1451 Debug<<"done."<<endl<<flush; 1452 1444 1453 // check whether the tree should be prunned 1445 1454 if (stat.rayRefs > mMaxRays) { 1455 Debug<<"Prunning rays..."<<endl<<flush; 1446 1456 PruneRays(mMaxRays); 1457 Debug<<"done."<<endl<<flush; 1447 1458 // UpdateTreeStatistics(); 1448 1459 } 1449 1460 1450 1461 } 1451 1462 … … 2486 2497 2487 2498 int 2488 RssTree::PruneRays (RssTreeLeaf *leaf,2489 const float contributionThreshold)2499 RssTree::PruneRaysRandom(RssTreeLeaf *leaf, 2500 const float ratio) 2490 2501 { 2491 2502 int i; … … 2493 2504 2494 2505 for (j=0, i=0; i < leaf->rays.size(); i++) { 2495 2496 if (leaf->rays[i].mRay->mWeightedPvsContribution > contributionThreshold) {2497 // copy a valid sample2498 leaf->rays[j] = leaf->rays[i];2499 j++;2500 } else {2501 // delete the ray2502 leaf->rays[i].mRay->Unref();2503 if (leaf->rays[i].mRay->RefCount() != 0) {2504 cerr<<"Error: refcount!=0, but"<<leaf->rays[j].mRay->RefCount()<<endl;2505 exit(1);2506 }2507 delete leaf->rays[i].mRay;2508 }2509 }2510 2511 2512 leaf->rays.resize(j);2513 int removed = (i-j);2514 stat.rayRefs -= removed;2515 return removed;2516 }2517 2518 int2519 RssTree::PruneRaysRandom(RssTreeLeaf *leaf,2520 const float ratio)2521 {2522 int i;2523 int j;2524 2525 for (j=0, i=0; i < leaf->rays.size(); i++) {2526 2527 2506 if (Random(1.0f) < ratio) { 2528 2507 // copy a valid sample … … 2586 2565 ) 2587 2566 { 2588 bool globalPrunning = false;2589 2567 2590 2568 stack<RssTreeNode *> tstack; … … 2596 2574 Debug<<"Prunning rays...\nOriginal size "<<stat.rayRefs<<endl<<flush; 2597 2575 2598 if (globalPrunning) { 2599 VssRayContainer allRays; 2600 allRays.reserve(stat.rayRefs); 2601 CollectRays(allRays); 2602 sort(allRays.begin(), 2603 allRays.end(), 2604 GreaterWeightedPvsContribution); 2605 2606 if ( maxRays >= allRays.size() ) 2607 return 0; 2608 2609 float contributionThreshold = allRays[desired]->mWeightedPvsContribution; 2610 2611 PushRoots(tstack); 2612 2613 while (!tstack.empty()) { 2614 RssTreeNode *node = tstack.top(); 2615 tstack.pop(); 2616 2617 if (node->IsLeaf()) { 2618 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 2619 prunned += PruneRays(leaf, contributionThreshold); 2620 } else { 2621 RssTreeInterior *in = (RssTreeInterior *)node; 2622 // both nodes for directional splits 2623 tstack.push(in->front); 2624 tstack.push(in->back); 2625 } 2626 } 2627 } else { 2628 // prune random rays from each leaf so that the ratio's remain the same 2629 PushRoots(tstack); 2630 2631 if ( maxRays >= stat.rayRefs ) 2632 return 0; 2633 2634 float ratio = desired/(float)stat.rayRefs; 2635 2636 while (!tstack.empty()) { 2637 RssTreeNode *node = tstack.top(); 2638 tstack.pop(); 2639 2640 if (node->IsLeaf()) { 2641 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 2642 // prunned += PruneRaysRandom(leaf, ratio); 2643 prunned += PruneRaysContribution(leaf, ratio); 2644 } else { 2645 RssTreeInterior *in = (RssTreeInterior *)node; 2646 // both nodes for directional splits 2647 tstack.push(in->front); 2648 tstack.push(in->back); 2649 } 2650 } 2651 2652 2653 2654 2655 } 2656 2657 2576 // prune random rays from each leaf so that the ratio's remain the same 2577 PushRoots(tstack); 2578 2579 if ( maxRays >= stat.rayRefs ) 2580 return 0; 2581 2582 float ratio = desired/(float)stat.rayRefs; 2583 2584 while (!tstack.empty()) { 2585 RssTreeNode *node = tstack.top(); 2586 tstack.pop(); 2587 2588 if (node->IsLeaf()) { 2589 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 2590 prunned += PruneRaysRandom(leaf, ratio); 2591 //prunned += PruneRaysContribution(leaf, ratio); 2592 } else { 2593 RssTreeInterior *in = (RssTreeInterior *)node; 2594 // both nodes for directional splits 2595 tstack.push(in->front); 2596 tstack.push(in->back); 2597 } 2598 } 2658 2599 2659 2600 Debug<<"Remained "<<stat.rayRefs<<" rays"<<endl<<flush; … … 2836 2777 RssTree::ComputeImportance(RssTreeLeaf *leaf) 2837 2778 { 2779 if (leaf->mTotalRays) 2780 leaf->mImportance = leaf->mTotalContribution / leaf->mTotalRays; 2781 else 2782 leaf->mImportance = 0.0f; 2783 return; 2784 2838 2785 if (0) 2839 2786 leaf->mImportance = leaf->GetAvgRayContribution(); -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h
r1876 r1877 433 433 RayInfoContainer rays; 434 434 int mTotalRays; 435 435 float mTotalContribution; 436 436 437 bool mValidPvs; 437 438 … … 440 441 RssTreeLeaf(RssTreeInterior *p, 441 442 const int nRays 442 ):RssTreeNode(p), rays(), mPvsSize(0), mTotalRays(0), mValidPvs(false) { 443 ):RssTreeNode(p), rays(), mPvsSize(0), mTotalRays(0), 444 mTotalContribution(0.0f), mValidPvs(false) { 443 445 rays.reserve(nRays); 444 446 } … … 455 457 456 458 void AddRay(const RayInfo &data) { 457 mValidPvs = false; 458 rays.push_back(data); 459 mTotalRays++; 460 data.mRay->Ref(); 459 mValidPvs = false; 460 rays.push_back(data); 461 mTotalRays++; 462 mTotalContribution += 463 ABS_CONTRIBUTION_WEIGHT*data.mRay->mPvsContribution + 464 (1.0f - ABS_CONTRIBUTION_WEIGHT)*data.mRay->mRelativePvsContribution; 465 data.mRay->Ref(); 461 466 } 462 467 … … 1066 1071 1067 1072 int 1068 PruneRays(RssTreeLeaf *leaf,1069 const float contributionThreshold);1070 int1071 1073 PruneRaysRandom(RssTreeLeaf *leaf, 1072 1074 const float ratio); -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1867 r1877 11 11 12 12 SamplingStrategy::SamplingStrategy(const Preprocessor &preprocessor): 13 mPreprocessor(preprocessor), mRatio(1.0f) 14 { 13 mPreprocessor(preprocessor), mRatio(1.0f), mTotalRays(0), mTotalContribution(0.0f) 14 { 15 15 16 } 16 17 … … 71 72 Vector3 origin, direction; 72 73 73 mPreprocessor.mViewCellsManager->GetViewPoint(origin); 74 74 float r[5]; 75 mHalton.GetNext(5, r); 76 77 mPreprocessor.mViewCellsManager->GetViewPoint(origin, Vector3(r[2],r[3],r[4])); 78 75 79 Vector3 point; 76 80 Vector3 normal; 77 //cout << "y"; 78 const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f); 81 82 r[0] *= mPreprocessor.mObjects.size()-1; 83 const int i = (int)r[0]; 79 84 80 85 Intersectable *object = mPreprocessor.mObjects[i]; 81 86 82 object->GetRandomSurfacePoint(point, normal); 87 // take the remainder as a parameter over objects surface 88 r[0] -= (float)i; 89 90 object->GetRandomSurfacePoint(r[0], r[1], point, normal); 91 83 92 direction = point - origin; 84 85 // $$ jb the pdf is yet not correct for all sampling methods! 86 const float c = Magnitude(direction); 87 93 94 const float c = Magnitude(direction); 95 88 96 if (c <= Limits::Small) 89 97 return false; … … 176 184 177 185 float r[6]; 178 halton.GetNext(r);186 mHalton.GetNext(6, r); 179 187 mPreprocessor.mViewCellsManager->GetViewPoint(origin, Vector3(r[0],r[1],r[2])); 180 188 … … 405 413 for (i=0; i < tries; i++) { 406 414 float r[4]; 407 halton.GetNext(r);415 mHalton.GetNext(4, r); 408 416 409 417 #if 0 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1867 r1877 57 57 int mType; 58 58 int mRays; 59 float mContribution;59 float mContribution; 60 60 float mTime; 61 61 float mRatio; 62 62 63 int mTotalRays; 64 float mTotalContribution; 63 65 protected: 64 66 … … 71 73 { 72 74 public: 73 75 HaltonSequence mHalton; 76 74 77 ObjectBasedDistribution(const Preprocessor &preprocessor): 75 78 SamplingStrategy(preprocessor) { … … 136 139 { 137 140 public: 138 Halton <6> halton;141 HaltonSequence mHalton; 139 142 SpatialBoxBasedDistribution(const Preprocessor &preprocessor): 140 143 SamplingStrategy(preprocessor){ … … 205 208 { 206 209 public: 207 Halton <4> halton;210 HaltonSequence mHalton; 208 211 //HaltonSequence mHalton; 209 212 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1867 r1877 120 120 mPvsCost(0), 121 121 mEntriesInPvs(0), 122 mPvsSizeValid(false) 122 mPvsSizeValid(false), 123 mFilteredPvsSize(0) 123 124 { 124 125 mId = -100; … … 133 134 mMergeCost(0), 134 135 mPvsCost(0), 135 mPvsSizeValid(false) 136 mPvsSizeValid(false), 137 mFilteredPvsSize(0) 136 138 //mMailbox(0) 137 139 { -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1876 r1877 27 27 28 28 29 // warning: Should not count origin object for sampling30 // because it disturbs heuristics31 #define SAMPLE_ORIGIN_OBJECTS 0 // matt temp32 29 33 30 // $$JB HACK … … 1871 1868 1872 1869 if (evaluateFilter) { 1873 ObjectPvs filteredPvs = viewcell->GetPvs();1870 ObjectPvs filteredPvs; 1874 1871 PvsFilterStatistics fstat = ApplyFilter2(viewcell, 1875 1876 1877 1872 false, 1873 2.0f, 1874 filteredPvs); 1878 1875 1879 1876 float filteredCost = filteredPvs.EvalPvsCost(); 1880 1877 stat.avgFilteredPvs += filteredCost; 1881 1878 stat.avgFilterContribution += filteredCost - pvsCost; 1882 1879 1883 1880 stat.avgFilterRadius += fstat.mAvgFilterRadius; 1884 1881 int sum = fstat.mGlobalFilterCount + fstat.mLocalFilterCount; … … 1887 1884 (float) sum; 1888 1885 } 1889 1890 1886 1891 1887 } else { … … 2012 2008 2013 2009 2014 float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 2010 2011 #define PVS_ADD_DIRTY 1 2012 2013 float 2014 ViewCellsManager::ComputeSampleContribution(VssRay &ray, 2015 2015 const bool addRays, 2016 2016 const bool storeViewCells) … … 2018 2018 ray.mPvsContribution = 0; 2019 2019 ray.mRelativePvsContribution = 0.0f; 2020 2020 2021 2021 if (ray.mTerminationObject==NULL) 2022 2022 return 0.0f; … … 2026 2026 static Ray hray; 2027 2027 hray.Init(ray); 2028 //hray.mFlags |= Ray::CULL_BACKFACES; 2029 //Ray hray(ray); 2030 2028 2031 2029 float tmin = 0, tmax = 1.0; 2032 2030 … … 2039 2037 ViewCell::NewMail(); 2040 2038 2041 // if (ray.mPdf!=1.0f)2042 // cout<<ray.mPdf<<" ";2043 2044 2045 2039 // traverse the view space subdivision 2046 2040 CastLineSegment(origin, termination, viewcells); 2047 2041 2048 2042 if (storeViewCells) 2049 { // copy viewcells memory efficiently 2043 { 2044 // copy viewcells memory efficiently 2050 2045 ray.mViewCells.reserve(viewcells.size()); 2051 2046 ray.mViewCells = viewcells; 2052 2047 } 2053 2054 Intersectable *obj = GetIntersectable(ray, true);2055 2048 2056 2049 ViewCellContainer::const_iterator it = viewcells.begin(); 2057 2050 2051 Intersectable *terminationObj = GetIntersectable(ray, true); 2052 2053 2058 2054 for (; it != viewcells.end(); ++ it) 2059 2055 { 2060 2056 ViewCell *viewcell = *it; 2061 // tests if view cell is in valid view space2057 2062 2058 if (viewcell->GetValid()) 2063 { 2059 { // if ray not outside of view space 2064 2060 float contribution; 2065 2061 2066 if (ray.mTerminationObject) { 2067 if (viewcell->GetPvs().GetSampleContribution(obj, 2068 ray.mPdf, 2069 contribution)) { 2070 ++ ray.mPvsContribution; 2062 if (terminationObj) 2063 { 2064 // todo: maybe not correct for kd node pvs 2065 if (viewcell->GetPvs().GetSampleContribution( 2066 terminationObj, ray.mPdf, contribution)) 2067 { 2068 ++ ray.mPvsContribution; 2069 if (addRays) { 2070 #if PVS_ADD_DIRTY 2071 viewcell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 2072 if (viewcell->GetPvs().RequiresResort()) { 2073 viewcell->GetPvs().SimpleSort(); 2074 } 2075 #else 2076 viewcell->GetPvs().AddSample(terminationObj, ray.mPdf); 2077 #endif 2078 } 2079 } 2080 2081 ray.mRelativePvsContribution += contribution; 2071 2082 } 2072 2073 ray.mRelativePvsContribution += contribution; 2074 // $$ test of different contribution measure 2075 // ray.mRelativePvsContribution += 1.0f/(viewcell->GetPvs().GetSize() + 10.0f); 2076 2077 } 2078 2079 #if SAMPLE_ORIGIN_OBJECTS 2080 2081 // for directional sampling it is important to count only contributions 2082 // made in one direction!!! 2083 // the other contributions of this sample will be counted for the oposite ray! 2084 2085 if (ray.mOriginObject && 2086 viewcell->GetPvs().GetSampleContribution(ray.mOriginObject, 2087 ray.mPdf, 2088 contribution)) 2089 { 2090 ++ ray.mPvsContribution; 2091 ray.mRelativePvsContribution += contribution; 2092 } 2093 #endif 2094 } 2095 } 2096 2097 // if true, the sampled entities are stored in the pvs 2098 if (addRays) 2099 { 2100 for (it = viewcells.begin(); it != viewcells.end(); ++ it) 2101 { 2102 ViewCell *viewcell = *it; 2103 2104 if (viewcell->GetValid()) 2105 { 2106 // if view point is valid, add new object to the pvs 2107 if (ray.mTerminationObject) 2108 { 2109 viewcell->GetPvs().AddSample(obj, ray.mPdf); 2110 } 2111 #if SAMPLE_ORIGIN_OBJECTS 2112 if (ray.mOriginObject) 2113 { 2114 viewcell->GetPvs().AddSample(ray.mOriginObject, ray.mPdf); 2115 } 2116 #endif 2117 } 2118 } 2119 } 2120 2121 return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 2122 (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 2123 } 2083 } 2084 } 2085 2086 return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 2087 (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 2088 } 2089 2124 2090 2125 2091 … … 2627 2593 2628 2594 2629 #if 12630 2595 PvsFilterStatistics 2631 2596 ViewCellsManager::ApplyFilter2(ViewCell *viewCell, 2632 2633 2634 2635 2636 2637 { 2638 2597 const bool useViewSpaceFilter, 2598 const float filterSize, 2599 ObjectPvs &pvs, 2600 vector<AxisAlignedBox3> *filteredBoxes 2601 ) 2602 { 2603 //cout<<"y"; 2639 2604 PvsFilterStatistics stats; 2640 2605 … … 2642 2607 Vector3 center = vbox.Center(); 2643 2608 // copy the PVS 2609 Intersectable::NewMail(); 2644 2610 ObjectPvs basePvs = viewCell->GetPvs(); 2645 Intersectable::NewMail();2646 2647 2611 ObjectPvsIterator pit = basePvs.GetIterator(); 2648 2612 2613 pvs.Reserve(viewCell->GetFilteredPvsSize()); 2614 2649 2615 #if !USE_KD_PVS 2650 // first mark all object from this pvs2616 // first mark all objects from this pvs 2651 2617 while (pit.HasMoreEntries()) { 2652 2653 2654 2655 2618 ObjectPvsEntry entry = pit.Next(); 2619 2620 Intersectable *object = entry.mObject; 2621 object->Mail(); 2656 2622 } 2657 2623 #endif 2658 2624 2659 2625 int pvsSize = 0; 2660 2626 int nPvsSize = 0; … … 2681 2647 2682 2648 if (useViewSpaceFilter) { 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2649 // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 2650 float radius = viewCellRadius/100.0f; 2651 vbox.Enlarge(radius); 2652 cout<<"vbox = "<<vbox<<endl; 2653 ViewCellContainer viewCells; 2654 ComputeBoxIntersections(vbox, viewCells); 2655 2656 ViewCellContainer::const_iterator it = viewCells.begin(), 2657 it_end = viewCells.end(); 2658 int i = 0; 2659 for (i=0; it != it_end; ++ it, ++ i) 2660 if ((*it) != viewCell) { 2661 //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 2662 basePvs.MergeInPlace((*it)->GetPvs()); 2663 } 2664 2665 // update samples and globalC 2666 samples = (float)pvs.GetSamples(); 2667 // cout<<"neighboring viewcells = "<<i-1<<endl; 2668 // cout<<"Samples' = "<<samples<<endl; 2703 2669 } 2704 2670 2705 2671 // Minimal number of samples so that filtering takes place 2706 2672 #define MIN_SAMPLES 50 2707 2673 2708 2674 if (samples > MIN_SAMPLES) { 2709 float globalC = 2.0f*filterSize/sqrt(samples); 2710 2711 pit = basePvs.GetIterator(); 2712 2713 ObjectContainer objects; 2714 2715 while (pit.HasMoreEntries()) 2716 { 2717 ObjectPvsEntry entry = pit.Next(); 2718 2719 Intersectable *object = entry.mObject; 2720 // compute filter size based on the distance and the numebr of samples 2721 AxisAlignedBox3 box = object->GetBox(); 2722 2723 float distance = Distance(center, box.Center()); 2724 float globalRadius = distance*globalC; 2725 2726 int objectSamples = (int)entry.mData.mSumPdf; 2727 float localRadius = MAX_FLOAT; 2728 2729 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 2730 sqrt((float)objectSamples); 2731 2732 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 2733 2734 // now compute the filter size 2735 float radius; 2736 2675 float globalC = 2.0f*filterSize/sqrt(samples); 2676 2677 pit = basePvs.GetIterator(); 2678 2679 ObjectContainer objects; 2680 2681 while (pit.HasMoreEntries()) { 2682 ObjectPvsEntry entry = pit.Next(); 2683 2684 Intersectable *object = entry.mObject; 2685 // compute filter size based on the distance and the numebr of samples 2686 AxisAlignedBox3 box = object->GetBox(); 2687 2688 float distance = Distance(center, box.Center()); 2689 float globalRadius = distance*globalC; 2690 2691 int objectSamples = (int)entry.mData.mSumPdf; 2692 float localRadius = MAX_FLOAT; 2693 2694 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/ 2695 sqrt((float)objectSamples); 2696 2697 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl; 2698 2699 // now compute the filter size 2700 float radius; 2701 2737 2702 #if 0 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2703 if (objectSamples <= 1) { 2704 if (localRadius > globalRadius) { 2705 radius = 0.5flRadius; 2706 stats.mLocalFilterCount++; 2707 } else { 2708 radius = globalRadius; 2709 stats.mGlobalFilterCount++; 2710 } 2711 } else { 2712 radius = localRadius; 2713 stats.mLocalFilterCount++; 2714 } 2750 2715 #else 2751 2752 2753 2716 radius = 0.5f*globalRadius + 0.5f*localRadius; 2717 stats.mLocalFilterCount++; 2718 stats.mGlobalFilterCount++; 2754 2719 #endif 2755 2756 stats.mAvgFilterRadius += radius; 2757 2758 // cout<<"box = "<<box<<endl; 2759 // cout<<"distance = "<<distance<<endl; 2760 // cout<<"radiues = "<<radius<<endl; 2761 2762 box.Enlarge(Vector3(radius)); 2763 if (filteredBoxes) 2764 filteredBoxes->push_back(box); 2765 objects.clear(); 2766 // $$ warning collect objects takes only unmailed ones! 2767 CollectObjects(box, objects); 2768 // cout<<"collected objects="<<objects.size()<<endl; 2769 ObjectContainer::const_iterator noi = objects.begin(); 2770 for (; noi != objects.end(); ++ noi) { 2771 Intersectable *o = *noi; 2772 // $$ JB warning: pdfs are not correct at this point! 2773 pvs.AddSampleDirty(o, Limits::Small); 2774 } 2775 } 2776 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 2720 2721 stats.mAvgFilterRadius += radius; 2722 2723 // cout<<"box = "<<box<<endl; 2724 // cout<<"distance = "<<distance<<endl; 2725 // cout<<"radiues = "<<radius<<endl; 2726 2727 box.Enlarge(Vector3(radius)); 2728 2729 if (filteredBoxes) 2730 filteredBoxes->push_back(box); 2731 2732 objects.clear(); 2733 // $$ warning collect objects takes only unmailed ones! 2734 CollectObjects(box, objects); 2735 // cout<<"collected objects="<<objects.size()<<endl; 2736 ObjectContainer::const_iterator noi = objects.begin(); 2737 for (; noi != objects.end(); ++ noi) { 2738 Intersectable *o = *noi; 2739 // $$ JB warning: pdfs are not correct at this point! 2740 pvs.AddSampleDirty(o, Limits::Small); 2741 } 2742 } 2743 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 2777 2744 } 2778 2745 2779 2746 Debug<<" nPvs size = "<<pvs.GetSize()<<endl; 2780 2747 2781 2748 #if !USE_KD_PVS 2782 2749 // copy the base pvs to the new pvs 2783 2750 pit = basePvs.GetIterator(); 2784 2751 while (pit.HasMoreEntries()) { 2785 2786 2752 ObjectPvsEntry entry = pit.Next(); 2753 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf); 2787 2754 } 2788 2755 #endif 2756 2757 pvs.SimpleSort(); 2789 2758 viewCell->SetFilteredPvsSize(pvs.GetSize()); 2790 2759 … … 2792 2761 return stats; 2793 2762 } 2794 #else2795 PvsFilterStatistics2796 ViewCellsManager::ApplyFilter2(ViewCell *viewCell,2797 const bool useViewSpaceFilter,2798 const float filterSize,2799 ObjectPvs &pvs2800 )2801 {2802 cout << "x";2803 PvsFilterStatistics stats;2804 2805 AxisAlignedBox3 vbox = GetViewCellBox(viewCell);2806 Vector3 center = vbox.Center();2807 // copy the PVS2808 ObjectPvs basePvs;// = viewCell->GetPvs();2809 Intersectable::NewMail();2810 2811 ObjectPvsIterator pit = viewCell->GetPvs().GetIterator();2812 2813 #if !USE_KD_PVS2814 // first mark all object from this pvs2815 while (pit.HasMoreEntries())2816 {2817 ObjectPvsEntry entry = pit.Next();2818 2819 Intersectable *object = entry.mObject;2820 object->Mail();2821 }2822 #endif2823 2824 int pvsSize = 0;2825 int nPvsSize = 0;2826 float samples = (float)viewCell->GetPvs().GetSamples();2827 2828 Debug<<"f #s="<<samples<<"pvs size = "<<viewCell->GetPvs().GetSize();2829 // cout<<"Filter size = "<<filterSize<<endl;2830 // cout<<"vbox = "<<vbox<<endl;2831 // cout<<"center = "<<center<<endl;2832 2833 2834 // Minimal number of local samples to take into account2835 // the local sampling density.2836 // The size of the filter is a minimum of the conservative2837 // local sampling density estimate (#rays intersecting teh viewcell and2838 // the object)2839 // and gobal estimate for the view cell2840 // (total #rays intersecting the viewcell)2841 #define MIN_LOCAL_SAMPLES 52842 2843 float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal());2844 2845 // now compute the filter box around the current viewCell2846 2847 if (useViewSpaceFilter)2848 {2849 // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius);2850 float radius = viewCellRadius/100.0f;2851 vbox.Enlarge(radius);2852 cout<<"vbox = "<<vbox<<endl;2853 ViewCellContainer viewCells;2854 ComputeBoxIntersections(vbox, viewCells);2855 2856 MergeViewCellsEfficient(basePvs, viewCells);2857 cout << "basepvs size " << basePvs.GetSize() << endl;2858 // update samples and globalC2859 samples = (float)pvs.GetSamples();2860 // cout<<"neighboring viewcells = "<<i-1<<endl;2861 // cout<<"Samples' = "<<samples<<endl;2862 }2863 else2864 {2865 basePvs = viewCell->GetPvs();2866 }2867 2868 // Minimal number of samples so that filtering takes place2869 #define MIN_SAMPLES 1002870 if (samples > MIN_SAMPLES)2871 {2872 float globalC = 2.0f*filterSize/sqrt(samples);2873 2874 pit = basePvs.GetIterator();2875 2876 ObjectContainer objects;2877 2878 while (pit.HasMoreEntries())2879 {2880 ObjectPvsEntry entry = pit.Next();2881 2882 Intersectable *object = entry.mObject;2883 // compute filter size based on the distance and the numebr of samples2884 AxisAlignedBox3 box = object->GetBox();2885 2886 float distance = Distance(center, box.Center());2887 float globalRadius = distance*globalC;2888 2889 int objectSamples = (int)entry.mData.mSumPdf;2890 float localRadius = MAX_FLOAT;2891 2892 if (objectSamples > MIN_LOCAL_SAMPLES)2893 {2894 localRadius = filterSize*0.5f*Magnitude(box.Diagonal())/2895 sqrt((float)objectSamples);2896 }2897 2898 // cout<<"lr="<<localRadius<<" gr="<<globalRadius<<endl;2899 2900 // now compute the filter size2901 float radius;2902 2903 if (localRadius < globalRadius)2904 {2905 radius = localRadius;2906 stats.mLocalFilterCount++;2907 }2908 else2909 {2910 radius = globalRadius;2911 stats.mGlobalFilterCount++;2912 }2913 2914 stats.mAvgFilterRadius += radius;2915 2916 // cout<<"box = "<<box<<endl;2917 // cout<<"distance = "<<distance<<endl;2918 // cout<<"radiues = "<<radius<<endl;2919 2920 box.Enlarge(Vector3(radius));2921 objects.clear();2922 2923 // $$ warning collect objects takes only unmailed ones!2924 CollectObjects(box, objects);2925 2926 // cout<<"collected objects="<<objects.size()<<endl;2927 ObjectContainer::const_iterator noi = objects.begin();2928 for (; noi != objects.end(); ++ noi)2929 {2930 Intersectable *o = *noi;2931 // $$ JB warning: pdfs are not correct at this point!2932 pvs.AddSampleDirty(o, Limits::Small);2933 }2934 }2935 2936 stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount);2937 }2938 2939 Debug<<" nPvs size = "<<pvs.GetSize()<<endl;2940 2941 #if !USE_KD_PVS2942 // copy the base pvs to the new pvs2943 pit = basePvs.GetIterator();2944 while (pit.HasMoreEntries())2945 {2946 ObjectPvsEntry entry = pit.Next();2947 pvs.AddSampleDirty(entry.mObject, entry.mData.mSumPdf);2948 }2949 #endif2950 viewCell->SetFilteredPvsSize(pvs.GetSize());2951 2952 Intersectable::NewMail();2953 2954 return stats;2955 }2956 #endif2957 2763 2958 2764 … … 6043 5849 6044 5850 6045 #define PVS_ADD_DIRTY 16046 6047 float6048 VspOspViewCellsManager::ComputeSampleContribution(VssRay &ray,6049 const bool addRays,6050 const bool storeViewCells)6051 {6052 ray.mPvsContribution = 0;6053 ray.mRelativePvsContribution = 0.0f;6054 6055 if (ray.mTerminationObject==NULL)6056 return 0.0f;6057 6058 ViewCellContainer viewcells;6059 6060 static Ray hray;6061 hray.Init(ray);6062 6063 float tmin = 0, tmax = 1.0;6064 6065 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax))6066 return 0;6067 6068 Vector3 origin = hray.Extrap(tmin);6069 Vector3 termination = hray.Extrap(tmax);6070 6071 ViewCell::NewMail();6072 6073 // traverse the view space subdivision6074 CastLineSegment(origin, termination, viewcells);6075 6076 if (storeViewCells)6077 {6078 // copy viewcells memory efficiently6079 ray.mViewCells.reserve(viewcells.size());6080 ray.mViewCells = viewcells;6081 }6082 6083 ViewCellContainer::const_iterator it = viewcells.begin();6084 6085 Intersectable *terminationObj = GetIntersectable(ray, true);6086 6087 #if SAMPLE_ORIGIN_OBJECTS6088 Intersectable *originObj = GetIntersectable(ray, false);6089 #endif6090 6091 for (; it != viewcells.end(); ++ it)6092 {6093 ViewCell *viewcell = *it;6094 6095 if (viewcell->GetValid())6096 { // if ray not outside of view space6097 float contribution;6098 6099 if (terminationObj)6100 {6101 // todo: maybe not correct for kd node pvs6102 if (viewcell->GetPvs().GetSampleContribution(6103 terminationObj, ray.mPdf, contribution))6104 {6105 ++ ray.mPvsContribution;6106 }6107 6108 ray.mRelativePvsContribution += contribution;6109 }6110 6111 ////////////////6112 //-- for directional sampling it is important to count6113 //-- only contributions made in one direction!6114 //-- the other contributions of this sample will be counted for the opposite ray!6115 6116 #if SAMPLE_ORIGIN_OBJECTS6117 6118 if (originObj &&6119 viewcell->GetPvs().GetSampleContribution(originObj,6120 ray.mPdf,6121 contribution))6122 {6123 ++ ray.mPvsContribution;6124 ray.mRelativePvsContribution += contribution;6125 }6126 #endif6127 }6128 }6129 6130 if (!addRays) {6131 return ray.mRelativePvsContribution;6132 }6133 6134 // sampled objects are stored in the pvs6135 for (it = viewcells.begin(); it != viewcells.end(); ++ it) {6136 ViewCell *viewCell = *it;6137 6138 if (!viewCell->GetValid())6139 break;6140 6141 //$$JB hack6142 6143 #if PVS_ADD_DIRTY6144 viewCell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf);6145 #else6146 viewCell->GetPvs().AddSample(terminationObj, ray.mPdf);6147 #endif6148 6149 #if SAMPLE_ORIGIN_OBJECTS6150 #if PVS_ADD_DIRTY6151 viewCell->GetPvs().AddSampleDirtyCheck(originObj, ray.mPdf);6152 #else6153 viewCell->GetPvs().AddSample(originObj, ray.mPdf);6154 #endif6155 #endif6156 if (viewCell->GetPvs().RequiresResort()) {6157 viewCell->GetPvs().Sort();6158 }6159 }6160 6161 return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution +6162 (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution;6163 }6164 5851 6165 5852 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1867 r1877 1128 1128 /** Stores sample contribution for kd cells or objects. 1129 1129 */ 1130 virtual float ComputeSampleContribution(VssRay &ray,1131 const bool addRays,1132 const bool storeViewCells);1130 // virtual float ComputeSampleContribution(VssRay &ray, 1131 // const bool addRays, 1132 // const bool storeViewCells); 1133 1133 1134 1134 ViewCellsManager *LoadViewCells(const string &filename, -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r1876 r1877 89 89 90 90 RssPreprocessor { 91 92 distributions rss+spatial+object 93 91 94 samplesPerPass 1000 92 95 initialSamples 2000000 93 vssSamples 2000000094 vssSamplesPerPass 300000096 vssSamples 50000000 97 vssSamplesPerPass 2000000 95 98 useImportanceSampling true 96 99 … … 102 105 rssTree false 103 106 rays true 104 numRays 10000107 numRays 5000 105 108 } 106 109 … … 128 131 maxCostRatio 1.0 129 132 maxRayContribution 1.0 130 maxRays 1000000 0133 maxRays 1000000 131 134 maxTotalMemory 400 132 135 maxStaticMemory 200 … … 137 140 hybridDepth 10 138 141 splitUseOnlyDrivingAxis false 139 #false140 142 importanceBasedCost false 141 143 -
GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
r1867 r1877 2 2 3 3 #COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+" 4 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter +"4 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter-" 5 5 6 6 #SCENE="../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d"
Note: See TracChangeset
for help on using the changeset viewer.