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

debugged bsp

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

Legend:

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

    r261 r262  
    1212Polygon3::Polygon3(Face *face, Mesh *parent) 
    1313{ 
    14         VertexIndexContainer::const_iterator it; 
     14        VertexIndexContainer::reverse_iterator it = face->mVertexIndices.rbegin(); 
    1515 
    16         for (it = face->mVertexIndices.begin(); it != face->mVertexIndices.end(); ++ it) 
     16        for (; it != face->mVertexIndices.rend();  ++it) 
    1717        { 
    1818                mVertices.push_back(parent->mVertices[*it]); 
    1919                mMaterial = parent->mMaterial; 
    2020                 
    21                 Debug << parent->mVertices[*it] << endl; 
     21                //Debug << parent->mVertices[*it] << endl; 
    2222        } 
    2323} 
     
    3131#endif 
    3232        return Plane3(mVertices[0], mVertices[1], mVertices[2]); 
    33 } 
    34  
    35 void Polygon3::DeletePolygons(PolygonContainer *polys) 
    36 { 
    37         while(!polys->empty()) 
    38         { 
    39                 DEL_PTR(polys->back()); 
    40                 polys->pop_back(); 
    41         } 
    4233} 
    4334 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r256 r262  
    6262 
    6363                 
    64         /** Deletes all polygons om the queue. 
    65         */ 
    66         static void DeletePolygons(PolygonContainer *polys); 
    67  
    6864        /// vertices are connected in counterclockwise order. 
    6965        VertexContainer mVertices; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r261 r262  
    77#include "Environment.h" 
    88 
     9Preprocessor::Preprocessor(): 
     10mKdTree(NULL), 
     11mBspTree(NULL) 
     12{ 
     13} 
    914 
    1015Preprocessor::~Preprocessor() 
    1116{ 
    12   // delete view cells 
    13   while (!mViewCells.empty()) 
    14   { 
    15           DEL_PTR(mViewCells.back()); 
    16           mViewCells.pop_back(); 
    17   } 
    18  
    19   // delete psp tree 
     17  CLEAR_CONTAINER(mViewCells); 
    2018  DEL_PTR(mBspTree); 
     19  DEL_PTR(mKdTree); 
    2120} 
    2221 
     
    2524{ 
    2625        X3dParser *parser = new X3dParser; 
    27  
    28         delete parser; 
    2926 
    3027        bool result = parser->ParseFile(filename, mViewCells); 
     
    3229        if (result) 
    3330        { 
    34                 Exporter *exporter = Exporter::GetExporter(filename); 
     31                Exporter *exporter = Exporter::GetExporter("viewcells.x3d"); 
    3532 
    3633                if (exporter)  
     34                { 
    3735                        exporter->ExportViewCells(&mViewCells); 
    38  
     36                        delete exporter; 
     37                } 
     38 
     39                Debug << "Generating view cells" << endl; 
    3940                GenerateViewCells(); 
     41                Debug << "Generated view cells" << endl; 
    4042        } 
     43 
     44        DEL_PTR(parser); 
     45         
     46 
    4147        return result; 
    4248} 
     
    9197Preprocessor::BuildBspTree() 
    9298{ 
    93         ObjectContainer objects; 
    94         mSceneGraph->CollectObjects(&objects); 
    95  
     99        DEL_PTR(mBspTree); 
    96100        mBspTree = new BspTree(); 
    97101 
     
    116120    } 
    117121 
     122        ObjectContainer objects; 
     123        RayContainer rays; 
     124 
    118125        switch (constructionMethod) 
    119126        { 
    120127        case BspTree::VIEWCELLS: 
     128                Debug << "Construction method: view cells\n"; 
     129 
    121130                // derive view cells from the scene objects 
    122                 //ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells); 
     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 
     138                mBspTree->Construct(mViewCells); 
     139                break; 
     140        case BspTree::SCENE_GEOMETRY: 
     141                Debug << "Construction method: geometry\n"; 
     142 
     143        CLEAR_CONTAINER(mViewCells); // we generate new view cells 
     144                mSceneGraph->CollectObjects(&objects); 
     145 
     146                mBspTree->Construct(objects, &mViewCells); 
     147                break; 
     148        case BspTree::RAYS: 
     149                Debug << "Construction method: rays\n"; 
     150 
     151                CLEAR_CONTAINER(mViewCells); // we generate new view cells 
    123152                 
    124                 mBspTree->Construct(mViewCells); 
    125                 break; 
    126         case BspTree::SCENE_GEOMETRY: 
    127                 CLEAR_CONTAINER(mViewCells); 
    128                 mBspTree->Construct(objects, &mViewCells); 
    129                 break; 
    130         case BspTree::RAYS: 
    131                 CLEAR_CONTAINER(mViewCells); 
    132                 mBspTree->Construct(objects, &mViewCells); 
     153                mBspTree->Construct(rays, &mViewCells); 
    133154                break; 
    134155        default: 
     156                Debug << "Error: Method not available\n"; 
    135157                break; 
    136158        } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r261 r262  
    2525class Preprocessor { 
    2626public: 
     27        /** Default constructor initialising e.g., KD tree and BSP tree. 
     28        */ 
     29        Preprocessor(); 
     30 
    2731   ~Preprocessor(); 
    2832 
     
    8892  /// scene graph loaded from file 
    8993  SceneGraph *mSceneGraph; 
    90   /// BSP tree representing the viewcells 
    91   BspTree *mViewCellBspTree; 
     94   
    9295  /// kD-tree organizing the scene graph (occluders + occludees) + viewcells 
    9396  KdTree *mKdTree; 
     
    100103  ViewCellContainer mViewCells; 
    101104   
    102   BspTree * mBspTree; 
     105  /// BSP tree representing the viewcells 
     106  BspTree *mBspTree; 
    103107}; 
    104108 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r261 r262  
    1111ViewCell::~ViewCell() 
    1212{ 
    13         // NOTE: should I really do this here? 
     13        // NOTE: should I really do this here? (I know that there is only one mesh per view cell) 
    1414        DEL_PTR(mMesh); 
    1515} 
     
    114114        // add top vertices      
    115115        for (int i = 0; i < 3; ++i) 
    116                 mesh->mVertices.push_back(topTri.mVertices[1]); 
     116                mesh->mVertices.push_back(topTri.mVertices[i]); 
    117117         
    118118        return new ViewCell(mesh); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r261 r262  
    6767 
    6868}; 
    69    
     69 
    7070//}; // GtpVisibilityPreprocessor 
    7171 
  • 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 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r261 r262  
    286286        bool StorePolys() const; 
    287287 
     288        /** Exports Bsp tree to file. 
     289        */ 
     290        bool Export(const string filename); 
     291 
     292 
    288293protected: 
    289294         
     
    386391        int CastRay(Ray &ray); 
    387392 
     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); 
     398 
    388399        /// Pointer to the root of the tree 
    389400        BspNode *mRoot; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r261 r262  
    237237 
    238238 
     239        //-- create and write indices 
    239240        if (mWireframe) 
    240241                stream << "<IndexedLineSet ccw=\"TRUE\" coordIndex=\"" << endl; 
     
    242243                stream << "<IndexedFaceSet ccw=\"TRUE\" coordIndex=\"" << endl; 
    243244 
    244         VertexContainer::const_iterator vi = poly->mVertices.begin(); 
    245  
     245        int index = 0; 
     246         
     247        VertexContainer::const_iterator vi;   
     248         
     249        for (vi = poly->mVertices.begin(); vi != poly->mVertices.end(); ++vi)  
     250        { 
     251                stream << index ++ << " "; 
     252        } 
     253        stream << "-1" << endl; 
     254 
     255        stream << "\" >" << endl; 
     256         
    246257        stream << "<Coordinate  point=\"" << endl; 
    247258   
    248         for (; vi != poly->mVertices.end(); ++vi)  
     259        for (vi = poly->mVertices.begin(); vi != poly->mVertices.end(); ++vi)  
    249260        { 
    250261                stream << (*vi).x << " " << (*vi).y << " " << (*vi).z; 
     
    252263        } 
    253264   
    254         stream<<"\" >"<<endl; 
    255         stream<<"</Coordinate>"<<endl; 
     265        stream << "\" >" << endl; 
     266        stream << "</Coordinate>" << endl; 
    256267 
    257268        if (mWireframe) 
     
    303314        Mesh *mesh = new Mesh; 
    304315 
    305         //AxisAlignedBox3 box = tree.GetBoundingBox(); 
    306         //ExportBox(box); 
     316        AxisAlignedBox3 box = tree.GetBoundingBox(); 
     317        ExportBox(box); 
    307318          
    308319        while (!tStack.empty())  
     
    332343                { 
    333344                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     345                         
    334346                        // export view cell geometry 
     347                         
    335348                        if (!tree.StorePolys() && leaf->GetViewCell()) 
     349                        { 
    336350                                ExportViewCell(leaf->GetViewCell()); 
     351                        } 
     352                         
    337353                } 
    338354  } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp

    r261 r262  
    378378 
    379379/*********************************************************** 
    380  *         class X3dViewCellsParseHandlers implemenation          * 
     380 *         class X3dViewCellsParseHandlers implemenation   * 
    381381 ***********************************************************/ 
    382382 
     
    421421        int len = attributes.getLength(); 
    422422        int i; 
    423          
     423        // clear previous vertex indices 
     424        mCurrentVertexIndices.clear(); 
    424425        for (i=0; i < len; i++)  
    425426        { 
     
    460461         
    461462        VertexContainer vertices; 
    462  
     463         
    463464        for (int i=0; i < len; i++)  
    464465        { 
     
    498499 
    499500                                Vector3 v(x, y, z); 
    500                                 vertices.push_back(v); 
     501                                vertices.push_back(v);                           
    501502                        } 
    502503                } 
    503504        } 
    504  
    505505 
    506506 
     
    511511                                                  vertices[mCurrentVertexIndices[i+2]]); 
    512512 
    513             // create view cell from base triangle 
     513                // create view cell from base triangle 
    514514                const float height = 10; 
    515515                mViewCells->push_back(ViewCell::ExtrudeViewCell(baseTri, height)); 
     516 
     517                Mesh *mesh = mViewCells->back()->GetMesh(); 
     518#ifdef _DEBUG 
     519                Debug << "Viewcell :"  
     520                          << mesh->mVertices[0] << " " << mesh->mVertices[1] << " " << mesh->mVertices[2] << " "  
     521                          << mesh->mVertices[3] << " " << mesh->mVertices[4] << " " << mesh->mVertices[5] << "\n"; 
     522#endif 
    516523        } 
    517524} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/common.h

    r261 r262  
    128128 
    129129#ifndef DEL_PTR 
    130 #define DEL_PTR(ptr) while (0) {if (ptr) {delete (ptr); (ptr) = NULL;}} 
    131 #endif 
    132  
     130#define DEL_PTR(ptr) do {if (ptr) {        \ 
     131                           delete (ptr);   \ 
     132                                                   (ptr) = 0;}}    \ 
     133                     while (0) 
     134#endif 
     135// Clears a container (i.e., a vector of pointers) and deletes the pointers 
    133136#ifndef CLEAR_CONTAINER 
    134 #define CLEAR_CONTAINER(co) while (!co.empty()) {delete co.back(); co.pop_back();} 
     137#define CLEAR_CONTAINER(co) do { while (!(co).empty()) {   \ 
     138                                                           DEL_PTR((co).back());     \ 
     139                                                                   (co).pop_back();}}      \ 
     140                                                        while (0) 
    135141#endif 
    136142 
Note: See TracChangeset for help on using the changeset viewer.