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 |
|
---|
9 | void 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 << "===== END OF Render Simulation statistics ==========\n";
|
---|
27 | }
|
---|
28 |
|
---|
29 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager):
|
---|
30 | Renderer(NULL, viewCellsManager),
|
---|
31 | mObjRenderCost(0.0f),
|
---|
32 | mVcOverhead(0.0f),
|
---|
33 | mMoveSpeed(0.0f),
|
---|
34 | mOnlyValid(false)
|
---|
35 | {}
|
---|
36 |
|
---|
37 |
|
---|
38 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager,
|
---|
39 | float objRenderCost,
|
---|
40 | float vcOverhead,
|
---|
41 | float moveSpeed):
|
---|
42 | Renderer(NULL, viewCellsManager),
|
---|
43 | mObjRenderCost(objRenderCost),
|
---|
44 | mVcOverhead(vcOverhead),
|
---|
45 | mMoveSpeed(moveSpeed),
|
---|
46 | mOnlyValid(false)
|
---|
47 | {
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | void RenderSimulator::SetObjectRenderCost(const float objRenderCost)
|
---|
52 | {
|
---|
53 | mObjRenderCost = objRenderCost;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | void RenderSimulator::SetRenderOnlyValid(const bool renderOnlyValid)
|
---|
58 | {
|
---|
59 | mOnlyValid = renderOnlyValid;
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | void RenderSimulator::SetVcOverhead(const float vcOverhead)
|
---|
64 | {
|
---|
65 | mVcOverhead = vcOverhead;
|
---|
66 | }
|
---|
67 |
|
---|
68 | void RenderSimulator::SetMoveSpeed(const float moveSpeed)
|
---|
69 | {
|
---|
70 | mMoveSpeed = moveSpeed;
|
---|
71 | }
|
---|
72 |
|
---|
73 | bool RenderSimulator::RenderScene()
|
---|
74 | {
|
---|
75 | mSimulationStatistics.Reset();
|
---|
76 | mSimulationStatistics.Start();
|
---|
77 |
|
---|
78 | Real renderTime = 0;
|
---|
79 |
|
---|
80 | // overhead for loading the PVS of the view cells
|
---|
81 | float loadPvsOverhead = 0;
|
---|
82 |
|
---|
83 | ViewCellContainer::const_iterator it,
|
---|
84 | it_end = mViewCellsManager->GetViewCells().end();
|
---|
85 |
|
---|
86 |
|
---|
87 | for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it)
|
---|
88 | {
|
---|
89 | ViewCell *vc = *it;
|
---|
90 |
|
---|
91 | if (mOnlyValid && !vc->GetValid())
|
---|
92 | continue;
|
---|
93 |
|
---|
94 | // probability of view cell
|
---|
95 | const float pInVc = mViewCellsManager->GetProbability(vc);
|
---|
96 |
|
---|
97 | // compute render time of PVS times probability
|
---|
98 | // that view point is in view cell
|
---|
99 | const float vcCost = pInVc *
|
---|
100 | mViewCellsManager->GetRendercost(vc, mObjRenderCost);
|
---|
101 |
|
---|
102 | // crossing the border of a view cell is depending on the move
|
---|
103 | // speed and the probability that a view cell border is crossed
|
---|
104 | loadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
|
---|
105 |
|
---|
106 | //Debug << "vccost: " << vcCost << " p in vc " << pInVc
|
---|
107 | //<< " cross vc " << GetCrossVcProbability() << endl;
|
---|
108 |
|
---|
109 | //-- update statistics
|
---|
110 | renderTime += vcCost;
|
---|
111 |
|
---|
112 | if (vcCost > mSimulationStatistics.maxCost)
|
---|
113 | mSimulationStatistics.maxCost = vcCost;
|
---|
114 | else if (vcCost < mSimulationStatistics.minCost)
|
---|
115 | mSimulationStatistics.minCost = vcCost;
|
---|
116 | }
|
---|
117 |
|
---|
118 | mSimulationStatistics.avgRtWithoutOverhead = renderTime;
|
---|
119 | mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
120 |
|
---|
121 | mSimulationStatistics.Stop();
|
---|
122 |
|
---|
123 | return true;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | float RenderSimulator::GetCrossVcProbability() const
|
---|
128 | {
|
---|
129 | // assume the view cells are uniformly distributed
|
---|
130 | //NOTE: should I take move speed relative to view space or absolute?
|
---|
131 | const float vcNum =
|
---|
132 | (float)mViewCellsManager->GetViewCells().size();
|
---|
133 |
|
---|
134 | const float prop = mMoveSpeed * vcNum;
|
---|
135 |
|
---|
136 | // clamp probability between 0 and 1
|
---|
137 | return min(1.0f, prop);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const
|
---|
141 | {
|
---|
142 | simStats = mSimulationStatistics;
|
---|
143 | } |
---|