Changeset 468


Ignore:
Timestamp:
12/15/05 18:45:12 (18 years ago)
Author:
mattausch
Message:

updated rendersimulator

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj

    r448 r468  
    249249                        </File> 
    250250                        <File 
     251                                RelativePath="..\src\Renderer.cpp"> 
     252                        </File> 
     253                        <File 
     254                                RelativePath="..\src\Renderer.h"> 
     255                        </File> 
     256                        <File 
    251257                                RelativePath="..\src\RenderSimulator.cpp"> 
    252258                        </File> 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r463 r468  
    1515class VspKdTree; 
    1616class VspBspTree; 
     17class RenderSimulator; 
    1718 
    1819/** Namespace for the external visibility preprocessor 
     
    100101  VspKdTree *mVspKdTree; 
    101102 
     103  /** Simulates rendering of the scene. 
     104  */ 
     105  RenderSimulator *mRenderSimulator; 
     106 
    102107protected: 
    103108 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp

    r465 r468  
    55#include "VspBspTree.h" 
    66#include "VspKdTree.h" 
     7#include "ViewCellsManager.h" 
    78 
    89void SimulationStatistics::Print(ostream &app) const 
     
    5253} 
    5354 
    54 /********************************************************/ 
    55 /*     class BspRenderSimulator implementation          */ 
    56 /********************************************************/ 
    57  
    58  
    59 BspRenderSimulator::BspRenderSimulator(BspTree *bspTree): 
    60 mBspTree(bspTree) 
     55bool RenderSimulator::RenderScene() 
    6156{ 
    62 } 
    63  
    64 BspRenderSimulator::BspRenderSimulator(float objRenderCost,  
    65                                                                                            float vcOverhead,  
    66                                                                                            float moveSpeed, 
    67                                                                                            BspTree *bspTree): 
    68 RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree) 
    69 { 
    70 } 
    71  
    72 SimulationStatistics BspRenderSimulator::SimulateRendering() 
    73 { 
    74         SimulationStatistics simStat; 
    75  
    76         simStat.Reset(); 
    77         simStat.Start(); 
     57        mSimulationStatistics.Reset(); 
     58        mSimulationStatistics.Start(); 
    7859 
    7960        Real renderTime = 0; 
     
    8162        // overhead for loading the PVS of the view cells 
    8263        float loadPvsOverhead = 0; 
    83         // probability that view point lies in a view cell 
    84         float pInVcTotal = 0; 
     64         
     65        ViewCellContainer::const_iterator it,  
     66                it_end = mViewCellsManager->GetViewCells().end(); 
    8567 
    86         // total probability that a view cell border is crossed 
    87         const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea(); 
     68        for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it) 
     69        { 
     70                ViewCell *vc = *it; 
    8871 
    89         // collect all view cells 
    90         ViewCellContainer viewCells; 
    91         mBspTree->CollectViewCells(viewCells); 
    92  
    93         ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    94  
    95         // surface area substitute for probability 
    96         PolygonContainer geom; 
    97 float overallarea = 0; 
    98         for (it = viewCells.begin(); it != it_end; ++ it) 
    99         { 
    100                 // compute view cell area 
    101                 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom); 
    102                 const float area = Polygon3::GetArea(geom); 
    103                 if (area < 0.0001) 
    104                         Debug << "warning, area: " << area << endl; 
    105                 CLEAR_CONTAINER(geom); 
    106  
    107                 // area substitute for view point probability 
    108                 float pInVc = area; 
     72                // probability of view cell 
     73                const float pInVc = mViewCellsManager->GetProbability(vc); 
    10974                                 
    11075                // compute render time of PVS times probability that view point is in view cell 
    111                 float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost); 
    112                 //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl; 
     76                const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc, mObjRenderCost); 
     77                 
     78                // crossing the border of a view cell is depending on the move speed 
     79                // and the probability that a view cell border is crossed 
     80                loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 
     81 
     82                //-- update statistics 
    11383                renderTime += vcCost; 
    11484 
    115                 if (vcCost > simStat.maxCost) 
    116                         simStat.maxCost = vcCost; 
    117                 else if (vcCost < simStat.minCost) 
    118                         simStat.minCost = vcCost; 
     85                if (vcCost > mSimulationStatistics.maxCost) 
     86                        mSimulationStatistics.maxCost = vcCost; 
     87                else if (vcCost < mSimulationStatistics.minCost) 
     88                        mSimulationStatistics.minCost = vcCost; 
     89        } 
     90         
     91        mSimulationStatistics.avgRtWithoutOverhead = renderTime; 
     92        mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead; 
     93         
     94        mSimulationStatistics.Stop(); 
    11995 
    120                 // probability that a view cell border is crossed 
    121                 float pCrossVc = area * mMoveSpeed; 
    122  
    123                 // crossing the border of a view cell is also depending on the move speed 
    124                 loadPvsOverhead += pCrossVc * mVcOverhead; 
    125 overallarea += area; 
    126                 pInVcTotal += pInVc; 
    127         } 
    128         Debug << "overall area: " << overallarea << endl; 
    129          
    130         renderTime /= pInVcTotal; 
    131         loadPvsOverhead /= pCrossVcTotal; 
    132  
    133         simStat.avgRtWithoutOverhead = renderTime; 
    134         simStat.avgRenderTime = renderTime + loadPvsOverhead; 
    135          
    136         simStat.maxCost /= pInVcTotal; 
    137         simStat.minCost /= pInVcTotal; 
    138  
    139         simStat.Stop(); 
    140  
    141         return simStat; 
     96        return true; 
    14297} 
    14398 
    144 Real BspRenderSimulator::RenderPvs(ViewCell &viewCell,  
    145                                                                    float objRenderTime) const 
     99float RenderSimulator::GetCrossVcProbability() 
    146100{ 
    147         return viewCell.GetPvs().GetSize() * objRenderTime; 
     101        return 0; 
    148102} 
    149103 
    150 /*******************************************************/ 
    151 /*     class KdenderSimulator implementation           */ 
    152 /*******************************************************/ 
    153  
    154 KdRenderSimulator::KdRenderSimulator(float objRenderCost,  
    155                                                                                          float vcOverhead, 
    156                                                                                          float moveSpeed, 
    157                                                                                          KdTree *kdTree): 
    158 RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree) 
     104void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const 
    159105{ 
     106        simStats = mSimulationStatistics; 
    160107} 
    161  
    162 KdRenderSimulator::KdRenderSimulator(KdTree *kdTree): 
    163 mKdTree(kdTree) 
    164 { 
    165 } 
    166  
    167 SimulationStatistics KdRenderSimulator::SimulateRendering() 
    168 { 
    169         SimulationStatistics simStat; 
    170  
    171         //mKdTree->CollectLeavesPvs(); 
    172         simStat.Reset(); 
    173         simStat.Start(); 
    174  
    175         // total render time 
    176         Real renderTime = 0; 
    177         // overhead for loading a view cell 
    178         float loadPvsOverhead = 0; 
    179  
    180         // probability that view point lies in a view cell 
    181         float pInVcTotal = 0;//mKdTree->GetBox().GetVolume(); 
    182  
    183         // total probability that a view cell border is crossed 
    184         const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea(); 
    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                  
    205                 float vcCost = pInVc * RenderPvs(*it, mObjRenderCost); 
    206                 renderTime += vcCost; 
    207  
    208                 if (vcCost > simStat.maxCost) 
    209                         simStat.maxCost = vcCost; 
    210                 else if (vcCost < simStat.minCost) 
    211                         simStat.minCost = vcCost; 
    212  
    213                 // probability that a view cell border is crossed 
    214                 const float pCrossVc = box.SurfaceArea() * mMoveSpeed; 
    215  
    216                 loadPvsOverhead += pCrossVc * mVcOverhead; 
    217  
    218                 pInVcTotal += pInVc; 
    219         } 
    220  
    221         renderTime /= pInVcTotal; 
    222         loadPvsOverhead /= pCrossVcTotal; 
    223  
    224     simStat.avgRtWithoutOverhead = renderTime; 
    225         simStat.avgRenderTime = renderTime + loadPvsOverhead; 
    226  
    227         simStat.maxCost /= pInVcTotal; 
    228         simStat.minCost /= pInVcTotal; 
    229  
    230         simStat.Stop(); 
    231  
    232         return simStat; 
    233 } 
    234  
    235 Real KdRenderSimulator::RenderPvs(KdLeaf *leaf,  
    236                                                                   float objRenderTime) const 
    237 { 
    238         return leaf->mKdPvs.GetSize() * objRenderTime; 
    239 } 
    240  
    241 /**********************************************************/ 
    242 /*       class BspRenderSimulator implementation          */ 
    243 /**********************************************************/ 
    244  
    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 } 
    337  
    338  
    339  
    340 /*************************************************************/ 
    341 /*        class VspKdRenderSimulator 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 {SimulationStatistics simStat; 
    361  
    362         simStat.Reset(); 
    363         simStat.Start(); 
    364  
    365         Real renderTime = 0; 
    366          
    367         // overhead for loading the PVS of the view cells 
    368         float loadPvsOverhead = 0; 
    369         // probability that view point lies in a view cell 
    370         float pInVcTotal = 0; 
    371  
    372         // total probability that a view cell border is crossed 
    373 /*      const float pCrossVcTotal = mVspBspTree->GetBoundingBox().SurfaceArea(); 
    374  
    375         // collect all view cells 
    376         ViewCellContainer viewCells; 
    377         mVspBspTree->CollectViewCells(viewCells); 
    378  
    379         ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    380  
    381         // surface area substitute for probability 
    382         PolygonContainer geom; 
    383 float overallarea = 0; 
    384         for (it = viewCells.begin(); it != it_end; ++ it) 
    385         { 
    386                 // compute view cell area 
    387                 mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom); 
    388  
    389                 const float area = Polygon3::GetArea(geom); 
    390                 if (area < 0.0001) 
    391                         Debug << "warning, area: " << area << endl; 
    392                 CLEAR_CONTAINER(geom); 
    393  
    394                 // area substitute for view point probability 
    395                 float pInVc = area; 
    396                                  
    397                 // compute render time of PVS times probability that view point is in view cell 
    398                 float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost); 
    399                 //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl; 
    400                 renderTime += vcCost; 
    401  
    402                 if (vcCost > simStat.maxCost) 
    403                         simStat.maxCost = vcCost; 
    404                 else if (vcCost < simStat.minCost) 
    405                         simStat.minCost = vcCost; 
    406  
    407                 // probability that a view cell border is crossed 
    408                 float pCrossVc = area * mMoveSpeed; 
    409  
    410                 // crossing the border of a view cell is also depending on the move speed 
    411                 loadPvsOverhead += pCrossVc * mVcOverhead; 
    412 overallarea += area; 
    413                 pInVcTotal += pInVc; 
    414         } 
    415         Debug << "overall area: " << overallarea << endl; 
    416          
    417         renderTime /= pInVcTotal; 
    418         loadPvsOverhead /= pCrossVcTotal; 
    419  
    420         simStat.avgRtWithoutOverhead = renderTime; 
    421         simStat.avgRenderTime = renderTime + loadPvsOverhead; 
    422          
    423         simStat.maxCost /= pInVcTotal; 
    424         simStat.minCost /= pInVcTotal; 
    425  
    426         simStat.Stop(); 
    427 */ 
    428         return simStat; 
    429 } 
    430  
    431 Real VspKdRenderSimulator::RenderPvs(ViewCell &viewCell,  
    432                                                                          float objRenderTime) const 
    433 { 
    434         return 0; // TODO 
    435 } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h

    r463 r468  
    44#include "common.h" 
    55#include "Statistics.h" 
     6#include "Renderer.h" 
    67 
    7 class BspTree; 
    8 class KdTree; 
    9 class ViewCell; 
    10 class KdLeaf; 
    11 class VspKdTree; 
    12 class VspBspTree; 
    138 
    149class SimulationStatistics: public StatisticsBase 
     
    4742 
    4843/** Simulated rendering using a simple render heuristics. Used to evaluate the  
    49         quality of the view cell partition. 
     44        quality of the view cell partition. Evaluates some statistics of the simulation. 
    5045*/ 
    51 class RenderSimulator 
     46class RenderSimulator: public Renderer 
    5247{ 
    5348 
     
    5954        */ 
    6055        RenderSimulator(float objRendercost, float vcOverhead, float moveSpeed); 
    61  
    62         /** Simulates rendering of the view cells. 
    63                 @returns the statistics of the simulation. 
    64         */ 
    65         virtual SimulationStatistics SimulateRendering() = 0; 
    6656 
    6757        /** Sets estimated render time for a single object in the PVS. 
     
    7767        void SetMoveSpeed(const float moveSpeed); 
    7868 
     69        /** Returns simulation statistics. 
     70        */ 
     71        void GetStatistics(SimulationStatistics &simStats) const; 
     72 
     73        /** Simulates rendering of the scene. 
     74        */ 
     75        bool RenderScene(); 
    7976 
    8077protected: 
    8178 
     79        /** Probability for crossing one view cell. 
     80        */ 
     81        float GetCrossVcProbability(); 
     82 
    8283        /// render time for single object of the PVS 
    8384        float mObjRenderCost; 
     85         
    8486        /// const overhead for crossing a view cell border 
    8587        float mVcOverhead; 
     88 
    8689        /// move speed of player 
    8790        float mMoveSpeed; 
    88 }; 
    8991 
    90 class BspRenderSimulator: public RenderSimulator 
    91 { 
    92 public: 
    93         BspRenderSimulator(BspTree *bspTree); 
    94  
    95         BspRenderSimulator(float objRenderCost,  
    96                                                            float vcOverhead,  
    97                                                            float moveSpeed,  
    98                                                            BspTree *bspTree); 
    99  
    100         SimulationStatistics SimulateRendering(); 
    101  
    102 protected: 
    103         /** Simulates rendering of the pvs of one view cell, with given rendering time for an object. 
    104                 @param viewCell the view cell holding the Pvs 
    105                 @param objRenderTime estimated render time for one object of the Pvs 
    106         */ 
    107         Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const; 
    108  
    109 private: 
    110         BspTree *mBspTree; 
    111 }; 
    112  
    113 class VspBspRenderSimulator: public RenderSimulator 
    114 { 
    115 public: 
    116         VspBspRenderSimulator(VspBspTree *vspBspTree); 
    117  
    118         VspBspRenderSimulator(float objRenderCost,  
    119                                                   float vcOverhead,  
    120                                                   float moveSpeed,  
    121                                                   VspBspTree *vspBspTree); 
    122  
    123         SimulationStatistics SimulateRendering(); 
    124  
    125 protected: 
    126         /** Simulates rendering of the pvs of one view cell, with given rendering time for an object. 
    127                 @param viewCell the view cell holding the Pvs 
    128                 @param objRenderTime estimated render time for one object of the Pvs 
    129         */ 
    130         Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const; 
    131  
    132 private: 
    133         VspBspTree *mVspBspTree; 
    134 }; 
    135  
    136 class KdRenderSimulator: public RenderSimulator 
    137 { 
    138 public: 
    139         KdRenderSimulator(KdTree *kdTree); 
    140  
    141         KdRenderSimulator(float objRenderCost,  
    142                                                           float vcOverhead,  
    143                                                           float moveSpeed,  
    144                                                           KdTree *kdTree); 
    145         SimulationStatistics SimulateRendering(); 
    146  
    147 protected: 
    148  
    149         Real RenderPvs(KdLeaf *leaf, float objRenderTime) const; 
    150  
    151         KdTree *mKdTree; 
    152 }; 
    153  
    154 class VspKdRenderSimulator: public RenderSimulator 
    155 { 
    156 public: 
    157         VspKdRenderSimulator(VspKdTree *vspKdTree); 
    158  
    159         VspKdRenderSimulator(float objRenderCost,  
    160                                                  float vcOverhead,  
    161                                                  float moveSpeed,  
    162                                                  VspKdTree *vspKdTree); 
    163  
    164         SimulationStatistics SimulateRendering(); 
    165  
    166 protected: 
    167         /** Simulates rendering of the pvs of one view cell, with given rendering time for an object. 
    168                 @param viewCell the view cell holding the Pvs 
    169                 @param objRenderTime estimated render time for one object of the Pvs 
    170         */ 
    171         Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const; 
    172  
    173 private: 
    174         VspKdTree *mVspKdTree; 
     92        /// Simulation statistics 
     93        SimulationStatistics mSimulationStatistics; 
    17594}; 
    17695 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp

    r467 r468  
    642642  cout << "\nevaluating bsp view cells render time after merge ... "; 
    643643   
    644   const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 
    645    
     644  mRenderSimulator->RenderScene(); 
     645  SimulationStatistics ss; 
     646  mRenderSimulator->GetStatistics(ss); 
     647 
    646648  cout << " finished" << endl; 
    647649  cout << ss << endl; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r466 r468  
    394394        cout << "\nevaluating bsp view cells render time after merge ... "; 
    395395                  
    396         const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 
    397                   
    398         cout << " finished" << endl; 
    399         cout << ss << endl; 
    400         Debug << ss << endl; 
     396         //-- render simulation after merge 
     397        cout << "\nevaluating bsp view cells render time after merge ... "; 
     398         
     399         mRenderSimulator->RenderScene(); 
     400         SimulationStatistics ss; 
     401         mRenderSimulator->GetStatistics(ss); 
     402          
     403         cout << " finished" << endl; 
     404         cout << ss << endl; 
     405         Debug << ss << endl; 
    401406         
    402407        // $$JB temporary removed 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r466 r468  
    18631863 
    18641864 
    1865 int 
    1866 BspTree::CastLineSegment(const Vector3 &origin, 
    1867                                                  const Vector3 &termination, 
    1868                                                  vector<ViewCell *> &viewcells 
    1869                                                  ) 
     1865int BspTree::CastLineSegment(const Vector3 &origin, 
     1866                                                         const Vector3 &termination, 
     1867                                                         vector<ViewCell *> &viewcells) 
    18701868{ 
    18711869  int hits = 0; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r467 r468  
    164164} 
    165165 
    166 SimulationStatistics ViewCellsManager::SimulateRendering() const 
    167 { 
    168         if (!ViewCellsConstructed() || !mRenderSimulator) 
    169                 return SimulationStatistics(); 
    170  
    171         return mRenderSimulator->SimulateRendering(); 
    172 } 
    173166 
    174167ViewCell *ViewCellsManager::GenerateViewCell(Mesh *mesh) const 
     
    242235} 
    243236 
     237ViewCellContainer &ViewCellsManager::GetViewCells() 
     238{ 
     239        return mViewCells; 
     240} 
     241 
     242void ViewCellsManager::ComputeSampleContributions(VssRay &ray) 
     243{ 
     244        ViewCellContainer viewcells; 
     245         
     246        CastLineSegment(ray.mOrigin, 
     247                                        ray.mTermination, 
     248                                        viewcells); 
     249         
     250        ray.mPvsContribution = 0; 
     251        ray.mRelativePvsContribution = 0.0f; 
     252   
     253        ViewCellContainer::const_iterator it = viewcells.begin(); 
     254         
     255        for (; it != viewcells.end(); ++it)  
     256        {        
     257                ViewCell *viewcell = *it; 
     258         
     259                // if ray not outside of view space 
     260                float contribution; 
     261                bool added =  
     262                        viewcell->GetPvs().AddSample(ray.mTerminationObject, 
     263                                                                                 contribution); 
     264                 
     265                if (added) 
     266                        ray.mPvsContribution++; 
     267                 
     268                ray.mRelativePvsContribution += contribution; 
     269        } 
     270} 
     271 
     272 
    244273/**********************************************************************/ 
    245274/*                   BspViewCellsManager implementation               */ 
     
    250279mBspTree(bspTree) 
    251280{ 
    252    mRenderSimulator = new BspRenderSimulator(bspTree); 
    253    InitRenderSimulator(); 
    254281} 
    255282 
     
    306333} 
    307334 
    308 void 
    309 ViewCellsManager::ComputeSampleContributions(VssRay &ray) 
    310 { 
    311  
    312   ViewCellContainer viewcells; 
    313    
    314   CastLineSegment(ray.mOrigin, 
    315                                   ray.mTermination, 
    316                                   viewcells 
    317                                   ); 
    318  
    319   ray.mPvsContribution = 0; 
    320   ray.mRelativePvsContribution = 0.0f; 
    321    
    322   ViewCellContainer::const_iterator it = viewcells.begin(); 
    323   for (; it != viewcells.end(); ++it) {          
    324         ViewCell *viewcell = *it; 
    325          
    326         // if ray not outside of view space 
    327         float contribution; 
    328         bool added =  
    329           viewcell->GetPvs().AddSample(ray.mTerminationObject, 
    330                                                                    contribution 
    331                                                                    ); 
    332         if (added) 
    333           ray.mPvsContribution++; 
    334          
    335         ray.mRelativePvsContribution += contribution; 
    336   } 
    337    
    338 } 
    339  
    340 int 
    341 BspViewCellsManager::CastLineSegment(const Vector3 &origin, 
    342                                                                          const Vector3 &termination, 
    343                                                                          ViewCellContainer &viewcells 
    344                                                                          ) 
    345 { 
    346   return mBspTree->CastLineSegment(origin, termination, viewcells); 
    347 } 
    348  
    349 int 
    350 BspViewCellsManager::PostProcess(const ObjectContainer &objects,  
    351                                                                  const VssRayContainer &rays) 
     335 
     336float BspViewCellsManager::GetProbability(ViewCell *viewCell) 
     337{ 
     338        PolygonContainer geom; 
     339 
     340        // compute view cell area 
     341        mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom); 
     342         
     343        const float area = Polygon3::GetArea(geom); 
     344        const float accArea = mBspTree->GetBoundingBox().SurfaceArea(); 
     345 
     346        CLEAR_CONTAINER(geom); 
     347 
     348        return area / accArea; 
     349} 
     350 
     351 
     352float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) 
     353{ 
     354        return viewCell->GetPvs().GetSize() * objRendercost; 
     355} 
     356 
     357 
     358int BspViewCellsManager::CastLineSegment(const Vector3 &origin, 
     359                                                                                 const Vector3 &termination, 
     360                                                                                 ViewCellContainer &viewcells) 
     361{ 
     362        return mBspTree->CastLineSegment(origin, termination, viewcells); 
     363} 
     364 
     365 
     366int BspViewCellsManager::PostProcess(const ObjectContainer &objects,  
     367                                                                         const VssRayContainer &rays) 
    352368{ 
    353369  if (!ViewCellsConstructed()) 
     
    392408                //-- render simulation 
    393409                cout << "\nevaluating bsp view cells render time before merge ... "; 
    394                   
    395                 const SimulationStatistics ss = SimulateRendering(); 
    396                           
    397                 cout << " finished" << endl; 
    398                 cout << ss << endl; 
    399                 Debug << ss << endl; 
     410                //-- render simulation after merge 
     411                cout << "\nevaluating bsp view cells render time after merge ... "; 
     412   
     413                 mRenderSimulator->RenderScene(); 
     414                 SimulationStatistics ss; 
     415                 mRenderSimulator->GetStatistics(ss); 
     416          
     417                 cout << " finished" << endl; 
     418                 cout << ss << endl; 
     419                 Debug << ss << endl; 
     420 
    400421        } 
    401422 
     
    819840mKdPvsDepth(100) 
    820841{ 
    821    mRenderSimulator = new KdRenderSimulator(mKdTree); 
    822    InitRenderSimulator(); 
     842} 
     843 
     844float KdViewCellsManager::GetProbability(ViewCell *viewCell) 
     845{ 
     846        return 0; 
     847} 
     848 
     849 
     850float KdViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) 
     851{ 
     852        return 0; 
    823853} 
    824854 
     
    9701000mVspKdTree(vspKdTree) 
    9711001{ 
    972    mRenderSimulator = new VspKdRenderSimulator(vspKdTree); 
    973    mVspKdTree->SetViewCellsManager(this); 
    974  
    975    InitRenderSimulator(); 
    976 } 
    977  
     1002        mVspKdTree->SetViewCellsManager(this); 
     1003} 
     1004 
     1005float VspKdViewCellsManager::GetProbability(ViewCell *viewCell) 
     1006{ 
     1007        /*AxisAlignedBox3 box = mKdTree->GetBox(*it); 
     1008                         
     1009        // volume or area substitutes for view point probability 
     1010        if (0) 
     1011                return box.GetVolume();  
     1012        else 
     1013                return box.SurfaceArea();*/ 
     1014 
     1015        return dynamic_cast<VspKdViewCell *>(viewCell)->GetSize(); 
     1016} 
     1017 
     1018 
     1019float VspKdViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) 
     1020{ 
     1021        return 0;//leaf->mKdPvs.GetSize() * objRendercost; 
     1022} 
    9781023 
    9791024VspKdViewCellsManager::~VspKdViewCellsManager() 
     
    11811226mVspBspTree(vspBspTree) 
    11821227{ 
    1183         mRenderSimulator = new VspBspRenderSimulator(vspBspTree); 
    1184         InitRenderSimulator(); 
    1185 } 
    1186  
    1187  
     1228} 
     1229 
     1230float VspBspViewCellsManager::GetProbability(ViewCell *viewCell) 
     1231{ 
     1232        PolygonContainer geom; 
     1233 
     1234        // compute view cell area 
     1235        mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom); 
     1236         
     1237        const float area = Polygon3::GetArea(geom); 
     1238        const float accArea = mVspBspTree->GetBoundingBox().SurfaceArea(); 
     1239 
     1240        CLEAR_CONTAINER(geom); 
     1241 
     1242        return area / accArea; 
     1243} 
     1244 
     1245 
     1246float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) 
     1247{ 
     1248        return viewCell->GetPvs().GetSize() * objRendercost; 
     1249} 
    11881250 
    11891251VspBspViewCellsManager::~VspBspViewCellsManager() 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r467 r468  
    6262                @param contributingSamples returns the number of contributingSamples 
    6363        */ 
    64   void  ComputeSampleContributions(const VssRayContainer &rays 
    65                                                                    ); 
     64  void  ComputeSampleContributions(const VssRayContainer &rays); 
    6665 
    6766 
     
    9493        virtual int GetType() const = 0; 
    9594 
    96         /** Simulates rendering with the given view cell partition. 
    97                 @returns render time statistics 
    98         */ 
    99         SimulationStatistics SimulateRendering() const; 
    100  
    10195        /** Load the input viewcells. The input viewcells should be given as a collection 
    10296                of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of 
     
    176170  PrintPvsStatistics(ostream &s); 
    177171 
     172  /** Returns probability that view point lies in one view cell. 
     173  */ 
     174  virtual float GetProbability(ViewCell *viewCell) = 0; 
     175 
     176  /** Returns render cost of a single view cell given the render cost of an object. 
     177  */ 
     178  virtual float GetRendercost(ViewCell *viewCell, float objRendercost) = 0; 
     179 
     180  /** Returns vector of loaded / generated view cells. 
     181  */ 
     182  ViewCellContainer &GetViewCells(); 
     183 
    178184protected: 
    179          
    180185         
    181186 
     
    239244        ~BspViewCellsManager(); 
    240245 
    241   int CastLineSegment(const Vector3 &origin, 
    242                                           const Vector3 &termination, 
    243                                           ViewCellContainer &viewcells 
    244                                           ); 
    245  
    246    
     246        int CastLineSegment(const Vector3 &origin, 
     247                                                const Vector3 &termination, 
     248                                                ViewCellContainer &viewcells); 
     249         
     250        float GetProbability(ViewCell *viewCell); 
     251        float GetRendercost(ViewCell *viewCell, float objRendercost); 
     252 
    247253protected: 
    248254 
     
    305311        */ 
    306312        virtual void PrintStatistics(ostream &s) const; 
     313 
     314        float GetProbability(ViewCell *viewCell); 
     315        float GetRendercost(ViewCell *viewCell, float objRendercost); 
    307316 
    308317protected: 
     
    353362    int CastLineSegment(const Vector3 &origin, 
    354363                                                const Vector3 &termination, 
    355                                                 ViewCellContainer &viewcells 
    356                                                 ) ; 
     364                                                ViewCellContainer &viewcells); 
     365 
     366        float GetProbability(ViewCell *viewCell); 
     367        float GetRendercost(ViewCell *viewCell, float objRendercost); 
    357368 
    358369protected: 
     
    394405 
    395406        void PrintStatistics(ostream &s) const; 
    396  
    397   int CastLineSegment(const Vector3 &origin, 
    398                                           const Vector3 &termination, 
    399                                           ViewCellContainer &viewcells 
    400                                           ) ; 
     407         
     408        int CastLineSegment(const Vector3 &origin, 
     409                                                const Vector3 &termination, 
     410                                                ViewCellContainer &viewcells); 
     411 
     412        float GetProbability(ViewCell *viewCell); 
     413        float GetRendercost(ViewCell *viewCell, float objRendercost); 
     414 
    401415 
    402416protected: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r466 r468  
    19011901 
    19021902 
    1903 int VspKdTree::CastRay(Ray &ray) 
     1903int VspKdTree::CastLineSegment(const Vector3 &origin, 
     1904                                                           const Vector3 &termination, 
     1905                                                           vector<ViewCell *> &viewcells) 
    19041906{ 
    19051907        int hits = 0; 
    19061908 
    1907         stack<RayTraversalData> tStack; 
    1908  
    1909         float maxt = 1e6; 
    1910         float mint = 0; 
     1909        float mint = 0.0f, maxt = 1.0f; 
     1910        const Vector3 dir = termination - origin; 
     1911 
     1912        stack<LineSegmentTraversalData > tStack; 
    19111913 
    19121914        Intersectable::NewMail(); 
    19131915 
    1914         if (!mBox.GetMinMaxT(ray, &mint, &maxt)) 
    1915                 return 0; 
     1916        //if (!mBox.GetMinMaxT(ray, &mint, &maxt)) return 0; 
    19161917 
    19171918        if (mint < 0) 
     
    19201921        maxt += Limits::Threshold; 
    19211922 
    1922         Vector3 entp = ray.Extrap(mint); 
    1923         Vector3 extp = ray.Extrap(maxt); 
     1923        Vector3 entp = origin; 
     1924        Vector3 extp = termination; 
    19241925 
    19251926        VspKdNode *node = mRoot; 
     
    19691970                        // $$ modification 3.5.2004 - hints from Kamil Ghais 
    19701971                        // case N4 or P4 
    1971                         float tdist = (position - ray.GetLoc(axis)) / ray.GetDir(axis); 
     1972                        float tdist = (position - origin[axis]) / dir[axis]; 
    19721973                        //tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO 
    1973                         extp = ray.GetLoc() + ray.GetDir()*tdist; 
     1974                        extp = origin + dir * tdist; 
    19741975                        maxt = tdist; 
    19751976                } 
     
    19771978                { 
    19781979                        // compute intersection with all objects in this leaf 
    1979                         /*KdLeaf *leaf = (KdLeaf *) node; 
    1980                         if (ray.mFlags & Ray::STORE_KDLEAVES) 
    1981                                 ray.kdLeaves.push_back(leaf); 
    1982  
    1983                         ObjectContainer::const_iterator mi; 
    1984                         for ( mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); mi++) 
    1985                         { 
    1986                                 Intersectable *object = *mi; 
    1987                                 if (!object->Mailed() ) 
    1988                                 { 
    1989                                         object->Mail(); 
    1990                                         if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 
    1991                                                 ray.testedObjects.push_back(object); 
    1992                                         hits += object->CastRay(ray); 
    1993                                 } 
    1994                         } 
    1995  
    1996                         if (hits && ray.GetType() == Ray::LOCAL_RAY) 
    1997                                 if (ray.intersections[0].mT <= maxt) 
    1998                                         break; 
     1980                        VspKdLeaf *leaf = dynamic_cast<VspKdLeaf *>(node); 
     1981                        ViewCell *vc = leaf->GetViewCell(); 
     1982 
     1983                        if (!vc->Mailed()) 
     1984                        { 
     1985                                vc->Mail(); 
     1986                                viewcells.push_back(vc); 
     1987                        } 
    19991988 
    20001989                        // get the next node from the stack 
     
    20041993                        entp = extp; 
    20051994                        mint = maxt; 
    2006                         if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
    2007                                 break; 
    2008  
    2009                         RayTraversalData &s  = tStack.top(); 
     1995                         
     1996                        LineSegmentTraversalData &s  = tStack.top(); 
    20101997                        node = s.mNode; 
    20111998                        extp = s.mExitPoint; 
    20121999                        maxt = s.mMaxT; 
    20132000                        tStack.pop(); 
    2014                         */ 
    20152001                } 
    20162002        } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h

    r465 r468  
    488488                                leafb->GetPvsSize() * (float)leafb->rays.size(); 
    489489#endif 
    490     } 
    491   }; 
    492    
    493   /** Simplified data for ray traversal only. 
    494   */ 
    495   struct RayTraversalData  
    496   { 
    497           RayInfo mRayData; 
    498           VspKdNode *mNode; 
    499        
    500           RayTraversalData() {} 
     490                } 
     491        }; 
     492   
     493        /** Simplified data for ray traversal only. 
     494        */ 
     495        struct RayTraversalData  
     496        { 
     497                RayInfo mRayData; 
     498                VspKdNode *mNode; 
     499 
     500                RayTraversalData() {} 
    501501           
    502           RayTraversalData(VspKdNode *n, const RayInfo &data): 
    503           mRayData(data), mNode(n) {} 
    504   }; 
    505          
     502                RayTraversalData(VspKdNode *n, const RayInfo &data): 
     503                mRayData(data), mNode(n) {} 
     504        }; 
     505         
     506        struct LineSegmentTraversalData  
     507        { 
     508                VspKdNode *mNode; 
     509                Vector3 mExitPoint; 
     510                 
     511                float mMaxT; 
     512     
     513                LineSegmentTraversalData () {} 
     514                LineSegmentTraversalData (VspKdNode *n, 
     515                                                                  const Vector3 &p, 
     516                                                                  const float maxt): 
     517                mNode(n), mExitPoint(p), mMaxT(maxt) {} 
     518        }; 
     519 
    506520public: 
    507521 
     
    558572                @returns the number of intersections with objects stored in the tree. 
    559573        */ 
    560         int CastRay(Ray &ray); 
     574        int CastLineSegment(const Vector3 &origin, 
     575                                                const Vector3 &termination, 
     576                                                vector<ViewCell *> &viewcells); 
    561577 
    562578        /** Collects view cells generated by this tree. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r466 r468  
    2727  environment->GetBoolValue("VssPreprocessor.useImportanceSampling", mUseImportanceSampling); 
    2828  environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples); 
    29          
     29 
    3030  mStats.open("stats.log"); 
    3131} 
     
    3737 
    3838void 
    39 VssPreprocessor::SetupRay(Ray &ray,  
    40                                                   const Vector3 &point,  
     39VssPreprocessor::SetupRay(Ray &ray, 
     40                                                  const Vector3 &point, 
    4141                                                  const Vector3 &direction 
    4242                                                  ) 
     
    6262  if (!sbox.IsInside(viewPoint)) 
    6363        return 0; 
    64          
     64 
    6565  SetupRay(ray, viewPoint, direction); 
    6666  // cast ray to KD tree to find intersection with other objects 
     
    8181        } 
    8282        pointA = ray.Extrap(tmax); 
    83                  
     83 
    8484  } 
    8585 
    8686  bool detectEmptyViewSpace = true; 
    87          
     87 
    8888  if (detectEmptyViewSpace) { 
    8989        SetupRay(ray, pointA, -direction); 
    9090  } else 
    9191        SetupRay(ray, viewPoint, -direction); 
    92          
    93          
     92 
     93 
    9494  if (mKdTree->CastRay(ray)) { 
    95                  
     95 
    9696        objectB = ray.intersections[0].mObject; 
    9797        pointB = ray.Extrap(ray.intersections[0].mT); 
     
    105105          //                    cerr<<"ray"<<ray<<endl; 
    106106        } 
    107                  
     107 
    108108        pointB = ray.Extrap(tmax); 
    109109  } 
     
    118118        } 
    119119  } 
    120          
     120 
    121121  if (validSample) { 
    122122        if (objectA) { 
     
    128128          hits ++; 
    129129        } 
    130                  
     130 
    131131        if (objectB) { 
    132132          vssRay = new VssRay(pointA, 
     
    138138        } 
    139139  } 
    140          
     140 
    141141  return hits; 
    142142} 
     
    147147{ 
    148148  AxisAlignedBox3 box; 
    149          
     149 
    150150  if (viewSpaceBox) 
    151151        box =*viewSpaceBox; 
    152   else  
     152  else 
    153153        box = mKdTree->GetBox(); 
    154          
     154 
    155155  // shrink the box in the y direction 
    156156  return box.GetRandomPoint(); 
     
    170170  } else { 
    171171        AxisAlignedBox3 box; 
    172                  
     172 
    173173        if (viewSpaceBox) 
    174174          box =*viewSpaceBox; 
    175         else  
     175        else 
    176176          box = mKdTree->GetBox(); 
    177                  
     177 
    178178        point = box.GetRandomPoint(); 
    179179        point.y = viewpoint.y; 
    180180  } 
    181          
     181 
    182182  return point - viewpoint; 
    183183} 
     
    194194        float maxRayContribution; 
    195195        float avgRayContribution; 
    196                  
     196 
    197197        vssTree->GetRayContributionStatistics(minRayContribution, 
    198198                                                                                  maxRayContribution, 
    199199                                                                                  avgRayContribution); 
    200                  
     200 
    201201        cout<< 
    202202          "#MIN_RAY_CONTRIB\n"<<minRayContribution<<endl<< 
    203203          "#MAX_RAY_CONTRIB\n"<<maxRayContribution<<endl<< 
    204204          "#AVG_RAY_CONTRIB\n"<<avgRayContribution<<endl; 
    205                  
     205 
    206206        float p = desiredSamples/(float)(avgRayContribution*vssTree->stat.Leaves()); 
    207207        num = vssTree->GenerateRays(p, rays); 
     
    210210        num = vssTree->GenerateRays(desiredSamples, leaves, rays); 
    211211  } 
    212          
     212 
    213213  cout<<"Generated "<<num<<" rays."<<endl; 
    214          
     214 
    215215  return num; 
    216216} 
     
    224224{ 
    225225  cout<<"Exporting vss rays..."<<endl<<flush; 
    226          
     226 
    227227  float prob = number/(float)vssRays.size(); 
    228228 
     
    241241        exporter->ResetForcedMaterial(); 
    242242  } 
    243          
     243 
    244244  VssRayContainer rays; for (int i=0; i < vssRays.size(); i++) 
    245245        if (RandomValue(0,1) < prob) 
     
    247247 
    248248  exporter->ExportRays(rays, RgbColor(1, 0, 0)); 
    249          
     249 
    250250  delete exporter; 
    251251 
     
    280280  exporter->SetWireframe(); 
    281281  exporter->ExportKdTree(*mKdTree); 
    282          
     282 
    283283  if (mViewSpaceBox) { 
    284284        exporter->SetForcedMaterial(RgbColor(1,0,0)); 
     
    286286        exporter->ResetForcedMaterial(); 
    287287  } 
    288          
     288 
    289289  exporter->SetForcedMaterial(RgbColor(0,0,1)); 
    290290  exporter->ExportBox(tree->GetBBox(leaf)); 
    291291  exporter->ResetForcedMaterial(); 
    292          
     292 
    293293  VssRayContainer rays[4]; 
    294294  for (int i=0; i < leaf->rays.size(); i++) { 
     
    296296        rays[k].push_back(leaf->rays[i].mRay); 
    297297  } 
    298          
     298 
    299299  // SOURCE RAY 
    300300  exporter->ExportRays(rays[0], RgbColor(1, 0, 0)); 
     
    342342  for (it = viewcells.begin(); it != it_end; ++ it) 
    343343        sum += tree->GetPvsSize(*it); 
    344          
     344 
    345345  return sum/(float)viewcells.size(); 
    346346} 
     
    349349VssPreprocessor::ComputeVisibility() 
    350350{ 
    351    
     351 
    352352  mSceneGraph->CollectObjects(&mObjects); 
    353          
     353 
    354354  long startTime = GetTime(); 
    355    
     355 
    356356  int totalSamples = 0; 
    357357 
     
    368368        box->SetMax(box->Max() + translation); 
    369369  } else { 
    370                  
     370 
    371371        // sample city like heights 
    372372        box->SetMin(1, box->Min(1) + box->Size(1)*0.2); 
     
    376376  if (use2dSampling) 
    377377        box->SetMax(1, box->Min(1)); 
    378          
     378 
    379379  if (useViewSpaceBox) 
    380380        mViewSpaceBox = box; 
    381381  else 
    382382        mViewSpaceBox = NULL; 
    383                  
     383 
    384384 
    385385  VssTree *vssTree = NULL; 
     
    390390        int passSamples = 0; 
    391391        int index = 0; 
    392                  
     392 
    393393        int sampleContributions; 
    394                  
     394 
    395395        int s = Min(mSamplesPerPass, mInitialSamples); 
    396396        for (int k=0; k < s; k++) { 
    397                          
     397 
    398398          Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 
    399399          Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 
    400                          
     400 
    401401          sampleContributions = CastRay(viewpoint, direction, mVssRays); 
    402                          
    403                          
     402 
     403 
    404404          //-- CORR matt: put block inside loop 
    405405          if (sampleContributions) { 
     
    410410          totalSamples++; 
    411411        } 
    412      
     412 
    413413        mPass++; 
    414                  
     414 
    415415        int pvsSize = 0; 
    416         float avgRayContrib = (passContributingSamples > 0) ?  
     416        float avgRayContrib = (passContributingSamples > 0) ? 
    417417          passSampleContributions/(float)passContributingSamples : 0; 
    418                  
     418 
    419419        cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    420         cout << "#TotalSamples=" << totalSamples/1000  
    421                  << "k   #SampleContributions=" << passSampleContributions << " ("  
     420        cout << "#TotalSamples=" << totalSamples/1000 
     421                 << "k   #SampleContributions=" << passSampleContributions << " (" 
    422422                 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
    423                  << pvsSize/(float)mObjects.size() << endl  
     423                 << pvsSize/(float)mObjects.size() << endl 
    424424                 << "avg ray contrib=" << avgRayContrib << endl; 
    425                  
     425 
    426426        mStats << 
    427427          "#Pass\n" <<mPass<<endl<< 
    428428          "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 
    429429          "#TotalSamples\n" << totalSamples<< endl<< 
    430           "#SampleContributions\n" << passSampleContributions << endl <<  
     430          "#SampleContributions\n" << passSampleContributions << endl << 
    431431          "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
    432432          "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 
     
    435435 
    436436 
    437                  
    438   } 
    439          
     437 
     438  } 
     439 
    440440  cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
    441441  cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush; 
    442          
     442 
    443443  //int numExportRays = 10000; 
    444444  int numExportRays = 0; 
     
    449449        ExportRays(filename, mVssRays, numExportRays); 
    450450  } 
    451          
     451 
    452452  mSceneGraph->CollectObjects(&mObjects); 
    453453 
     
    457457  vssTree = new VssTree; 
    458458  // viewcells = Construct(mVssRays); 
    459          
     459 
    460460  vssTree->Construct(mVssRays, mViewSpaceBox); 
    461461  cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 
    462    
     462 
    463463  if (0) 
    464464  { 
     
    482482          if (RandomValue(0.0f,1.0f) < prob) 
    483483                kdViewcells.push_back(mKdTree->GetBox(*it)); 
    484                  
     484 
    485485        float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 
    486486        cout<<"Initial average PVS size = "<<avgPvs<<endl; 
    487487  } 
    488488 
    489          
     489 
    490490  int samples = 0; 
    491491  int pass = 0; 
     
    498498        SimpleRayContainer rays; 
    499499        VssRayContainer vssRays; 
    500                  
     500 
    501501        if (!mUseImportanceSampling) { 
    502502          for (int j=0; j < num; j++) { 
     
    508508          num = GenerateImportanceRays(vssTree, num, rays); 
    509509        } 
    510          
     510 
    511511        for (int i=0; i < rays.size(); i++) 
    512512          CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 
    513                  
     513 
    514514        vssTree->AddRays(vssRays); 
    515                  
     515 
    516516        if (0) { 
    517517          int subdivided = vssTree->UpdateSubdivision(); 
     
    528528          else 
    529529                sprintf(filename, "vss-rays-%04d.x3d", pass); 
    530                          
     530 
    531531          ExportRays(filename, vssRays, numExportRays); 
    532532        } 
     
    547547  } 
    548548 
     549 
    549550  { 
    550551        VssRayContainer storedRays; 
     
    552553                                                                                 mViewCellsManager->GetPostProcessSamples(), 
    553554                                                                                 mViewCellsManager->GetVisualizationSamples())); 
    554          
     555 
    555556        //-- post process view cells 
    556557        mViewCellsManager->PostProcess(mObjects, storedRays); 
    557          
     558 
    558559        //-- several visualizations and statistics 
    559560        mViewCellsManager->PrintStatistics(Debug); 
     
    563564        CLEAR_CONTAINER(storedRays); 
    564565  } 
     566 
     567  //-- render simulation after merge 
     568  cout << "\nevaluating bsp view cells render time after merge ... "; 
    565569 
    566570  //-- render simulation after merge 
    567571  cout << "\nevaluating bsp view cells render time after merge ... "; 
    568572   
    569   const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 
    570    
     573  mRenderSimulator->RenderScene(); 
     574  SimulationStatistics ss; 
     575  mRenderSimulator->GetStatistics(ss); 
     576 
    571577  cout << " finished" << endl; 
    572578  cout << ss << endl; 
    573579  Debug << ss << endl; 
    574    
    575    
     580 
     581 
    576582  delete vssTree; 
    577    
     583 
    578584  return true; 
    579585} 
Note: See TracChangeset for help on using the changeset viewer.