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

Revision 991, 2.3 KB checked in by mattausch, 18 years ago (diff)
  • 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        {cout << "here18 " << mSamples << endl;
33                renderer->SampleRenderCost(mSamples, samples);
34        }
35
36        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
37
38
39        //-- Evaluate properties
40       
41
42        //-- compute histogram from the samples
43        int avgPvs = 0;
44        int maxPvs = 0;
45
46        vector<int> histogram(intervals);
47 
48        int i;
49
50        /// initialise histogram
51        for (i = 0; i < intervals; ++ i)
52        {
53                histogram[i] = 0;
54        }
55
56       
57
58        for (i = 0; i < mSamples; ++ i)
59        {
60                if (samples[i].mVisibleObjects > maxPvs)
61                {
62                        maxPvs = samples[i].mVisibleObjects;
63                }
64
65                avgPvs += samples[i].mVisibleObjects;
66        }
67
68        // sometimes need need to unifiy maximum pvs to compare with other method's histograms
69        // => choose histoMaxPvs accordingly (higher than all pvsss)
70        const int maxVal = max(histoMaxVal, maxPvs);
71       
72        for (i = 0; i < mSamples; ++ i)
73        {
74                const int bin = (samples[i].mVisibleObjects * intervals) / maxVal;
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
88        Debug << "****************************************" << endl;
89        Debug << "From point queries: " << endl;
90
91        for (i = 0; i < intervals; ++ i)
92        {
93                outstream << "#Pass\n" << i << endl;
94                outstream << "#Pvs\n" << histogram[i] << endl;
95                //cout << histogram[i] << endl;
96        }
97
98        outstream.close();
99
100        avgPvs /= mSamples;
101               
102        Debug << "max pvs: " << maxPvs << endl;
103        Debug << "avg pvs: " << avgPvs << endl;
104 
105        return true;
106}
107
108
109
110}
Note: See TracBrowser for help on using the repository browser.