#include "RenderSimulator.h" #include "KdTree.h" #include "ViewCellBsp.h" #include "ViewCell.h" #include "VspBspTree.h" #include "ViewCellsManager.h" namespace GtpVisibilityPreprocessor { void SimulationStatistics::Print(ostream &app) const { app << "============== Render Simulation statistics ==============\n"; app << setprecision(4); app << "#N_CTIME ( Simulation time [s] )\n" << Time() << " \n"; app << "#MAX_COST ( maximal cost of a view cell )\n" << maxCost << "\n"; app << "#MIN_COST ( minimal cost of a view cell )\n" << minCost << "\n"; app << "#AVG_RENDER_TIME ( average render time )\n" << avgRenderTime << "\n"; app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n" << avgRtWithoutOverhead << "\n"; app << "#VALID_MAX_COST ( maximal cost of a valid view cell )\n" << validMaxCost << "\n"; app << "#VALID_MIN_COST ( minimal cost of a valid view cell )\n" << validMinCost << "\n"; app << "#VALID_AVG_RENDER_TIME ( average render time )\n" << validAvgRenderTime << "\n"; app << "#VALID_AVG_RENDER_TIME_NO_OVERHEAD ( valid average render time without overhead )\n" << validAvgRtWithoutOverhead << "\n"; app << "=========== END OF Render Simulation statistics ==========\n"; } RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager): Renderer(NULL, viewCellsManager), mObjRenderCost(0.0f), mVcOverhead(0.0f), mMoveSpeed(0.0f) {} RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager, float objRenderCost, float vcOverhead, float moveSpeed): Renderer(NULL, viewCellsManager), mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead), mMoveSpeed(moveSpeed) { } void RenderSimulator::SetObjectRenderCost(const float objRenderCost) { mObjRenderCost = objRenderCost; } void RenderSimulator::SetVcOverhead(const float vcOverhead) { mVcOverhead = vcOverhead; } void RenderSimulator::SetMoveSpeed(const float moveSpeed) { mMoveSpeed = moveSpeed; } bool RenderSimulator::RenderScene() { mSimulationStatistics.Reset(); mSimulationStatistics.Start(); Real renderTime = 0; Real validRenderTime = 0; // overhead for loading the PVS of the view cells float loadPvsOverhead = 0; float validLoadPvsOverhead = 0; ViewCellContainer::const_iterator it, it_end = mViewCellsManager->GetViewCells().end(); for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it) { ViewCell *vc = *it; const bool valid = vc->GetValid(); // probability of view cell const float pInVc = mViewCellsManager->GetProbability(vc); //Debug << "vc prob: " << pInVc << endl; // compute render time of PVS times probability // that view point is in view cell const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc/*, mObjRenderCost*/); renderTime += vcCost; // crossing the border of a view cell is depending on the move // speed and the probability that a view cell border is crossed loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; //-- update statistics if (vcCost > mSimulationStatistics.maxCost) mSimulationStatistics.maxCost = vcCost; else if (vcCost < mSimulationStatistics.minCost) mSimulationStatistics.minCost = vcCost; //-- different statistics for only valid view cells if (valid) { validLoadPvsOverhead += GetCrossVcProbability() * mVcOverhead; validRenderTime += vcCost; if (vcCost > mSimulationStatistics.validMaxCost) mSimulationStatistics.validMaxCost = vcCost; else if (vcCost < mSimulationStatistics.validMinCost) mSimulationStatistics.validMinCost = vcCost; } } mSimulationStatistics.avgRtWithoutOverhead = renderTime; mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead; mSimulationStatistics.validAvgRtWithoutOverhead = renderTime; mSimulationStatistics.validAvgRenderTime = renderTime + loadPvsOverhead; mSimulationStatistics.Stop(); return true; } float RenderSimulator::GetCrossVcProbability() const { // assume the view cells are uniformly distributed //NOTE: should I take move speed relative to view space or absolute? const float vcNum = (float)mViewCellsManager->GetViewCells().size(); const float prop = mMoveSpeed * vcNum; // clamp probability between 0 and 1 return min(1.0f, prop); } void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const { simStats = mSimulationStatistics; } }