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

Revision 605, 4.4 KB checked in by mattausch, 18 years ago (diff)
Line 
1#include "RenderSimulator.h"
2#include "KdTree.h"
3#include "ViewCellBsp.h"
4#include "ViewCell.h"
5#include "VspBspTree.h"
6#include "VspKdTree.h"
7#include "ViewCellsManager.h"
8
9void SimulationStatistics::Print(ostream &app) const
10{
11        app << "===== Render Simulation statistics ===============\n";
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
23        app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n"
24                << avgRtWithoutOverhead << "\n";
25       
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       
35        app << "===== END OF Render Simulation statistics ==========\n";
36}
37
38RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager):
39Renderer(NULL, viewCellsManager),
40mObjRenderCost(0.0f),
41mVcOverhead(0.0f),
42mMoveSpeed(0.0f)
43{}
44
45
46RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager,
47                                                                 float objRenderCost,
48                                                                 float vcOverhead,
49                                                                 float moveSpeed):
50Renderer(NULL, viewCellsManager),
51mObjRenderCost(objRenderCost),
52mVcOverhead(vcOverhead),
53mMoveSpeed(moveSpeed)
54{
55}
56
57
58void RenderSimulator::SetObjectRenderCost(const float objRenderCost)
59{
60        mObjRenderCost = objRenderCost;
61}
62
63
64void RenderSimulator::SetVcOverhead(const float vcOverhead)
65{
66        mVcOverhead = vcOverhead;
67}
68
69
70void RenderSimulator::SetMoveSpeed(const float moveSpeed)
71{
72        mMoveSpeed = moveSpeed;
73}
74
75
76bool RenderSimulator::RenderScene()
77{
78        mSimulationStatistics.Reset();
79        mSimulationStatistics.Start();
80
81        Real renderTime = 0;
82        Real validRenderTime = 0;
83
84        // overhead for loading the PVS of the view cells
85        float loadPvsOverhead = 0;
86        float validLoadPvsOverhead = 0;
87
88        ViewCellContainer::const_iterator it,
89                it_end = mViewCellsManager->GetViewCells().end();
90
91       
92        for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it)
93        {
94                ViewCell *vc = *it;
95
96                const bool valid = vc->GetValid();
97       
98
99                // probability of view cell
100                const float pInVc = mViewCellsManager->GetProbability(vc);
101
102                //Debug << "vc prob: " << pInVc << endl;
103
104                // compute render time of PVS times probability
105                // that view point is in view cell
106                const float vcCost = pInVc *
107                        mViewCellsManager->GetRendercost(vc, mObjRenderCost);
108       
109                renderTime += vcCost;
110
111                // crossing the border of a view cell is depending on the move
112                // speed and the probability that a view cell border is crossed
113                loadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
114               
115                //-- update statistics
116
117                if (vcCost > mSimulationStatistics.maxCost)
118                        mSimulationStatistics.maxCost = vcCost;
119                else if (vcCost < mSimulationStatistics.minCost)
120                        mSimulationStatistics.minCost = vcCost;
121
122                //-- different statistics for only valid view cells
123                if (valid)
124                {
125                        validLoadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
126                        validRenderTime += vcCost;
127               
128                        if (vcCost > mSimulationStatistics.validMaxCost)
129                                mSimulationStatistics.validMaxCost = vcCost;
130                        else if (vcCost < mSimulationStatistics.validMinCost)
131                                mSimulationStatistics.validMinCost = vcCost;
132                }
133        }
134       
135        mSimulationStatistics.avgRtWithoutOverhead = renderTime;
136        mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead;
137
138        mSimulationStatistics.validAvgRtWithoutOverhead = renderTime;
139        mSimulationStatistics.validAvgRenderTime = renderTime + loadPvsOverhead;
140       
141        mSimulationStatistics.Stop();
142
143        return true;
144}
145
146
147float RenderSimulator::GetCrossVcProbability() const
148{
149        // assume the view cells are uniformly distributed
150        //NOTE: should I take move speed relative to view space or absolute?
151        const float vcNum =
152                (float)mViewCellsManager->GetViewCells().size();
153
154        const float prop = mMoveSpeed * vcNum;
155
156        // clamp probability between 0 and 1
157        return min(1.0f, prop);
158}
159
160void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const
161{
162        simStats = mSimulationStatistics;
163}
Note: See TracBrowser for help on using the repository browser.