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

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

siggraph submission

  • Property svn:executable set to *
RevLine 
[871]1#include "Environment.h"
2#include "RenderSampler.h"
3#include "GlRenderer.h"
4
5namespace GtpVisibilityPreprocessor {
6
7
8RenderSampler::RenderSampler():Preprocessor()
9{
[1004]10  Environment::GetSingleton()->GetIntValue("RenderSampler.samples", mSamples);
[991]11  cout << "number of render samples: " << mSamples << endl;
[871]12}
13
14bool
15RenderSampler::ComputeVisibility()
16{
[991]17        long startTime = GetTime();
18       
19        int histoMaxVal = 0;
20        int histoIntervals = 0;
[1001]21        int threshold;
22        bool useOcclusionQueries;
23
[1004]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);
[871]28
[2638]29#if SG08_HACK
30        // evaluate histogram of loaded pvs solution
31       
32
33
34
35#endif
36       
37       
38
39       
[1001]40        Debug << "************* render sampler ****************" << endl;
41        Debug << "threshold: " << threshold << endl;
[991]42        const int intervals = histoIntervals;
43
44        cout << "starting sampling of render cost ... ";
45
[1002]46        vector<RenderCostSample> samples(mSamples);
47 
[991]48        if (renderer)
[997]49        {
[1001]50                renderer->SampleRenderCost(mSamples, samples, useOcclusionQueries, threshold);
[991]51        }
[871]52
[991]53        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
[871]54
55
[1000]56        //-- Evaluate results   
[991]57
58        //-- compute histogram from the samples
59        int avgPvs = 0;
60        int maxPvs = 0;
61
62        vector<int> histogram(intervals);
[871]63 
[1001]64
[997]65        // initialise histogram
66        for (int i = 0; i < intervals; ++ i)
[991]67        {
68                histogram[i] = 0;
69        }
[1004]70
[997]71        // store maximal pvs
72        for (int i = 0; i < mSamples; ++ i)
[991]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
[997]83        // => choose histoMaxPvs accordingly (higher than all pvss) ( but smaller than highest possible pvs?)
84
[991]85        const int maxVal = max(histoMaxVal, maxPvs);
[997]86        //const int maxVal = min(max(histoMaxVal, maxPvs), mObjects.size());
87
88        for (int i = 0; i < mSamples; ++ i)
[991]89        {
90                const int bin = (samples[i].mVisibleObjects * intervals) / maxVal;
[997]91                //const int bin = samples[i].mVisibleObjects;
[991]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
[997]107        for (int i = 0; i < intervals; ++ i)
[991]108        {
109                outstream << "#Pass\n" << i << endl;
[997]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;
[991]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;
[871]123 
[991]124        return true;
[871]125}
126
[991]127
128
[871]129}
Note: See TracBrowser for help on using the repository browser.