source: trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp @ 465

Revision 465, 11.7 KB checked in by mattausch, 19 years ago (diff)

worked on vspkd leaves merge, implemented post merge collapse

Line 
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
8void SimulationStatistics::Print(ostream &app) const
9{
10        app << "===== Simulation statistics ===============\n";
11
12        app << setprecision(4);
13
14        app << "#N_CTIME  ( Simulation time [s] )\n" << Time() << " \n";
15
16        app << "#MAX_COST ( maximal cost of a view cell )\n" << maxCost << "\n";
17
18        app << "#MIN_COST ( minimal cost of a view cell )\n" << minCost << "\n";
19
20        app << "#AVG_RENDER_TIME ( average render time )\n" << avgRenderTime << "\n";
21
22        app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n" << avgRtWithoutOverhead << "\n";
23       
24        app << "===== END OF Simulation statistics ==========\n";
25}
26
27RenderSimulator::RenderSimulator()
28{}
29
30RenderSimulator::RenderSimulator(float objRenderCost,
31                                                                 float vcOverhead,
32                                                                 float moveSpeed):
33mObjRenderCost(objRenderCost),
34mVcOverhead(vcOverhead),
35mMoveSpeed(moveSpeed)
36{
37}
38
39void RenderSimulator::SetObjectRenderCost(const float objRenderCost)
40{
41        mObjRenderCost = objRenderCost;
42}
43
44void RenderSimulator::SetVcOverhead(const float vcOverhead)
45{
46        mVcOverhead = vcOverhead;
47}
48
49void RenderSimulator::SetMoveSpeed(const float moveSpeed)
50{
51        mMoveSpeed = moveSpeed;
52}
53
54/********************************************************/
55/*     class BspRenderSimulator implementation          */
56/********************************************************/
57
58
59BspRenderSimulator::BspRenderSimulator(BspTree *bspTree):
60mBspTree(bspTree)
61{
62}
63
64BspRenderSimulator::BspRenderSimulator(float objRenderCost,
65                                                                                           float vcOverhead,
66                                                                                           float moveSpeed,
67                                                                                           BspTree *bspTree):
68RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree)
69{
70}
71
72SimulationStatistics BspRenderSimulator::SimulateRendering()
73{
74        SimulationStatistics simStat;
75
76        simStat.Reset();
77        simStat.Start();
78
79        Real renderTime = 0;
80       
81        // overhead for loading the PVS of the view cells
82        float loadPvsOverhead = 0;
83        // probability that view point lies in a view cell
84        float pInVcTotal = 0;
85
86        // total probability that a view cell border is crossed
87        const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea();
88
89        // collect all view cells
90        ViewCellContainer viewCells;
91        mBspTree->CollectViewCells(viewCells);
92
93        ViewCellContainer::const_iterator it, it_end = viewCells.end();
94
95        // surface area substitute for probability
96        PolygonContainer geom;
97float overallarea = 0;
98        for (it = viewCells.begin(); it != it_end; ++ it)
99        {
100                // compute view cell area
101                mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
102                const float area = Polygon3::GetArea(geom);
103                if (area < 0.0001)
104                        Debug << "warning, area: " << area << endl;
105                CLEAR_CONTAINER(geom);
106
107                // area substitute for view point probability
108                float pInVc = area;
109                               
110                // compute render time of PVS times probability that view point is in view cell
111                float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
112                //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
113                renderTime += vcCost;
114
115                if (vcCost > simStat.maxCost)
116                        simStat.maxCost = vcCost;
117                else if (vcCost < simStat.minCost)
118                        simStat.minCost = vcCost;
119
120                // probability that a view cell border is crossed
121                float pCrossVc = area * mMoveSpeed;
122
123                // crossing the border of a view cell is also depending on the move speed
124                loadPvsOverhead += pCrossVc * mVcOverhead;
125overallarea += area;
126                pInVcTotal += pInVc;
127        }
128        Debug << "overall area: " << overallarea << endl;
129       
130        renderTime /= pInVcTotal;
131        loadPvsOverhead /= pCrossVcTotal;
132
133        simStat.avgRtWithoutOverhead = renderTime;
134        simStat.avgRenderTime = renderTime + loadPvsOverhead;
135       
136        simStat.maxCost /= pInVcTotal;
137        simStat.minCost /= pInVcTotal;
138
139        simStat.Stop();
140
141        return simStat;
142}
143
144Real BspRenderSimulator::RenderPvs(ViewCell &viewCell,
145                                                                   float objRenderTime) const
146{
147        return viewCell.GetPvs().GetSize() * objRenderTime;
148}
149
150/*******************************************************/
151/*     class KdenderSimulator implementation           */
152/*******************************************************/
153
154KdRenderSimulator::KdRenderSimulator(float objRenderCost,
155                                                                                         float vcOverhead,
156                                                                                         float moveSpeed,
157                                                                                         KdTree *kdTree):
158RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
159{
160}
161
162KdRenderSimulator::KdRenderSimulator(KdTree *kdTree):
163mKdTree(kdTree)
164{
165}
166
167SimulationStatistics KdRenderSimulator::SimulateRendering()
168{
169        SimulationStatistics simStat;
170
171        //mKdTree->CollectLeavesPvs();
172        simStat.Reset();
173        simStat.Start();
174
175        // total render time
176        Real renderTime = 0;
177        // overhead for loading a view cell
178        float loadPvsOverhead = 0;
179
180        // probability that view point lies in a view cell
181        float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
182
183        // total probability that a view cell border is crossed
184        const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea();
185
186        vector<KdLeaf *> leaves;
187        mKdTree->CollectLeaves(leaves);
188       
189        AxisAlignedBox3 box;
190
191        vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
192       
193        for (it = leaves.begin(); it != it_end; ++ it)
194        {
195                box = mKdTree->GetBox(*it);
196                       
197                // volume substitute for view point probability
198                float pInVc = 0;
199               
200                if (0)
201                        pInVc = box.GetVolume();
202                else
203                        pInVc = box.SurfaceArea();
204               
205                float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
206                renderTime += vcCost;
207
208                if (vcCost > simStat.maxCost)
209                        simStat.maxCost = vcCost;
210                else if (vcCost < simStat.minCost)
211                        simStat.minCost = vcCost;
212
213                // probability that a view cell border is crossed
214                const float pCrossVc = box.SurfaceArea() * mMoveSpeed;
215
216                loadPvsOverhead += pCrossVc * mVcOverhead;
217
218                pInVcTotal += pInVc;
219        }
220
221        renderTime /= pInVcTotal;
222        loadPvsOverhead /= pCrossVcTotal;
223
224    simStat.avgRtWithoutOverhead = renderTime;
225        simStat.avgRenderTime = renderTime + loadPvsOverhead;
226
227        simStat.maxCost /= pInVcTotal;
228        simStat.minCost /= pInVcTotal;
229
230        simStat.Stop();
231
232        return simStat;
233}
234
235Real KdRenderSimulator::RenderPvs(KdLeaf *leaf,
236                                                                  float objRenderTime) const
237{
238        return leaf->mKdPvs.GetSize() * objRenderTime;
239}
240
241/**********************************************************/
242/*       class BspRenderSimulator implementation          */
243/**********************************************************/
244
245VspBspRenderSimulator::VspBspRenderSimulator(VspBspTree *vspBspTree):
246mVspBspTree(vspBspTree)
247{
248}
249
250VspBspRenderSimulator::VspBspRenderSimulator(float objRenderCost,
251                                                                                         float vcOverhead,
252                                                                                         float moveSpeed,
253                                                                                         VspBspTree *vspBspTree):
254RenderSimulator(objRenderCost, vcOverhead, moveSpeed),
255mVspBspTree(vspBspTree)
256{
257}
258
259SimulationStatistics VspBspRenderSimulator::SimulateRendering()
260{
261        SimulationStatistics simStat;
262
263        simStat.Reset();
264        simStat.Start();
265
266        Real renderTime = 0;
267       
268        // overhead for loading the PVS of the view cells
269        float loadPvsOverhead = 0;
270        // probability that view point lies in a view cell
271        float pInVcTotal = 0;
272
273        // total probability that a view cell border is crossed
274        const float pCrossVcTotal = mVspBspTree->GetBoundingBox().SurfaceArea();
275
276        // collect all view cells
277        ViewCellContainer viewCells;
278        mVspBspTree->CollectViewCells(viewCells);
279
280        ViewCellContainer::const_iterator it, it_end = viewCells.end();
281
282        // surface area substitute for probability
283        PolygonContainer geom;
284float overallarea = 0;
285        for (it = viewCells.begin(); it != it_end; ++ it)
286        {
287                // compute view cell area
288                mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
289
290                const float area = Polygon3::GetArea(geom);
291                if (area < 0.0001)
292                        Debug << "warning, area: " << area << endl;
293                CLEAR_CONTAINER(geom);
294
295                // area substitute for view point probability
296                float pInVc = area;
297                               
298                // compute render time of PVS times probability that view point is in view cell
299                float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
300                //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
301                renderTime += vcCost;
302
303                if (vcCost > simStat.maxCost)
304                        simStat.maxCost = vcCost;
305                else if (vcCost < simStat.minCost)
306                        simStat.minCost = vcCost;
307
308                // probability that a view cell border is crossed
309                float pCrossVc = area * mMoveSpeed;
310
311                // crossing the border of a view cell is also depending on the move speed
312                loadPvsOverhead += pCrossVc * mVcOverhead;
313overallarea += area;
314                pInVcTotal += pInVc;
315        }
316        Debug << "overall area: " << overallarea << endl;
317       
318        renderTime /= pInVcTotal;
319        loadPvsOverhead /= pCrossVcTotal;
320
321        simStat.avgRtWithoutOverhead = renderTime;
322        simStat.avgRenderTime = renderTime + loadPvsOverhead;
323       
324        simStat.maxCost /= pInVcTotal;
325        simStat.minCost /= pInVcTotal;
326
327        simStat.Stop();
328
329        return simStat;
330}
331
332Real VspBspRenderSimulator::RenderPvs(ViewCell &viewCell,
333                                                                          float objRenderTime) const
334{
335        return viewCell.GetPvs().GetSize() * objRenderTime;
336}
337
338
339
340/*************************************************************/
341/*        class VspKdRenderSimulator implementation          */
342/*************************************************************/
343
344
345VspKdRenderSimulator::VspKdRenderSimulator(VspKdTree *vspKdTree):
346mVspKdTree(vspKdTree)
347{
348}
349
350VspKdRenderSimulator::VspKdRenderSimulator(float objRenderCost,
351                                                                                   float vcOverhead,
352                                                                                   float moveSpeed,
353                                                                                   VspKdTree *vspKdTree):
354RenderSimulator(objRenderCost, vcOverhead, moveSpeed),
355mVspKdTree(vspKdTree)
356{
357}
358
359SimulationStatistics VspKdRenderSimulator::SimulateRendering()
360{SimulationStatistics simStat;
361
362        simStat.Reset();
363        simStat.Start();
364
365        Real renderTime = 0;
366       
367        // overhead for loading the PVS of the view cells
368        float loadPvsOverhead = 0;
369        // probability that view point lies in a view cell
370        float pInVcTotal = 0;
371
372        // total probability that a view cell border is crossed
373/*      const float pCrossVcTotal = mVspBspTree->GetBoundingBox().SurfaceArea();
374
375        // collect all view cells
376        ViewCellContainer viewCells;
377        mVspBspTree->CollectViewCells(viewCells);
378
379        ViewCellContainer::const_iterator it, it_end = viewCells.end();
380
381        // surface area substitute for probability
382        PolygonContainer geom;
383float overallarea = 0;
384        for (it = viewCells.begin(); it != it_end; ++ it)
385        {
386                // compute view cell area
387                mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
388
389                const float area = Polygon3::GetArea(geom);
390                if (area < 0.0001)
391                        Debug << "warning, area: " << area << endl;
392                CLEAR_CONTAINER(geom);
393
394                // area substitute for view point probability
395                float pInVc = area;
396                               
397                // compute render time of PVS times probability that view point is in view cell
398                float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
399                //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
400                renderTime += vcCost;
401
402                if (vcCost > simStat.maxCost)
403                        simStat.maxCost = vcCost;
404                else if (vcCost < simStat.minCost)
405                        simStat.minCost = vcCost;
406
407                // probability that a view cell border is crossed
408                float pCrossVc = area * mMoveSpeed;
409
410                // crossing the border of a view cell is also depending on the move speed
411                loadPvsOverhead += pCrossVc * mVcOverhead;
412overallarea += area;
413                pInVcTotal += pInVc;
414        }
415        Debug << "overall area: " << overallarea << endl;
416       
417        renderTime /= pInVcTotal;
418        loadPvsOverhead /= pCrossVcTotal;
419
420        simStat.avgRtWithoutOverhead = renderTime;
421        simStat.avgRenderTime = renderTime + loadPvsOverhead;
422       
423        simStat.maxCost /= pInVcTotal;
424        simStat.minCost /= pInVcTotal;
425
426        simStat.Stop();
427*/
428        return simStat;
429}
430
431Real VspKdRenderSimulator::RenderPvs(ViewCell &viewCell,
432                                                                         float objRenderTime) const
433{
434        return 0; // TODO
435}
Note: See TracBrowser for help on using the repository browser.