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

Revision 477, 3.3 KB checked in by mattausch, 19 years ago (diff)

changed render simulator (probability that view cell is crossed)

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#include "ViewCellsManager.h"
8
9void SimulationStatistics::Print(ostream &app) const
10{
11        app << "===== Render Simulation statistics ===============\n";
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
23        app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n"
24                << avgRtWithoutOverhead << "\n";
25       
26        app << "===== END OF Render Simulation statistics ==========\n";
27}
28
29RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager):
30Renderer(viewCellsManager)
31{}
32
33RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager,
34                                                                 float objRenderCost,
35                                                                 float vcOverhead,
36                                                                 float moveSpeed):
37Renderer(viewCellsManager),
38mObjRenderCost(objRenderCost),
39mVcOverhead(vcOverhead),
40mMoveSpeed(moveSpeed)
41{
42}
43
44void RenderSimulator::SetObjectRenderCost(const float objRenderCost)
45{
46        mObjRenderCost = objRenderCost;
47}
48
49void RenderSimulator::SetVcOverhead(const float vcOverhead)
50{
51        mVcOverhead = vcOverhead;
52}
53
54void RenderSimulator::SetMoveSpeed(const float moveSpeed)
55{
56        mMoveSpeed = moveSpeed;
57}
58
59bool RenderSimulator::RenderScene()
60{
61        mSimulationStatistics.Reset();
62        mSimulationStatistics.Start();
63
64        Real renderTime = 0;
65       
66        // overhead for loading the PVS of the view cells
67        float loadPvsOverhead = 0;
68       
69        ViewCellContainer::const_iterator it,
70                it_end = mViewCellsManager->GetViewCells().end();
71
72       
73        for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it)
74        {
75                ViewCell *vc = *it;
76
77                // probability of view cell
78                const float pInVc = mViewCellsManager->GetProbability(vc);
79                Debug << "prop: " << pInVc << endl;
80                // compute render time of PVS times probability that view point is in view cell
81                const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc, mObjRenderCost);
82                Debug << "cost: " << vcCost << " rcost: "
83                          << mViewCellsManager->GetRendercost(vc, mObjRenderCost) << endl;
84
85                // crossing the border of a view cell is depending on the move speed
86                // and the probability that a view cell border is crossed
87                loadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
88
89                Debug << "crossvc: " << GetCrossVcProbability() * mVcOverhead << endl;
90                //-- update statistics
91                renderTime += vcCost;
92       
93                if (vcCost > mSimulationStatistics.maxCost)
94                        mSimulationStatistics.maxCost = vcCost;
95                else if (vcCost < mSimulationStatistics.minCost)
96                        mSimulationStatistics.minCost = vcCost;
97        }
98       
99        mSimulationStatistics.avgRtWithoutOverhead = renderTime;
100        mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead;
101       
102        mSimulationStatistics.Stop();
103
104        return true;
105}
106
107float RenderSimulator::GetCrossVcProbability() const
108{
109        // assume the view cells are uniformly distributed
110        const float vcNum =
111                (float)mViewCellsManager->GetViewCells().size();
112
113        return 1.0f - (1 / mMoveSpeed * vcNum);
114}
115
116void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const
117{
118        simStats = mSimulationStatistics;
119}
Note: See TracBrowser for help on using the repository browser.