[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"
|
---|
[2012] | 14 | #include "RayCaster.h"
|
---|
[1891] | 15 |
|
---|
| 16 |
|
---|
[2015] | 17 |
|
---|
[1891] | 18 | namespace GtpVisibilityPreprocessor {
|
---|
| 19 |
|
---|
[2015] | 20 |
|
---|
[1966] | 21 | const bool pruneInvalidRays = true;
|
---|
[1891] | 22 |
|
---|
| 23 |
|
---|
| 24 | CombinedPreprocessor::CombinedPreprocessor():
|
---|
| 25 | Preprocessor()
|
---|
| 26 | {
|
---|
| 27 | // this should increase coherence of the samples
|
---|
[1966] | 28 | // Environment::GetSingleton()->GetIntValue("RssPreprocessor.vssSamples", mTotalSamples);
|
---|
| 29 | // Environment::GetSingleton()->GetIntValue("RssPreprocessor.samplesPerPass", mSamplesPerPass);
|
---|
| 30 | // Environment::GetSingleton()->GetIntValue("RssPreprocessor.vssSamplesPerPass",
|
---|
| 31 | // mSamplesPerEvaluation);
|
---|
[1891] | 32 |
|
---|
| 33 |
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[2049] | 36 |
|
---|
| 37 |
|
---|
[1891] | 38 | bool
|
---|
| 39 | CombinedPreprocessor::ComputeVisibility()
|
---|
| 40 | {
|
---|
| 41 |
|
---|
| 42 | Debug << "Preprocessor type: combined" << endl;
|
---|
| 43 | cout<<"Combined Preprocessor started\n"<<flush;
|
---|
| 44 |
|
---|
| 45 | // if not already loaded, construct view cells from file
|
---|
| 46 | if (!mLoadViewCells) {
|
---|
| 47 | // construct view cells using it's own set of samples
|
---|
| 48 | mViewCellsManager->Construct(this);
|
---|
| 49 |
|
---|
| 50 | //-- several visualizations and statistics
|
---|
| 51 | Debug << "view cells construction finished: " << endl;
|
---|
| 52 | mViewCellsManager->PrintStatistics(Debug);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | // now decode distribution string
|
---|
| 57 | char buff[1024];
|
---|
| 58 | Environment::GetSingleton()->GetStringValue("RssPreprocessor.distributions",
|
---|
| 59 | buff);
|
---|
| 60 |
|
---|
[2002] | 61 |
|
---|
[1891] | 62 | mMixtureDistribution = new MixtureDistribution(*this);
|
---|
| 63 | mMixtureDistribution->Construct(buff);
|
---|
| 64 |
|
---|
| 65 | SimpleRayContainer rays;
|
---|
| 66 | VssRayContainer vssRays;
|
---|
| 67 |
|
---|
| 68 | int lastEvaluation = 0;
|
---|
[2574] | 69 | // int totalVssRays = 0;
|
---|
[1891] | 70 | mPass = 0;
|
---|
| 71 |
|
---|
[2002] | 72 | vector<VssRayContainer> rayBuffer;
|
---|
[2012] | 73 | rays.reserve(mSamplesPerPass);
|
---|
| 74 | rayBuffer.reserve(2*mSamplesPerPass);
|
---|
[2002] | 75 |
|
---|
[1891] | 76 | long startTime = GetTime();
|
---|
[2048] | 77 |
|
---|
[1891] | 78 | for (int i=0; i < mTotalSamples; i += mSamplesPerPass, mPass++) {
|
---|
[2012] | 79 | mRayCaster->InitPass();
|
---|
| 80 |
|
---|
[2043] | 81 | cout<<"Progress :"<<i/1e6f<<"M rays, "<<(100.0f*i)/mTotalSamples<<"%"<<endl;
|
---|
[2036] | 82 |
|
---|
[1891] | 83 | rays.clear();
|
---|
| 84 | vssRays.clear();
|
---|
| 85 |
|
---|
[2012] | 86 |
|
---|
[1891] | 87 | mMixtureDistribution->GenerateSamples(mSamplesPerPass, rays);
|
---|
[2574] | 88 |
|
---|
| 89 | cerr<<"Casting rays..."<<endl;
|
---|
| 90 | // bool doubleRays = true;
|
---|
[1984] | 91 | bool doubleRays = true;
|
---|
| 92 | CastRays(rays, vssRays, doubleRays, pruneInvalidRays);
|
---|
[2574] | 93 | mTotalRaysCast += (int)vssRays.size();
|
---|
| 94 | cerr<<"Done..."<<endl;
|
---|
[1900] | 95 |
|
---|
[2574] | 96 | cerr<<"Computing ray contributions..."<<endl;
|
---|
[1942] | 97 | mMixtureDistribution->ComputeContributions(vssRays);
|
---|
[2574] | 98 | cerr<<"Done..."<<endl;
|
---|
[1942] | 99 |
|
---|
[2015] | 100 |
|
---|
[1900] | 101 | if (mExportRays) {
|
---|
| 102 | Debug<<"Exporting rays..."<<endl<<flush;
|
---|
| 103 | char filename[256];
|
---|
[1942] | 104 |
|
---|
| 105 | VssRayContainer contributingRays;
|
---|
| 106 | vssRays.GetContributingRays(contributingRays, 0);
|
---|
| 107 | sprintf(filename, "rss-crays-%04d.x3d", mPass);
|
---|
| 108 | ExportRays(filename, contributingRays, mExportNumRays);
|
---|
| 109 |
|
---|
[1900] | 110 | sprintf(filename, "rss-rays-i%04d.x3d", mPass);
|
---|
| 111 | ExportRays(filename, vssRays, mExportNumRays);
|
---|
[1942] | 112 |
|
---|
[2002] | 113 |
|
---|
| 114 | if (mExportAnimation) {
|
---|
| 115 | rayBuffer.push_back(VssRayContainer());
|
---|
| 116 | vssRays.SelectRays(mExportNumRays, rayBuffer[rayBuffer.size()-1], true);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[1900] | 119 | Debug<<"done."<<endl<<flush;
|
---|
| 120 | }
|
---|
[2574] | 121 |
|
---|
[1942] | 122 | mMixtureDistribution->UpdateDistributions(vssRays);
|
---|
| 123 |
|
---|
[1900] | 124 | if (i - lastEvaluation >= mSamplesPerEvaluation) {
|
---|
[2066] | 125 | Real time = TimeDiff(startTime, GetTime());
|
---|
[1900] | 126 | mViewCellsManager->PrintPvsStatistics(mStats);
|
---|
| 127 | mStats <<
|
---|
| 128 | "#Pass\n" <<mPass<<endl<<
|
---|
[2046] | 129 | "#Time\n" << time <<endl<<
|
---|
[1900] | 130 | "#TotalSamples\n" <<i<<endl<<
|
---|
[2574] | 131 | "#RssSamples\n" <<mTotalRaysCast<<endl;
|
---|
[2051] | 132 |
|
---|
| 133 | float last = 0.0f;
|
---|
| 134 | for (int k=0; k < 6; k++) {
|
---|
| 135 | float ratio = 0.0f;
|
---|
| 136 | if (k < mMixtureDistribution->mDistributions.size()) {
|
---|
| 137 | ratio = mMixtureDistribution->mDistributions[k]->mRatio-last;
|
---|
| 138 | last = mMixtureDistribution->mDistributions[k]->mRatio;;
|
---|
| 139 | }
|
---|
| 140 | mStats <<
|
---|
| 141 | "#Distribution"<<k<<endl<<
|
---|
| 142 | ratio<<endl;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[1900] | 145 | lastEvaluation = i;
|
---|
[2051] | 146 |
|
---|
[2002] | 147 | if (renderer) {
|
---|
| 148 | ComputeRenderError();
|
---|
| 149 | }
|
---|
[1900] | 150 | }
|
---|
[2051] | 151 |
|
---|
| 152 |
|
---|
[2066] | 153 | Real time = TimeDiff(startTime, GetTime());
|
---|
[2049] | 154 | if (mTotalTime!= -1 && time/1000 > mTotalTime)
|
---|
| 155 | break;
|
---|
| 156 |
|
---|
[2012] | 157 | #if 0
|
---|
[1966] | 158 | cerr<<"deleting rays"<<endl;
|
---|
| 159 | //clear all unreferenced rays
|
---|
| 160 | for (int j=0; j < vssRays.size(); j++) {
|
---|
| 161 | if (vssRays[j]->RefCount() == 0)
|
---|
| 162 | delete vssRays[j];
|
---|
| 163 | }
|
---|
| 164 | cerr<<"done."<<endl;
|
---|
[2012] | 165 | #endif
|
---|
[1900] | 166 |
|
---|
[1966] | 167 | // if (!mMixtureDistribution->RequiresRays())
|
---|
| 168 | // CLEAR_CONTAINER(vssRays);
|
---|
[1931] | 169 |
|
---|
| 170 |
|
---|
[1891] | 171 | }
|
---|
[2002] | 172 |
|
---|
[1942] | 173 | EvalViewCellHistogram();
|
---|
| 174 |
|
---|
[2002] | 175 | if (mExportAnimation && mExportRays) {
|
---|
| 176 | char filename[64];
|
---|
| 177 | sprintf(filename, "rss-rays-i.x3d");
|
---|
| 178 | //rayBuffer.resize(mPass);
|
---|
| 179 | ExportRayAnimation(filename, rayBuffer);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[1894] | 182 | return true;
|
---|
[1891] | 183 | }
|
---|
| 184 |
|
---|
| 185 | }
|
---|