source: trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp @ 580

Revision 580, 4.4 KB checked in by mattausch, 19 years ago (diff)

implemented variance
started implementing merge history

RevLine 
[406]1#include "RenderSimulator.h"
2#include "KdTree.h"
3#include "ViewCellBsp.h"
4#include "ViewCell.h"
[448]5#include "VspBspTree.h"
[449]6#include "VspKdTree.h"
[468]7#include "ViewCellsManager.h"
[406]8
[463]9void SimulationStatistics::Print(ostream &app) const
10{
[475]11        app << "===== Render Simulation statistics ===============\n";
[463]12
13        app << setprecision(4);
14
15        app << "#N_CTIME  ( Simulation time [s] )\n" << Time() << " \n";
16
17        app << "#MAX_COST ( maximal cost of a view cell )\n" << maxCost << "\n";
18
19        app << "#MIN_COST ( minimal cost of a view cell )\n" << minCost << "\n";
20
21        app << "#AVG_RENDER_TIME ( average render time )\n" << avgRenderTime << "\n";
22
[475]23        app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n"
24                << avgRtWithoutOverhead << "\n";
[463]25       
[574]26        app << "#VALID_MAX_COST ( maximal cost of a valid view cell )\n" << validMaxCost << "\n";
27
28        app << "#VALID_MIN_COST ( minimal cost of a valid view cell )\n" << validMinCost << "\n";
29
30        app << "#VALID_AVG_RENDER_TIME ( average render time )\n" << validAvgRenderTime << "\n";
31
32        app << "#VALID_AVG_RENDER_TIME_NO_OVERHEAD ( valid average render time without overhead )\n"
33                << validAvgRtWithoutOverhead << "\n";
34       
[475]35        app << "===== END OF Render Simulation statistics ==========\n";
[414]36}
37
[473]38RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager):
[564]39Renderer(NULL, viewCellsManager),
40mObjRenderCost(0.0f),
41mVcOverhead(0.0f),
[574]42mMoveSpeed(0.0f)
[406]43{}
44
[564]45
[473]46RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager,
47                                                                 float objRenderCost,
[439]48                                                                 float vcOverhead,
49                                                                 float moveSpeed):
[497]50Renderer(NULL, viewCellsManager),
[439]51mObjRenderCost(objRenderCost),
52mVcOverhead(vcOverhead),
[574]53mMoveSpeed(moveSpeed)
[406]54{
55}
[463]56
[564]57
[463]58void RenderSimulator::SetObjectRenderCost(const float objRenderCost)
59{
60        mObjRenderCost = objRenderCost;
[439]61}
[406]62
[564]63
[463]64void RenderSimulator::SetVcOverhead(const float vcOverhead)
65{
66        mVcOverhead = vcOverhead;
67}
68
[574]69
[463]70void RenderSimulator::SetMoveSpeed(const float moveSpeed)
71{
72        mMoveSpeed = moveSpeed;
73}
74
[574]75
[468]76bool RenderSimulator::RenderScene()
[440]77{
[468]78        mSimulationStatistics.Reset();
79        mSimulationStatistics.Start();
[406]80
81        Real renderTime = 0;
[574]82        Real validRenderTime = 0;
83
[409]84        // overhead for loading the PVS of the view cells
85        float loadPvsOverhead = 0;
[574]86        float validLoadPvsOverhead = 0;
87
[468]88        ViewCellContainer::const_iterator it,
89                it_end = mViewCellsManager->GetViewCells().end();
[418]90
[475]91       
[468]92        for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it)
[406]93        {
[468]94                ViewCell *vc = *it;
[409]95
[580]96                const bool valid = vc->GetValid();
[574]97       
[564]98
[468]99                // probability of view cell
100                const float pInVc = mViewCellsManager->GetProbability(vc);
[551]101
[482]102                // compute render time of PVS times probability
103                // that view point is in view cell
104                const float vcCost = pInVc *
105                        mViewCellsManager->GetRendercost(vc, mObjRenderCost);
[479]106       
[551]107                // crossing the border of a view cell is depending on the move
108                // speed and the probability that a view cell border is crossed
[468]109                loadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
[574]110                renderTime += vcCost;
[482]111
[574]112                //-- update statistics
[482]113
[468]114                if (vcCost > mSimulationStatistics.maxCost)
115                        mSimulationStatistics.maxCost = vcCost;
116                else if (vcCost < mSimulationStatistics.minCost)
117                        mSimulationStatistics.minCost = vcCost;
[574]118
119                //-- different statistics for only valid view cells
120                if (valid)
121                {
122                        validLoadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
123                        validRenderTime += vcCost;
124               
125                        if (vcCost > mSimulationStatistics.validMaxCost)
126                                mSimulationStatistics.validMaxCost = vcCost;
127                        else if (vcCost < mSimulationStatistics.validMinCost)
128                                mSimulationStatistics.validMinCost = vcCost;
129                }
[448]130        }
131       
[468]132        mSimulationStatistics.avgRtWithoutOverhead = renderTime;
133        mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead;
[574]134
135        mSimulationStatistics.validAvgRtWithoutOverhead = renderTime;
136        mSimulationStatistics.validAvgRenderTime = renderTime + loadPvsOverhead;
[448]137       
[468]138        mSimulationStatistics.Stop();
[448]139
[468]140        return true;
[448]141}
142
[479]143
[477]144float RenderSimulator::GetCrossVcProbability() const
[448]145{
[477]146        // assume the view cells are uniformly distributed
[479]147        //NOTE: should I take move speed relative to view space or absolute?
[477]148        const float vcNum =
149                (float)mViewCellsManager->GetViewCells().size();
[476]150
[479]151        const float prop = mMoveSpeed * vcNum;
152
153        // clamp probability between 0 and 1
154        return min(1.0f, prop);
[448]155}
[449]156
[468]157void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const
[449]158{
[468]159        simStats = mSimulationStatistics;
[449]160}
Note: See TracBrowser for help on using the repository browser.