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

Revision 1004, 3.0 KB checked in by mattausch, 18 years ago (diff)

environment as a singleton

  • 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
[1001]29        Debug << "************* render sampler ****************" << endl;
30        Debug << "threshold: " << threshold << endl;
[991]31        const int intervals = histoIntervals;
32
33        cout << "starting sampling of render cost ... ";
34
[1002]35        vector<RenderCostSample> samples(mSamples);
36 
[991]37        if (renderer)
[997]38        {
[1001]39                renderer->SampleRenderCost(mSamples, samples, useOcclusionQueries, threshold);
[991]40        }
[871]41
[991]42        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
[871]43
44
[1000]45        //-- Evaluate results   
[991]46
47        //-- compute histogram from the samples
48        int avgPvs = 0;
49        int maxPvs = 0;
50
51        vector<int> histogram(intervals);
[871]52 
[1001]53
[997]54        // initialise histogram
55        for (int i = 0; i < intervals; ++ i)
[991]56        {
57                histogram[i] = 0;
58        }
[1004]59
[997]60        // store maximal pvs
61        for (int i = 0; i < mSamples; ++ i)
[991]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
[997]72        // => choose histoMaxPvs accordingly (higher than all pvss) ( but smaller than highest possible pvs?)
73
[991]74        const int maxVal = max(histoMaxVal, maxPvs);
[997]75        //const int maxVal = min(max(histoMaxVal, maxPvs), mObjects.size());
76
77        for (int i = 0; i < mSamples; ++ i)
[991]78        {
79                const int bin = (samples[i].mVisibleObjects * intervals) / maxVal;
[997]80                //const int bin = samples[i].mVisibleObjects;
[991]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
[997]96        for (int i = 0; i < intervals; ++ i)
[991]97        {
98                outstream << "#Pass\n" << i << endl;
[997]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;
[991]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;
[871]112 
[991]113        return true;
[871]114}
115
[991]116
117
[871]118}
Note: See TracBrowser for help on using the repository browser.