Changeset 1891 for GTP/trunk/Lib/Vis
- Timestamp:
- 12/13/06 23:12:27 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r1884 r1891 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: st 13. XII 00:50:2420063 # Generated by qmake (2.00a) (Qt 4.1.2) on: st 13. XII 23:09:08 2006 4 4 # Project: preprocessor.pro 5 5 # Template: app -
GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorFactory.cpp
r1486 r1891 6 6 #include "RenderSampler.h" 7 7 #include "GvsPreprocessor.h" 8 #include "CombinedPreprocessor.h" 8 9 9 10 … … 17 18 return new VssPreprocessor(); 18 19 } 19 20 21 if (preprocessorType == "combined") 22 { 23 return new CombinedPreprocessor(); 24 } 25 20 26 if (preprocessorType == "rss") 21 27 { -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r1884 r1891 435 435 Randomize(0); 436 436 437 if ( 1) {437 if (0) { 438 438 Exporter *exporter = Exporter::GetExporter("samples.wrl"); 439 439 exporter->SetFilled(); … … 501 501 char *curr = buff; 502 502 mUseRssTree = false; 503 503 504 while (1) { 504 505 char *e = strchr(curr,'+'); … … 542 543 mMixtureDistribution->Init(); 543 544 bool oldGenerator = false; 545 546 const int batch = 100000; 544 547 545 548 if (mLoadInitialSamples) { … … 579 582 580 583 } else { 581 const int batch = 1000;582 584 for (int i=0; i < mInitialSamples; i+=batch) { 583 585 rays.clear(); -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1884 r1891 29 29 #include "SceneGraph.h" 30 30 #include "SamplingStrategy.h" 31 #include "ViewCellsManager.h" 31 32 32 33 … … 2733 2734 // if small very high importance of the last sample 2734 2735 // if 1.0f then weighs = 1 1/2 1/3 1/4 2735 float passSampleWeightDecay = 1.0f;2736 float passSampleWeightDecay = 2.0f; 2736 2737 //float passSampleWeightDecay = 1000.0f; 2737 2738 … … 2740 2741 { 2741 2742 int passDiff = mCurrentPass - pass; 2743 if (passDiff < 0) { 2744 cerr<<"Error: passdif < 0"<<passDiff<<endl; 2745 exit(1); 2746 } 2742 2747 float weight; 2743 if ( 0)2748 if (1) 2744 2749 weight = 1.0f/(passDiff + passSampleWeightDecay); 2745 2750 else … … 2788 2793 RssTree::ComputeImportance(RssTreeLeaf *leaf) 2789 2794 { 2790 #if 12795 #if 0 2791 2796 if (leaf->mTotalRays) 2792 2797 leaf->mImportance = leaf->mTotalContribution / leaf->mTotalRays; … … 2856 2861 2857 2862 if (sumWeights != 0.0f) { 2863 #if 1 2858 2864 leaf->mImportance = 2859 sqr(((weightAbsContributions*sumContributions +2860 (1.0f - weightAbsContributions)*sumRelContributions)/sumWeights));2861 2862 //leaf->mImportance =2863 //(weightAbsContributions*maxContribution +2864 //(1.0f - weightAbsContributions)*maxRelContribution)/sumWeights;2865 2865 pow(((weightAbsContributions*sumContributions + 2866 (1.0f - weightAbsContributions)*sumRelContributions)/sumWeights), 3); 2867 #else 2868 leaf->mImportance = 2869 (weightAbsContributions*maxContribution + 2870 (1.0f - weightAbsContributions)*maxRelContribution)/sumWeights; 2871 #endif 2866 2872 } else 2867 2873 leaf->mImportance = 0.0f; … … 2877 2883 RssTreeNode::GetImportance() const 2878 2884 { 2879 // return sqr(mImportance);2885 // return mImportance*mImportance; 2880 2886 return mImportance; 2881 2887 } … … 3120 3126 float r[5]; 3121 3127 3122 if (mRssTree == NULL)3123 return false;3124 3125 3128 mHalton.GetNext(5, r); 3126 3129 3127 SimpleRayContainer rays; 3128 mRssTree->GenerateRay(r, rays); 3129 ray = rays[0]; 3130 3131 return false; 3130 if (mRssTree == NULL) { 3131 // use direction based distribution 3132 Vector3 origin, direction; 3133 mPreprocessor.mViewCellsManager->GetViewPoint(origin, Vector3(r[0], r[1], r[2])); 3134 3135 direction = UniformRandomVector(r[3], r[4]); 3136 3137 const float pdf = 1.0f; 3138 ray = SimpleRay(origin, direction, RSS_BASED_DISTRIBUTION, pdf); 3139 3140 } else { 3141 3142 SimpleRayContainer rays; 3143 mRssTree->GenerateRay(r, rays); 3144 ray = rays[0]; 3145 } 3146 3147 return true; 3132 3148 } 3133 3149 … … 3141 3157 /// compute view cell contribution of rays if view cells manager already constructed 3142 3158 // mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 3143 3144 3159 mRssTree->Construct(mPreprocessor.mObjects, vssRays); 3145 3160 mRssTree->stat.Print(mPreprocessor.mStats); … … 3147 3162 3148 3163 } else { 3164 mRssTree->SetPass(mPass); 3149 3165 Debug<<"Adding rays...\n"<<flush; 3150 3166 mRssTree->AddRays(vssRays); -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1888 r1891 5 5 #include "ViewCellsManager.h" 6 6 #include "AxisAlignedBox3.h" 7 7 #include "RssTree.h" 8 8 9 9 namespace GtpVisibilityPreprocessor { … … 475 475 for (int i=0; i < mDistributions.size(); i++) { 476 476 // small non-zero value 477 mDistributions[i]->m Rays = 1;477 mDistributions[i]->mTotalRays = 0; 478 478 // unit contribution per ray 479 mDistributions[i]->m Contribution = 1.0f;479 mDistributions[i]->mTotalContribution = 0.0f; 480 480 } 481 481 UpdateRatios(); … … 490 490 491 491 // pickup a distribution 492 for (int i=0; i < mDistributions.size() ; i++)492 for (int i=0; i < mDistributions.size()-1; i++) 493 493 if (r < mDistributions[i]->mRatio) 494 494 break; 495 495 496 496 return mDistributions[i]->GenerateSample(ray); 497 497 } … … 505 505 VssRayContainer::iterator it = vssRays.begin(); 506 506 507 for (i=0; i < mDistributions.size(); i++) { 508 mDistributions[i]->mContribution = 0; 509 mDistributions[i]->mRays = 0; 510 } 511 507 512 for(; it != vssRays.end(); ++it) { 508 513 VssRay *ray = *it; 509 for (i=0; i < mDistributions.size()-1; i++) 514 for (i=0; i < mDistributions.size()-1; i++) { 510 515 if (mDistributions[i]->mType == ray->mDistribution) 511 516 break; 517 } 518 512 519 float contribution = 513 mPreprocessor.mViewCellsManager->ComputeSampleContribution s(vssRays, true, false);520 mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray, true, false); 514 521 mDistributions[i]->mContribution += contribution; 515 522 mDistributions[i]->mRays ++; 523 524 mDistributions[i]->mTotalContribution += contribution; 525 mDistributions[i]->mTotalRays ++; 516 526 } 517 527 518 528 // now update the distributions with all the rays 519 for (i=0; i < mDistributions.size(); i++) 529 for (i=0; i < mDistributions.size(); i++) { 520 530 mDistributions[i]->Update(vssRays); 531 } 521 532 522 533 … … 531 542 int i; 532 543 for (i=0; i < mDistributions.size(); i++) { 533 float importance = mDistributions[i]->mContribution/mDistributions[i]->mRays; 544 cout<<i<<": c="<<mDistributions[i]->mContribution<< 545 " rays="<<mDistributions[i]->mRays<<endl; 546 float importance = 0.0f; 547 if (mDistributions[i]->mRays != 0) { 548 importance = pow(mDistributions[i]->mContribution/mDistributions[i]->mRays, 3); 549 } 550 if (importance < Limits::Small) 551 importance = Limits::Small; 534 552 mDistributions[i]->mRatio = importance; 535 553 sum += importance; 536 554 } 537 555 556 const float minratio = 0.05f; 557 float threshold = minratio*sum; 558 for (i=0; i < mDistributions.size(); i++) { 559 if (mDistributions[i]->mRatio < threshold) { 560 sum += threshold - mDistributions[i]->mRatio; 561 mDistributions[i]->mRatio = threshold; 562 } 563 } 538 564 539 565 mDistributions[0]->mRatio /= sum; 566 540 567 for (i=1; i < mDistributions.size(); i++) { 541 568 float r = mDistributions[i]->mRatio / sum; … … 548 575 cout<<endl; 549 576 } 550 } 551 552 577 578 579 580 bool 581 MixtureDistribution::Construct(char *str) 582 { 583 char *curr = str; 584 585 while (1) { 586 char *e = strchr(curr,'+'); 587 if (e!=NULL) { 588 *e=0; 589 } 590 591 if (strcmp(curr, "rss")==0) { 592 mDistributions.push_back(new RssBasedDistribution(mPreprocessor)); 593 } else 594 if (strcmp(curr, "object")==0) { 595 mDistributions.push_back(new ObjectBasedDistribution(mPreprocessor)); 596 } else 597 if (strcmp(curr, "spatial")==0) { 598 mDistributions.push_back(new SpatialBoxBasedDistribution(mPreprocessor)); 599 } else 600 if (strcmp(curr, "global")==0) { 601 mDistributions.push_back(new GlobalLinesDistribution(mPreprocessor)); 602 } else 603 if (strcmp(curr, "direction")==0) { 604 mDistributions.push_back(new DirectionBasedDistribution(mPreprocessor)); 605 } else 606 if (strcmp(curr, "object_direction")==0) { 607 mDistributions.push_back(new ObjectDirectionBasedDistribution(mPreprocessor)); 608 } else 609 if (strcmp(curr, "reverse_object")==0) { 610 mDistributions.push_back(new ReverseObjectBasedDistribution(mPreprocessor)); 611 } else 612 if (strcmp(curr, "reverse_viewspace_border")==0) { 613 mDistributions.push_back(new ReverseViewSpaceBorderBasedDistribution(mPreprocessor)); 614 } 615 616 if (e==NULL) 617 break; 618 curr = e+1; 619 } 620 621 Init(); 622 return true; 623 } 624 625 } 626 627 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1888 r1891 73 73 int mRays; 74 74 float mContribution; 75 float mTime;76 float mRatio;77 75 78 76 int mTotalRays; 79 77 float mTotalContribution; 78 79 float mTime; 80 float mRatio; 81 80 82 protected: 81 83 … … 159 161 SpatialBoxBasedDistribution(Preprocessor &preprocessor): 160 162 SamplingStrategy(preprocessor){ 161 mType = DIRECTION_BOX_BASED_DISTRIBUTION;163 mType = SPATIAL_BOX_BASED_DISTRIBUTION; 162 164 } 163 165 … … 172 174 ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor): 173 175 SamplingStrategy(preprocessor){ 174 mType = SPATIAL_BOX_BASED_DISTRIBUTION;176 mType = VIEWSPACE_BORDER_BASED_DISTRIBUTION; 175 177 } 176 178 … … 185 187 ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor): 186 188 SamplingStrategy(preprocessor){ 187 mType = SPATIAL_BOX_BASED_DISTRIBUTION;189 mType = REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION; 188 190 } 189 191 … … 199 201 public: 200 202 ViewCellBorderBasedDistribution(Preprocessor &preprocessor): 201 SamplingStrategy(preprocessor) {} 203 SamplingStrategy(preprocessor) { 204 mType = VIEWCELL_BORDER_BASED_DISTRIBUTION; 205 206 } 202 207 203 208 virtual bool GenerateSample(SimpleRay &ray); … … 261 266 UpdateRatios(); 262 267 268 // construct distribution mixyure from a string describing the required distributions 269 bool 270 Construct(char *str); 271 263 272 264 273 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1889 r1891 30 30 31 31 #define KD_PVS_AREA (1e-5f) 32 33 34 32 35 33 namespace GtpVisibilityPreprocessor { -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r1884 r1891 48 48 # type sampling 49 49 # type vss 50 type rss 50 # type rss 51 type combined 51 52 # type render 52 53 detectEmptyViewSpace true … … 88 89 } 89 90 91 90 92 RssPreprocessor { 91 93 92 94 # distributions rss+spatial+object_direction 93 distributions object_direction+spatial95 distributions rss+object_direction+spatial+object+direction 94 96 # distributions object_direction 95 97 96 samplesPerPass 100098 samplesPerPass 200000 97 99 initialSamples 2000000 98 100 vssSamples 50000000 99 vssSamplesPerPass 2000000101 vssSamplesPerPass 500000 100 102 useImportanceSampling true 101 103 … … 133 135 maxCostRatio 1.0 134 136 maxRayContribution 1.0 135 maxRays 1000000 137 maxRays 10000000 136 138 maxTotalMemory 400 137 139 maxStaticMemory 200 -
GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
r1883 r1891 109 109 InternalRayCaster.cpp IntelRayCaster.cpp \ 110 110 RayCaster.cpp PreprocessorFactory.cpp GvsPreprocessor.cpp \ 111 Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp QtGlViewer.cpp Mailable.cpp 111 Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp QtGlViewer.cpp \ 112 Mailable.cpp \ 113 CombinedPreprocessor.cpp 112 114 113 115
Note: See TracChangeset
for help on using the changeset viewer.