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

Revision 416, 5.5 KB checked in by mattausch, 19 years ago (diff)
RevLine 
[406]1#include "RenderSimulator.h"
2#include "KdTree.h"
3#include "ViewCellBsp.h"
4#include "ViewCell.h"
5
[414]6void 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]25RenderSimulator::RenderSimulator()
26{}
27
[409]28RenderSimulator::RenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed):
29mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead), mMoveSpeed(moveSpeed)
[406]30{
31}
32
33/*****************************************************
34 *     class ViewCellRenderSimulator implementation  *
35 *****************************************************/
36
[409]37BspViewCellRenderSimulator::BspViewCellRenderSimulator(float objRenderCost,
[406]38                                                                                           float vcOverhead,
[409]39                                                                                           float moveSpeed,
[406]40                                                                                           BspTree *bspTree):
[409]41RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree)
[406]42{
43}
44
[409]45Real BspViewCellRenderSimulator::SimulateRendering()
[406]46{
[414]47        mStat.Reset();
48        mStat.Start();
49
[406]50        Real renderTime = 0;
[414]51       
[409]52        // overhead for loading the PVS of the view cells
53        float loadPvsOverhead = 0;
54        // probability that view point lies in a view cell
55        float pInVcTotal = 0;
56        // total probability that a view cell border is crossed
57        float pCrossVcTotal = 0;
58
59        // collect all view cells
[406]60        ViewCellContainer viewCells;
61        mBspTree->CollectViewCells(viewCells);
62
63        ViewCellContainer::const_iterator it, it_end = viewCells.end();
[407]64
65        // surface area substitute for probability
[409]66        PolygonContainer geom;
[407]67
[406]68        for (it = viewCells.begin(); it != it_end; ++ it)
69        {
[410]70                // compute view cell area
[409]71                mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
[410]72                const float area = Polygon3::GetArea(geom);
[409]73                CLEAR_CONTAINER(geom);
74
75                // area substitute for view point probability
76                float pInVc = area;
77                               
78                // compute render time of PVS times probability that view point is in view cell
[414]79                float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
[416]80                Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
[414]81                renderTime += vcCost;
82
83                if (vcCost > mStat.maxCost)
84                        mStat.maxCost = vcCost;
85                else if (vcCost < mStat.minCost)
86                        mStat.minCost = vcCost;
87
[409]88                // probability that a view cell border is crossed
89                float pCrossVc = area;
90
[414]91                // crossing the border of a view cell is also depending on the move speed
[409]92                loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
93
94                pInVcTotal += pInVc;
95                pCrossVcTotal += pCrossVc;
[406]96        }
97
[409]98       
99        renderTime /= pInVcTotal;
100        loadPvsOverhead /= pCrossVcTotal;
[406]101
[416]102        Debug << "bsp RT: " << renderTime << endl;
103        Debug << "bsp pvsOverhead: " << loadPvsOverhead << endl;
104
[414]105        mStat.avgRtWithoutOverhead = renderTime;
106        mStat.avgRenderTime = renderTime + loadPvsOverhead;
[409]107       
[414]108        mStat.Stop();
109
[409]110        return renderTime + loadPvsOverhead;
[406]111}
112
[409]113Real BspViewCellRenderSimulator::RenderPvs(ViewCell &viewCell,
[407]114                                                                           float objRenderTime) const
[406]115{
116        return viewCell.GetPvs().GetSize() * objRenderTime;
117}
118
[407]119/********************************************************
120 *     class KdLeafRenderSimulator implementation       *
121 *******************************************************/
[406]122
[409]123KdViewCellRenderSimulator::KdViewCellRenderSimulator(float objRenderCost,
124                                                                                         float vcOverhead,
125                                                                                         float moveSpeed,
[406]126                                                                                         KdTree *kdTree):
[409]127RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
[406]128{
129}
130
[409]131Real KdViewCellRenderSimulator::SimulateRendering()
[406]132{
[407]133        //mKdTree->CollectLeavesPvs();
[414]134        mStat.Reset();
135        mStat.Start();
[407]136
137        // total render time
[406]138        Real renderTime = 0;
[407]139        // overhead for loading a view cell
[409]140        float loadPvsOverhead = 0;
[406]141
[407]142        // probability that view point lies in a view cell
143        float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
[406]144
[407]145        // total probability that a view cell border is crossed
146        float pCrossVcTotal = 0;
147
148        vector<KdLeaf *> leaves;
149        mKdTree->CollectLeaves(leaves);
150       
151        AxisAlignedBox3 box;
152
153        vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
154       
155        for (it = leaves.begin(); it != it_end; ++ it)
156        {
157                box = mKdTree->GetBox(*it);
158                       
159                // volume substitute for view point probability
160                float pInVc = 0;
161               
162                if (0)
163                        pInVc = box.GetVolume();
164                else
165                        pInVc = box.SurfaceArea();
166               
167                // probability that a view cell border is crossed
168                const float pCrossVc = box.SurfaceArea();
169
[414]170                float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
171                renderTime += vcCost;
172
173                if (vcCost > mStat.maxCost)
174                        mStat.maxCost = vcCost;
175                else if (vcCost < mStat.minCost)
176                        mStat.minCost = vcCost;
177
[409]178                loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
[407]179
180                pInVcTotal += pInVc;
181                pCrossVcTotal += pCrossVc;
182        }
183
[414]184        Debug << "RT: " << renderTime << endl;
185        Debug << "pvsOverhead: " << loadPvsOverhead << endl;
186
187
[407]188        renderTime /= pInVcTotal;
[409]189        loadPvsOverhead /= pCrossVcTotal;
[407]190
[414]191    mStat.avgRtWithoutOverhead = renderTime;
192        mStat.avgRenderTime = renderTime + loadPvsOverhead;
193       
194        mStat.Stop();
195
[409]196        return renderTime + loadPvsOverhead;
[407]197}
198
[409]199Real KdViewCellRenderSimulator::RenderPvs(KdLeaf *leaf,
[407]200                                                                                   float objRenderTime) const
201{
202        return leaf->mKdPvs.GetSize() * objRenderTime;
[406]203}
Note: See TracBrowser for help on using the repository browser.