1 | #include "Environment.h"
|
---|
2 | #include "RenderSampler.h"
|
---|
3 | #include "GlRenderer.h"
|
---|
4 |
|
---|
5 | namespace GtpVisibilityPreprocessor {
|
---|
6 |
|
---|
7 |
|
---|
8 | RenderSampler::RenderSampler():Preprocessor()
|
---|
9 | {
|
---|
10 | Environment::GetSingleton()->GetIntValue("RenderSampler.samples", mSamples);
|
---|
11 | cout << "number of render samples: " << mSamples << endl;
|
---|
12 | }
|
---|
13 |
|
---|
14 | bool
|
---|
15 | RenderSampler::ComputeVisibility()
|
---|
16 | {
|
---|
17 | long startTime = GetTime();
|
---|
18 |
|
---|
19 | int histoMaxVal = 0;
|
---|
20 | int histoIntervals = 0;
|
---|
21 | int threshold;
|
---|
22 | bool useOcclusionQueries;
|
---|
23 |
|
---|
24 | Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal);
|
---|
25 | Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.intervals", histoIntervals);
|
---|
26 | Environment::GetSingleton()->GetIntValue("RenderSampler.visibleThreshold", threshold);
|
---|
27 | Environment::GetSingleton()->GetBoolValue("RenderSampler.useOcclusionQueries", useOcclusionQueries);
|
---|
28 |
|
---|
29 | Debug << "************* render sampler ****************" << endl;
|
---|
30 | Debug << "threshold: " << threshold << endl;
|
---|
31 | const int intervals = histoIntervals;
|
---|
32 |
|
---|
33 | cout << "starting sampling of render cost ... ";
|
---|
34 |
|
---|
35 | vector<RenderCostSample> samples(mSamples);
|
---|
36 |
|
---|
37 | if (renderer)
|
---|
38 | {
|
---|
39 | renderer->SampleRenderCost(mSamples, samples, useOcclusionQueries, threshold);
|
---|
40 | }
|
---|
41 |
|
---|
42 | cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
|
---|
43 |
|
---|
44 |
|
---|
45 | //-- Evaluate results
|
---|
46 |
|
---|
47 | //-- compute histogram from the samples
|
---|
48 | int avgPvs = 0;
|
---|
49 | int maxPvs = 0;
|
---|
50 |
|
---|
51 | vector<int> histogram(intervals);
|
---|
52 |
|
---|
53 |
|
---|
54 | // initialise histogram
|
---|
55 | for (int i = 0; i < intervals; ++ i)
|
---|
56 | {
|
---|
57 | histogram[i] = 0;
|
---|
58 | }
|
---|
59 |
|
---|
60 | // store maximal pvs
|
---|
61 | for (int i = 0; i < mSamples; ++ i)
|
---|
62 | {
|
---|
63 | if (samples[i].mVisibleObjects > maxPvs)
|
---|
64 | {
|
---|
65 | maxPvs = samples[i].mVisibleObjects;
|
---|
66 | }
|
---|
67 |
|
---|
68 | avgPvs += samples[i].mVisibleObjects;
|
---|
69 | }
|
---|
70 |
|
---|
71 | // sometimes need need to unifiy maximum pvs to compare with other method's histograms
|
---|
72 | // => choose histoMaxPvs accordingly (higher than all pvss) ( but smaller than highest possible pvs?)
|
---|
73 |
|
---|
74 | const int maxVal = max(histoMaxVal, maxPvs);
|
---|
75 | //const int maxVal = min(max(histoMaxVal, maxPvs), mObjects.size());
|
---|
76 |
|
---|
77 | for (int i = 0; i < mSamples; ++ i)
|
---|
78 | {
|
---|
79 | const int bin = (samples[i].mVisibleObjects * intervals) / maxVal;
|
---|
80 | //const int bin = samples[i].mVisibleObjects;
|
---|
81 |
|
---|
82 | ++ histogram[bin];
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | //-- output the histogram
|
---|
87 |
|
---|
88 | const string filename("fromPointHisto.log");
|
---|
89 | std::ofstream outstream;
|
---|
90 | outstream.open(filename.c_str());
|
---|
91 |
|
---|
92 |
|
---|
93 | Debug << "****************************************" << endl;
|
---|
94 | Debug << "From point queries: " << endl;
|
---|
95 |
|
---|
96 | for (int i = 0; i < intervals; ++ i)
|
---|
97 | {
|
---|
98 | outstream << "#Pass\n" << i << endl;
|
---|
99 | outstream << "#Pvs\n" << (float)(i * maxVal) / (float)intervals << endl;
|
---|
100 |
|
---|
101 | // HACK: #point samples substitute for volume
|
---|
102 | outstream << "#VolumeDif\n" << (float)histogram[i] / (float)mSamples << endl;
|
---|
103 | //cout << histogram[i] << endl;
|
---|
104 | }
|
---|
105 |
|
---|
106 | outstream.close();
|
---|
107 |
|
---|
108 | avgPvs /= mSamples;
|
---|
109 |
|
---|
110 | Debug << "max pvs: " << maxPvs << endl;
|
---|
111 | Debug << "avg pvs: " << avgPvs << endl;
|
---|
112 |
|
---|
113 | return true;
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 | }
|
---|