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