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

Revision 997, 2.5 KB checked in by mattausch, 18 years ago (diff)

fixed bug for histogram
improved samplerenderer
todo: difference detectempty true / false

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