source: GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp @ 2638

Revision 2638, 3.1 KB checked in by bittner, 16 years ago (diff)

siggraph submission

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