[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 |
|
---|
[1966] | 18 | const bool pruneInvalidRays = true;
|
---|
[1891] | 19 |
|
---|
| 20 |
|
---|
| 21 | CombinedPreprocessor::CombinedPreprocessor():
|
---|
| 22 | Preprocessor()
|
---|
| 23 | {
|
---|
| 24 | // this should increase coherence of the samples
|
---|
[1966] | 25 | // Environment::GetSingleton()->GetIntValue("RssPreprocessor.vssSamples", mTotalSamples);
|
---|
| 26 | // Environment::GetSingleton()->GetIntValue("RssPreprocessor.samplesPerPass", mSamplesPerPass);
|
---|
| 27 | // Environment::GetSingleton()->GetIntValue("RssPreprocessor.vssSamplesPerPass",
|
---|
| 28 | // mSamplesPerEvaluation);
|
---|
[1891] | 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 |
|
---|
[2002] | 57 |
|
---|
[1891] | 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 |
|
---|
[2002] | 68 |
|
---|
| 69 |
|
---|
| 70 | bool mExportAnimation = false;
|
---|
| 71 | vector<VssRayContainer> rayBuffer;
|
---|
| 72 |
|
---|
| 73 |
|
---|
[1891] | 74 | long startTime = GetTime();
|
---|
| 75 | for (int i=0; i < mTotalSamples; i += mSamplesPerPass, mPass++) {
|
---|
| 76 |
|
---|
| 77 | cout<<"Progress : "<<(100.0f*i)/mTotalSamples<<"%"<<endl;
|
---|
| 78 | rays.clear();
|
---|
| 79 | vssRays.clear();
|
---|
| 80 |
|
---|
| 81 | mMixtureDistribution->GenerateSamples(mSamplesPerPass, rays);
|
---|
[1984] | 82 |
|
---|
| 83 | bool doubleRays = true;
|
---|
| 84 | CastRays(rays, vssRays, doubleRays, pruneInvalidRays);
|
---|
[1894] | 85 | totalVssRays += (int)vssRays.size();
|
---|
[1900] | 86 |
|
---|
[1942] | 87 | mMixtureDistribution->ComputeContributions(vssRays);
|
---|
| 88 |
|
---|
[1900] | 89 | if (mExportRays) {
|
---|
| 90 | Debug<<"Exporting rays..."<<endl<<flush;
|
---|
| 91 | char filename[256];
|
---|
[1942] | 92 |
|
---|
| 93 | VssRayContainer contributingRays;
|
---|
| 94 | vssRays.GetContributingRays(contributingRays, 0);
|
---|
| 95 | sprintf(filename, "rss-crays-%04d.x3d", mPass);
|
---|
| 96 | ExportRays(filename, contributingRays, mExportNumRays);
|
---|
| 97 |
|
---|
[1900] | 98 | sprintf(filename, "rss-rays-i%04d.x3d", mPass);
|
---|
| 99 | ExportRays(filename, vssRays, mExportNumRays);
|
---|
[1942] | 100 |
|
---|
[2002] | 101 |
|
---|
| 102 | if (mExportAnimation) {
|
---|
| 103 | rayBuffer.push_back(VssRayContainer());
|
---|
| 104 | vssRays.SelectRays(mExportNumRays, rayBuffer[rayBuffer.size()-1], true);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[1900] | 107 | Debug<<"done."<<endl<<flush;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[1942] | 110 | mMixtureDistribution->UpdateDistributions(vssRays);
|
---|
| 111 |
|
---|
[1900] | 112 | if (i - lastEvaluation >= mSamplesPerEvaluation) {
|
---|
| 113 | mViewCellsManager->PrintPvsStatistics(mStats);
|
---|
| 114 | mStats <<
|
---|
| 115 | "#Pass\n" <<mPass<<endl<<
|
---|
| 116 | "#Time\n" << TimeDiff(startTime, GetTime())<<endl<<
|
---|
| 117 | "#TotalSamples\n" <<i<<endl<<
|
---|
| 118 | "#RssSamples\n" <<totalVssRays<<endl;
|
---|
| 119 | lastEvaluation = i;
|
---|
[2002] | 120 |
|
---|
| 121 | if (renderer) {
|
---|
| 122 | ComputeRenderError();
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[1900] | 125 | }
|
---|
| 126 |
|
---|
[1966] | 127 | cerr<<"deleting rays"<<endl;
|
---|
| 128 | //clear all unreferenced rays
|
---|
| 129 | for (int j=0; j < vssRays.size(); j++) {
|
---|
| 130 | if (vssRays[j]->RefCount() == 0)
|
---|
| 131 | delete vssRays[j];
|
---|
| 132 | }
|
---|
| 133 | cerr<<"done."<<endl;
|
---|
| 134 |
|
---|
[1900] | 135 |
|
---|
[1966] | 136 | // if (!mMixtureDistribution->RequiresRays())
|
---|
| 137 | // CLEAR_CONTAINER(vssRays);
|
---|
[1931] | 138 |
|
---|
| 139 |
|
---|
[1891] | 140 | }
|
---|
[2002] | 141 |
|
---|
[1942] | 142 | EvalViewCellHistogram();
|
---|
| 143 |
|
---|
[2002] | 144 | if (mExportAnimation && mExportRays) {
|
---|
| 145 | char filename[64];
|
---|
| 146 | sprintf(filename, "rss-rays-i.x3d");
|
---|
| 147 | //rayBuffer.resize(mPass);
|
---|
| 148 | ExportRayAnimation(filename, rayBuffer);
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[1894] | 151 | return true;
|
---|
[1891] | 152 | }
|
---|
| 153 |
|
---|
| 154 | }
|
---|