1 | #include "RenderSimulator.h"
|
---|
2 | #include "KdTree.h"
|
---|
3 | #include "ViewCellBsp.h"
|
---|
4 | #include "ViewCell.h"
|
---|
5 |
|
---|
6 | void SimulationStatistics::Print(ostream &app) const |
---|
7 | { |
---|
8 | app << "===== Simulation statistics ===============\n"; |
---|
9 | |
---|
10 | app << setprecision(4); |
---|
11 | |
---|
12 | app << "#N_CTIME ( Simulation time [s] )\n" << Time() << " \n"; |
---|
13 | |
---|
14 | app << "#MAX_COST ( maximal cost of a view cell )\n" << maxCost << "\n"; |
---|
15 | |
---|
16 | app << "#MIN_COST ( minimal cost of a view cell )\n" << minCost << "\n"; |
---|
17 | |
---|
18 | app << "#AVG_RENDER_TIME ( average render time )\n" << avgRenderTime << "\n"; |
---|
19 | |
---|
20 | app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n" << avgRtWithoutOverhead << "\n"; |
---|
21 | |
---|
22 | app << "===== END OF Simulation statistics ==========\n"; |
---|
23 | }
|
---|
24 |
|
---|
25 | RenderSimulator::RenderSimulator()
|
---|
26 | {}
|
---|
27 |
|
---|
28 | RenderSimulator::RenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed):
|
---|
29 | mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead), mMoveSpeed(moveSpeed)
|
---|
30 | {
|
---|
31 | }
|
---|
32 |
|
---|
33 | /*****************************************************
|
---|
34 | * class ViewCellRenderSimulator implementation *
|
---|
35 | *****************************************************/
|
---|
36 |
|
---|
37 | BspViewCellRenderSimulator::BspViewCellRenderSimulator(float objRenderCost,
|
---|
38 | float vcOverhead,
|
---|
39 | float moveSpeed,
|
---|
40 | BspTree *bspTree):
|
---|
41 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree)
|
---|
42 | {
|
---|
43 | }
|
---|
44 |
|
---|
45 | Real BspViewCellRenderSimulator::SimulateRendering()
|
---|
46 | {
|
---|
47 | mStat.Reset();
|
---|
48 | mStat.Start();
|
---|
49 |
|
---|
50 | Real renderTime = 0;
|
---|
51 |
|
---|
52 | // overhead for loading the PVS of the view cells
|
---|
53 | float loadPvsOverhead = 0;
|
---|
54 | // probability that view point lies in a view cell
|
---|
55 | float pInVcTotal = 0;
|
---|
56 | // total probability that a view cell border is crossed
|
---|
57 | float pCrossVcTotal = 0;
|
---|
58 |
|
---|
59 | // collect all view cells
|
---|
60 | ViewCellContainer viewCells;
|
---|
61 | mBspTree->CollectViewCells(viewCells);
|
---|
62 |
|
---|
63 | ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
64 |
|
---|
65 | // surface area substitute for probability
|
---|
66 | PolygonContainer geom;
|
---|
67 |
|
---|
68 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
69 | {
|
---|
70 | // compute view cell area
|
---|
71 | mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
|
---|
72 | const float area = Polygon3::GetArea(geom);
|
---|
73 | CLEAR_CONTAINER(geom);
|
---|
74 |
|
---|
75 | // area substitute for view point probability
|
---|
76 | float pInVc = area;
|
---|
77 |
|
---|
78 | // compute render time of PVS times probability that view point is in view cell
|
---|
79 | float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
|
---|
80 |
|
---|
81 | renderTime += vcCost;
|
---|
82 |
|
---|
83 | if (vcCost > mStat.maxCost)
|
---|
84 | mStat.maxCost = vcCost;
|
---|
85 | else if (vcCost < mStat.minCost)
|
---|
86 | mStat.minCost = vcCost;
|
---|
87 |
|
---|
88 | // probability that a view cell border is crossed
|
---|
89 | float pCrossVc = area;
|
---|
90 |
|
---|
91 | // crossing the border of a view cell is also depending on the move speed
|
---|
92 | loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
|
---|
93 |
|
---|
94 | pInVcTotal += pInVc;
|
---|
95 | pCrossVcTotal += pCrossVc;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | renderTime /= pInVcTotal;
|
---|
100 | loadPvsOverhead /= pCrossVcTotal;
|
---|
101 |
|
---|
102 | mStat.avgRtWithoutOverhead = renderTime;
|
---|
103 | mStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
104 |
|
---|
105 | mStat.Stop();
|
---|
106 |
|
---|
107 | return renderTime + loadPvsOverhead;
|
---|
108 | }
|
---|
109 |
|
---|
110 | Real BspViewCellRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
111 | float objRenderTime) const
|
---|
112 | {
|
---|
113 | return viewCell.GetPvs().GetSize() * objRenderTime;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /********************************************************
|
---|
117 | * class KdLeafRenderSimulator implementation *
|
---|
118 | *******************************************************/
|
---|
119 |
|
---|
120 | KdViewCellRenderSimulator::KdViewCellRenderSimulator(float objRenderCost,
|
---|
121 | float vcOverhead,
|
---|
122 | float moveSpeed,
|
---|
123 | KdTree *kdTree):
|
---|
124 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
|
---|
125 | {
|
---|
126 | }
|
---|
127 |
|
---|
128 | Real KdViewCellRenderSimulator::SimulateRendering()
|
---|
129 | {
|
---|
130 | //mKdTree->CollectLeavesPvs();
|
---|
131 | mStat.Reset();
|
---|
132 | mStat.Start();
|
---|
133 |
|
---|
134 | // total render time
|
---|
135 | Real renderTime = 0;
|
---|
136 | // overhead for loading a view cell
|
---|
137 | float loadPvsOverhead = 0;
|
---|
138 |
|
---|
139 | // probability that view point lies in a view cell
|
---|
140 | float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
|
---|
141 |
|
---|
142 | // total probability that a view cell border is crossed
|
---|
143 | float pCrossVcTotal = 0;
|
---|
144 |
|
---|
145 | vector<KdLeaf *> leaves;
|
---|
146 | mKdTree->CollectLeaves(leaves);
|
---|
147 |
|
---|
148 | AxisAlignedBox3 box;
|
---|
149 |
|
---|
150 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
151 |
|
---|
152 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
153 | {
|
---|
154 | box = mKdTree->GetBox(*it);
|
---|
155 |
|
---|
156 | // volume substitute for view point probability
|
---|
157 | float pInVc = 0;
|
---|
158 |
|
---|
159 | if (0)
|
---|
160 | pInVc = box.GetVolume();
|
---|
161 | else
|
---|
162 | pInVc = box.SurfaceArea();
|
---|
163 |
|
---|
164 | // probability that a view cell border is crossed
|
---|
165 | const float pCrossVc = box.SurfaceArea();
|
---|
166 |
|
---|
167 | float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
|
---|
168 | renderTime += vcCost;
|
---|
169 |
|
---|
170 | if (vcCost > mStat.maxCost)
|
---|
171 | mStat.maxCost = vcCost;
|
---|
172 | else if (vcCost < mStat.minCost)
|
---|
173 | mStat.minCost = vcCost;
|
---|
174 |
|
---|
175 | loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
|
---|
176 |
|
---|
177 | pInVcTotal += pInVc;
|
---|
178 | pCrossVcTotal += pCrossVc;
|
---|
179 | }
|
---|
180 |
|
---|
181 | Debug << "RT: " << renderTime << endl;
|
---|
182 | Debug << "pvsOverhead: " << loadPvsOverhead << endl;
|
---|
183 |
|
---|
184 |
|
---|
185 | renderTime /= pInVcTotal;
|
---|
186 | loadPvsOverhead /= pCrossVcTotal;
|
---|
187 |
|
---|
188 | mStat.avgRtWithoutOverhead = renderTime;
|
---|
189 | mStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
190 |
|
---|
191 | mStat.Stop();
|
---|
192 |
|
---|
193 | return renderTime + loadPvsOverhead;
|
---|
194 | }
|
---|
195 |
|
---|
196 | Real KdViewCellRenderSimulator::RenderPvs(KdLeaf *leaf,
|
---|
197 | float objRenderTime) const
|
---|
198 | {
|
---|
199 | return leaf->mKdPvs.GetSize() * objRenderTime;
|
---|
200 | } |
---|