[406] | 1 | #include "RenderSimulator.h"
|
---|
| 2 | #include "KdTree.h"
|
---|
| 3 | #include "ViewCellBsp.h"
|
---|
| 4 | #include "ViewCell.h"
|
---|
| 5 |
|
---|
[414] | 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 |
|
---|
[406] | 25 | RenderSimulator::RenderSimulator()
|
---|
| 26 | {}
|
---|
| 27 |
|
---|
[439] | 28 | RenderSimulator::RenderSimulator(float objRenderCost,
|
---|
| 29 | float vcOverhead,
|
---|
| 30 | float moveSpeed):
|
---|
| 31 | mObjRenderCost(objRenderCost),
|
---|
| 32 | mVcOverhead(vcOverhead),
|
---|
| 33 | mMoveSpeed(moveSpeed)
|
---|
[406] | 34 | {
|
---|
| 35 | }
|
---|
[439] | 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 | }
|
---|
[406] | 51 |
|
---|
[439] | 52 | /********************************************************/
|
---|
| 53 | /* class BspRenderSimulator implementation */
|
---|
| 54 | /********************************************************/
|
---|
[440] | 55 | BspRenderSimulator::BspRenderSimulator(BspTree *bspTree):
|
---|
| 56 | mBspTree(bspTree)
|
---|
| 57 | {
|
---|
| 58 | }
|
---|
[406] | 59 |
|
---|
[439] | 60 | BspRenderSimulator::BspRenderSimulator(float objRenderCost,
|
---|
[406] | 61 | float vcOverhead,
|
---|
[409] | 62 | float moveSpeed,
|
---|
[406] | 63 | BspTree *bspTree):
|
---|
[409] | 64 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree)
|
---|
[406] | 65 | {
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[439] | 68 | SimulationStatistics BspRenderSimulator::SimulateRendering()
|
---|
[406] | 69 | {
|
---|
[439] | 70 | SimulationStatistics simStat;
|
---|
[414] | 71 |
|
---|
[439] | 72 | simStat.Reset();
|
---|
| 73 | simStat.Start();
|
---|
| 74 |
|
---|
[406] | 75 | Real renderTime = 0;
|
---|
[414] | 76 |
|
---|
[409] | 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;
|
---|
[418] | 81 |
|
---|
[409] | 82 | // total probability that a view cell border is crossed
|
---|
[418] | 83 | const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea();
|
---|
[409] | 84 |
|
---|
| 85 | // collect all view cells
|
---|
[406] | 86 | ViewCellContainer viewCells;
|
---|
| 87 | mBspTree->CollectViewCells(viewCells);
|
---|
| 88 |
|
---|
| 89 | ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
[407] | 90 |
|
---|
| 91 | // surface area substitute for probability
|
---|
[409] | 92 | PolygonContainer geom;
|
---|
[420] | 93 | float overallarea = 0;
|
---|
[406] | 94 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
| 95 | {
|
---|
[410] | 96 | // compute view cell area
|
---|
[409] | 97 | mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
|
---|
[410] | 98 | const float area = Polygon3::GetArea(geom);
|
---|
[420] | 99 | if (area < 0.0001)
|
---|
| 100 | Debug << "warning, area: " << area << endl;
|
---|
[409] | 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
|
---|
[414] | 107 | float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
|
---|
[418] | 108 | //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
|
---|
[414] | 109 | renderTime += vcCost;
|
---|
| 110 |
|
---|
[439] | 111 | if (vcCost > simStat.maxCost)
|
---|
| 112 | simStat.maxCost = vcCost;
|
---|
| 113 | else if (vcCost < simStat.minCost)
|
---|
| 114 | simStat.minCost = vcCost;
|
---|
[414] | 115 |
|
---|
[409] | 116 | // probability that a view cell border is crossed
|
---|
[418] | 117 | float pCrossVc = area * mMoveSpeed;
|
---|
[409] | 118 |
|
---|
[414] | 119 | // crossing the border of a view cell is also depending on the move speed
|
---|
[418] | 120 | loadPvsOverhead += pCrossVc * mVcOverhead;
|
---|
[439] | 121 | overallarea += area;
|
---|
[409] | 122 | pInVcTotal += pInVc;
|
---|
[406] | 123 | }
|
---|
[420] | 124 | Debug << "overall area: " << overallarea << endl;
|
---|
[409] | 125 |
|
---|
| 126 | renderTime /= pInVcTotal;
|
---|
| 127 | loadPvsOverhead /= pCrossVcTotal;
|
---|
[406] | 128 |
|
---|
[439] | 129 | simStat.avgRtWithoutOverhead = renderTime;
|
---|
| 130 | simStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
[409] | 131 |
|
---|
[439] | 132 | simStat.maxCost /= pInVcTotal;
|
---|
| 133 | simStat.minCost /= pInVcTotal;
|
---|
[420] | 134 |
|
---|
[439] | 135 | simStat.Stop();
|
---|
[414] | 136 |
|
---|
[439] | 137 | return simStat;
|
---|
[406] | 138 | }
|
---|
| 139 |
|
---|
[439] | 140 | Real BspRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
[407] | 141 | float objRenderTime) const
|
---|
[406] | 142 | {
|
---|
| 143 | return viewCell.GetPvs().GetSize() * objRenderTime;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[407] | 146 | /********************************************************
|
---|
| 147 | * class KdLeafRenderSimulator implementation *
|
---|
| 148 | *******************************************************/
|
---|
[406] | 149 |
|
---|
[439] | 150 | KdRenderSimulator::KdRenderSimulator(float objRenderCost,
|
---|
[409] | 151 | float vcOverhead,
|
---|
| 152 | float moveSpeed,
|
---|
[406] | 153 | KdTree *kdTree):
|
---|
[409] | 154 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
|
---|
[406] | 155 | {
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[440] | 158 | KdRenderSimulator::KdRenderSimulator(KdTree *kdTree):
|
---|
| 159 | mKdTree(kdTree)
|
---|
| 160 | {
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[439] | 163 | SimulationStatistics KdRenderSimulator::SimulateRendering()
|
---|
[406] | 164 | {
|
---|
[439] | 165 | SimulationStatistics simStat;
|
---|
| 166 |
|
---|
[407] | 167 | //mKdTree->CollectLeavesPvs();
|
---|
[439] | 168 | simStat.Reset();
|
---|
| 169 | simStat.Start();
|
---|
[407] | 170 |
|
---|
| 171 | // total render time
|
---|
[406] | 172 | Real renderTime = 0;
|
---|
[407] | 173 | // overhead for loading a view cell
|
---|
[409] | 174 | float loadPvsOverhead = 0;
|
---|
[406] | 175 |
|
---|
[407] | 176 | // probability that view point lies in a view cell
|
---|
| 177 | float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
|
---|
[406] | 178 |
|
---|
[407] | 179 | // total probability that a view cell border is crossed
|
---|
[418] | 180 | const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea();
|
---|
[407] | 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 |
|
---|
[414] | 201 | float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
|
---|
| 202 | renderTime += vcCost;
|
---|
| 203 |
|
---|
[439] | 204 | if (vcCost > simStat.maxCost)
|
---|
| 205 | simStat.maxCost = vcCost;
|
---|
| 206 | else if (vcCost < simStat.minCost)
|
---|
| 207 | simStat.minCost = vcCost;
|
---|
[414] | 208 |
|
---|
[418] | 209 | // probability that a view cell border is crossed
|
---|
| 210 | const float pCrossVc = box.SurfaceArea() * mMoveSpeed;
|
---|
[407] | 211 |
|
---|
[418] | 212 | loadPvsOverhead += pCrossVc * mVcOverhead;
|
---|
| 213 |
|
---|
[407] | 214 | pInVcTotal += pInVc;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | renderTime /= pInVcTotal;
|
---|
[409] | 218 | loadPvsOverhead /= pCrossVcTotal;
|
---|
[407] | 219 |
|
---|
[439] | 220 | simStat.avgRtWithoutOverhead = renderTime;
|
---|
| 221 | simStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
[419] | 222 |
|
---|
[439] | 223 | simStat.maxCost /= pInVcTotal;
|
---|
| 224 | simStat.minCost /= pInVcTotal;
|
---|
[420] | 225 |
|
---|
[439] | 226 | simStat.Stop();
|
---|
[414] | 227 |
|
---|
[439] | 228 | return simStat;
|
---|
[407] | 229 | }
|
---|
| 230 |
|
---|
[439] | 231 | Real KdRenderSimulator::RenderPvs(KdLeaf *leaf,
|
---|
| 232 | float objRenderTime) const
|
---|
[407] | 233 | {
|
---|
| 234 | return leaf->mKdPvs.GetSize() * objRenderTime;
|
---|
[406] | 235 | } |
---|