[406] | 1 | #include "RenderSimulator.h"
|
---|
| 2 | #include "KdTree.h"
|
---|
| 3 | #include "ViewCellBsp.h"
|
---|
| 4 | #include "ViewCell.h"
|
---|
[448] | 5 | #include "VspBspTree.h"
|
---|
[449] | 6 | #include "VspKdTree.h"
|
---|
[468] | 7 | #include "ViewCellsManager.h"
|
---|
[406] | 8 |
|
---|
[463] | 9 | void SimulationStatistics::Print(ostream &app) const
|
---|
| 10 | {
|
---|
[475] | 11 | app << "===== Render Simulation statistics ===============\n";
|
---|
[463] | 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 |
|
---|
[475] | 23 | app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n"
|
---|
| 24 | << avgRtWithoutOverhead << "\n";
|
---|
[463] | 25 |
|
---|
[475] | 26 | app << "===== END OF Render Simulation statistics ==========\n";
|
---|
[414] | 27 | }
|
---|
| 28 |
|
---|
[473] | 29 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager):
|
---|
[497] | 30 | Renderer(NULL, viewCellsManager)
|
---|
[406] | 31 | {}
|
---|
| 32 |
|
---|
[473] | 33 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager,
|
---|
| 34 | float objRenderCost,
|
---|
[439] | 35 | float vcOverhead,
|
---|
| 36 | float moveSpeed):
|
---|
[497] | 37 | Renderer(NULL, viewCellsManager),
|
---|
[439] | 38 | mObjRenderCost(objRenderCost),
|
---|
| 39 | mVcOverhead(vcOverhead),
|
---|
| 40 | mMoveSpeed(moveSpeed)
|
---|
[406] | 41 | {
|
---|
| 42 | }
|
---|
[463] | 43 |
|
---|
| 44 | void RenderSimulator::SetObjectRenderCost(const float objRenderCost)
|
---|
| 45 | {
|
---|
| 46 | mObjRenderCost = objRenderCost;
|
---|
[439] | 47 | }
|
---|
[406] | 48 |
|
---|
[463] | 49 | void RenderSimulator::SetVcOverhead(const float vcOverhead)
|
---|
| 50 | {
|
---|
| 51 | mVcOverhead = vcOverhead;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | void RenderSimulator::SetMoveSpeed(const float moveSpeed)
|
---|
| 55 | {
|
---|
| 56 | mMoveSpeed = moveSpeed;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[468] | 59 | bool RenderSimulator::RenderScene()
|
---|
[440] | 60 | {
|
---|
[468] | 61 | mSimulationStatistics.Reset();
|
---|
| 62 | mSimulationStatistics.Start();
|
---|
[406] | 63 |
|
---|
| 64 | Real renderTime = 0;
|
---|
[414] | 65 |
|
---|
[409] | 66 | // overhead for loading the PVS of the view cells
|
---|
| 67 | float loadPvsOverhead = 0;
|
---|
[468] | 68 |
|
---|
| 69 | ViewCellContainer::const_iterator it,
|
---|
| 70 | it_end = mViewCellsManager->GetViewCells().end();
|
---|
[418] | 71 |
|
---|
[475] | 72 |
|
---|
[468] | 73 | for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it)
|
---|
[406] | 74 | {
|
---|
[468] | 75 | ViewCell *vc = *it;
|
---|
[409] | 76 |
|
---|
[468] | 77 | // probability of view cell
|
---|
| 78 | const float pInVc = mViewCellsManager->GetProbability(vc);
|
---|
[551] | 79 |
|
---|
[482] | 80 | // compute render time of PVS times probability
|
---|
| 81 | // that view point is in view cell
|
---|
| 82 | const float vcCost = pInVc *
|
---|
| 83 | mViewCellsManager->GetRendercost(vc, mObjRenderCost);
|
---|
[479] | 84 |
|
---|
[551] | 85 | // crossing the border of a view cell is depending on the move
|
---|
| 86 | // speed and the probability that a view cell border is crossed
|
---|
[468] | 87 | loadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
|
---|
[482] | 88 |
|
---|
| 89 | //Debug << "vccost: " << vcCost << " p in vc " << pInVc
|
---|
| 90 | //<< " cross vc " << GetCrossVcProbability() << endl;
|
---|
| 91 |
|
---|
[468] | 92 | //-- update statistics
|
---|
[448] | 93 | renderTime += vcCost;
|
---|
[473] | 94 |
|
---|
[468] | 95 | if (vcCost > mSimulationStatistics.maxCost)
|
---|
| 96 | mSimulationStatistics.maxCost = vcCost;
|
---|
| 97 | else if (vcCost < mSimulationStatistics.minCost)
|
---|
| 98 | mSimulationStatistics.minCost = vcCost;
|
---|
[448] | 99 | }
|
---|
| 100 |
|
---|
[468] | 101 | mSimulationStatistics.avgRtWithoutOverhead = renderTime;
|
---|
| 102 | mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
[448] | 103 |
|
---|
[468] | 104 | mSimulationStatistics.Stop();
|
---|
[448] | 105 |
|
---|
[468] | 106 | return true;
|
---|
[448] | 107 | }
|
---|
| 108 |
|
---|
[479] | 109 |
|
---|
[477] | 110 | float RenderSimulator::GetCrossVcProbability() const
|
---|
[448] | 111 | {
|
---|
[477] | 112 | // assume the view cells are uniformly distributed
|
---|
[479] | 113 | //NOTE: should I take move speed relative to view space or absolute?
|
---|
[477] | 114 | const float vcNum =
|
---|
| 115 | (float)mViewCellsManager->GetViewCells().size();
|
---|
[476] | 116 |
|
---|
[479] | 117 | const float prop = mMoveSpeed * vcNum;
|
---|
| 118 |
|
---|
| 119 | // clamp probability between 0 and 1
|
---|
| 120 | return min(1.0f, prop);
|
---|
[448] | 121 | }
|
---|
[449] | 122 |
|
---|
[468] | 123 | void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const
|
---|
[449] | 124 | {
|
---|
[468] | 125 | simStats = mSimulationStatistics;
|
---|
[449] | 126 | } |
---|