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

Revision 2176, 4.5 KB checked in by mattausch, 17 years ago (diff)

removed using namespace std from .h

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