Ignore:
Timestamp:
09/09/05 15:03:48 (19 years ago)
Author:
mattausch
Message:

debugged bsp

File:
1 edited

Legend:

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

    r261 r262  
    1111#include <time.h> 
    1212#include <iomanip> 
     13#include "Exporter.h" 
    1314 
    1415#define INITIAL_COST 999999// unreachable high initial cost for heuristic evaluation 
     
    200201mRoot(NULL),  
    201202mIsIncremential(false), 
    202 mStorePolys(false) 
     203mStorePolys(true) 
    203204{ 
    204205        Randomize(); // initialise random generator for heuristics 
     
    279280            tStack.pop(); 
    280281         
    281                 /// if we store 
    282                 if (mStorePolys) 
    283                         Polygon3::DeletePolygons(&node->mPolygons); 
     282                /// if we stored the polygons 
     283                CLEAR_CONTAINER(node->mPolygons); 
    284284 
    285285                if (!node->IsLeaf()) 
     
    365365        mTermMaxDepth = maxDepth; 
    366366        mStat.nodes = 1; 
     367         
    367368        mBox.Initialize();      // initialise bsp tree bounding box 
    368369} 
     
    438439        const int maxPolygons = 0; 
    439440        const int maxDepth = 99999; 
     441         
    440442        InitTree(maxPolygons, maxDepth); 
    441443         
    442  
    443         // tree is completely constructed before  
    444         // view cells are not inserted one after another => better tree behaviour 
     444        // tree is completely constructed once before  
     445        // view cells are inserted one after another =>  
     446        // global tree optimization possible 
    445447        if (!mIsIncremential) 
    446448        { 
     449                Debug << "Not incremential => constructing tree in advance\n"; 
    447450                // copy view cell meshes into one big polygon soup 
    448451                PolygonContainer *polys = new PolygonContainer(); 
     
    451454                // construct tree from viewcell polygons 
    452455                Construct(polys); 
    453         } 
    454  
    455         // insert all viewcells 
     456 
     457                Export("bsp.x3d"); 
     458        } 
     459         
     460        //-- insert all viewcells 
    456461        ViewCellContainer::const_iterator it; 
    457462 
     463        int counter = 0; 
     464 
     465        Debug << "View cells insertion...\n"; Debug.flush(); 
    458466        for (it = viewCells.begin(); it != viewCells.end(); ++ it) 
    459467        { 
     468                Debug << "Inserting view cell " << ++counter; 
    460469                InsertViewCell(*it); 
    461470        } 
     471        Debug << "finished view cells insertion"; 
    462472} 
    463473 
     
    465475void BspTree::Construct(const ObjectContainer &objects, ViewCellContainer *viewCells) 
    466476{ 
    467 #ifdef _DEBUG 
    468         Debug << "Constructing tree using object container\n"; 
    469 #endif 
    470477        // take termination criteria from globals 
    471478        InitTree(mTermMaxPolygons, mTermMaxDepth); 
    472  
     479        Debug << "HAHAHAHHA";Debug.flush(); 
    473480        PolygonContainer *polys = new PolygonContainer(); 
    474481         
     
    490497{ 
    491498        std::stack<BspTraversalData> tStack; 
    492         // new root corresponding to unbounded space 
    493         BspTraversalData tData(new BspLeaf(), mRoot->GetParent(), polys, 0); 
     499        Debug << "HDDHDH"; Debug.flush(); 
     500 
     501        BspTraversalData tData(new BspLeaf(), NULL, polys, 0); 
    494502 
    495503        tStack.push(tData); 
    496504 
     505        Debug << "Contructing tree using objects..."; Debug.flush(); 
    497506        while (!tStack.empty())  
    498507        { 
     
    500509            tStack.pop(); 
    501510 
     511         
    502512                // subdivide leaf node 
    503513                BspNode *root = Subdivide(tStack, tData); 
    504514 
    505                 if (!mRoot) // empty tree => new root 
     515                // empty tree => // new root corresponding to unbounded space 
     516                if (!mRoot)  
    506517                        mRoot = root; 
    507518        } 
     519 
     520        Debug << "finished\n"; 
    508521} 
    509522 
     
    543556} 
    544557 
     558bool 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} 
     573 
    545574BspNode *BspTree::SubdivideNode(BspLeaf *leaf,  
    546575                                                                BspInterior *parent,  
     
    554583        { 
    555584                // add or delete remaining polygons 
    556                 if (mStorePolys) 
    557                         leaf->AddPolygons(polys); 
    558                 else 
    559                         Polygon3::DeletePolygons(polys); 
    560  
    561                 delete polys; 
     585                ProcessPolygons(polys, leaf); 
    562586 
    563587                return leaf; 
     
    572596        Debug << node << endl; 
    573597#endif 
     598 
    574599        // split polygon according to current plane 
    575600        int splits = 0; 
     
    795820        return mStorePolys; 
    796821} 
     822 
    797823void BspTree::EvaluateLeafStats(const BspTraversalData &data) 
    798824{ 
     
    929955} 
    930956 
     957bool BspTree::Export(const string filename) 
     958{ 
     959        Exporter *exporter = Exporter::GetExporter(filename); 
     960 
     961        if (exporter)  
     962        { 
     963                exporter->ExportBspTree(*this); 
     964                delete exporter; 
     965 
     966                return true; 
     967        }        
     968 
     969        return false; 
     970} 
    931971//} // GtpVisibilityPreprocessor 
Note: See TracChangeset for help on using the changeset viewer.