[1891] | 1 | #include "SceneGraph.h"
|
---|
| 2 | #include "KdTree.h"
|
---|
| 3 | #include "X3dExporter.h"
|
---|
| 4 | #include "Environment.h"
|
---|
| 5 | #include "Polygon3.h"
|
---|
| 6 | #include "VssRay.h"
|
---|
| 7 | #include "RssTree.h"
|
---|
| 8 | #include "ViewCellsManager.h"
|
---|
| 9 | #include "RenderSimulator.h"
|
---|
| 10 | #include "GlRenderer.h"
|
---|
| 11 | #include "SamplingStrategy.h"
|
---|
| 12 | #include "PreprocessorThread.h"
|
---|
| 13 | #include "CombinedPreprocessor.h"
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | namespace GtpVisibilityPreprocessor {
|
---|
| 17 |
|
---|
| 18 | const bool pruneInvalidRays = false;
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | CombinedPreprocessor::CombinedPreprocessor():
|
---|
| 22 | Preprocessor()
|
---|
| 23 | {
|
---|
| 24 | // this should increase coherence of the samples
|
---|
| 25 | Environment::GetSingleton()->GetIntValue("RssPreprocessor.vssSamples", mTotalSamples);
|
---|
| 26 | Environment::GetSingleton()->GetIntValue("RssPreprocessor.samplesPerPass", mSamplesPerPass);
|
---|
| 27 | Environment::GetSingleton()->GetIntValue("RssPreprocessor.vssSamplesPerPass",
|
---|
| 28 | mSamplesPerEvaluation);
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | bool
|
---|
| 35 | CombinedPreprocessor::ComputeVisibility()
|
---|
| 36 | {
|
---|
| 37 |
|
---|
| 38 | Debug << "Preprocessor type: combined" << endl;
|
---|
| 39 | cout<<"Combined Preprocessor started\n"<<flush;
|
---|
| 40 |
|
---|
| 41 | // if not already loaded, construct view cells from file
|
---|
| 42 | if (!mLoadViewCells) {
|
---|
| 43 | // construct view cells using it's own set of samples
|
---|
| 44 | mViewCellsManager->Construct(this);
|
---|
| 45 |
|
---|
| 46 | //-- several visualizations and statistics
|
---|
| 47 | Debug << "view cells construction finished: " << endl;
|
---|
| 48 | mViewCellsManager->PrintStatistics(Debug);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | // now decode distribution string
|
---|
| 53 | char buff[1024];
|
---|
| 54 | Environment::GetSingleton()->GetStringValue("RssPreprocessor.distributions",
|
---|
| 55 | buff);
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | mMixtureDistribution = new MixtureDistribution(*this);
|
---|
| 59 | mMixtureDistribution->Construct(buff);
|
---|
| 60 |
|
---|
| 61 | SimpleRayContainer rays;
|
---|
| 62 | VssRayContainer vssRays;
|
---|
| 63 |
|
---|
| 64 | int lastEvaluation = 0;
|
---|
| 65 | int totalVssRays = 0;
|
---|
| 66 | mPass = 0;
|
---|
| 67 |
|
---|
| 68 | long startTime = GetTime();
|
---|
| 69 | for (int i=0; i < mTotalSamples; i += mSamplesPerPass, mPass++) {
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | cout<<"Progress : "<<(100.0f*i)/mTotalSamples<<"%"<<endl;
|
---|
| 73 | rays.clear();
|
---|
| 74 | vssRays.clear();
|
---|
| 75 |
|
---|
| 76 | mMixtureDistribution->GenerateSamples(mSamplesPerPass, rays);
|
---|
| 77 |
|
---|
| 78 | CastRays(rays, vssRays, true, pruneInvalidRays);
|
---|
[1894] | 79 | totalVssRays += (int)vssRays.size();
|
---|
[1900] | 80 |
|
---|
[1942] | 81 | mMixtureDistribution->ComputeContributions(vssRays);
|
---|
| 82 |
|
---|
[1900] | 83 | if (mExportRays) {
|
---|
| 84 | Debug<<"Exporting rays..."<<endl<<flush;
|
---|
| 85 | char filename[256];
|
---|
[1942] | 86 |
|
---|
| 87 | VssRayContainer contributingRays;
|
---|
| 88 | vssRays.GetContributingRays(contributingRays, 0);
|
---|
| 89 | sprintf(filename, "rss-crays-%04d.x3d", mPass);
|
---|
| 90 | ExportRays(filename, contributingRays, mExportNumRays);
|
---|
| 91 |
|
---|
[1900] | 92 | sprintf(filename, "rss-rays-i%04d.x3d", mPass);
|
---|
| 93 | ExportRays(filename, vssRays, mExportNumRays);
|
---|
[1942] | 94 |
|
---|
[1900] | 95 | Debug<<"done."<<endl<<flush;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[1942] | 98 | mMixtureDistribution->UpdateDistributions(vssRays);
|
---|
| 99 |
|
---|
[1900] | 100 | if (i - lastEvaluation >= mSamplesPerEvaluation) {
|
---|
| 101 | mViewCellsManager->PrintPvsStatistics(mStats);
|
---|
| 102 | mStats <<
|
---|
| 103 | "#Pass\n" <<mPass<<endl<<
|
---|
| 104 | "#Time\n" << TimeDiff(startTime, GetTime())<<endl<<
|
---|
| 105 | "#TotalSamples\n" <<i<<endl<<
|
---|
| 106 | "#RssSamples\n" <<totalVssRays<<endl;
|
---|
| 107 | lastEvaluation = i;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | if (!mMixtureDistribution->RequiresRays())
|
---|
| 113 | CLEAR_CONTAINER(vssRays);
|
---|
[1931] | 114 |
|
---|
| 115 | if (renderer) {
|
---|
| 116 | ComputeRenderError();
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[1891] | 119 | }
|
---|
[1942] | 120 |
|
---|
| 121 | EvalViewCellHistogram();
|
---|
| 122 |
|
---|
[1894] | 123 | return true;
|
---|
[1891] | 124 | }
|
---|
| 125 |
|
---|
| 126 | }
|
---|