Changeset 332


Ignore:
Timestamp:
10/17/05 18:57:10 (19 years ago)
Author:
mattausch
Message:

fixed bug when asigning bsp root
subdivision termination criterium based on rays

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r331 r332  
    99#       filename vienna.x3d 
    1010#       filename ../data/vienna/vienna-simple.x3d 
    11 #       filename ../data/vienna/vienna-buildings.x3d 
     11        filename ../data/vienna/vienna-buildings.x3d 
    1212#       filename ../data/vienna/viewcells-25-sel.x3d 
    13         filename ../data/atlanta/atlanta2.x3d 
     13#       filename ../data/atlanta/atlanta2.x3d 
    1414#       filename ../data/soda/soda.dat 
    1515#       filename ../data/soda/soda5.dat 
     
    9292        # vertical axis        = 64 
    9393        # blocked rays         = 128 
    94          
     94        # least ray splits     = 256 
     95        # balanced rays        = 512 
     96 
    9597        # least splits + balanced polygons 
    9698        #splitPlaneStrategy 12 
     
    108110        #splitPlaneStrategy 72 
    109111         
    110         splitPlaneStrategy 8 
     112        # axis aligned + blocked rays 
     113        #splitPlaneStrategy 130 
    111114         
    112         maxCandidates 50 
     115        splitPlaneStrategy 66 
     116         
     117        maxCandidates 130 
    113118         
    114119        Termination { 
     120                # autopartition 
     121                maxRays -1 
     122                maxPolygons 4 
     123                maxDepth 100 
     124                 
     125                #axis aligned split 
    115126                maxPolysForAxisAligned 100 
    116                 maxPolygons 2 
    117                 maxDepth 100 
     127                maxCostRatio 0.9 
     128                ct_div_ci 0.5 
    118129        } 
     130         
     131        #axis aligned split 
     132        splitBorder 0.01 
     133         
    119134        # if split polys are stored for visualization 
    120135        storeSplitPolys false 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r329 r332  
    11801180          "0.002"); 
    11811181 
    1182  
    11831182  RegisterOption("BspTree.Termination.maxPolygons", 
    11841183                 optInt, 
    11851184                 "-bsp_term_max_polygons=", 
    11861185                 "5"); 
    1187    
     1186 
     1187   RegisterOption("BspTree.Termination.maxRays", 
     1188                 optInt, 
     1189                 "-bsp_term_max_rays=", 
     1190                 "-1"); 
     1191 
    11881192  RegisterOption("BspTree.Termination.maxPolysForAxisAligned", 
    11891193                 optInt, 
     
    11951199                 "-bsp_term_max_depth=", 
    11961200                 "100"); 
     1201   
     1202  RegisterOption("BspTree.Termination.maxCostRatio", 
     1203                 optFloat, 
     1204                 "-bsp_term_max_cost_ratio=", 
     1205                 "1.5"); 
     1206 
     1207  RegisterOption("BspTree.Termination.ct_div_ci", 
     1208                 optFloat, 
     1209                 "-bsp_term_ct_div_ci=", 
     1210                 "1.0"); 
     1211 
     1212  RegisterOption("BspTree.splitBorder", 
     1213                 optFloat, 
     1214                 "-bsp_split_border=", 
     1215                 "0.1"); 
    11971216 
    11981217  RegisterOption("BspTree.storeSplitPolys", 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r331 r332  
    5858        { 
    5959        case BspTree::FROM_INPUT_VIEW_CELLS: 
     60                mBspTree->SetGenerateViewCells(false); 
    6061                mBspTree->Construct(mViewCells); 
    6162                break; 
    6263        case BspTree::FROM_SCENE_GEOMETRY: 
    6364                DeleteViewCells(); // we generate new view cells 
     65                mBspTree->SetGenerateViewCells(true); 
    6466                mSceneGraph->CollectObjects(&objects); 
    65                 mBspTree->Construct(objects, &mViewCells);       
     67                mBspTree->Construct(objects); 
     68                Debug << "collecting view cells" << endl; 
     69                mBspTree->CollectViewCells(mViewCells); 
    6670                break; 
    6771        case BspTree::FROM_RAYS: 
    6872                DeleteViewCells(); // we generate new view cells 
    69                 mBspTree->Construct(mSampleRays, &mViewCells); 
     73                mBspTree->SetGenerateViewCells(true); 
     74                mBspTree->Construct(mSampleRays); 
     75                Debug << "collecting view cells" << endl; 
     76                mBspTree->CollectViewCells(mViewCells); 
    7077                break; 
    7178        default: 
     
    407414                                                        (totalSamples < mBspConstructionSamples)) 
    408415                                                { 
    409                                                         //cout << "pushing back sampling ray << " << mSampleRays.size() << endl; 
    410416                                                        mSampleRays.push_back(new Ray(ray)); 
    411417                                                } 
     
    417423                                                                BuildBspTree(); 
    418424 
     425                                                                cout << "generated " << (int)mViewCells.size() << " view cells" << endl; 
     426                                                                passContributingSamples += mBspTree->GetStat().contributingSamples; 
     427                                                                passSampleContributions += mBspTree->GetStat().pvs; 
     428 
    419429                                                                BspTreeStatistics(Debug);        
    420430                                                                Export("vc_bsptree.x3d", false, false, true); 
    421431                                                        } 
    422                                                         // check whether we can add this to the rays 
    423                                                         for (int k = 0; k < ray.viewCells.size(); ++ k) 
    424                                                                 for (int j = 0; j < (int)pvsViewCells.size(); ++ j)  
    425                                                                         if (pvsViewCells[j] == ray.viewCells[k])  
    426                                                                         { 
    427                                                                                 vcRays[j].push_back(ray); 
    428                                                                         } 
     432                                                                                                         
    429433                                                        // some random view cells for output 
    430434                                                        if (pvsViewCells.empty()) 
     
    438442                                                                        pvsViewCells.push_back(mViewCells[Random((int)mViewCells.size())]); 
    439443                                                                } 
     444                                                        } 
     445                                                        else 
     446                                                        { 
     447                                                                // check whether we can add the current ray to the rays 
     448                                                                for (int k = 0; k < (int)ray.viewCells.size(); ++ k) 
     449                                                                        for (int j = 0; j < (int)pvsViewCells.size(); ++ j)  
     450                                                                                if (pvsViewCells[j] == ray.viewCells[k])  
     451                                                                                        vcRays[j].push_back(ray);                                                        
    440452                                                        } 
    441453                                                }                                
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r331 r332  
    2020int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 
    2121int BspTree::sTermMaxPolysForAxisAligned = 50; 
     22int BspTree::sTermMaxRays = -1; 
    2223 
    2324float BspTree::sCt_div_ci = 1.0f; 
     
    3435float BspTree::sLargestPolyAreaFactor = 1.0f; 
    3536float BspTree::sBlockedRaysFactor = 1.0f; 
     37float BspTree::sLeastRaySplitsFactor = 1.0f; 
     38float BspTree::sBalancedRaysFactor = 1.0f; 
    3639 
    3740bool BspTree::sStoreSplitPolys = false; 
     
    5053/****************************************************************/ 
    5154 
    52 BspNode::BspNode(): mParent(NULL), mPolygons(NULL)//,mViewCellIdx(0) 
     55BspNode::BspNode():  
     56mParent(NULL), mPolygons(NULL) 
    5357{} 
    5458 
    55 BspNode::BspNode(BspInterior *parent): mParent(parent), mPolygons(NULL)//,mViewCellIdx(0) 
     59BspNode::BspNode(BspInterior *parent):  
     60mParent(parent), mPolygons(NULL) 
    5661{} 
    5762 
     
    343348} 
    344349 
    345 int BspLeaf::GenerateViewCell(const RayContainer &rays,  
    346                                                            ViewCellContainer &viewCells) 
    347 { 
    348         int sampleContri = 0; 
    349         ViewCell *viewCell = new ViewCell(); 
    350         viewCells.push_back(viewCell); 
    351                                  
    352     mViewCell = viewCell; 
     350int BspLeaf::GenerateViewCell(const RayContainer &rays) 
     351{ 
     352        int contributingSamples = 0; 
     353 
     354        mViewCell = new ViewCell(); 
    353355 
    354356    RayContainer::const_iterator it, it_end = rays.end(); 
     
    357359        for (it = rays.begin(); it != it_end; ++ it) 
    358360        { 
    359                 for (int i = 0; i < (int)(*it)->intersections.size(); ++ i) 
    360                         sampleContri = viewCell->GetPvs().AddSample((*it)->intersections[i].mObject); 
    361         } 
    362         return sampleContri; 
     361                if (!(*it)->intersections.empty()) 
     362                {        
     363            if (mViewCell->GetPvs().AddSample((*it)->intersections[0].mObject) > 0) 
     364                                ++ contributingSamples; 
     365                } 
     366        } 
     367 
     368        return contributingSamples; 
    363369} 
    364370 
     
    369375 
    370376BspTree::BspTree(ViewCell *viewCell):  
    371 mRoot(NULL),  
    372 mRootCell(viewCell) 
     377mRootCell(viewCell), mRoot(NULL), mGenerateViewCells(false) 
    373378{ 
    374379        Randomize(); // initialise random generator for heuristics 
     
    404409 
    405410        app << "#N_INPUT_POLYGONS (number of input polygons )\n" <<     polys << endl; 
     411 
     412        app << "#N_PVS: " << pvs << endl; 
    406413 
    407414        app << "#N_ROUTPUT_INPUT_POLYGONS ( ratio polygons after subdivision / input polygons )\n" << 
     
    447454} 
    448455 
    449 void BspTree::InsertPolygons(PolygonContainer *polys, ViewCellContainer *viewCells) 
     456void BspTree::InsertPolygons(PolygonContainer *polys) 
    450457{        
    451458        std::stack<BspTraversalData> tStack; 
    452459         
    453460        // traverse existing tree or create new tree 
    454     BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 
    455  
    456         tStack.push(BspTraversalData(firstNode, polys, 0, mRootCell, new RayContainer())); 
     461    if (!mRoot) 
     462                mRoot = new BspLeaf(); 
     463 
     464        tStack.push(BspTraversalData(mRoot, polys, 0, mRootCell, new RayContainer())); 
    457465 
    458466        while (!tStack.empty()) 
     
    486494                                ViewCell *backViewCell = mRootCell; 
    487495         
    488                                 if (!viewCells) 
     496                                if (!mGenerateViewCells) 
    489497                                { 
    490498                                        ExtractViewCells(&backViewCell, 
     
    518526                        DEL_PTR(tData.mPolygons); 
    519527                } 
    520                 else // reached leaf => subdivide current viewcell 
    521                 { 
    522                         // root of the new subtree 
    523                         BspNode *subRoot = Subdivide(tStack, tData);             
    524  
    525                         int sampleContri = 0; 
    526  
    527                         // generate new view cell for each leaf 
    528                         if (viewCells && subRoot->IsLeaf()) 
    529                                 sampleContri += dynamic_cast<BspLeaf *>(subRoot)-> 
    530                                         GenerateViewCell(*tData.mRays, *viewCells); 
    531  
    532                         DEL_PTR(tData.mRays); 
     528                else 
     529                { 
     530                        // reached leaf => subdivide current viewcell 
     531                        BspNode *subRoot = Subdivide(tStack, tData); 
    533532                } 
    534533        } 
     
    604603} 
    605604 
    606 int BspTree::Construct(const ViewCellContainer &viewCells) 
     605void BspTree::Construct(const ViewCellContainer &viewCells) 
    607606{ 
    608607        mStat.nodes = 1; 
     
    614613 
    615614        // construct tree from the view cell polygons 
    616         return Construct(polys, new RayContainer()); 
    617 } 
    618  
    619  
    620 int BspTree::Construct(const ObjectContainer &objects, ViewCellContainer *viewCells) 
     615        Construct(polys, new RayContainer()); 
     616} 
     617 
     618 
     619void BspTree::Construct(const ObjectContainer &objects) 
    621620{ 
    622621        mStat.nodes = 1; 
     
    629628 
    630629        // construct tree from polygon soup 
    631         return Construct(polys, new RayContainer(), viewCells); 
    632 } 
    633  
    634 int BspTree::Construct(const RayContainer &sampleRays,  
    635                                                 ViewCellContainer *viewCells) 
     630        Construct(polys, new RayContainer()); 
     631} 
     632 
     633void BspTree::Construct(const RayContainer &sampleRays) 
    636634{ 
    637635        mStat.nodes = 1; 
     
    648646        std::map<Face *, Polygon3 *> facePolyMap; 
    649647 
    650         //-- extract polygons from faces stored in the rays 
     648        //-- extract polygons intersected by the rays 
    651649        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
    652650        { 
     
    655653                rays->push_back(ray); 
    656654 
    657                 for (int i = 0; i < (int)ray->intersections.size(); ++ i) 
    658                 { 
    659                         MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->intersections[i].mObject); 
    660                         Face *face = obj->GetMesh()->mFaces[ray->intersections[i].mFace]; 
    661  
    662                         // store rays piercing a face with the polygon representing the face 
     655                // get ray-face intersection. Store polygon representing the rays together 
     656                // with rays intersecting the face. 
     657                if (!ray->intersections.empty()) 
     658                { 
     659                        MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->intersections[0].mObject); 
     660                        Face *face = obj->GetMesh()->mFaces[ray->intersections[0].mFace]; 
     661 
    663662                        std::map<Face *, Polygon3 *>::iterator it= facePolyMap.find(face); 
    664663 
     
    671670                                Polygon3 *poly = new Polygon3(face, obj->GetMesh()); 
    672671                                polys->push_back(poly); 
    673                                 Debug << "poly: " << *poly << endl; 
    674672                                poly->AddPiercingRay(ray); 
    675673 
     
    683681 
    684682        Debug << "**** Finished polygon extraction ****" << endl; 
    685         Debug << polys->size() << " polys extracted from " << rays->size() << " rays" << endl; 
     683        Debug << (int)polys->size() << " polys extracted from " << (int)rays->size() << " rays" << endl; 
    686684        Debug << "extraction time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    687685 
    688         return Construct(polys, rays, viewCells); 
    689 } 
    690  
    691 int BspTree::Construct(PolygonContainer *polys,  
    692                                            RayContainer *rays,  
    693                                            ViewCellContainer *viewCells) 
     686        Construct(polys, rays); 
     687} 
     688 
     689void BspTree::Construct(PolygonContainer *polys, RayContainer *rays) 
    694690{ 
    695691        std::stack<BspTraversalData> tStack; 
    696692 
    697         BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell, rays); 
     693        mRoot = new BspLeaf(); 
     694 
     695        BspTraversalData tData(mRoot, polys, 0, mRootCell, rays); 
    698696        tStack.push(tData); 
    699697 
     
    701699        cout << "**** Contructing bsp tree ****\n"; 
    702700 
    703         int sampleContri = 0; 
    704  
    705701        while (!tStack.empty())  
    706702        { 
     
    710706                // subdivide leaf node 
    711707                BspNode *subRoot = Subdivide(tStack, tData); 
    712  
    713                 if (viewCells && subRoot->IsLeaf()) 
    714                         sampleContri += dynamic_cast<BspLeaf *>(subRoot)-> 
    715                                         GenerateViewCell(*tData.mRays, *viewCells); 
    716                 DEL_PTR(tData.mRays); 
    717708        } 
    718709 
    719710        cout << "**** Finished tree construction ****\n"; 
    720711        Debug << "BSP tree contruction time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    721         return sampleContri; 
    722712} 
    723713 
     
    726716{ 
    727717        //-- terminate traversal   
    728         if ((tData.mPolygons->size() <= sTermMaxPolygons) || (tData.mDepth >= sTermMaxDepth)) 
    729         { 
    730 //#ifdef _DEBUG 
    731                 Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: "  
    732                           << (int)tData.mPolygons->size() << endl; 
    733 //#endif 
     718        if (((int)tData.mPolygons->size() <= sTermMaxPolygons) ||  
     719                ((int)tData.mRays->size() <= sTermMaxRays) || 
     720                (tData.mDepth >= sTermMaxDepth)) 
     721                 
     722        { 
     723                BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 
     724         
     725                // generate new view cell for each leaf 
     726                if (mGenerateViewCells) 
     727                        mStat.contributingSamples += leaf->GenerateViewCell(*tData.mRays); 
     728                else 
     729                        // add view cell to leaf 
     730                        leaf->SetViewCell(tData.mViewCell); 
     731                 
    734732                EvaluateLeafStats(tData); 
    735                 BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 
    736  
    737                 // add view cell to leaf 
    738                 leaf->SetViewCell(tData.mViewCell); 
    739                  
     733 
    740734                //-- clean up 
    741  
    742735                // remaining polygons are discarded or added to node 
    743736                leaf->ProcessPolygons(tData.mPolygons, sStoreSplitPolys); 
    744737                DEL_PTR(tData.mPolygons); 
    745          
     738                DEL_PTR(tData.mRays); 
     739 
    746740                return leaf; 
    747741        } 
     
    762756                                                                                  *frontPolys, 
    763757                                                                                  *backPolys, 
    764                                                                                    coincident, 
    765                                                                                    *tData.mRays, 
    766                                                                                    *frontRays, 
    767                                                                                    *backRays); 
     758                                                                                  coincident, 
     759                                                                                  *tData.mRays, 
     760                                                                                  *frontRays, 
     761                                                                                  *backRays); 
    768762        ViewCell *frontViewCell = mRootCell; 
    769763        ViewCell *backViewCell = mRootCell; 
     
    778772        // extract view cells from coincident polygons according to plane normal 
    779773    // only if front or back polygons are empty 
    780         ExtractViewCells(&backViewCell, 
    781                                          &frontViewCell, 
    782                                          coincident, 
    783                                          interior->mPlane, 
    784                                          backPolys->empty(), 
    785                                          frontPolys->empty()); 
     774        if (!mGenerateViewCells) 
     775        { 
     776                ExtractViewCells(&backViewCell, 
     777                                                 &frontViewCell, 
     778                                                 coincident, 
     779                                                 interior->mPlane, 
     780                                                 backPolys->empty(), 
     781                                                 frontPolys->empty()); 
     782        } 
    786783         
    787784        // don't need coincident polygons anymore 
     
    804801        DEL_PTR(tData.mNode); 
    805802        DEL_PTR(tData.mPolygons); 
    806          
     803        DEL_PTR(tData.mRays); 
     804 
    807805        return interior; 
    808806} 
     
    11021100        } 
    11031101 
    1104         // strategies where the effect of the split plane is tested 
    1105         // on all input polygons  
    11061102        if (!((sSplitPlaneStrategy & BALANCED_POLYS)      || 
    11071103                  (sSplitPlaneStrategy & LEAST_SPLITS)        || 
     
    11131109        } 
    11141110 
     1111        // -- strategies where the effect of the split plane is tested 
     1112        // on all input polygons  
     1113 
    11151114        float sumBalancedPolys = 0; 
    11161115        float sumSplits = 0; 
     
    11181117        float sumBalancedViewCells = 0; 
    11191118        float sumBlockedRays = 0; 
    1120  
    11211119        float totalBlockedRays = 0; 
    11221120        //float totalArea = 0; 
     
    11441142                        //totalArea += area; 
    11451143                } 
    1146  
    11471144                 
    11481145                if (sSplitPlaneStrategy & BLOCKED_RAYS) 
    11491146                { 
    11501147                        float blockedRays = (float)(*it)->GetPiercingRays()->size(); 
     1148                 
    11511149                        if (classification == Plane3::COINCIDENT) 
    1152                         { 
    11531150                                sumBlockedRays += blockedRays; 
    1154                         } 
     1151                        Debug << "adding rays: " << blockedRays << endl; 
    11551152 
    11561153                        totalBlockedRays += blockedRays; 
     
    12191216                        (float)(frontViewCells.size() + backViewCells.size()); 
    12201217        } 
     1218 
     1219        float sumBalancedRays = 0; 
     1220        float sumRaySplits = 0; 
     1221 
     1222        RayContainer::const_iterator rit, rit_end = rays.end(); 
     1223 
     1224        for (rit = rays.begin(); rit != rays.end(); ++ rit) 
     1225        { 
     1226                if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) 
     1227                { 
     1228                } 
     1229 
     1230                if (sSplitPlaneStrategy & BALANCED_RAYS) 
     1231                { 
     1232                } 
     1233        } 
     1234        if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) 
     1235                if (!rays.empty()) 
     1236                        val += sLeastRaySplitsFactor * sumRaySplits / (float)rays.size(); 
     1237 
     1238        if (sSplitPlaneStrategy & BALANCED_RAYS) 
     1239                if (!rays.empty()) 
     1240                        val += sBalancedRaysFactor * fabs(sumBalancedRays) / (float)rays.size(); 
    12211241 
    12221242        // return linear combination of the sums 
     
    12471267        Debug << "Construction method: " << constructionMethodStr << endl; 
    12481268 
     1269        //-- termination criteria for autopartition 
    12491270        environment->GetIntValue("BspTree.Termination.maxDepth", sTermMaxDepth); 
    12501271        environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons); 
     1272        environment->GetIntValue("BspTree.Termination.maxRays", sTermMaxRays); 
     1273 
     1274        //-- termination criteria for axis aligned split 
     1275        environment->GetFloatValue("BspTree.Termination.ct_div_ci", sCt_div_ci); 
     1276        environment->GetFloatValue("BspTree.Termination.maxCostRatio", sMaxCostRatio); 
    12511277        environment->GetIntValue("BspTree.Termination.maxPolysForAxisAligned",  
    12521278                                                         sTermMaxPolysForAxisAligned); 
     1279         
     1280        //-- partition criteria 
    12531281        environment->GetIntValue("BspTree.maxCandidates", sMaxCandidates); 
    12541282        environment->GetIntValue("BspTree.splitPlaneStrategy", sSplitPlaneStrategy); 
    1255  
    1256         // need kdtree criteria for axis aligned split 
    1257         environment->GetFloatValue("MeshKdTree.Termination.ct_div_ci", sCt_div_ci); 
    1258         environment->GetFloatValue("MeshKdTree.splitBorder", sSplitBorder); 
    1259         environment->GetFloatValue("MeshKdTree.Termination.maxCostRatio", sMaxCostRatio); 
    1260  
     1283        environment->GetFloatValue("BspTree.splitBorder", sSplitBorder); 
     1284         
    12611285        environment->GetBoolValue("BspTree.storeSplitPolys", sStoreSplitPolys); 
    12621286 
     
    13411365 
    13421366        if (leaf->mViewCell != mRootCell) 
     1367        {        
    13431368                ++ mStat.viewCells; 
    1344  
    1345 #ifdef _DEBUG 
    1346         Debug << "BSP Traversal data. Depth: " << data.mDepth  
    1347                   << " (max: " << mTermMaxDepth << "), #polygons: "  
    1348                   << data.mPolygons->size() << " (max: "  
    1349                   << sTermMaxPolygons << ")" << endl; 
    1350 #endif 
     1369                mStat.pvs += leaf->mViewCell->GetPvs().GetSize(); 
     1370        } 
     1371         
     1372//#ifdef _DEBUG 
     1373        Debug << "BSP stats: " 
     1374                  << "Depth: " << data.mDepth << " (max: " << sTermMaxDepth << "), " 
     1375                  << "#polygons: " << (int)data.mPolygons->size() << " (max: " << sTermMaxPolygons << "), " 
     1376                  << "#rays: " << (int)data.mRays->size() << " (max: " << sTermMaxRays << ")" << endl; 
     1377//#endif 
    13511378} 
    13521379 
     
    14741501} 
    14751502 
    1476 void BspTree::CollectViewCells(BspNode *n, ViewCellContainer &viewCells) 
     1503void BspTree::CollectViewCells(ViewCellContainer &viewCells) const 
    14771504{ 
    14781505        stack<BspNode *> nodeStack; 
    1479  
    1480         nodeStack.push(n); 
     1506        nodeStack.push(mRoot); 
     1507 
     1508        ViewCell::NewMail(); 
    14811509 
    14821510        while (!nodeStack.empty())  
     
    14981526                { 
    14991527                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1528 
    15001529                        nodeStack.push(interior->mFront); 
    15011530                        nodeStack.push(interior->mBack); 
     
    15041533} 
    15051534 
    1506  
    1507 //} // GtpVisibilityPreprocessor 
     1535void BspTree::SetGenerateViewCells(int generateViewCells) 
     1536{ 
     1537        mGenerateViewCells = generateViewCells; 
     1538} 
     1539 
     1540BspTreeStatistics &BspTree::GetStat() 
     1541{ 
     1542        return mStat; 
     1543} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r331 r332  
    5050  /// number of view cells different to the view cell representing unbounded space. 
    5151  int viewCells; 
    52  
     52  /// size of the VPS 
     53  int pvs; 
     54  /// samples contributing to pvs 
     55  int contributingSamples; 
    5356  // Constructor 
    5457  BspTreeStatistics()  
     
    7275          accumDepth = 0; 
    7376          viewCells = 0; 
     77          pvs = 0; 
     78          contributingSamples = 0; 
    7479  } 
    7580 
     
    229234        void SetViewCell(ViewCell *viewCell); 
    230235 
    231         /** Generates new view cell and stores it back in the container. 
    232                 @returns the number of sample contributions from the rays 
    233         */ 
    234         int GenerateViewCell(const RayContainer &rays, ViewCellContainer &viewCells); 
     236        /** Generates new view cell and adds rays to the PVS. 
     237                @returns the number of samples contributing to the pvs. 
     238        */ 
     239        int GenerateViewCell(const RayContainer &rays); 
    235240 
    236241protected: 
     
    300305                Many leafs can point to the same viewcell. 
    301306        */ 
    302         int Construct(const ViewCellContainer &viewCells); 
     307        void Construct(const ViewCellContainer &viewCells); 
    303308 
    304309        /** Constructs tree using the given list of objects.  
    305310            @note the objects are not taken as view cells, but the view cells are 
    306311                constructed from the subdivision: Each leaf is taken as one viewcell. 
    307  
    308312                @param objects list of objects 
    309                 @returns list of view cells. 
    310         */ 
    311         int Construct(const ObjectContainer &objects, ViewCellContainer *viewCells); 
     313        */ 
     314        void Construct(const ObjectContainer &objects); 
    312315 
    313316        /** Constructs the tree from a given set of rays. 
     
    316319                created in the leafs and stored in the conatainer 
    317320        */ 
    318         int Construct(const RayContainer &sampleRays,  
    319                               ViewCellContainer *viewCells = NULL); 
     321        void Construct(const RayContainer &sampleRays); 
    320322 
    321323        /** Returns list of BSP leaves. 
     
    335337        bool Export(const string filename); 
    336338 
    337         void CollectViewCells(BspNode *n, ViewCellContainer &viewCells); 
     339        /** Collects the leaf view cells of the tree 
     340                @param viewCells returns the view cells  
     341        */ 
     342        void CollectViewCells(ViewCellContainer &viewCells) const; 
    338343 
    339344        /** A ray is cast possible intersecting the tree. 
     
    343348        int CastRay(Ray &ray); 
    344349 
     350        /** Set true if view cells shall be generated in each leaf. 
     351        */ 
     352        void SetGenerateViewCells(int generateViewCells); 
     353 
    345354        /// bsp tree construction types 
    346355        enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_RAYS}; 
     356 
     357        /** Returns statistics. 
     358        */ 
     359        BspTreeStatistics &GetStat(); 
    347360 
    348361protected: 
     
    380393        BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData); 
    381394 
    382         /** Constructs the tree from the given list of polygons. 
    383                 @param rayContainer stores bundle of rays on which subdivision may be based 
    384                 @param viewCells if not NULL, new view cells are  
    385                 created in the leafs and stored in the conatainer 
    386         */ 
    387         int Construct(PolygonContainer *polys,  
    388                           RayContainer *rays,  
    389                                   ViewCellContainer *viewCells = NULL); 
     395        /** Constructs the tree from the given list of polygons and rays. 
     396                @param polys stores set of polygons on which subdivision may be based 
     397                @param rays storesset of rays on which subdivision may be based 
     398        */ 
     399        void Construct(PolygonContainer *polys, RayContainer *rays); 
    390400 
    391401        /** Selects the best possible splitting plane.  
     
    413423        /** Inserts polygons down the tree. The polygons are filtered until a leaf is reached, 
    414424                then further subdivided. 
    415                 @param viewCellContainer if not null, a new viewcell is created and stored in the container 
    416         */ 
    417         void InsertPolygons(PolygonContainer *polys, ViewCellContainer *viewCells = NULL); 
     425        */ 
     426        void InsertPolygons(PolygonContainer *polys); 
    418427 
    419428        /** Subdivide leaf. 
     
    550559                  LARGEST_POLY_AREA = 32, 
    551560                  VERTICAL_AXIS = 64, 
    552                   BLOCKED_RAYS = 128 
     561                  BLOCKED_RAYS = 128, 
     562                  LEAST_RAY_SPLITS = 256, 
     563                  BALANCED_RAYS = 512 
    553564                }; 
    554565 
     
    558569        /// view cell corresponding to unbounded space 
    559570        ViewCell *mRootCell; 
     571 
     572        bool mGenerateViewCells; 
    560573 
    561574public: 
     
    563576        static void ParseEnvironment(); 
    564577 
    565         /// maximal number of polygons where tree construction is terminated 
     578        /// maximal number of polygons before subdivision termination 
    566579        static int sTermMaxPolygons; 
     580        /// maximal number of rays before subdivision termination 
     581        static int sTermMaxRays; 
    567582        /// maximal possible depth 
    568583        static int sTermMaxDepth; 
     
    576591        static int sTermMaxPolysForAxisAligned; 
    577592 
     593        /// axis aligned split criteria 
    578594        static float sCt_div_ci; 
    579595        static float sSplitBorder; 
    580596        static float sMaxCostRatio; 
    581597 
    582         // factors to guid the split plane heuristics 
     598        // factors guiding the split plane heuristics 
    583599        static float sLeastSplitsFactor; 
    584600        static float sBalancedPolysFactor; 
     
    587603        static float sLargestPolyAreaFactor; 
    588604        static float sBlockedRaysFactor; 
    589          
     605        static float sLeastRaySplitsFactor; 
     606        static float sBalancedRaysFactor; 
     607 
    590608        /// if polygons should be stored in the tree 
    591609        static bool sStoreSplitPolys; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r331 r332  
    6060         
    6161          p->BuildBspTree(); 
     62         
    6263          p->Export("vc_bsptree.x3d", false, false, true); 
    6364          p->BspTreeStatistics(Debug); 
Note: See TracChangeset for help on using the changeset viewer.