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,
|
---|
29 | float vcOverhead,
|
---|
30 | float moveSpeed):
|
---|
31 | mObjRenderCost(objRenderCost),
|
---|
32 | mVcOverhead(vcOverhead),
|
---|
33 | mMoveSpeed(moveSpeed)
|
---|
34 | {
|
---|
35 | }
|
---|
36 | |
---|
37 | void RenderSimulator::SetObjectRenderCost(const float objRenderCost) |
---|
38 | { |
---|
39 | mObjRenderCost = objRenderCost; |
---|
40 | } |
---|
41 | |
---|
42 | void RenderSimulator::SetVcOverhead(const float vcOverhead) |
---|
43 | { |
---|
44 | mVcOverhead = vcOverhead; |
---|
45 | } |
---|
46 | |
---|
47 | void RenderSimulator::SetMoveSpeed(const float moveSpeed) |
---|
48 | { |
---|
49 | mMoveSpeed = moveSpeed; |
---|
50 | }
|
---|
51 |
|
---|
52 | /********************************************************/
|
---|
53 | /* class BspRenderSimulator implementation */
|
---|
54 | /********************************************************/
|
---|
55 | BspRenderSimulator::BspRenderSimulator(BspTree *bspTree):
|
---|
56 | mBspTree(bspTree)
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | BspRenderSimulator::BspRenderSimulator(float objRenderCost,
|
---|
61 | float vcOverhead,
|
---|
62 | float moveSpeed,
|
---|
63 | BspTree *bspTree):
|
---|
64 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree)
|
---|
65 | {
|
---|
66 | }
|
---|
67 |
|
---|
68 | SimulationStatistics BspRenderSimulator::SimulateRendering()
|
---|
69 | {
|
---|
70 | SimulationStatistics simStat;
|
---|
71 |
|
---|
72 | simStat.Reset();
|
---|
73 | simStat.Start();
|
---|
74 |
|
---|
75 | Real renderTime = 0;
|
---|
76 |
|
---|
77 | // overhead for loading the PVS of the view cells
|
---|
78 | float loadPvsOverhead = 0;
|
---|
79 | // probability that view point lies in a view cell
|
---|
80 | float pInVcTotal = 0;
|
---|
81 |
|
---|
82 | // total probability that a view cell border is crossed
|
---|
83 | const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea();
|
---|
84 |
|
---|
85 | // collect all view cells
|
---|
86 | ViewCellContainer viewCells;
|
---|
87 | mBspTree->CollectViewCells(viewCells);
|
---|
88 |
|
---|
89 | ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
90 |
|
---|
91 | // surface area substitute for probability
|
---|
92 | PolygonContainer geom;
|
---|
93 | float overallarea = 0;
|
---|
94 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
95 | {
|
---|
96 | // compute view cell area
|
---|
97 | mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
|
---|
98 | const float area = Polygon3::GetArea(geom);
|
---|
99 | if (area < 0.0001)
|
---|
100 | Debug << "warning, area: " << area << endl;
|
---|
101 | CLEAR_CONTAINER(geom);
|
---|
102 |
|
---|
103 | // area substitute for view point probability
|
---|
104 | float pInVc = area;
|
---|
105 |
|
---|
106 | // compute render time of PVS times probability that view point is in view cell
|
---|
107 | float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
|
---|
108 | //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
|
---|
109 | renderTime += vcCost;
|
---|
110 |
|
---|
111 | if (vcCost > simStat.maxCost)
|
---|
112 | simStat.maxCost = vcCost;
|
---|
113 | else if (vcCost < simStat.minCost)
|
---|
114 | simStat.minCost = vcCost;
|
---|
115 |
|
---|
116 | // probability that a view cell border is crossed
|
---|
117 | float pCrossVc = area * mMoveSpeed;
|
---|
118 |
|
---|
119 | // crossing the border of a view cell is also depending on the move speed
|
---|
120 | loadPvsOverhead += pCrossVc * mVcOverhead;
|
---|
121 | overallarea += area;
|
---|
122 | pInVcTotal += pInVc;
|
---|
123 | }
|
---|
124 | Debug << "overall area: " << overallarea << endl;
|
---|
125 |
|
---|
126 | renderTime /= pInVcTotal;
|
---|
127 | loadPvsOverhead /= pCrossVcTotal;
|
---|
128 |
|
---|
129 | simStat.avgRtWithoutOverhead = renderTime;
|
---|
130 | simStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
131 |
|
---|
132 | simStat.maxCost /= pInVcTotal;
|
---|
133 | simStat.minCost /= pInVcTotal;
|
---|
134 |
|
---|
135 | simStat.Stop();
|
---|
136 |
|
---|
137 | return simStat;
|
---|
138 | }
|
---|
139 |
|
---|
140 | Real BspRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
141 | float objRenderTime) const
|
---|
142 | {
|
---|
143 | return viewCell.GetPvs().GetSize() * objRenderTime;
|
---|
144 | }
|
---|
145 |
|
---|
146 | /********************************************************
|
---|
147 | * class KdLeafRenderSimulator implementation *
|
---|
148 | *******************************************************/
|
---|
149 |
|
---|
150 | KdRenderSimulator::KdRenderSimulator(float objRenderCost,
|
---|
151 | float vcOverhead,
|
---|
152 | float moveSpeed,
|
---|
153 | KdTree *kdTree):
|
---|
154 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
|
---|
155 | {
|
---|
156 | }
|
---|
157 |
|
---|
158 | KdRenderSimulator::KdRenderSimulator(KdTree *kdTree):
|
---|
159 | mKdTree(kdTree)
|
---|
160 | {
|
---|
161 | }
|
---|
162 |
|
---|
163 | SimulationStatistics KdRenderSimulator::SimulateRendering()
|
---|
164 | {
|
---|
165 | SimulationStatistics simStat;
|
---|
166 |
|
---|
167 | //mKdTree->CollectLeavesPvs();
|
---|
168 | simStat.Reset();
|
---|
169 | simStat.Start();
|
---|
170 |
|
---|
171 | // total render time
|
---|
172 | Real renderTime = 0;
|
---|
173 | // overhead for loading a view cell
|
---|
174 | float loadPvsOverhead = 0;
|
---|
175 |
|
---|
176 | // probability that view point lies in a view cell
|
---|
177 | float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
|
---|
178 |
|
---|
179 | // total probability that a view cell border is crossed
|
---|
180 | const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea();
|
---|
181 |
|
---|
182 | vector<KdLeaf *> leaves;
|
---|
183 | mKdTree->CollectLeaves(leaves);
|
---|
184 |
|
---|
185 | AxisAlignedBox3 box;
|
---|
186 |
|
---|
187 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
188 |
|
---|
189 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
190 | {
|
---|
191 | box = mKdTree->GetBox(*it);
|
---|
192 |
|
---|
193 | // volume substitute for view point probability
|
---|
194 | float pInVc = 0;
|
---|
195 |
|
---|
196 | if (0)
|
---|
197 | pInVc = box.GetVolume();
|
---|
198 | else
|
---|
199 | pInVc = box.SurfaceArea();
|
---|
200 |
|
---|
201 | float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
|
---|
202 | renderTime += vcCost;
|
---|
203 |
|
---|
204 | if (vcCost > simStat.maxCost)
|
---|
205 | simStat.maxCost = vcCost;
|
---|
206 | else if (vcCost < simStat.minCost)
|
---|
207 | simStat.minCost = vcCost;
|
---|
208 |
|
---|
209 | // probability that a view cell border is crossed
|
---|
210 | const float pCrossVc = box.SurfaceArea() * mMoveSpeed;
|
---|
211 |
|
---|
212 | loadPvsOverhead += pCrossVc * mVcOverhead;
|
---|
213 |
|
---|
214 | pInVcTotal += pInVc;
|
---|
215 | }
|
---|
216 |
|
---|
217 | renderTime /= pInVcTotal;
|
---|
218 | loadPvsOverhead /= pCrossVcTotal;
|
---|
219 |
|
---|
220 | simStat.avgRtWithoutOverhead = renderTime;
|
---|
221 | simStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
222 |
|
---|
223 | simStat.maxCost /= pInVcTotal;
|
---|
224 | simStat.minCost /= pInVcTotal;
|
---|
225 |
|
---|
226 | simStat.Stop();
|
---|
227 |
|
---|
228 | return simStat;
|
---|
229 | }
|
---|
230 |
|
---|
231 | Real KdRenderSimulator::RenderPvs(KdLeaf *leaf,
|
---|
232 | float objRenderTime) const
|
---|
233 | {
|
---|
234 | return leaf->mKdPvs.GetSize() * objRenderTime;
|
---|
235 | } |
---|