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 |
|
---|
57 | // total probability that a view cell border is crossed
|
---|
58 | const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea();
|
---|
59 |
|
---|
60 | // collect all view cells
|
---|
61 | ViewCellContainer viewCells;
|
---|
62 | mBspTree->CollectViewCells(viewCells);
|
---|
63 |
|
---|
64 | ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
65 |
|
---|
66 | // surface area substitute for probability
|
---|
67 | PolygonContainer geom;
|
---|
68 | float overallarea = 0;
|
---|
69 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
70 | {
|
---|
71 | // compute view cell area
|
---|
72 | mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
|
---|
73 | const float area = Polygon3::GetArea(geom);
|
---|
74 | if (area < 0.0001)
|
---|
75 | Debug << "warning, area: " << area << endl;
|
---|
76 | CLEAR_CONTAINER(geom);
|
---|
77 |
|
---|
78 | // area substitute for view point probability
|
---|
79 | float pInVc = area;
|
---|
80 |
|
---|
81 | // compute render time of PVS times probability that view point is in view cell
|
---|
82 | float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
|
---|
83 | //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
|
---|
84 | renderTime += vcCost;
|
---|
85 |
|
---|
86 | if (vcCost > mStat.maxCost)
|
---|
87 | mStat.maxCost = vcCost;
|
---|
88 | else if (vcCost < mStat.minCost)
|
---|
89 | mStat.minCost = vcCost;
|
---|
90 |
|
---|
91 | // probability that a view cell border is crossed
|
---|
92 | float pCrossVc = area * mMoveSpeed;
|
---|
93 |
|
---|
94 | // crossing the border of a view cell is also depending on the move speed
|
---|
95 | loadPvsOverhead += pCrossVc * mVcOverhead;
|
---|
96 | overallarea+=area;
|
---|
97 | pInVcTotal += pInVc;
|
---|
98 | }
|
---|
99 | Debug << "overall area: " << overallarea << endl;
|
---|
100 |
|
---|
101 | renderTime /= pInVcTotal;
|
---|
102 | loadPvsOverhead /= pCrossVcTotal;
|
---|
103 |
|
---|
104 | mStat.avgRtWithoutOverhead = renderTime;
|
---|
105 | mStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
106 |
|
---|
107 | mStat.maxCost /= pInVcTotal;
|
---|
108 | mStat.minCost /= pInVcTotal;
|
---|
109 |
|
---|
110 | mStat.Stop();
|
---|
111 |
|
---|
112 | return renderTime + loadPvsOverhead;
|
---|
113 | }
|
---|
114 |
|
---|
115 | Real BspViewCellRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
116 | float objRenderTime) const
|
---|
117 | {
|
---|
118 | return viewCell.GetPvs().GetSize() * objRenderTime;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /********************************************************
|
---|
122 | * class KdLeafRenderSimulator implementation *
|
---|
123 | *******************************************************/
|
---|
124 |
|
---|
125 | KdViewCellRenderSimulator::KdViewCellRenderSimulator(float objRenderCost,
|
---|
126 | float vcOverhead,
|
---|
127 | float moveSpeed,
|
---|
128 | KdTree *kdTree):
|
---|
129 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
|
---|
130 | {
|
---|
131 | }
|
---|
132 |
|
---|
133 | Real KdViewCellRenderSimulator::SimulateRendering()
|
---|
134 | {
|
---|
135 | //mKdTree->CollectLeavesPvs();
|
---|
136 | mStat.Reset();
|
---|
137 | mStat.Start();
|
---|
138 |
|
---|
139 | // total render time
|
---|
140 | Real renderTime = 0;
|
---|
141 | // overhead for loading a view cell
|
---|
142 | float loadPvsOverhead = 0;
|
---|
143 |
|
---|
144 | // probability that view point lies in a view cell
|
---|
145 | float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
|
---|
146 |
|
---|
147 | // total probability that a view cell border is crossed
|
---|
148 | const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea();
|
---|
149 |
|
---|
150 | vector<KdLeaf *> leaves;
|
---|
151 | mKdTree->CollectLeaves(leaves);
|
---|
152 |
|
---|
153 | AxisAlignedBox3 box;
|
---|
154 |
|
---|
155 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
156 |
|
---|
157 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
158 | {
|
---|
159 | box = mKdTree->GetBox(*it);
|
---|
160 |
|
---|
161 | // volume substitute for view point probability
|
---|
162 | float pInVc = 0;
|
---|
163 |
|
---|
164 | if (0)
|
---|
165 | pInVc = box.GetVolume();
|
---|
166 | else
|
---|
167 | pInVc = box.SurfaceArea();
|
---|
168 |
|
---|
169 | float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
|
---|
170 | renderTime += vcCost;
|
---|
171 |
|
---|
172 | if (vcCost > mStat.maxCost)
|
---|
173 | mStat.maxCost = vcCost;
|
---|
174 | else if (vcCost < mStat.minCost)
|
---|
175 | mStat.minCost = vcCost;
|
---|
176 |
|
---|
177 | // probability that a view cell border is crossed
|
---|
178 | const float pCrossVc = box.SurfaceArea() * mMoveSpeed;
|
---|
179 |
|
---|
180 | loadPvsOverhead += pCrossVc * mVcOverhead;
|
---|
181 |
|
---|
182 | pInVcTotal += pInVc;
|
---|
183 | }
|
---|
184 |
|
---|
185 | renderTime /= pInVcTotal;
|
---|
186 | loadPvsOverhead /= pCrossVcTotal;
|
---|
187 |
|
---|
188 | mStat.avgRtWithoutOverhead = renderTime;
|
---|
189 | mStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
190 |
|
---|
191 | mStat.maxCost /= pInVcTotal;
|
---|
192 | mStat.minCost /= pInVcTotal;
|
---|
193 |
|
---|
194 | mStat.Stop();
|
---|
195 |
|
---|
196 | return renderTime + loadPvsOverhead;
|
---|
197 | }
|
---|
198 |
|
---|
199 | Real KdViewCellRenderSimulator::RenderPvs(KdLeaf *leaf,
|
---|
200 | float objRenderTime) const
|
---|
201 | {
|
---|
202 | return leaf->mKdPvs.GetSize() * objRenderTime;
|
---|
203 | } |
---|