source: GTP/trunk/Lib/Vis/Preprocessing/src/RenderSimulator.cpp @ 1006

Revision 1006, 4.5 KB checked in by mattausch, 18 years ago (diff)

started viewspace-objectspace subdivision
removed memory leaks

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