#include "Environment.h" #include "RenderSampler.h" #include "GlRenderer.h" namespace GtpVisibilityPreprocessor { RenderSampler::RenderSampler():Preprocessor() { Environment::GetSingleton()->GetIntValue("RenderSampler.samples", mSamples); cout << "number of render samples: " << mSamples << endl; } bool RenderSampler::ComputeVisibility() { long startTime = GetTime(); int histoMaxVal = 0; int histoIntervals = 0; int threshold; bool useOcclusionQueries; Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal); Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.intervals", histoIntervals); Environment::GetSingleton()->GetIntValue("RenderSampler.visibleThreshold", threshold); Environment::GetSingleton()->GetBoolValue("RenderSampler.useOcclusionQueries", useOcclusionQueries); Debug << "************* render sampler ****************" << endl; Debug << "threshold: " << threshold << endl; const int intervals = histoIntervals; cout << "starting sampling of render cost ... "; vector samples(mSamples); if (renderer) { renderer->SampleRenderCost(mSamples, samples, useOcclusionQueries, threshold); } cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; //-- Evaluate results //-- compute histogram from the samples int avgPvs = 0; int maxPvs = 0; vector histogram(intervals); // initialise histogram for (int i = 0; i < intervals; ++ i) { histogram[i] = 0; } // store maximal pvs for (int i = 0; i < mSamples; ++ i) { if (samples[i].mVisibleObjects > maxPvs) { maxPvs = samples[i].mVisibleObjects; } avgPvs += samples[i].mVisibleObjects; } // sometimes need need to unifiy maximum pvs to compare with other method's histograms // => choose histoMaxPvs accordingly (higher than all pvss) ( but smaller than highest possible pvs?) const int maxVal = max(histoMaxVal, maxPvs); //const int maxVal = min(max(histoMaxVal, maxPvs), mObjects.size()); for (int i = 0; i < mSamples; ++ i) { const int bin = (samples[i].mVisibleObjects * intervals) / maxVal; //const int bin = samples[i].mVisibleObjects; ++ histogram[bin]; } //-- output the histogram const string filename("fromPointHisto.log"); std::ofstream outstream; outstream.open(filename.c_str()); Debug << "****************************************" << endl; Debug << "From point queries: " << endl; for (int i = 0; i < intervals; ++ i) { outstream << "#Pass\n" << i << endl; outstream << "#Pvs\n" << (float)(i * maxVal) / (float)intervals << endl; // HACK: #point samples substitute for volume outstream << "#VolumeDif\n" << (float)histogram[i] / (float)mSamples << endl; //cout << histogram[i] << endl; } outstream.close(); avgPvs /= mSamples; Debug << "max pvs: " << maxPvs << endl; Debug << "avg pvs: " << avgPvs << endl; return true; } }