[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"
|
---|
[2709] | 15 | #include <windows.h>
|
---|
[1891] | 16 |
|
---|
| 17 |
|
---|
| 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;
|
---|
[2593] | 69 |
|
---|
[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 |
|
---|
[2580] | 78 | mCurrentSamples = 0;
|
---|
| 79 |
|
---|
| 80 | for (mCurrentSamples =0; mCurrentSamples < mTotalSamples; mCurrentSamples += mSamplesPerPass, mPass++) {
|
---|
[2709] | 81 | while (mSynchronize)
|
---|
| 82 | {
|
---|
| 83 | // hack: sleep during walthrough computation
|
---|
| 84 | Sleep(1000);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[2012] | 87 | mRayCaster->InitPass();
|
---|
| 88 |
|
---|
[2580] | 89 | cout<<"Progress :"<<mCurrentSamples/1e6f<<"M rays, "<<(100.0f*mCurrentSamples)/mTotalSamples<<"%"<<endl;
|
---|
[2036] | 90 |
|
---|
[1891] | 91 | rays.clear();
|
---|
| 92 | vssRays.clear();
|
---|
| 93 |
|
---|
[2012] | 94 |
|
---|
[1891] | 95 | mMixtureDistribution->GenerateSamples(mSamplesPerPass, rays);
|
---|
[2574] | 96 |
|
---|
| 97 | cerr<<"Casting rays..."<<endl;
|
---|
[2586] | 98 |
|
---|
[1984] | 99 | bool doubleRays = true;
|
---|
| 100 | CastRays(rays, vssRays, doubleRays, pruneInvalidRays);
|
---|
[2574] | 101 | mTotalRaysCast += (int)vssRays.size();
|
---|
[2586] | 102 |
|
---|
[2574] | 103 | cerr<<"Done..."<<endl;
|
---|
[1900] | 104 |
|
---|
[2574] | 105 | cerr<<"Computing ray contributions..."<<endl;
|
---|
[1942] | 106 | mMixtureDistribution->ComputeContributions(vssRays);
|
---|
[2574] | 107 | cerr<<"Done..."<<endl;
|
---|
[1942] | 108 |
|
---|
[2015] | 109 |
|
---|
[1900] | 110 | if (mExportRays) {
|
---|
| 111 | Debug<<"Exporting rays..."<<endl<<flush;
|
---|
| 112 | char filename[256];
|
---|
[1942] | 113 |
|
---|
| 114 | VssRayContainer contributingRays;
|
---|
| 115 | vssRays.GetContributingRays(contributingRays, 0);
|
---|
| 116 | sprintf(filename, "rss-crays-%04d.x3d", mPass);
|
---|
| 117 | ExportRays(filename, contributingRays, mExportNumRays);
|
---|
| 118 |
|
---|
[1900] | 119 | sprintf(filename, "rss-rays-i%04d.x3d", mPass);
|
---|
| 120 | ExportRays(filename, vssRays, mExportNumRays);
|
---|
[1942] | 121 |
|
---|
[2002] | 122 |
|
---|
| 123 | if (mExportAnimation) {
|
---|
| 124 | rayBuffer.push_back(VssRayContainer());
|
---|
| 125 | vssRays.SelectRays(mExportNumRays, rayBuffer[rayBuffer.size()-1], true);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[1900] | 128 | Debug<<"done."<<endl<<flush;
|
---|
| 129 | }
|
---|
[2574] | 130 |
|
---|
[1942] | 131 | mMixtureDistribution->UpdateDistributions(vssRays);
|
---|
| 132 |
|
---|
[2580] | 133 | if (mCurrentSamples - lastEvaluation >= mSamplesPerEvaluation) {
|
---|
[2066] | 134 | Real time = TimeDiff(startTime, GetTime());
|
---|
[1900] | 135 | mViewCellsManager->PrintPvsStatistics(mStats);
|
---|
| 136 | mStats <<
|
---|
| 137 | "#Pass\n" <<mPass<<endl<<
|
---|
[2046] | 138 | "#Time\n" << time <<endl<<
|
---|
[2580] | 139 | "#TotalSamples\n" << mCurrentSamples <<endl<<
|
---|
[2574] | 140 | "#RssSamples\n" <<mTotalRaysCast<<endl;
|
---|
[2051] | 141 |
|
---|
| 142 | float last = 0.0f;
|
---|
| 143 | for (int k=0; k < 6; k++) {
|
---|
| 144 | float ratio = 0.0f;
|
---|
| 145 | if (k < mMixtureDistribution->mDistributions.size()) {
|
---|
| 146 | ratio = mMixtureDistribution->mDistributions[k]->mRatio-last;
|
---|
| 147 | last = mMixtureDistribution->mDistributions[k]->mRatio;;
|
---|
| 148 | }
|
---|
| 149 | mStats <<
|
---|
| 150 | "#Distribution"<<k<<endl<<
|
---|
| 151 | ratio<<endl;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[2580] | 154 | lastEvaluation = mCurrentSamples;
|
---|
[2051] | 155 |
|
---|
[2002] | 156 | if (renderer) {
|
---|
[2610] | 157 | cout<<"Evaluating render error"<<endl;
|
---|
[2002] | 158 | ComputeRenderError();
|
---|
[2680] | 159 | cout<<"finished evaluating error"<<endl;
|
---|
[2002] | 160 | }
|
---|
[1900] | 161 | }
|
---|
[2051] | 162 |
|
---|
| 163 |
|
---|
[2066] | 164 | Real time = TimeDiff(startTime, GetTime());
|
---|
[2049] | 165 | if (mTotalTime!= -1 && time/1000 > mTotalTime)
|
---|
| 166 | break;
|
---|
| 167 |
|
---|
[2012] | 168 | #if 0
|
---|
[1966] | 169 | cerr<<"deleting rays"<<endl;
|
---|
| 170 | //clear all unreferenced rays
|
---|
| 171 | for (int j=0; j < vssRays.size(); j++) {
|
---|
| 172 | if (vssRays[j]->RefCount() == 0)
|
---|
| 173 | delete vssRays[j];
|
---|
| 174 | }
|
---|
| 175 | cerr<<"done."<<endl;
|
---|
[2012] | 176 | #endif
|
---|
[1900] | 177 |
|
---|
[1966] | 178 | // if (!mMixtureDistribution->RequiresRays())
|
---|
| 179 | // CLEAR_CONTAINER(vssRays);
|
---|
[1931] | 180 |
|
---|
| 181 |
|
---|
[1891] | 182 | }
|
---|
[2002] | 183 |
|
---|
[1942] | 184 | EvalViewCellHistogram();
|
---|
| 185 |
|
---|
[2002] | 186 | if (mExportAnimation && mExportRays) {
|
---|
| 187 | char filename[64];
|
---|
| 188 | sprintf(filename, "rss-rays-i.x3d");
|
---|
| 189 | //rayBuffer.resize(mPass);
|
---|
| 190 | ExportRayAnimation(filename, rayBuffer);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[1894] | 193 | return true;
|
---|
[1891] | 194 | }
|
---|
| 195 |
|
---|
| 196 | }
|
---|