- Timestamp:
- 12/13/06 01:13:15 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
r1883 r1884 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (2.00a) (Qt 4.1.2) on: po 11. XII 10:42:2320063 # Generated by qmake (2.00a) (Qt 4.1.2) on: st 13. XII 00:50:24 2006 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 63 63 $(MAKE) -f $(MAKEFILE).Debug uninstall 64 64 65 Makefile: preprocessor.pro C:/Qt/4.1.2/mkspecs/win32-msvc 2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \65 Makefile: preprocessor.pro C:/Qt/4.1.2/mkspecs/win32-msvc.net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 66 66 C:\Qt\4.1.2\mkspecs\features\qt_config.prf \ 67 67 C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \ -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1883 r1884 1017 1017 1018 1018 1019 SamplingStrategy *Preprocessor::GenerateSamplingStrategy(const int strategyId) const1019 SamplingStrategy *Preprocessor::GenerateSamplingStrategy(const int strategyId) 1020 1020 { 1021 1021 switch (strategyId) -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1867 r1884 96 96 /** Returns the specified sample strategy, NULL if no valid strategy. 97 97 */ 98 SamplingStrategy *GenerateSamplingStrategy(const int strategyId) const;98 SamplingStrategy *GenerateSamplingStrategy(const int strategyId); 99 99 100 100 /** Export preprocessor data. -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r1883 r1884 537 537 curr = e+1; 538 538 } 539 540 mMixtureDistribution = new MixtureDistribution(*this); 541 mMixtureDistribution->mDistributions = mDistributions; 542 mMixtureDistribution->Init(); 543 bool oldGenerator = false; 539 544 540 545 if (mLoadInitialSamples) { … … 545 550 SimpleRayContainer rays; 546 551 547 cout<<"Generating initial rays..."<<endl<<flush; 548 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 564 565 566 cout<<"Casting initial rays..."<<endl<<flush; 567 CastRays(rays, mVssRays, true, pruneInvalidRays); 568 569 ExportObjectRays(mVssRays, 1546); 552 if (oldGenerator) { 553 554 cout<<"Generating initial rays..."<<endl<<flush; 555 556 int count = 0; 557 int i; 558 559 // Generate initial samples 560 for (i=0; i < mDistributions.size(); i++) 561 if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 562 count++; 563 564 for (i=0; i < mDistributions.size(); i++) 565 if (mDistributions[i]->mType != SamplingStrategy::RSS_BASED_DISTRIBUTION) 566 GenerateRays(mInitialSamples/count, 567 *mDistributions[i], 568 rays); 569 570 cout<<"Casting initial rays..."<<endl<<flush; 571 CastRays(rays, mVssRays, true, pruneInvalidRays); 572 573 ExportObjectRays(mVssRays, 1546); 574 575 cout<<"Computing sample contributions..."<<endl<<flush; 576 // evaluate contributions of the intitial rays 577 mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 578 cout<<"done.\n"<<flush; 579 580 } else { 581 const int batch = 1000; 582 for (int i=0; i < mInitialSamples; i+=batch) { 583 rays.clear(); 584 mVssRays.clear(); 585 mMixtureDistribution->GenerateSamples(batch, rays); 586 CastRays(rays, mVssRays, true, pruneInvalidRays); 587 mMixtureDistribution->ComputeContributions(mVssRays); 588 } 589 } 570 590 } 571 591 … … 593 613 } 594 614 595 cout<<"Computing sample contributions..."<<endl<<flush;596 // evaluate contributions of the intitial rays597 mViewCellsManager->ComputeSampleContributions(mVssRays, true, false);598 cout<<"done.\n"<<flush;599 615 600 616 long time = GetTime(); -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h
r1867 r1884 7 7 #include "Preprocessor.h" 8 8 #include "VssRay.h" 9 #include "SamplingStrategy.h" 9 10 10 11 namespace GtpVisibilityPreprocessor { … … 22 23 public: 23 24 vector<SamplingStrategy *> mDistributions; 25 MixtureDistribution *mMixtureDistribution; 24 26 int mSamplesPerPass; 25 27 int mRssSamplesPerPass; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1883 r1884 1922 1922 1923 1923 GenerateLeafRay(params, rays, node->bbox, node->dirBBox); 1924 1925 1926 1924 } 1927 1925 … … 3117 3115 3118 3116 3119 3120 3121 } 3117 bool 3118 RssBasedDistribution::GenerateSample(SimpleRay &ray) 3119 { 3120 float r[5]; 3121 3122 if (mRssTree == NULL) 3123 return false; 3124 3125 mHalton.GetNext(5, r); 3126 3127 SimpleRayContainer rays; 3128 mRssTree->GenerateRay(r, rays); 3129 ray = rays[0]; 3130 3131 return false; 3132 } 3133 3134 void 3135 RssBasedDistribution::Update(VssRayContainer &vssRays) 3136 { 3137 if (mRssTree == NULL) { 3138 mRssTree = new RssTree; 3139 mRssTree->SetPass(mPass); 3140 3141 /// compute view cell contribution of rays if view cells manager already constructed 3142 // mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 3143 3144 mRssTree->Construct(mPreprocessor.mObjects, vssRays); 3145 mRssTree->stat.Print(mPreprocessor.mStats); 3146 cout<<"RssTree root PVS size = "<<mRssTree->GetRootPvsSize()<<endl; 3147 3148 } else { 3149 Debug<<"Adding rays...\n"<<flush; 3150 mRssTree->AddRays(vssRays); 3151 Debug<<"done.\n"<<flush; 3152 if (1) { 3153 // if (mUpdateSubdivision) { 3154 Debug<<"Updating rss tree...\n"<<flush; 3155 int subdivided = mRssTree->UpdateSubdivision(); 3156 Debug<<"done.\n"<<flush; 3157 cout<<"subdivided leafs = "<<subdivided<<endl; 3158 cout<<"#total leaves = "<<mRssTree->stat.Leaves()<<endl; 3159 } 3160 } 3161 mPass++; 3162 } 3163 3164 } -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h
r1877 r1884 27 27 28 28 #include "Containers.h" 29 #include "SamplingStrategy.h" 29 30 30 31 namespace GtpVisibilityPreprocessor { … … 1115 1116 }; 1116 1117 1118 1119 class RssBasedDistribution: public SamplingStrategy 1120 { 1121 public: 1122 HaltonSequence mHalton; 1123 RssTree *mRssTree; 1124 // id of sampling pass (a pass is defined by two consecutive updates) 1125 int mPass; 1126 1127 RssBasedDistribution(Preprocessor &preprocessor): 1128 SamplingStrategy(preprocessor){ 1129 mType = RSS_BASED_DISTRIBUTION; 1130 mRssTree = NULL; 1131 mPass = 0; 1132 } 1133 1134 virtual void Update(VssRayContainer &vssRays); 1135 1136 private: 1137 1138 virtual bool GenerateSample(SimpleRay &ray); 1139 1117 1140 }; 1118 1141 1142 1143 }; 1144 1119 1145 #endif // __RSSTREE_H__ 1120 1146 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1883 r1884 10 10 11 11 12 SamplingStrategy::SamplingStrategy( constPreprocessor &preprocessor):12 SamplingStrategy::SamplingStrategy(Preprocessor &preprocessor): 13 13 mPreprocessor(preprocessor), mRatio(1.0f), mTotalRays(0), mTotalContribution(0.0f) 14 14 { … … 401 401 402 402 403 bool404 RssBasedDistribution::GenerateSample(SimpleRay &ray)405 {406 return false;407 }408 403 409 404 … … 463 458 MixtureDistribution::Init() 464 459 { 465 466 } 467 468 // Generate a new sample according to a mixture distribution 460 for (int i=0; i < mDistributions.size(); i++) { 461 // small non-zero value 462 mDistributions[i]->mRays = 1; 463 // unit contribution per ray 464 if (1 || mDistributions[i]->mType != RSS_BASED_DISTRIBUTION) 465 mDistributions[i]->mContribution = 1.0f; 466 else 467 mDistributions[i]->mContribution = 0.0f; 468 } 469 UpdateRatios(); 470 } 471 472 void 473 MixtureDistribution::Reset() 474 { 475 for (int i=0; i < mDistributions.size(); i++) { 476 // small non-zero value 477 mDistributions[i]->mRays = 1; 478 // unit contribution per ray 479 mDistributions[i]->mContribution = 1.0f; 480 } 481 UpdateRatios(); 482 } 483 484 // Generate a new sample according to a mixture distribution 469 485 bool 470 486 MixtureDistribution::GenerateSample(SimpleRay &ray) 471 487 { 472 473 return false; 488 float r; 489 mHalton.GetNext(1, &r); 490 491 // pickup a distribution 492 for (int i=0; i < mDistributions.size(); i++) 493 if (r < mDistributions[i]->mRatio) 494 break; 495 496 return mDistributions[i]->GenerateSample(ray); 474 497 } 475 498 476 499 // add contributions of the sample to the strategies 477 500 void 478 MixtureDistribution::UpdateContributions(VssRayContainer &vssRays) 479 { 480 481 } 482 483 } 484 485 501 MixtureDistribution::ComputeContributions(VssRayContainer &vssRays) 502 { 503 int i; 504 505 VssRayContainer::iterator it = vssRays.begin(); 506 507 for(; it != vssRays.end(); ++it) { 508 VssRay *ray = *it; 509 for (i=0; i < mDistributions.size()-1; i++) 510 if (mDistributions[i]->mType == ray->mDistribution) 511 break; 512 float contribution = 513 mPreprocessor.mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 514 mDistributions[i]->mContribution + contribution; 515 mDistributions[i]->mRays ++; 516 } 517 518 // now update the distributions with all the rays 519 for (i=0; i < mDistributions.size(); i++) 520 mDistributions[i]->Update(vssRays); 521 522 523 UpdateRatios(); 524 } 525 526 void 527 MixtureDistribution::UpdateRatios() 528 { 529 // now compute importance (ratio) of all distributions 530 float sum = 0.0f; 531 int i; 532 for (i=0; i < mDistributions.size(); i++) { 533 float importance = mDistributions[i]->mContribution/mDistributions[i]->mRays; 534 mDistributions[i]->mRatio = importance; 535 sum += importance; 536 } 537 538 539 mDistributions[0]->mRatio /= sum; 540 for (i=1; i < mDistributions.size(); i++) { 541 float r = mDistributions[i]->mRatio / sum; 542 mDistributions[i]->mRatio = mDistributions[i-1]->mRatio + r; 543 } 544 545 cout<<"ratios: "; 546 for (i=0; i < mDistributions.size(); i++) 547 cout<<mDistributions[i]->mRatio<<" "; 548 cout<<endl; 549 } 550 } 551 552 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1883 r1884 45 45 /** Default constructor 46 46 */ 47 SamplingStrategy( constPreprocessor &preprocessor);47 SamplingStrategy(Preprocessor &preprocessor); 48 48 49 49 virtual ~SamplingStrategy(); … … 55 55 virtual int GenerateSamples(const int number, SimpleRayContainer &rays); 56 56 57 private:58 57 59 58 virtual bool GenerateSample(SimpleRay &ray) = 0; 59 60 61 62 virtual void Update(VssRayContainer &vssRays) {} 63 64 65 66 friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) { 67 return a->mRatio < b->mRatio; 68 } 60 69 61 70 public: … … 71 80 protected: 72 81 73 constPreprocessor &mPreprocessor;82 Preprocessor &mPreprocessor; 74 83 75 84 }; … … 81 90 HaltonSequence mHalton; 82 91 83 ObjectBasedDistribution( constPreprocessor &preprocessor):92 ObjectBasedDistribution(Preprocessor &preprocessor): 84 93 SamplingStrategy(preprocessor) { 85 94 mType = OBJECT_BASED_DISTRIBUTION; … … 95 104 public: 96 105 97 ReverseObjectBasedDistribution( constPreprocessor &preprocessor):106 ReverseObjectBasedDistribution(Preprocessor &preprocessor): 98 107 SamplingStrategy(preprocessor) { 99 108 mType = REVERSE_OBJECT_BASED_DISTRIBUTION; … … 110 119 111 120 public: 112 ObjectDirectionBasedDistribution( constPreprocessor &preprocessor):121 ObjectDirectionBasedDistribution(Preprocessor &preprocessor): 113 122 SamplingStrategy(preprocessor) { 114 123 mType = OBJECT_DIRECTION_BASED_DISTRIBUTION; … … 122 131 { 123 132 public: 124 DirectionBasedDistribution( constPreprocessor &preprocessor):133 DirectionBasedDistribution(Preprocessor &preprocessor): 125 134 SamplingStrategy(preprocessor){ 126 135 mType = DIRECTION_BASED_DISTRIBUTION; … … 134 143 { 135 144 public: 136 DirectionBoxBasedDistribution( constPreprocessor &preprocessor):145 DirectionBoxBasedDistribution(Preprocessor &preprocessor): 137 146 SamplingStrategy(preprocessor){ 138 147 mType = DIRECTION_BOX_BASED_DISTRIBUTION; … … 148 157 public: 149 158 HaltonSequence mHalton; 150 SpatialBoxBasedDistribution( constPreprocessor &preprocessor):159 SpatialBoxBasedDistribution(Preprocessor &preprocessor): 151 160 SamplingStrategy(preprocessor){ 152 161 mType = DIRECTION_BOX_BASED_DISTRIBUTION; … … 161 170 { 162 171 public: 163 ViewSpaceBorderBasedDistribution( constPreprocessor &preprocessor):172 ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor): 164 173 SamplingStrategy(preprocessor){ 165 174 mType = SPATIAL_BOX_BASED_DISTRIBUTION; … … 174 183 { 175 184 public: 176 ReverseViewSpaceBorderBasedDistribution( constPreprocessor &preprocessor):185 ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor): 177 186 SamplingStrategy(preprocessor){ 178 187 mType = SPATIAL_BOX_BASED_DISTRIBUTION; … … 184 193 185 194 186 class RssBasedDistribution: public SamplingStrategy187 {188 public:189 RssBasedDistribution(const Preprocessor &preprocessor):190 SamplingStrategy(preprocessor){191 mType = RSS_BASED_DISTRIBUTION;192 }193 194 195 virtual int GenerateSamples(const int number, SimpleRayContainer &ray) {196 // TBD!!!197 return 0;198 }199 200 private:201 virtual bool GenerateSample(SimpleRay &ray);202 203 };204 195 205 196 … … 207 198 { 208 199 public: 209 ViewCellBorderBasedDistribution( constPreprocessor &preprocessor):200 ViewCellBorderBasedDistribution(Preprocessor &preprocessor): 210 201 SamplingStrategy(preprocessor) {} 211 202 … … 219 210 HaltonSequence mHalton; 220 211 221 GlobalLinesDistribution( constPreprocessor &preprocessor):212 GlobalLinesDistribution(Preprocessor &preprocessor): 222 213 SamplingStrategy(preprocessor) { 223 214 mType = GLOBAL_LINES_DISTRIBUTION; … … 234 225 { 235 226 public: 236 ObjectsInteriorDistribution( constPreprocessor &preprocessor):227 ObjectsInteriorDistribution(Preprocessor &preprocessor): 237 228 SamplingStrategy(preprocessor) {} 238 229 … … 249 240 vector<SamplingStrategy *> mDistributions; 250 241 251 MixtureDistribution( constPreprocessor &preprocessor):242 MixtureDistribution(Preprocessor &preprocessor): 252 243 SamplingStrategy(preprocessor) 253 244 { … … 256 247 // has to called before first usage 257 248 void Init(); 249 250 // equalize distribution contributions 251 void 252 Reset(); 258 253 259 254 // Generate a new sample according to a mixture distribution … … 261 256 262 257 // add contributions of the sample to the strategies 263 void UpdateContributions(VssRayContainer &vssRays); 264 265 protected: 266 // distributions sorted according to their contribution 267 // used for new sample generation accordint to the pdf 268 vector<SamplingStrategy *> mSortedDistributions; 258 void ComputeContributions(VssRayContainer &vssRays); 259 260 void 261 UpdateRatios(); 262 269 263 270 264 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/default.env
r1883 r1884 90 90 RssPreprocessor { 91 91 92 distributions rss+spatial+object_direction 92 # distributions rss+spatial+object_direction 93 distributions object_direction+spatial 93 94 # distributions object_direction 94 95
Note: See TracChangeset
for help on using the changeset viewer.