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

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