Ignore:
Timestamp:
11/14/05 15:59:20 (19 years ago)
Author:
mattausch
Message:

worked on kd view space partitioning structure
worked on render simulation

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r408 r409  
    12101210                 "0.05"); 
    12111211 
     1212  RegisterOption("Simulation.moveSpeed", 
     1213                 optFloat, 
     1214                 "-simulation_moveSpeed", 
     1215                 "1.0"); 
     1216 
    12121217  RegisterOption("BspTree.Construction.input", 
    12131218          optString, 
     
    12441249                 "-bsp_term_min_area=", 
    12451250                 "0.001"); 
     1251   
     1252  RegisterOption("BspTree.Termination.maxRayContribution", 
     1253                 optFloat, 
     1254                 "-bsp_term_ray_contribution=", 
     1255                 "0.005"); 
     1256 
     1257  RegisterOption("BspTree.Termination.maxAccRayLenght", 
     1258                 optFloat, 
     1259                 "-bsp_term_max_acc_ray_length=", 
     1260                 "50"); 
    12461261 
    12471262   RegisterOption("BspTree.Termination.maxRays", 
     
    13041319          "-view_cells_max_viewcells=", 
    13051320          "0"); 
    1306  
    13071321   
    13081322  RegisterOption("BspTree.Visualization.samples", 
     
    13471361  RegisterOption("VspKdTree.accessTimeThreshold", optInt, "accesstime=", "1000"); 
    13481362  RegisterOption("VspKdTree.minCollapseDepth", optInt, "colldepth=", "4"); 
    1349  
    1350  
    1351  
    1352  
    1353  
    1354  
    1355  
    1356  
    1357  
    13581363 
    13591364        RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12"); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r387 r409  
    66#include "ViewCell.h" 
    77#include "Environment.h" 
     8#include "RenderSimulator.h" 
    89 
    910Preprocessor::Preprocessor(): 
    1011mKdTree(NULL), 
    11 mBspTree(NULL) 
     12mBspTree(NULL), 
     13mRenderSimulator(NULL) 
    1214{ 
    1315} 
     
    2022        DEL_PTR(mBspTree); 
    2123        DEL_PTR(mKdTree); 
     24 
     25        DEL_PTR(mRenderSimulator); 
    2226} 
    2327 
     
    5256 
    5357        if (strcmp(viewCellsStr, "bspTree") == 0) 
     58        { 
    5459                ViewCell::sHierarchy = ViewCell::BSP; 
     60        } 
    5561        else if (strcmp(viewCellsStr, "kdTree") == 0) 
     62        { 
    5663                ViewCell::sHierarchy = ViewCell::KD; 
     64        } 
    5765        else if (strcmp(viewCellsStr, "sceneDependent") == 0) 
    5866        { 
     
    6876} 
    6977 
     78RenderSimulator *Preprocessor::GetRenderSimulator() 
     79{ 
     80        if (mRenderSimulator) 
     81                return mRenderSimulator; 
     82 
     83    float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0; 
     84 
     85        environment->GetFloatValue("Simulation.objRenderCost",objRenderCost); 
     86        environment->GetFloatValue("Simulation.vcOverhead", vcOverhead); 
     87        environment->GetFloatValue("Simulation.moveSpeed", moveSpeed); 
     88 
     89        if (ViewCell::sHierarchy = ViewCell::BSP) 
     90                mRenderSimulator = new BspViewCellRenderSimulator(objRenderCost, vcOverhead, moveSpeed, mBspTree); 
     91        else // KD view cells 
     92                mRenderSimulator = new KdViewCellRenderSimulator(objRenderCost, vcOverhead, moveSpeed, mKdTree); 
     93 
     94        return mRenderSimulator; 
     95} 
     96 
    7097void Preprocessor::DeleteViewCells() 
    7198{ 
    72         for (int i = 0; i < mViewCells.size(); ++ i) 
    73                 delete mViewCells[i]->GetMesh(); 
    74  
     99        for (int i = 0; i < (int)mViewCells.size(); ++ i) 
     100        { 
     101                Mesh *mesh = mViewCells[i]->GetMesh(); 
     102                DEL_PTR(mesh); 
     103        } 
    75104        CLEAR_CONTAINER(mViewCells); 
    76105} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r392 r409  
    99#include "ViewCellBsp.h" 
    1010#include "ViewCell.h" 
    11 //#include "SceneGraph.h" 
    1211 
     12class RenderSimulator; 
    1313class SceneGraph; 
    1414 
     
    9393  void DeleteViewCells(); 
    9494 
     95  RenderSimulator *GetRenderSimulator(); 
     96 
    9597  /** Parses the view cell options 
    9698  */ 
     
    115117  /// the view cell corresponding to unbounded space 
    116118  BspViewCell mUnbounded; 
     119 
     120  RenderSimulator *mRenderSimulator; 
    117121}; 
    118122 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp

    r407 r409  
    77{} 
    88 
    9 RenderSimulator::RenderSimulator(float objRenderCost, float vcOverhead): 
    10 mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead) 
     9RenderSimulator::RenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed): 
     10mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead), mMoveSpeed(moveSpeed) 
    1111{ 
    1212} 
     
    1616 *****************************************************/ 
    1717 
    18 BspTreeRenderSimulator::BspTreeRenderSimulator(float objRenderCost,  
     18BspViewCellRenderSimulator::BspViewCellRenderSimulator(float objRenderCost,  
    1919                                                                                           float vcOverhead,  
     20                                                                                           float moveSpeed, 
    2021                                                                                           BspTree *bspTree): 
    21 RenderSimulator(objRenderCost, vcOverhead), mBspTree(bspTree) 
     22RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree) 
    2223{ 
    2324} 
    2425 
    25 Real BspTreeRenderSimulator::SimulateRendering() 
     26Real BspViewCellRenderSimulator::SimulateRendering() 
    2627{ 
    2728        Real renderTime = 0; 
    2829 
    29         // total area of view cells 
    30         float totalArea = 0;//= mKdTree->GetBox().SurfaceArea(); 
     30        // overhead for loading the PVS of the view cells 
     31        float loadPvsOverhead = 0; 
    3132 
     33        // probability that view point lies in a view cell 
     34        float pInVcTotal = 0; 
     35 
     36        // total probability that a view cell border is crossed 
     37        float pCrossVcTotal = 0; 
     38 
     39        // collect all view cells 
    3240        ViewCellContainer viewCells; 
    33  
    3441        mBspTree->CollectViewCells(viewCells); 
    3542 
     
    3744 
    3845        // surface area substitute for probability 
    39         PolygonContainer cell; 
     46        PolygonContainer geom; 
    4047 
    4148        for (it = viewCells.begin(); it != it_end; ++ it) 
    4249        { 
    43                 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), cell); 
    44                 CLEAR_CONTAINER(cell); 
    45                 float area = Polygon3::GetArea(cell); 
     50                mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom); 
     51                CLEAR_CONTAINER(geom); 
     52 
     53                const float area = Polygon3::GetArea(geom); 
     54                // area substitute for view point probability 
     55                float pInVc = area; 
     56                                 
     57                // compute render time of PVS times probability that view point is in view cell 
     58                renderTime += pInVc * RenderPvs(*(*it), mObjRenderCost); 
    4659                 
    47                 renderTime += area * (RenderPvs(*(*it), mObjRenderCost) + mVcOverhead); 
    48                 totalArea += area; 
     60                // probability that a view cell border is crossed 
     61                float pCrossVc = area; 
     62 
     63                loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed; 
     64 
     65                pInVcTotal += pInVc; 
     66                pCrossVcTotal += pCrossVc; 
    4967        } 
    5068 
    51         renderTime /= totalArea; 
     69         
     70        renderTime /= pInVcTotal; 
     71        loadPvsOverhead /= pCrossVcTotal; 
    5272 
    5373        //Debug << "render time without overhead: " << renderTime * 1e-3 << endl; 
    54         //renderTime += (float)viewCells.size() * vcOverhead; 
    55  
    56         return renderTime; 
     74         
     75        return renderTime + loadPvsOverhead; 
    5776} 
    5877 
    59 Real BspTreeRenderSimulator::RenderPvs(ViewCell &viewCell,  
     78Real BspViewCellRenderSimulator::RenderPvs(ViewCell &viewCell,  
    6079                                                                           float objRenderTime) const 
    6180{ 
     
    6786 *******************************************************/ 
    6887 
    69 KdTreeRenderSimulator::KdTreeRenderSimulator(float objRenderCost,  
    70                                                                                          float vcOverhead,  
     88KdViewCellRenderSimulator::KdViewCellRenderSimulator(float objRenderCost,  
     89                                                                                         float vcOverhead, 
     90                                                                                         float moveSpeed, 
    7191                                                                                         KdTree *kdTree): 
    72 RenderSimulator(objRenderCost, vcOverhead), mKdTree(kdTree) 
     92RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree) 
    7393{ 
    7494} 
    7595 
    76 Real KdTreeRenderSimulator::SimulateRendering() 
     96Real KdViewCellRenderSimulator::SimulateRendering() 
    7797{ 
    7898        //mKdTree->CollectLeavesPvs(); 
     
    81101        Real renderTime = 0; 
    82102        // overhead for loading a view cell 
    83         float loadOverhead = 0; 
     103        float loadPvsOverhead = 0; 
    84104 
    85105        // probability that view point lies in a view cell 
     
    112132 
    113133                renderTime += pInVc * RenderPvs(*it, mObjRenderCost); 
    114                 loadOverhead += pCrossVc * mVcOverhead; 
     134                loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed; 
    115135 
    116136                pInVcTotal += pInVc; 
     
    119139 
    120140        renderTime /= pInVcTotal; 
    121         loadOverhead /= pCrossVcTotal; 
     141        loadPvsOverhead /= pCrossVcTotal; 
    122142 
    123         return renderTime + loadOverhead; 
     143        return renderTime + loadPvsOverhead; 
    124144} 
    125145 
    126 Real KdTreeRenderSimulator::RenderPvs(KdLeaf *leaf,  
     146Real KdViewCellRenderSimulator::RenderPvs(KdLeaf *leaf,  
    127147                                                                                   float objRenderTime) const 
    128148{ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h

    r407 r409  
    1616public: 
    1717        RenderSimulator(); 
    18         RenderSimulator(float objRendercost, float vcOverhead); 
     18        RenderSimulator(float objRendercost, float vcOverhead, float moveSpeed); 
    1919        virtual Real SimulateRendering() = 0; 
    2020 
    21 protected: 
    22         // render time for single object of the PVS 
     21        /// render time for single object of the PVS 
    2322        float mObjRenderCost; 
    24         // const overhead for crossing a view cell border 
     23        /// const overhead for crossing a view cell border 
    2524        float mVcOverhead; 
     25        /// move speed of player 
     26        float mMoveSpeed; 
    2627}; 
    2728 
    28 class BspTreeRenderSimulator: public RenderSimulator 
     29class BspViewCellRenderSimulator: public RenderSimulator 
    2930{ 
    3031public: 
    31         BspTreeRenderSimulator(float objRenderCost, float vcOverhead, BspTree *bspTree); 
     32        BspViewCellRenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed, BspTree *bspTree); 
    3233 
    3334        Real SimulateRendering(); 
     
    4344}; 
    4445 
    45 class KdTreeRenderSimulator: public RenderSimulator 
     46class KdViewCellRenderSimulator: public RenderSimulator 
    4647{ 
    4748public: 
    48         KdTreeRenderSimulator(float objRenderCost, float vcOverhead, KdTree *kdTree); 
     49        KdViewCellRenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed, KdTree *kdTree); 
    4950        Real SimulateRendering(); 
    5051 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r407 r409  
    1717  environment->GetIntValue("ViewCells.PostProcessing.samples", mPostProcessSamples); 
    1818  environment->GetIntValue("BspTree.Visualization.samples", mVisualizationSamples); 
    19   environment->GetFloatValue("Simulation.objRenderCost", mObjRenderCost); 
    20   environment->GetFloatValue("Simulation.vcOverhead", mVcOverhead); 
    21  
     19  
    2220  mKdPvsDepth = 100; 
    2321  mStats.open("stats.log"); 
    24  
    2522} 
    2623 
     
    543540                //-- render simulation 
    544541                cout << "\nevaluating bsp view cells render time before merge ... "; 
    545                 Real rt = BspTreeRenderSimulator(mObjRenderCost, mVcOverhead, mBspTree).SimulateRendering(); 
     542                Real rt = GetRenderSimulator()->SimulateRendering(); 
    546543                 
    547544                cout << "avg render time: " << rt * 1e-3 << endl; 
     
    589586                cout << "\nevaluating render time after merge ... "; 
    590587                         
    591                 rt = BspTreeRenderSimulator(mObjRenderCost, mVcOverhead, mBspTree).SimulateRendering(); 
     588                rt = GetRenderSimulator()->SimulateRendering(); 
    592589 
    593590                cout << "render time: " << rt * 1e-3 << endl; 
     
    655652        { 
    656653                cout << "\nevaluating kd view cells render time ... "; 
    657                 Real rt = KdTreeRenderSimulator(mObjRenderCost, mVcOverhead, mKdTree).SimulateRendering(); 
     654                Real rt = GetRenderSimulator()->SimulateRendering(); 
    658655                 
    659656                cout << "avg render time: " << rt * 1e-3 << endl; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r406 r409  
    9898        */ 
    9999        int PostprocessViewCells(const RayContainer &rays); 
    100  
    101         // rendering costs for a single object 
    102         float mObjRenderCost; 
    103         // rendering overhead when crossing a view cell border 
    104         float mVcOverhead; 
    105100}; 
    106101 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r407 r409  
    1414#include "Plane3.h" 
    1515 
     16int BspTree::sMaxPolyCandidates = 10; 
     17int BspTree::sMaxRayCandidates = 10; 
     18int BspTree::sSplitPlaneStrategy = BALANCED_POLYS;  
     19int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 
     20 
     21 
    1622int BspTree::sTermMaxPolygons = 10; 
    1723int BspTree::sTermMinPvs = 20; 
    1824int BspTree::sTermMaxDepth = 20; 
    1925float BspTree::sTermMinArea = 0.001f; 
    20 int BspTree::sMaxPolyCandidates = 10; 
    21 int BspTree::sMaxRayCandidates = 10; 
    22 int BspTree::sSplitPlaneStrategy = BALANCED_POLYS;  
    23 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 
    2426int BspTree::sTermMaxPolysForAxisAligned = 50; 
    2527int BspTree::sTermMaxObjectsForAxisAligned = 50; 
    2628int BspTree::sTermMaxRaysForAxisAligned = -1; 
    2729int BspTree::sTermMaxRays = -1; 
     30float BspTree::sTermMaxRayContribution = 0.05f; 
     31float BspTree::sTermMaxAccRayLength = 50; 
     32 
     33 
    2834int BspTree::sMinPvsDif = 10; 
    2935int BspTree::sMinPvs = 10; 
     
    704710                 (data.mPvs <= sTermMinPvs) || 
    705711                 (data.mArea <= sTermMinArea) || 
    706                  (data.mDepth >= sTermMaxDepth)); 
     712                 (data.mDepth >= sTermMaxDepth) || 
     713                 (((float)data.mPvs / (float)data.mRays->size()) < sTermMaxRayContribution)); 
    707714} 
    708715 
     
    863870                                                                                        coincident); 
    864871 
    865         // split geometry 
    866         tData.mGeometry->SplitGeometry(*frontData.mGeometry, *backData.mGeometry,  
    867                                                                    *this, interior->mPlane); 
    868          
    869         // compute area 
    870         frontData.mArea = frontData.mGeometry->GetArea(); 
    871         backData.mArea = backData.mGeometry->GetArea(); 
    872  
    873         // compute pvs 
     872    // compute pvs 
    874873        frontData.mPvs = ComputePvsSize(*frontData.mRays); 
    875874        backData.mPvs = ComputePvsSize(*backData.mRays); 
    876875 
     876        // split geometry and compute area 
     877        if (1) 
     878        { 
     879                tData.mGeometry->SplitGeometry(*frontData.mGeometry,  
     880                                                                           *backData.mGeometry,  
     881                                                                           *this,  
     882                                                                           interior->mPlane); 
     883         
     884                 
     885                frontData.mArea = frontData.mGeometry->GetArea(); 
     886                backData.mArea = backData.mGeometry->GetArea(); 
     887        } 
     888 
     889        // compute accumulated ray length 
     890        //frontData.mAccRayLength = AccumulatedRayLength(*frontData.mRays); 
     891        //backData.mAccRayLength = AccumulatedRayLength(*backData.mRays); 
    877892 
    878893        //-- create front and back leaf 
     
    15021517                           (pOverall * (float)pvs * 2); 
    15031518 
    1504                 // give penalty for unbalanced cell 
    1505                 if (((pFront * 0.2 + 0.00001) > pBack) || (pFront < (pBack * 0.2 + 0.00001))) 
     1519                // give penalty to unbalanced split 
     1520                if (((pFront * 0.2 + Limits::Small) > pBack) || (pFront < (pBack * 0.2 + Limits::Small))) 
    15061521                        val += 0.5; 
    15071522        } 
     
    16331648        environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons); 
    16341649        environment->GetIntValue("BspTree.Termination.maxRays", sTermMaxRays); 
    1635         environment->GetFloatValue("BspTree.Termination.minArea", sTermMinArea); 
     1650        environment->GetFloatValue("BspTree.Termination.minArea", sTermMinArea);         
     1651        environment->GetFloatValue("BspTree.Termination.maxRayContribution", sTermMaxRayContribution); 
     1652        environment->GetFloatValue("BspTree.Termination.maxAccRayLenght", sTermMaxAccRayLength); 
    16361653 
    16371654        //-- termination criteria for axis aligned split 
     
    17431760                mStat.minDepth = data.mDepth; 
    17441761 
    1745         // store minimal and maximal pvs 
    1746         /*if (data.mPvs > mStat.pvs)mStat.pvs = data.mPvs; 
    1747         if (data.mPvs < mStat.pvs)      mStat.pvs = data.mPvs;*/ 
    1748  
    1749         // accumulate depth to compute average 
     1762        // accumulate depth to compute average depth 
    17501763        mStat.accumDepth += data.mDepth; 
    17511764         
     
    17571770                  << "#polygons: " << (int)data.mPolygons->size() << " (max: " << sTermMaxPolygons << "), " 
    17581771                  << "#rays: " << (int)data.mRays->size() << " (max: " << sTermMaxRays << "), "  
    1759                   << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << endl; 
     1772                  << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "=, " 
     1773                  << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 
    17601774//#endif 
    17611775} 
     
    20282042{ 
    20292043        return mStat; 
     2044} 
     2045 
     2046float BspTree::AccumulatedRayLength(BoundedRayContainer &rays) const 
     2047{ 
     2048        float len = 0; 
     2049 
     2050        BoundedRayContainer::const_iterator it, it_end = rays.end(); 
     2051 
     2052        for (it = rays.begin(); it != it_end; ++ it) 
     2053        { 
     2054                len += SqrDistance((*it)->mRay->Extrap((*it)->mMinT),  
     2055                                                   (*it)->mRay->Extrap((*it)->mMaxT)); 
     2056        } 
     2057 
     2058        return len; 
    20302059} 
    20312060 
     
    20772106 
    20782107                                DEL_PTR(bRay); 
    2079  
    2080                                 ++ splits; 
    20812108                        } 
    20822109                        break; 
     
    20892116                                backRays.push_back(new BoundedRay(ray, bRay->mMinT, newT)); 
    20902117                                frontRays.push_back(new BoundedRay(ray, newT, bRay->mMaxT)); 
    2091                                  
    20922118                                DEL_PTR(bRay); 
    20932119 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r407 r409  
    734734        bool TerminationCriteriaMet(const BspTraversalData &data) const; 
    735735 
     736        float AccumulatedRayLength(BoundedRayContainer &rays) const; 
     737 
    736738        /// Pointer to the root of the tree 
    737739        BspNode *mRoot; 
     
    794796        static int sTermMaxObjectsForAxisAligned; 
    795797 
     798        static float sTermMaxRayContribution; 
     799        static float sTermMaxAccRayLength; 
     800 
    796801        static bool sStoreLeavesWithRays; 
    797802 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r408 r409  
    3434VspKdTreeLeaf::mailID = 0; 
    3535 
    36 inline void 
    37 AddObject2Pvs(Intersectable *object, 
    38                                                         const int side, 
    39                                                         int &pvsBack, 
    40                                                         int &pvsFront) 
    41 { 
    42  
     36inline void AddObject2Pvs(Intersectable *object, 
     37                                                  const int side, 
     38                                                  int &pvsBack, 
     39                                                  int &pvsFront) 
     40{ 
    4341        if (!object) 
    4442                return; 
    4543                 
    46         if (side <= 0) { 
    47                 if (!object->Mailed() && !object->Mailed(2)) { 
    48                         pvsBack++; 
     44        if (side <= 0)  
     45        { 
     46                if (!object->Mailed() && !object->Mailed(2))  
     47                { 
     48                        ++ pvsBack; 
     49 
    4950                        if (object->Mailed(1)) 
    5051                                object->Mail(2); 
     
    5455        } 
    5556         
    56         if (side >= 0) { 
    57                 if (!object->Mailed(1) && !object->Mailed(2)) { 
    58                         pvsFront++; 
     57        if (side >= 0)  
     58        { 
     59                if (!object->Mailed(1) && !object->Mailed(2))  
     60                { 
     61                        ++ pvsFront; 
    5962                        if (object->Mailed()) 
    6063                                object->Mail(2); 
     
    6972VspKdTree::VspKdTree() 
    7073{ 
    71   environment->GetIntValue("VspKdTree.maxDepth", termMaxDepth); 
     74        environment->GetIntValue("VspKdTree.maxDepth", termMaxDepth); 
    7275        environment->GetIntValue("VspKdTree.minPvs", termMinPvs); 
    7376        environment->GetIntValue("VspKdTree.minRays", termMinRays); 
    7477        environment->GetFloatValue("VspKdTree.maxRayContribution", termMaxRayContribution); 
    75   environment->GetFloatValue("VspKdTree.maxCostRatio", termMaxCostRatio); 
    76  
    77   environment->GetFloatValue("VspKdTree.minSize", termMinSize); 
    78   termMinSize = sqr(termMinSize); 
    79          
    80   environment->GetFloatValue("VspKdTree.refDirBoxMaxSize", refDirBoxMaxSize); 
    81   refDirBoxMaxSize = sqr(refDirBoxMaxSize); 
    82    
    83   environment->GetFloatValue("VspKdTree.epsilon", epsilon); 
    84   environment->GetFloatValue("VspKdTree.ct_div_ci", ct_div_ci); 
    85          
    86   environment->GetFloatValue("VspKdTree.maxTotalMemory", maxTotalMemory); 
    87   environment->GetFloatValue("VspKdTree.maxStaticMemory", maxStaticMemory); 
    88    
    89    
    90  
    91  
    92   float refDirAngle; 
    93   environment->GetFloatValue("VspKdTree.refDirAngle", refDirAngle); 
    94  
    95   environment->GetIntValue("VspKdTree.accessTimeThreshold", accessTimeThreshold); 
    96   //= 1000; 
    97   environment->GetIntValue("VspKdTree.minCollapseDepth", minCollapseDepth); 
    98   //  int minCollapseDepth = 4; 
    99  
    100   //  pRefDirThresh = cos(0.5*M_PI - M_PI*refDirAngle/180.0); 
    101         //  cosRefDir = cos(M_PI*refDirAngle/180.0); 
    102         //  sinRefDir = sin(M_PI*refDirAngle/180.0); 
    103    
    104    
    105   // split type 
     78        environment->GetFloatValue("VspKdTree.maxCostRatio", termMaxCostRatio); 
     79 
     80        environment->GetFloatValue("VspKdTree.minSize", termMinSize); 
     81        termMinSize = sqr(termMinSize); 
     82         
     83        environment->GetFloatValue("VspKdTree.refDirBoxMaxSize", refDirBoxMaxSize); 
     84        refDirBoxMaxSize = sqr(refDirBoxMaxSize); 
     85   
     86        environment->GetFloatValue("VspKdTree.epsilon", epsilon); 
     87        environment->GetFloatValue("VspKdTree.ct_div_ci", ct_div_ci); 
     88         
     89        environment->GetFloatValue("VspKdTree.maxTotalMemory", maxTotalMemory); 
     90        environment->GetFloatValue("VspKdTree.maxStaticMemory", maxStaticMemory); 
     91   
     92   
     93        float refDirAngle; 
     94        environment->GetFloatValue("VspKdTree.refDirAngle", refDirAngle); 
     95 
     96        environment->GetIntValue("VspKdTree.accessTimeThreshold", accessTimeThreshold); 
     97        //= 1000; 
     98        environment->GetIntValue("VspKdTree.minCollapseDepth", minCollapseDepth); 
     99  
     100 
     101        // split type 
    106102        char sname[128]; 
    107103        environment->GetStringValue("VspKdTree.splitType", sname); 
    108   string name(sname); 
    109          
    110   if (name.compare("regular") == 0) 
    111     splitType = ESplitRegular; 
    112   else 
    113     if (name.compare("heuristic") == 0) 
    114       splitType = ESplitHeuristic; 
    115                 else { 
    116                         cerr<<"Invalid VspKdTree split type "<<name<<endl; 
     104        string name(sname); 
     105         
     106        if (name.compare("regular") == 0) 
     107                splitType = ESplitRegular; 
     108        else 
     109        { 
     110                if (name.compare("heuristic") == 0) 
     111                        splitType = ESplitHeuristic; 
     112                else  
     113                { 
     114                        cerr << "Invalid VspKdTree split type " << name << endl; 
    117115                        exit(1); 
    118116                } 
    119          
    120   environment->GetBoolValue("VspKdTree.randomize", randomize); 
    121  
    122   root = NULL; 
    123    
    124   splitCandidates = new vector<SortableEntry>; 
     117        } 
     118 
     119        environment->GetBoolValue("VspKdTree.randomize", randomize); 
     120 
     121        root = NULL; 
     122 
     123        splitCandidates = new vector<SortableEntry>; 
    125124} 
    126125 
     
    128127VspKdTree::~VspKdTree() 
    129128{ 
    130   if (root) 
    131     delete root; 
     129        if (root) 
     130                delete root; 
    132131} 
    133132 
     
    204203VspKdTreeLeaf::UpdatePvsSize() 
    205204{ 
    206         if (!mValidPvs) { 
     205        if (!mValidPvs)  
     206        { 
    207207                Intersectable::NewMail(); 
    208208                int pvsSize = 0; 
    209                 for(VspKdTreeNode::RayInfoContainer::iterator ri = rays.begin(); 
    210                                 ri != rays.end(); 
    211                                 ri++) 
    212                         if ((*ri).mRay->IsActive()) { 
     209                for(VspKdTreeNode::RayInfoContainer::iterator ri = rays.begin();  
     210                        ri != rays.end(); ++ ri) 
     211                { 
     212                        if ((*ri).mRay->IsActive())  
     213                        { 
    213214                                Intersectable *object; 
    214215#if BIDIRECTIONAL_RAY 
    215216                                object = (*ri).mRay->mOriginObject; 
    216                                 if (object && !object->Mailed()) { 
    217                                         pvsSize++; 
     217                         
     218                                if (object && !object->Mailed())  
     219                                { 
     220                                        ++ pvsSize; 
    218221                                        object->Mail(); 
    219222                                } 
    220223#endif 
    221224                                object = (*ri).mRay->mTerminationObject; 
    222                                 if (object && !object->Mailed()) { 
    223                                         pvsSize++; 
     225                                if (object && !object->Mailed())  
     226                                { 
     227                                        ++ pvsSize; 
    224228                                        object->Mail(); 
    225229                                } 
    226230                        } 
     231                } 
     232 
    227233                mPvsSize = pvsSize; 
    228234                mValidPvs = true; 
     
    232238 
    233239void 
    234 VspKdTree::Construct( 
    235                                                                          VssRayContainer &rays, 
    236                                                                          AxisAlignedBox3 *forcedBoundingBox 
    237                                                                          ) 
    238 { 
    239   stat.Start(); 
     240VspKdTree::Construct(VssRayContainer &rays, 
     241                                         AxisAlignedBox3 *forcedBoundingBox) 
     242{ 
     243        stat.Start(); 
    240244   
    241245        maxMemory = maxStaticMemory; 
    242246 
    243   if (root) 
    244     delete root; 
    245  
    246   root = new VspKdTreeLeaf(NULL, rays.size()); 
    247   // first construct a leaf that will get subdivide 
    248   VspKdTreeLeaf *leaf = (VspKdTreeLeaf *) root; 
    249  
    250   stat.nodes = 1; 
    251    
    252   bbox.Initialize(); 
    253   dirBBox.Initialize(); 
    254    
    255   for(VssRayContainer::const_iterator ri = rays.begin(); 
    256       ri != rays.end(); 
    257       ri++) { 
    258     leaf->AddRay(VspKdTreeNode::RayInfo(*ri)); 
    259  
    260     bbox.Include((*ri)->GetOrigin()); 
    261     bbox.Include((*ri)->GetTermination()); 
    262      
    263                  
    264                 dirBBox.Include(Vector3( 
    265                                                                                                                 (*ri)->GetDirParametrization(0), 
    266                                                                                                                 (*ri)->GetDirParametrization(1), 
    267                                                                                                                 0 
    268                                                                                                                 ) 
    269                                                                                 ); 
    270         } 
    271          
    272          
    273         if ( forcedBoundingBox ) 
     247        if (root) 
     248                delete root; 
     249 
     250        root = new VspKdTreeLeaf(NULL, rays.size()); 
     251 
     252        // first construct a leaf that will get subdivide 
     253        VspKdTreeLeaf *leaf = (VspKdTreeLeaf *) root; 
     254 
     255         
     256        stat.nodes = 1; 
     257         
     258        bbox.Initialize(); 
     259        dirBBox.Initialize(); 
     260   
     261         
     262        for (VssRayContainer::const_iterator ri = rays.begin(); ri != rays.end(); ++ ri) 
     263        { 
     264                leaf->AddRay(VspKdTreeNode::RayInfo(*ri)); 
     265 
     266                bbox.Include((*ri)->GetOrigin()); 
     267                bbox.Include((*ri)->GetTermination());     
     268                 
     269                dirBBox.Include(Vector3((*ri)->GetDirParametrization(0), (*ri)->GetDirParametrization(1), 0)); 
     270        } 
     271         
     272        if (forcedBoundingBox) 
    274273                bbox = *forcedBoundingBox; 
    275274 
     
    277276        cout<<"Dirr Bbox = "<<dirBBox<<endl; 
    278277 
    279   stat.rays = leaf->rays.size(); 
     278        stat.rays = leaf->rays.size(); 
    280279        leaf->UpdatePvsSize(); 
    281   stat.initialPvsSize = leaf->GetPvsSize(); 
    282   // Subdivide(); 
    283   root = Subdivide(TraversalData(leaf, bbox, 0)); 
    284  
    285   if (splitCandidates) { 
    286     // force realease of this vector 
    287     delete splitCandidates; 
    288     splitCandidates = new vector<SortableEntry>; 
    289   } 
    290    
    291   stat.Stop(); 
     280         
     281        stat.initialPvsSize = leaf->GetPvsSize(); 
     282         
     283        // Subdivide(); 
     284        root = Subdivide(TraversalData(leaf, bbox, 0)); 
     285 
     286        if (splitCandidates)  
     287        { 
     288                // force realease of this vector 
     289                delete splitCandidates; 
     290                splitCandidates = new vector<SortableEntry>; 
     291        } 
     292   
     293        stat.Stop(); 
    292294 
    293295        stat.Print(cout); 
    294         cout<<"#Total memory="<<GetMemUsage()<<endl; 
    295  
    296 } 
    297  
    298  
    299  
    300 VspKdTreeNode * 
    301 VspKdTree::Subdivide(const TraversalData &tdata) 
    302 { 
    303   VspKdTreeNode *result = NULL; 
    304  
    305   priority_queue<TraversalData> tStack; 
    306   //  stack<TraversalData> tStack; 
    307    
    308   tStack.push(tdata); 
    309  
    310   AxisAlignedBox3 backBox; 
    311   AxisAlignedBox3 frontBox; 
    312  
     296        cout<<"#Total memory=" << GetMemUsage() << endl; 
     297} 
     298 
     299 
     300 
     301VspKdTreeNode *VspKdTree::Subdivide(const TraversalData &tdata) 
     302{ 
     303        VspKdTreeNode *result = NULL; 
     304 
     305        priority_queue<TraversalData> tStack; 
     306        //  stack<TraversalData> tStack; 
     307   
     308        tStack.push(tdata); 
     309 
     310        AxisAlignedBox3 backBox; 
     311        AxisAlignedBox3 frontBox; 
    313312   
    314313        int lastMem = 0; 
    315   while (!tStack.empty()) { 
    316  
     314        while (!tStack.empty())  
     315        { 
    317316                float mem = GetMemUsage(); 
    318317                 
    319                 if ( lastMem/10 != ((int)mem)/10) { 
    320                         cout<<mem<<" MB"<<endl; 
     318                if ( lastMem/10 != ((int)mem)/10)  
     319                { 
     320                        cout << mem << " MB" << endl; 
    321321                } 
    322322                lastMem = (int)mem; 
    323323                 
    324                 if (  mem > maxMemory ) { 
    325       // count statistics on unprocessed leafs 
    326       while (!tStack.empty()) { 
     324                if (  mem > maxMemory )  
     325                { 
     326                        // count statistics on unprocessed leafs 
     327                        while (!tStack.empty())  
     328                        { 
    327329                                EvaluateLeafStats(tStack.top()); 
    328330                                tStack.pop(); 
    329       } 
    330       break; 
    331     } 
     331                        } 
     332                        break; 
     333                } 
    332334     
    333     TraversalData data = tStack.top(); 
    334     tStack.pop(); 
     335                TraversalData data = tStack.top(); 
     336                tStack.pop(); 
    335337     
    336     VspKdTreeNode *node = SubdivideNode((VspKdTreeLeaf *) data.node, 
    337                                                                                                                                                         data.bbox, 
    338                                                                                                                                                         backBox, 
    339                                                                                                                                                         frontBox 
    340                                                                                                                                                         ); 
    341     if (result == NULL) 
    342       result = node; 
     338                 
     339                VspKdTreeNode *node = SubdivideNode((VspKdTreeLeaf *) data.node, 
     340                                                                                        data.bbox, backBox,     frontBox); 
     341                if (result == NULL) 
     342                        result = node; 
    343343     
    344     if (!node->IsLeaf()) { 
    345                          
    346       VspKdTreeInterior *interior = (VspKdTreeInterior *) node; 
    347       // push the children on the stack 
    348       tStack.push(TraversalData(interior->back, backBox, data.depth+1)); 
    349       tStack.push(TraversalData(interior->front, frontBox, data.depth+1)); 
    350                          
    351     } else { 
    352       EvaluateLeafStats(data); 
    353     } 
    354   } 
    355  
    356   return result; 
     344                if (!node->IsLeaf())  
     345                { 
     346                        VspKdTreeInterior *interior = (VspKdTreeInterior *) node; 
     347 
     348                        // push the children on the stack 
     349                        tStack.push(TraversalData(interior->back, backBox, data.depth+1)); 
     350                        tStack.push(TraversalData(interior->front, frontBox, data.depth+1)); 
     351                }  
     352                else  
     353                { 
     354                        EvaluateLeafStats(data); 
     355                } 
     356        } 
     357 
     358        return result; 
    357359} 
    358360 
     
    360362// returns selected plane for subdivision 
    361363int 
    362 VspKdTree::SelectPlane( 
    363                                                                                  VspKdTreeLeaf *leaf, 
    364                                                                                  const AxisAlignedBox3 &box, 
    365                                                                                  float &position, 
    366                                                                                  int &raysBack, 
    367                                                                                  int &raysFront, 
    368                                                                                  int &pvsBack, 
    369                                                                                  int &pvsFront 
    370                                                                                  ) 
     364VspKdTree::SelectPlane(VspKdTreeLeaf *leaf, 
     365                                           const AxisAlignedBox3 &box, 
     366                                           float &position, 
     367                                           int &raysBack, 
     368                                           int &raysFront, 
     369                                           int &pvsBack, 
     370                                           int &pvsFront) 
    371371{ 
    372372 
     
    776776{ 
    777777   
    778   if ( (leaf->GetPvsSize() < termMinPvs) || 
    779                          (leaf->rays.size() < termMinRays) || 
    780                          //                      (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 
    781        (leaf->depth >= termMaxDepth) || 
    782                          SqrMagnitude(box.Size()) <= termMinSize ) { 
     778  if ( (leaf->GetPvsSize() < termMinPvs) || (leaf->rays.size() < termMinRays) || 
     779        // (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 
     780       (leaf->depth >= termMaxDepth) || SqrMagnitude(box.Size()) <= termMinSize )  
     781  { 
    783782 
    784783#if 0 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r387 r409  
    2525  BspTree::ParseEnvironment(); 
    2626 
    27         char buff[128]; 
    28  
    29         environment->GetStringValue("Preprocessor.type", buff); 
    30  
    31         string preprocessorType(buff); 
     27  char buff[128]; 
     28   
     29  environment->GetStringValue("Preprocessor.type", buff); 
     30  string preprocessorType(buff); 
    3231         
    3332  Preprocessor *p; 
     
    8382          p->Export("vc_bsptree.x3d", false, false, true); 
    8483          p->BspTreeStatistics(Debug); 
    85  
    86 #if 0 
    87           //-- export the complementary view cells 
    88           // i.e., the view cells not associated with leafs in the tree. 
    89           Exporter *exporter = Exporter::GetExporter("viewcells_compl.x3d"); 
    90  
    91           ViewCellContainer::iterator vc_compl_it; 
    92           ViewCellContainer vc_compl(p->mViewCells.size() + X3dExporter::foundViewCells.size()); 
    93    
    94           sort(p->mViewCells.begin(), p->mViewCells.end()); 
    95  
    96           vc_compl_it = set_difference(p->mViewCells.begin(), p->mViewCells.end(),  
    97                   X3dExporter::foundViewCells.begin(), X3dExporter::foundViewCells.end(), vc_compl.begin()); 
    98  
    99           vc_compl.erase(vc_compl_it, vc_compl.end()); 
    100    
    101  
    102           if (exporter)  
    103           {      
    104                   Debug << "Exporting complementary view cells" << endl; 
    105                   exporter->ExportViewCells(vc_compl); // export view cells 
    106                   delete exporter; 
    107           } 
    108 #endif 
    10984  } 
    11085 
Note: See TracChangeset for help on using the changeset viewer.