Ignore:
Timestamp:
09/12/05 02:07:02 (19 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
11 edited

Legend:

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

    r242 r263  
    9797    exporter->SetWireframe(); 
    9898    exporter->ExportKdTree(*tree); 
    99 //      exporter->ExportBspTree(*tree); 
     99        //exporter->ExportBspTree(*bsptree); 
    100100    exporter->ExportRays(rays, 10000); 
    101101    exporter->SetFilled(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Containers.h

    r236 r263  
    1111class SceneGraphNode; 
    1212class Intersectable; 
     13class Polygon3; 
    1314 
     15/** Container storing polygons used during BSP tree construction 
     16*/ 
     17typedef vector<Polygon3 *> PolygonContainer; 
    1418 
    1519/** Container for Mesh pointers primarily for the use within the kDTree and 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r262 r263  
    1313class Face; 
    1414 
    15 /** Container storing polygons used during BSP tree construction 
    16 */ 
    17 typedef vector<Polygon3 *> PolygonContainer; 
    1815 
    1916/** Class representing a general planar polygon in 3d. 
     
    6764        /// we can also store materials with polygons 
    6865        Material *mMaterial; 
     66 
     67        static int mLeastSplitTable[4]; 
     68        static int mBalancedTreeTable[4]; 
    6969}; 
    7070 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r262 r263  
    2323Preprocessor::LoadViewCells(const string filename) 
    2424{ 
    25         X3dParser *parser = new X3dParser; 
    26  
    27         bool result = parser->ParseFile(filename, mViewCells); 
    28  
    29         if (result) 
    30         { 
    31                 Exporter *exporter = Exporter::GetExporter("viewcells.x3d"); 
    32  
    33                 if (exporter)  
    34                 { 
    35                         exporter->ExportViewCells(&mViewCells); 
    36                         delete exporter; 
    37                 } 
    38  
    39                 Debug << "Generating view cells" << endl; 
    40                 GenerateViewCells(); 
    41                 Debug << "Generated view cells" << endl; 
    42         } 
    43  
    44         DEL_PTR(parser); 
    45          
    46  
    47         return result; 
     25        return X3dParser().ParseFile(filename, mViewCells); 
    4826} 
    4927 
     
    5129Preprocessor::GenerateViewCells() 
    5230{ 
    53         return BuildBspTree(); 
     31        // TODO 
     32        // HACK: derive view cells from the scene objects 
     33        ObjectContainer objects; 
     34 
     35        int maxViewCells = 0; 
     36        environment->GetIntValue("BspTree.maxViewCells", maxViewCells); 
     37 
     38        mSceneGraph->CollectObjects(&objects); 
     39        ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells); 
     40 
     41        return true; 
    5442} 
    5543 
     
    9482} 
    9583 
     84 
    9685bool 
    9786Preprocessor::BuildBspTree() 
     
    10089        mBspTree = new BspTree(); 
    10190 
    102         char constructionMethodStr[64]; 
    103         int maxViewCells = 0; 
    104  
    105         environment->GetIntValue("BspTree.maxViewCells", maxViewCells); 
    106         environment->GetStringValue("BspTree.constructionMethod", constructionMethodStr); 
    107  
    108         int constructionMethod = BspTree::VIEWCELLS; 
    109          
    110         if (strcmp(constructionMethodStr, "viewCells") == 0) 
    111                 constructionMethod = BspTree::VIEWCELLS; 
    112         else if (strcmp(constructionMethodStr, "sceneGeometry") == 0) 
    113                 constructionMethod = BspTree::SCENE_GEOMETRY; 
    114         else if (strcmp(constructionMethodStr, "rays") == 0) 
    115                 constructionMethod = BspTree::RAYS; 
    116         else  
    117         { 
    118                 cerr << "Wrong bsp construction method " << constructionMethodStr << endl; 
    119                 exit(1); 
    120     } 
    121  
    12291        ObjectContainer objects; 
    12392        RayContainer rays; 
    12493 
    125         switch (constructionMethod) 
     94        switch (BspTree::sConstructionMethod) 
    12695        { 
    127         case BspTree::VIEWCELLS: 
     96        case BspTree::VIEW_CELLS: 
    12897                Debug << "Construction method: view cells\n"; 
    129  
    130                 // derive view cells from the scene objects 
    131                 if (mViewCells.empty())          
    132                 { 
    133                         Debug << "View cells empty => generating new ones\n"; Debug.flush(); 
    134                         mSceneGraph->CollectObjects(&objects); 
    135                         ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells); 
    136                 } 
    137  
     98                 
    13899                mBspTree->Construct(mViewCells); 
    139100                break; 
     
    142103 
    143104        CLEAR_CONTAINER(mViewCells); // we generate new view cells 
     105 
    144106                mSceneGraph->CollectObjects(&objects); 
    145  
    146107                mBspTree->Construct(objects, &mViewCells); 
    147108                break; 
     
    149110                Debug << "Construction method: rays\n"; 
    150111 
    151                 CLEAR_CONTAINER(mViewCells); // we generate new view cells 
    152                  
     112                CLEAR_CONTAINER(mViewCells); // we generate new view cells       
    153113                mBspTree->Construct(rays, &mViewCells); 
    154114                break; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r262 r263  
    6767   
    6868   /** Build the BSP tree of currently loaded occluders/occludees/viewcells. The construction 
    69       is driven by the environment settings, which also sais which of the three types of 
     69      is driven by the environment settings, which also says which of the three types of 
    7070      entities should be used to drive the heuristical construction (only occluders by default) 
    7171  */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r262 r263  
    116116                mesh->mVertices.push_back(topTri.mVertices[i]); 
    117117         
     118        mesh->Preprocess(); 
     119 
    118120        return new ViewCell(mesh); 
    119121} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r262 r263  
    1919int BspTree::sSplitPlaneStrategy = NEXT_POLYGON;  
    2020int BspTree::sMaxCandidates = 10; 
     21int BspTree::sConstructionMethod = VIEW_CELLS; 
     22 
     23/** Evaluates split plane classification with respect to the plane's  
     24        contribution for a balanced tree. 
     25*/ 
     26int BspTree::sLeastSplitsTable[4] = {0, 0, 1, 0}; 
     27/** Evaluates split plane classification with respect to the plane's  
     28        contribution for a minimum number splits in the tree. 
     29*/ 
     30int BspTree::sBalancedTreeTable[4] = {-1, 1, 0, 0}; 
    2131 
    2232/****************************************************************/ 
     
    5161} 
    5262 
     63void BspNode::AddPolygons(PolygonContainer *polys) 
     64{ 
     65        while (!polys->empty()) 
     66        { 
     67                mPolygons.push_back(polys->back()); 
     68                polys->pop_back(); 
     69        } 
     70} 
     71 
     72 
    5373/****************************************************************/ 
    5474/*              class BspInterior implementation                */ 
     
    5676 
    5777 
    58 BspInterior::BspInterior(Plane3 plane): mPlane(plane)  
     78BspInterior::BspInterior(const Plane3 &plane):  
     79mPlane(plane), mFront(NULL), mBack(NULL) 
    5980{} 
    6081 
     
    95116    mBack = b; 
    96117    mFront = f; 
     118} 
     119 
     120void BspInterior::ProcessPolygon(Polygon3 *poly, bool storePolys) 
     121{ 
     122        if (storePolys)  
     123                mPolygons.push_back(poly); 
     124        else 
     125                delete poly; 
    97126} 
    98127 
     
    116145                { 
    117146                        case Polygon3::COINCIDENT: 
    118                                 // same sides => discard 
    119                                 if (DotProd(poly->GetSupportingPlane().mNormal, mPlane.mNormal) > 0)  
    120                                 { 
    121                                         if (storePolys) 
    122                                                 mPolygons.push_back(poly); 
    123                                         else 
    124                                                 DEL_PTR(poly); 
    125                                 } 
    126                                 else 
    127                                         backPolys->push_back(poly); 
    128                                 break; // TODO: compare normals 
     147                                // discard polygons or saves them in node 
     148                                ProcessPolygon(poly, storePolys); 
     149                                break; 
    129150                        case Polygon3::FRONT_SIDE: 
    130151                                frontPolys->push_back(poly); 
     
    142163                                frontPolys->push_back(front_piece); 
    143164                                backPolys->push_back(back_piece); 
     165 
     166#ifdef _DEBUG 
     167                                Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 
     168#endif 
     169                                // save or discard polygons 
     170                                ProcessPolygon(poly, storePolys); 
    144171                                 
    145                                 if (storePolys) 
    146                                         mPolygons.push_back(poly); 
    147                                 else 
    148                                         DEL_PTR(poly); 
    149 #ifdef _DEBUG 
    150                                 Debug << "split " << poly << endl << front << endl << back << endl; 
    151 #endif 
    152172                                break; 
    153173                        default: 
     
    164184/*                  class BspLeaf implementation                */ 
    165185/****************************************************************/ 
     186BspLeaf::BspLeaf(): mViewCell(NULL) 
     187{ 
     188} 
    166189 
    167190BspLeaf::BspLeaf(ViewCell *viewCell): mViewCell(viewCell)  
    168191{ 
    169192} 
     193 
     194BspLeaf::BspLeaf(BspInterior *parent): BspNode(parent), mViewCell(NULL) 
     195{} 
    170196 
    171197ViewCell *BspLeaf::GetViewCell() 
     
    184210} 
    185211 
    186 void BspLeaf::AddPolygons(PolygonContainer *polys) 
    187 { 
    188         while (!polys->empty()) 
    189         { 
    190                 mPolygons.push_back(polys->back()); 
    191                 polys->pop_back(); 
    192         } 
    193 } 
    194212/****************************************************************/ 
    195213/*                  class BspTree implementation                */ 
     
    218236 
    219237        app << "#N_RAYS Number of rays )\n" 
    220                 << rays <<endl; 
     238                << rays << endl; 
    221239        app << "#N_DOMAINS  ( Number of query domains )\n" 
    222240                << queryDomains <<endl; 
     
    247265 
    248266        app << "#N_PEMPTYLEAVES  ( Percentage of leaves with zero query domains )\n"<< 
    249         zeroQueryNodes*100/(double)Leaves()<<endl; 
     267        zeroQueryNodes*100/(double)Leaves() << endl; 
    250268 
    251269        app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< 
     
    300318{        
    301319        std::stack<BspTraversalData> tStack; 
    302          
    303         PolygonContainer polys; 
    304  
    305         // copy polygon information to guide the split process 
    306         AddMesh2Polygons(viewCell->GetMesh(), polys); 
     320                Debug << "getting polygons" << endl; Debug.flush(); 
     321        PolygonContainer *polys = new PolygonContainer(); 
     322 
     323        // extract polygons that guide the split process 
     324        AddMesh2Polygons(viewCell->GetMesh(), *polys); 
    307325        mBox.Include(viewCell->GetBox()); // add to BSP aabb 
    308326 
    309         BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); // traverse tree or create new one 
    310  
    311         tStack.push(BspTraversalData(firstNode, NULL, &polys, 0)); 
    312  
     327         // traverse tree or create new one 
     328        BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 
     329 
     330        tStack.push(BspTraversalData(firstNode, NULL, polys, 0)); 
     331 
     332        Debug << "starting traversal" << endl; Debug.flush(); 
    313333        while (!tStack.empty()) 
    314334        { 
     335                Debug << "new traversal step" << endl; Debug.flush(); 
     336                 
    315337                // filter polygons donw the tree 
    316338                BspTraversalData tData = tStack.top(); 
    317  
    318339            tStack.pop(); 
    319                                  
    320         if (!tData.mNode->IsLeaf()) 
    321                 { 
     340                         
     341                Debug << "popped stack" << endl; Debug.flush(); 
     342                if (!tData.mNode) 
     343                        Debug << "ERROR NO NODE\n"; Debug.flush(); 
     344                if (!tData.mNode->IsLeaf()) 
     345                { 
     346                        Debug << "no leaf" << endl; Debug.flush(); 
    322347                        BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
    323348 
     
    327352 
    328353                        int splits = 0; 
    329                         // split viecell polygons with respect to split plane 
    330                         interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits); 
    331  
    332                         mStat.splits += splits; 
    333  
    334                         // push the children on the stack 
    335                         if (frontPolys->size() > 0) // if polygons on front side of bsp tree 
     354                 
     355                        if ((int)tData.mPolygons->size() > 0) 
    336356                        { 
     357                                Debug << "traversing down tree" << endl; Debug.flush(); 
     358                                // split viecell polygons with respect to split plane 
     359                                interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits, mStorePolys); 
     360                                Debug << "polygon splitted" << endl; Debug.flush(); 
     361                                //Debug << "Reached level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl; 
     362                                mStat.splits += splits; 
     363 
     364                                // push the children on the stack 
    337365                                tStack.push(BspTraversalData(interior->GetFront(), interior->GetParent(),  
    338366                                                        frontPolys, tData.mDepth + 1)); 
    339                         } 
    340                         else // front side polygons empty 
    341                                 delete frontPolys; 
    342  
    343                         if (backPolys->size() > 0) // if polygons on backc side of bsp tree 
    344                         { 
     367                         
    345368                                tStack.push(BspTraversalData(interior->GetBack(), interior->GetParent(),  
    346369                                                        backPolys, tData.mDepth + 1)); 
     370                         
    347371                        } 
    348                         else // back side polygons empty 
    349                                 delete backPolys; 
     372                        else 
     373                        { 
     374                                Debug << "deleting data" << endl; Debug.flush(); 
     375                                DEL_PTR(tData.mPolygons); 
     376                                Debug << "deleted data" << endl; Debug.flush(); 
     377                        } 
    350378                } 
    351379                else // reached leaf => subdivide current viewcell 
    352380                { 
    353                         BspNode *root = Subdivide(tStack, tData, viewCell); 
     381                        Debug << "reached leaf" << endl; Debug.flush(); 
     382                        BspNode *root = Subdivide(tStack, tData, viewCell);              
    354383 
    355384            // tree empty => new root 
    356385                        if (!mRoot) 
    357                                 mRoot = root;                            
    358                 } 
    359         } 
     386                                mRoot = root;            
     387                        Debug << "subdivision done" << endl; Debug.flush(); 
     388                } 
     389                Debug << "ended one traversal step" << endl; Debug.flush(); 
     390        } 
     391        Debug << "ended traversal" << endl; Debug.flush(); 
    360392} 
    361393 
     
    434466         
    435467        /* for this type of construction we filter all viewcells down the  
    436          * tree until there is no polygon left. The split of the last polygon  
     468         * tree. If there is no polygon left, the last split plane 
    437469         * decides inside or outside of the viewcell. 
    438470    */ 
    439         const int maxPolygons = 0; 
    440         const int maxDepth = 99999; 
    441          
    442         InitTree(maxPolygons, maxDepth); 
    443          
     471        InitTree(sTermMaxPolygons, sTermMaxDepth); 
     472 
     473    bool savedStorePolys = mStorePolys; 
     474 
    444475        // tree is completely constructed once before  
    445476        // view cells are inserted one after another =>  
     
    447478        if (!mIsIncremential) 
    448479        { 
    449                 Debug << "Not incremential => constructing tree in advance\n"; 
    450480                // copy view cell meshes into one big polygon soup 
    451481                PolygonContainer *polys = new PolygonContainer(); 
    452482                Copy2PolygonSoup(viewCells, *polys, sMaxCandidates); 
    453483 
     484                // polygons are stored only during view cell insertion 
     485                mStorePolys = false; 
     486 
    454487                // construct tree from viewcell polygons 
    455488                Construct(polys); 
    456  
    457                 Export("bsp.x3d"); 
     489                //Export("bsp.x3d"); 
    458490        } 
    459491         
     
    461493        ViewCellContainer::const_iterator it; 
    462494 
     495        mStorePolys = savedStorePolys; 
     496 
    463497        int counter = 0; 
    464498 
    465         Debug << "View cells insertion...\n"; Debug.flush(); 
     499        Debug << "\n**** Started view cells insertion ****\n\n"; 
    466500        for (it = viewCells.begin(); it != viewCells.end(); ++ it) 
    467501        { 
    468                 Debug << "Inserting view cell " << ++counter; 
     502                Debug << "*** Inserting view cell " << counter << " ***" << endl; 
    469503                InsertViewCell(*it); 
    470         } 
    471         Debug << "finished view cells insertion"; 
     504                Debug << "*** view cell " << ++ counter << " inserted ***" << endl; 
     505        } 
     506        Debug << "**** finished view cells insertion ****" << endl; Debug.flush(); 
    472507} 
    473508 
     
    476511{ 
    477512        // take termination criteria from globals 
    478         InitTree(mTermMaxPolygons, mTermMaxDepth); 
    479         Debug << "HAHAHAHHA";Debug.flush(); 
     513        InitTree(sTermMaxPolygons, sTermMaxDepth); 
     514         
    480515        PolygonContainer *polys = new PolygonContainer(); 
    481516         
     
    497532{ 
    498533        std::stack<BspTraversalData> tStack; 
    499         Debug << "HDDHDH"; Debug.flush(); 
    500  
     534         
    501535        BspTraversalData tData(new BspLeaf(), NULL, polys, 0); 
    502536 
    503537        tStack.push(tData); 
    504538 
    505         Debug << "Contructing tree using objects..."; Debug.flush(); 
     539        Debug << "**** Contructing tree using objects ****\n"; 
    506540        while (!tStack.empty())  
    507541        { 
    508542                tData = tStack.top(); 
    509543            tStack.pop(); 
    510  
    511544         
    512545                // subdivide leaf node 
    513546                BspNode *root = Subdivide(tStack, tData); 
    514547 
    515                 // empty tree => // new root corresponding to unbounded space 
     548                // empty tree => new root corresponding to unbounded space 
    516549                if (!mRoot)  
    517550                        mRoot = root; 
    518551        } 
    519552 
    520         Debug << "finished\n"; 
     553        Debug << "**** tree construction finished ****\n"; 
    521554} 
    522555 
     
    526559                                                         ViewCell *viewCell) 
    527560{ 
     561        Debug << "subdividing" << endl; Debug.flush(); 
    528562        PolygonContainer *backPolys = new PolygonContainer(); 
    529563        PolygonContainer *frontPolys = new PolygonContainer(); 
     
    538572        if (!node->IsLeaf()) // node was subdivided 
    539573        { 
     574                Debug << "node was subdivided" << endl; Debug.flush(); 
    540575                BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    541576 
     
    544579                tStack.push(BspTraversalData(interior->GetFront(), interior, frontPolys, tData.mDepth + 1)); 
    545580        } 
    546         else // tree terminates here 
    547         { 
     581        else // traversal terminates 
     582        { 
     583                Debug << "eval stats" << endl; Debug.flush(); 
    548584                EvaluateLeafStats(tData); 
    549585 
    550                 // add view cell if in positive halfspace 
    551                 if (!tData.mParent || (node == tData.mParent->GetFront())) 
    552                         dynamic_cast<BspLeaf *>(node)->SetViewCell(viewCell); 
     586        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     587 
     588                // add view cell if in negative halfspace (== inside object)  
     589                // or if there is still geometry left 
     590                if (viewCell &&  
     591                        (!node->GetParent() || (node == node->GetParent()->GetBack()) ||  
     592                         (tData.mPolygons->size() > 0))) 
     593                { 
     594                        Debug << "** view cell inserted **\n"; 
     595                        leaf->SetViewCell(viewCell); 
     596                } 
     597 
     598                Debug << "storing or deleting polygons: " << mStorePolys << endl; Debug.flush(); 
     599                // add or delete remaining polygons 
     600                if (mStorePolys) 
     601                        leaf->AddPolygons(tData.mPolygons); 
     602                else 
     603                        CLEAR_CONTAINER(*tData.mPolygons); 
     604 
     605                DEL_PTR(tData.mPolygons); 
     606                Debug << "deleted polygon container" << endl; Debug.flush(); 
    553607        } 
    554608 
     
    556610} 
    557611 
    558 bool BspTree::ProcessPolygons(PolygonContainer *polys, BspLeaf *leaf) 
    559 { 
    560         bool result = false; 
    561  
    562         if (mStorePolys) 
    563         { 
    564                 leaf->AddPolygons(polys); 
    565                 result = true; 
    566         } 
    567         else 
    568                 CLEAR_CONTAINER(*polys); 
    569  
    570         delete polys; 
    571         return result; 
    572 } 
    573612 
    574613BspNode *BspTree::SubdivideNode(BspLeaf *leaf,  
     
    579618                                                                PolygonContainer *backPolys) 
    580619{ 
    581         // terminate traversal 
    582         if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 
    583         { 
    584                 // add or delete remaining polygons 
    585                 ProcessPolygons(polys, leaf); 
    586  
     620        if (leaf->GetViewCell() && (polys->size() == 0)) 
     621                Debug << "error: no distinct view cells!!!!!!!!!!!\n"; 
     622         
     623        // terminate traversal   
     624        if (//!leaf->GetViewCell() &&  
     625                ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth))) 
     626        {Debug << "subdividing node termination" << endl; Debug.flush(); 
    587627                return leaf; 
    588628        } 
     
    600640        int splits = 0; 
    601641                 
     642        Debug << "splipoly" << endl; Debug.flush(); 
    602643        node->SplitPolygons(polys, frontPolys, backPolys, splits, mStorePolys); 
    603644         
     
    605646 
    606647        // two new leaves 
    607         BspLeaf *back = new BspLeaf(); 
    608         BspLeaf *front = new BspLeaf(); 
     648        BspLeaf *back = new BspLeaf(node); 
     649        BspLeaf *front = new BspLeaf(node); 
    609650 
    610651        // replace a link from node's parent 
    611652        if (parent) 
    612         { 
    613653                parent->ReplaceChildLink(leaf, node); 
    614         } 
    615  
     654         
    616655        // and setup child links 
    617656        node->SetupChildLinks(back, front); 
    618  
    619         delete leaf; // leaf not member of tree anymore 
     657         
     658        DEL_PTR(leaf); // leaf not member of tree anymore 
    620659         
    621660        return node; 
    622661} 
    623662 
    624 Plane3 BspTree::SelectPlane(PolygonContainer *polygons)  const 
    625 { 
     663Plane3 BspTree::SelectPlane(PolygonContainer *polys)  const 
     664{ 
     665        if (polys->size() == 0) 
     666        { 
     667                Debug << "Warning: No split candidate available\n"; 
     668                return Plane3(); 
     669        } 
     670 
    626671        // simple strategy: just take next polygon 
    627672        if (sSplitPlaneStrategy == NEXT_POLYGON) 
    628673        { 
    629                 return polygons->front()->GetSupportingPlane(); 
     674                return polys->front()->GetSupportingPlane(); 
    630675        } 
    631676         
    632677        // use heuristics to find appropriate plane 
    633         return SelectPlaneHeuristics(polygons, sMaxCandidates); 
     678        return SelectPlaneHeuristics(polys, sMaxCandidates); 
    634679} 
    635680 
     
    672717                if ((sSplitPlaneStrategy == BALANCED_TREE) || (sSplitPlaneStrategy == COMBINED)) 
    673718                { 
    674                         sum += EvalForBalancedTree(classification); 
     719                        sum += sBalancedTreeTable[classification]; 
    675720                } 
    676721                 
    677722                if ((sSplitPlaneStrategy == LEAST_SPLITS) || (sSplitPlaneStrategy == COMBINED)) 
    678723                { 
    679                         sum2 += EvalForLeastSplits(classification); 
     724                        sum2 += sLeastSplitsTable[classification]; 
    680725                } 
    681726        } 
     
    684729        return abs(sum) + abs(sum2); 
    685730} 
    686  
    687 int BspTree::EvalForBalancedTree(const int classification) 
    688 { 
    689         // there should be roughly the same number of front and back polygons 
    690         if (classification == Polygon3::FRONT_SIDE) 
    691                 return 1; 
    692         else if (classification == Polygon3::BACK_SIDE) 
    693                 return -1; 
    694  
    695         return 0; 
    696 } 
    697  
    698 int BspTree::EvalForLeastSplits(const int classification) 
    699 { 
    700         if (classification == Polygon3::SPLIT) 
    701                 return 1; 
    702  
    703         return 0; 
    704 } 
    705  
    706731 
    707732void BspTree::ParseEnvironment() 
     
    729754                exit(1); 
    730755    } 
     756 
     757        //-- parse BSP tree construction method 
     758        char constructionMethodStr[64]; 
     759         
     760        environment->GetStringValue("BspTree.constructionMethod", constructionMethodStr); 
     761 
     762        sConstructionMethod = BspTree::VIEW_CELLS; 
     763         
     764        if (strcmp(constructionMethodStr, "viewCells") == 0) 
     765                sConstructionMethod = BspTree::VIEW_CELLS; 
     766        else if (strcmp(constructionMethodStr, "sceneGeometry") == 0) 
     767                sConstructionMethod = BspTree::SCENE_GEOMETRY; 
     768        else if (strcmp(constructionMethodStr, "rays") == 0) 
     769                sConstructionMethod = BspTree::RAYS; 
     770        else  
     771        { 
     772                cerr << "Wrong bsp construction method " << constructionMethodStr << endl; 
     773                exit(1); 
     774    } 
     775 
    731776} 
    732777 
     
    919964                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
    920965                        //ray.leaves.push_back(leaf); 
    921        
     966      // TODO 
    922967                        /*ObjectContainer::const_iterator mi; 
    923968                        for (mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); ++mi)  
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r262 r263  
    7272 
    7373  int Nodes() const {return nodes;} 
    74   int Interior() const { return nodes/2; } 
    75   int Leaves() const { return (nodes/2) + 1; } 
     74  int Interior() const { return nodes / 2; } 
     75  int Leaves() const { return (nodes / 2) + 1; } 
    7676 
    7777  void Reset()  
     
    128128        PolygonContainer *GetPolygons(); 
    129129 
     130        /** Adds polygons to node. 
     131        */ 
     132        void AddPolygons(PolygonContainer *polys); 
     133 
    130134protected: 
    131135 
     
    143147        /** Standard contructor taking split plane as argument. 
    144148        */ 
    145         BspInterior(Plane3 plane); 
     149        BspInterior(const Plane3 &plane); 
    146150        /** @return false since it is an interior node  
    147151        */ 
     
    173177protected: 
    174178         
     179        /** Discards or stores polygon in node. 
     180                @param polys the polygons 
     181                @param storePolys if the polygons should be stored or discarded 
     182        */ 
     183        void ProcessPolygon(Polygon3 *poly, bool storePolys); 
     184 
    175185        /// Splitting plane corresponding to this node 
    176186        Plane3 mPlane; 
     
    188198 
    189199public: 
    190         BspLeaf(ViewCell *viewCell = NULL); 
     200        BspLeaf(); 
     201        BspLeaf(ViewCell *viewCell); 
     202        BspLeaf(BspInterior *parent); 
    191203 
    192204        /** @return true since it is an interior node  
     
    201213 
    202214protected: 
    203  
    204         /** Helper function used to add remaining polygons to leaf. 
    205         */ 
    206         void AddPolygons(PolygonContainer *polys); 
    207215 
    208216        /// polygonal representation of this viewcell 
     
    239247 
    240248        /// BSP tree construction type 
    241         enum {VIEWCELLS, SCENE_GEOMETRY, RAYS}; 
     249        enum {VIEW_CELLS, SCENE_GEOMETRY, RAYS}; 
    242250 
    243251        /** Default constructor creating an empty tree. 
     
    305313        void Construct(PolygonContainer *polys); 
    306314 
    307         /** Evaluates plane classification with respect to the plane's  
    308                 contribution for a balanced tree. 
    309         */ 
    310         static inline int EvalForBalancedTree(const int classficiation); 
    311         /** Evaluates plane classification with respect to the plane's  
    312                 contribution for a minimum number splits in the tree. 
    313         */ 
    314         static inline int EvalForLeastSplits(const int classification); 
    315  
    316315        /** Evaluates the contribution of the candidate split plane. 
    317316        */ 
     
    331330 
    332331        /** Selects a splitting plane.  
    333                 @param polygons the polygon data on which the split decition is based 
    334         */ 
    335         Plane3 SelectPlane(PolygonContainer *polygons) const; 
     332                @param polys the polygon list on which the split decition is based 
     333        */ 
     334        Plane3 SelectPlane(PolygonContainer *polys) const; 
    336335 
    337336        /** Filters next viewcell down the tree and inserts it into the appropriate leaves 
     
    391390        int CastRay(Ray &ray); 
    392391 
    393         /** Discards or stores polygons in leaf and deletes the container. 
    394                 @param polys the polygons 
    395                 @param leaf the leaf where polygons are stored 
    396         */ 
    397         bool ProcessPolygons(PolygonContainer *polys, BspLeaf *node); 
     392 
    398393 
    399394        /// Pointer to the root of the tree 
     
    433428        /// number of candidates evaluated for the next split plane 
    434429        static int sMaxCandidates; 
     430        /// BSP tree construction method 
     431        static int sConstructionMethod; 
     432 
     433private: 
     434        /** Evaluates split plane classification with respect to the plane's  
     435                contribution for a balanced tree. 
     436        */ 
     437        static int sLeastSplitsTable[4]; 
     438        /** Evaluates split plane classification with respect to the plane's  
     439                contribution for a minimum number splits in the tree. 
     440        */ 
     441        static int sBalancedTreeTable[4]; 
    435442}; 
    436443 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r262 r263  
    274274} 
    275275 
     276void X3dExporter::ExportPolygons(PolygonContainer *polys) 
     277{ 
     278        stream << "<Shape>" << endl; 
     279        stream << "<Appearance>" << endl; 
     280   
     281        // $$ tmp -> random material 
     282   
     283        float r, g, b; 
     284 
     285        if (mUseForcedMaterial)  
     286        { 
     287                r = mForcedMaterial.mDiffuseColor.r; 
     288                g = mForcedMaterial.mDiffuseColor.g; 
     289                b = mForcedMaterial.mDiffuseColor.b; 
     290        }  
     291        else  
     292        { 
     293                r = RandomValue(0.5, 1.0); 
     294                g = RandomValue(0.5, 1.0); 
     295                b = RandomValue(0.5, 1.0); 
     296        } 
     297 
     298        stream << "<Material diffuseColor=\"" << r << " " << g << " " << b  
     299                   << "\" specularColor=\"0.0 0.0 0.0\"/>" << endl; 
     300 
     301    stream << "</Appearance>" << endl; 
     302 
     303 
     304        //-- create and write indices 
     305        if (mWireframe) 
     306                stream << "<IndexedLineSet ccw=\"TRUE\" coordIndex=\"" << endl; 
     307        else 
     308                stream << "<IndexedFaceSet ccw=\"TRUE\" coordIndex=\"" << endl; 
     309 
     310        int index = 0; 
     311         
     312        PolygonContainer::const_iterator pit; 
     313 
     314    VertexContainer::const_iterator vi;   
     315         
     316        for (pit = polys->begin(); pit != polys->end(); ++pit) 
     317        { 
     318                Polygon3 *poly = *pit; 
     319                for (vi = poly->mVertices.begin(); vi != poly->mVertices.end(); ++vi)  
     320                { 
     321                        stream << index ++ << " "; 
     322                } 
     323                stream << "-1" << endl; 
     324        } 
     325 
     326        stream << "\" >" << endl; 
     327         
     328        stream << "<Coordinate  point=\"" << endl; 
     329        for (pit = polys->begin(); pit != polys->end(); ++pit) 
     330        { 
     331                Polygon3 *poly = *pit; 
     332        for (vi = poly->mVertices.begin(); vi != poly->mVertices.end(); ++vi)  
     333                { 
     334                        stream << (*vi).x << " " << (*vi).y << " " << (*vi).z; 
     335                        stream << "," << endl; 
     336                } 
     337        } 
     338        stream << "\" >" << endl; 
     339        stream << "</Coordinate>" << endl; 
     340 
     341        if (mWireframe) 
     342                stream << "</IndexedLineSet>" << endl; 
     343        else 
     344                stream << "</IndexedFaceSet>" << endl; 
     345   
     346        stream << "</Shape>" << endl; 
     347} 
    276348 
    277349bool 
     
    305377        if (mExportRayDensity)  
    306378        { 
    307                 return false;//ExportKdTreeRayDensity(tree); 
     379                return ExportBspTreeRayDensity(tree); 
    308380        } 
    309381   
     
    340412 
    341413                } 
    342                 else 
     414                else if (!tree.StorePolys()) 
    343415                { 
    344                         BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     416                        ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
    345417                         
    346                         // export view cell geometry 
    347                          
    348                         if (!tree.StorePolys() && leaf->GetViewCell()) 
    349                         { 
    350                                 ExportViewCell(leaf->GetViewCell()); 
    351                         } 
    352                          
     418                        if (viewCell) // export view cell geometry 
     419                                ExportViewCell(viewCell);        
    353420                } 
    354   } 
    355    
    356   return true; 
     421        } 
     422         
     423        return true; 
    357424} 
    358425 
     
    402469} 
    403470 
     471 
     472bool 
     473X3dExporter::ExportBspTreeRayDensity(const BspTree &tree) 
     474{ 
     475        // TODO 
     476        return true; 
     477} 
    404478 
    405479bool 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r261 r263  
    5050  ExportPolygon(Polygon3 *poly); 
    5151 
     52  virtual void ExportPolygons(PolygonContainer *polys); 
     53 
    5254  virtual bool 
    5355  ExportBox(const AxisAlignedBox3 &box); 
     
    7577  ExportKdTreeRayDensity(const KdTree &tree); 
    7678 
    77    
     79  bool 
     80  ExportBspTreeRayDensity(const BspTree &tree);   
    7881}; 
    7982  
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r261 r263  
    3535  environment->GetStringValue("Scene.viewcells", buff); 
    3636 
    37   string viewCellsFile(buff); 
    38   p->LoadViewCells(viewCellsFile); 
     37  string vcFileName(buff); 
    3938 
     39  // if BSP tree construction method needs predefined view cells 
     40  if (BspTree::sConstructionMethod == BspTree::VIEW_CELLS) 
     41  { 
     42          if (vcFileName != "") 
     43          p->LoadViewCells(vcFileName); 
     44          else 
     45                  p->GenerateViewCells(); 
     46  } 
     47 
     48  p->BuildBspTree(); 
    4049  p->BspTreeStatistics(Debug); 
     50  p->Export(filename + "-bsptree.x3d", false, false, true); 
     51 
    4152#endif 
    4253 
     
    4455  if (0) { 
    4556    p->Export(filename + "-out.x3d", true, false, false); 
    46     p->Export(filename + "-kdtree.x3d", false, true, false); 
     57    p->Export(filename + "-kdtree.x3d", false, true, false);     
    4758  } 
    4859   
Note: See TracChangeset for help on using the changeset viewer.