[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"
|
---|
[406] | 7 |
|
---|
[414] | 8 | void 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 |
|
---|
[406] | 27 | RenderSimulator::RenderSimulator()
|
---|
| 28 | {}
|
---|
| 29 |
|
---|
[439] | 30 | RenderSimulator::RenderSimulator(float objRenderCost,
|
---|
| 31 | float vcOverhead,
|
---|
| 32 | float moveSpeed):
|
---|
| 33 | mObjRenderCost(objRenderCost),
|
---|
| 34 | mVcOverhead(vcOverhead),
|
---|
| 35 | mMoveSpeed(moveSpeed)
|
---|
[406] | 36 | {
|
---|
| 37 | }
|
---|
[439] | 38 | |
---|
| 39 | void RenderSimulator::SetObjectRenderCost(const float objRenderCost) |
---|
| 40 | { |
---|
| 41 | mObjRenderCost = objRenderCost; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | void RenderSimulator::SetVcOverhead(const float vcOverhead) |
---|
| 45 | { |
---|
| 46 | mVcOverhead = vcOverhead; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | void RenderSimulator::SetMoveSpeed(const float moveSpeed) |
---|
| 50 | { |
---|
| 51 | mMoveSpeed = moveSpeed; |
---|
| 52 | }
|
---|
[406] | 53 |
|
---|
[439] | 54 | /********************************************************/
|
---|
| 55 | /* class BspRenderSimulator implementation */
|
---|
| 56 | /********************************************************/
|
---|
[448] | 57 |
|
---|
| 58 |
|
---|
[440] | 59 | BspRenderSimulator::BspRenderSimulator(BspTree *bspTree):
|
---|
| 60 | mBspTree(bspTree)
|
---|
| 61 | {
|
---|
| 62 | }
|
---|
[406] | 63 |
|
---|
[439] | 64 | BspRenderSimulator::BspRenderSimulator(float objRenderCost,
|
---|
[406] | 65 | float vcOverhead,
|
---|
[409] | 66 | float moveSpeed,
|
---|
[406] | 67 | BspTree *bspTree):
|
---|
[409] | 68 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree)
|
---|
[406] | 69 | {
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[439] | 72 | SimulationStatistics BspRenderSimulator::SimulateRendering()
|
---|
[406] | 73 | {
|
---|
[439] | 74 | SimulationStatistics simStat;
|
---|
[414] | 75 |
|
---|
[439] | 76 | simStat.Reset();
|
---|
| 77 | simStat.Start();
|
---|
| 78 |
|
---|
[406] | 79 | Real renderTime = 0;
|
---|
[414] | 80 |
|
---|
[409] | 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;
|
---|
[418] | 85 |
|
---|
[409] | 86 | // total probability that a view cell border is crossed
|
---|
[418] | 87 | const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea();
|
---|
[409] | 88 |
|
---|
| 89 | // collect all view cells
|
---|
[406] | 90 | ViewCellContainer viewCells;
|
---|
| 91 | mBspTree->CollectViewCells(viewCells);
|
---|
| 92 |
|
---|
| 93 | ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
[407] | 94 |
|
---|
| 95 | // surface area substitute for probability
|
---|
[409] | 96 | PolygonContainer geom;
|
---|
[420] | 97 | float overallarea = 0;
|
---|
[406] | 98 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
| 99 | {
|
---|
[410] | 100 | // compute view cell area
|
---|
[409] | 101 | mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
|
---|
[410] | 102 | const float area = Polygon3::GetArea(geom);
|
---|
[420] | 103 | if (area < 0.0001)
|
---|
| 104 | Debug << "warning, area: " << area << endl;
|
---|
[409] | 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
|
---|
[414] | 111 | float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
|
---|
[418] | 112 | //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
|
---|
[414] | 113 | renderTime += vcCost;
|
---|
| 114 |
|
---|
[439] | 115 | if (vcCost > simStat.maxCost)
|
---|
| 116 | simStat.maxCost = vcCost;
|
---|
| 117 | else if (vcCost < simStat.minCost)
|
---|
| 118 | simStat.minCost = vcCost;
|
---|
[414] | 119 |
|
---|
[409] | 120 | // probability that a view cell border is crossed
|
---|
[418] | 121 | float pCrossVc = area * mMoveSpeed;
|
---|
[409] | 122 |
|
---|
[414] | 123 | // crossing the border of a view cell is also depending on the move speed
|
---|
[418] | 124 | loadPvsOverhead += pCrossVc * mVcOverhead;
|
---|
[439] | 125 | overallarea += area;
|
---|
[409] | 126 | pInVcTotal += pInVc;
|
---|
[406] | 127 | }
|
---|
[420] | 128 | Debug << "overall area: " << overallarea << endl;
|
---|
[409] | 129 |
|
---|
| 130 | renderTime /= pInVcTotal;
|
---|
| 131 | loadPvsOverhead /= pCrossVcTotal;
|
---|
[406] | 132 |
|
---|
[439] | 133 | simStat.avgRtWithoutOverhead = renderTime;
|
---|
| 134 | simStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
[409] | 135 |
|
---|
[439] | 136 | simStat.maxCost /= pInVcTotal;
|
---|
| 137 | simStat.minCost /= pInVcTotal;
|
---|
[420] | 138 |
|
---|
[439] | 139 | simStat.Stop();
|
---|
[414] | 140 |
|
---|
[439] | 141 | return simStat;
|
---|
[406] | 142 | }
|
---|
| 143 |
|
---|
[439] | 144 | Real BspRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
[448] | 145 | float objRenderTime) const
|
---|
[406] | 146 | {
|
---|
| 147 | return viewCell.GetPvs().GetSize() * objRenderTime;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[449] | 150 | /*******************************************************/
|
---|
| 151 | /* class KdenderSimulator implementation */
|
---|
| 152 | /*******************************************************/
|
---|
[406] | 153 |
|
---|
[439] | 154 | KdRenderSimulator::KdRenderSimulator(float objRenderCost,
|
---|
[409] | 155 | float vcOverhead,
|
---|
| 156 | float moveSpeed,
|
---|
[406] | 157 | KdTree *kdTree):
|
---|
[409] | 158 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
|
---|
[406] | 159 | {
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[440] | 162 | KdRenderSimulator::KdRenderSimulator(KdTree *kdTree):
|
---|
| 163 | mKdTree(kdTree)
|
---|
| 164 | {
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[439] | 167 | SimulationStatistics KdRenderSimulator::SimulateRendering()
|
---|
[406] | 168 | {
|
---|
[439] | 169 | SimulationStatistics simStat;
|
---|
| 170 |
|
---|
[407] | 171 | //mKdTree->CollectLeavesPvs();
|
---|
[439] | 172 | simStat.Reset();
|
---|
| 173 | simStat.Start();
|
---|
[407] | 174 |
|
---|
| 175 | // total render time
|
---|
[406] | 176 | Real renderTime = 0;
|
---|
[407] | 177 | // overhead for loading a view cell
|
---|
[409] | 178 | float loadPvsOverhead = 0;
|
---|
[406] | 179 |
|
---|
[407] | 180 | // probability that view point lies in a view cell
|
---|
| 181 | float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
|
---|
[406] | 182 |
|
---|
[407] | 183 | // total probability that a view cell border is crossed
|
---|
[418] | 184 | const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea();
|
---|
[407] | 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 |
|
---|
[414] | 205 | float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
|
---|
| 206 | renderTime += vcCost;
|
---|
| 207 |
|
---|
[439] | 208 | if (vcCost > simStat.maxCost)
|
---|
| 209 | simStat.maxCost = vcCost;
|
---|
| 210 | else if (vcCost < simStat.minCost)
|
---|
| 211 | simStat.minCost = vcCost;
|
---|
[414] | 212 |
|
---|
[418] | 213 | // probability that a view cell border is crossed
|
---|
| 214 | const float pCrossVc = box.SurfaceArea() * mMoveSpeed;
|
---|
[407] | 215 |
|
---|
[418] | 216 | loadPvsOverhead += pCrossVc * mVcOverhead;
|
---|
| 217 |
|
---|
[407] | 218 | pInVcTotal += pInVc;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | renderTime /= pInVcTotal;
|
---|
[409] | 222 | loadPvsOverhead /= pCrossVcTotal;
|
---|
[407] | 223 |
|
---|
[439] | 224 | simStat.avgRtWithoutOverhead = renderTime;
|
---|
| 225 | simStat.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
[419] | 226 |
|
---|
[439] | 227 | simStat.maxCost /= pInVcTotal;
|
---|
| 228 | simStat.minCost /= pInVcTotal;
|
---|
[420] | 229 |
|
---|
[439] | 230 | simStat.Stop();
|
---|
[414] | 231 |
|
---|
[439] | 232 | return simStat;
|
---|
[407] | 233 | }
|
---|
| 234 |
|
---|
[439] | 235 | Real KdRenderSimulator::RenderPvs(KdLeaf *leaf,
|
---|
| 236 | float objRenderTime) const
|
---|
[407] | 237 | {
|
---|
| 238 | return leaf->mKdPvs.GetSize() * objRenderTime;
|
---|
[448] | 239 | }
|
---|
| 240 |
|
---|
| 241 | /********************************************************/
|
---|
| 242 | /* class BspRenderSimulator implementation */
|
---|
| 243 | /********************************************************/
|
---|
[449] | 244 |
|
---|
[448] | 245 | VspBspRenderSimulator::VspBspRenderSimulator(VspBspTree *vspBspTree):
|
---|
| 246 | mVspBspTree(vspBspTree)
|
---|
| 247 | {
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | VspBspRenderSimulator::VspBspRenderSimulator(float objRenderCost,
|
---|
| 251 | float vcOverhead,
|
---|
| 252 | float moveSpeed,
|
---|
| 253 | VspBspTree *vspBspTree):
|
---|
| 254 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed),
|
---|
| 255 | mVspBspTree(vspBspTree)
|
---|
| 256 | {
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | SimulationStatistics 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;
|
---|
| 284 | float 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;
|
---|
| 313 | overallarea += 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 |
|
---|
| 332 | Real VspBspRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
| 333 | float objRenderTime) const
|
---|
| 334 | {
|
---|
| 335 | return viewCell.GetPvs().GetSize() * objRenderTime;
|
---|
| 336 | }
|
---|
[449] | 337 |
|
---|
| 338 |
|
---|
| 339 |
|
---|
| 340 | /********************************************************/
|
---|
| 341 | /* class BspRenderSimulator implementation */
|
---|
| 342 | /********************************************************/
|
---|
| 343 |
|
---|
| 344 |
|
---|
| 345 | VspKdRenderSimulator::VspKdRenderSimulator(VspKdTree *vspKdTree):
|
---|
| 346 | mVspKdTree(vspKdTree)
|
---|
| 347 | {
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | VspKdRenderSimulator::VspKdRenderSimulator(float objRenderCost,
|
---|
| 351 | float vcOverhead,
|
---|
| 352 | float moveSpeed,
|
---|
| 353 | VspKdTree *vspKdTree):
|
---|
| 354 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed),
|
---|
| 355 | mVspKdTree(vspKdTree)
|
---|
| 356 | {
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | SimulationStatistics VspKdRenderSimulator::SimulateRendering()
|
---|
| 360 | {
|
---|
| 361 | SimulationStatistics simStat;
|
---|
| 362 |
|
---|
| 363 | simStat.Reset();
|
---|
| 364 | simStat.Start();
|
---|
| 365 |
|
---|
| 366 | // TODO
|
---|
| 367 | simStat.Stop();
|
---|
| 368 |
|
---|
| 369 | return simStat;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | Real VspKdRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
| 373 | float objRenderTime) const
|
---|
| 374 | {
|
---|
| 375 | return 0; // TODO
|
---|
| 376 | } |
---|