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