Ignore:
Timestamp:
09/08/05 01:52:52 (19 years ago)
Author:
mattausch
Message:

added viewcell stuff

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
2 added
15 edited

Legend:

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

    r238 r260  
    10661066                 optString, 
    10671067                 "-scene_filename=", 
    1068                  "soda.x3d"); 
     1068                 "atlanta2.x3d"); 
     1069 
     1070  RegisterOption("Scene.viewcells", 
     1071                 optString, 
     1072                 "-viewcells_filename=", 
     1073                 "atlanta_viewcells_large.x3d"); 
    10691074 
    10701075  RegisterOption("Unigraphics.meshGrouping", 
     
    11791184          optInt, 
    11801185          "-bsp_max_viewcells=", 
    1181           "100"); 
     1186          "9999"); 
    11821187} 
    11831188 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r256 r260  
    3535void Polygon3::DeletePolygons(PolygonContainer *polys) 
    3636{ 
    37         // don't need to store polygon information => delete polygons 
    3837        while(!polys->empty()) 
    3938        { 
    40                 Polygon3 *poly = polys->back(); 
     39                DEL_PTR(polys->back()); 
    4140                polys->pop_back(); 
    42                 DEL_PTR(poly); 
    4341        } 
    4442} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r242 r260  
    7979        else if (strcmp(constructionMethodStr, "sceneGeometry") == 0) 
    8080                constructionMethod = BspTree::SCENE_GEOMETRY; 
     81        else if (strcmp(constructionMethodStr, "rays") == 0) 
     82                constructionMethod = BspTree::RAYS; 
    8183        else  
    8284        { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h

    r240 r260  
    8585        int Compress() {return 0;} 
    8686         
    87         int GetSize() {return mEntries.size();} 
     87        int GetSize() {return (int)mEntries.size();} 
    8888         
    8989        void GetData(const int index, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp

    r176 r260  
    5050  return number; 
    5151} 
    52  
    53  
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r256 r260  
    7676        } 
    7777} 
     78 
     79ViewCell *ViewCell::Convert2ViewCell(Face *face, float scale) 
     80{ 
     81        // TODO: delete mesh 
     82        Mesh *mesh = new Mesh(); 
     83        mesh->mFaces.push_back(face); 
     84     
     85 
     86        return new ViewCell(mesh); 
     87} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r239 r260  
    5151                                                                ViewCellContainer &viewCells,  
    5252                                                                const int maxViewCells); 
     53 
     54        static ViewCell *Convert2ViewCell(Face *face); 
    5355protected: 
    5456 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r258 r260  
    4545} 
    4646 
     47PolygonContainer *BspNode::GetPolygons() 
     48{ 
     49        return &mPolygons; 
     50} 
     51 
    4752/****************************************************************/ 
    4853/*              class BspInterior implementation                */ 
     
    9499                                                                PolygonContainer *frontPolys,  
    95100                                                                PolygonContainer *backPolys,  
    96                                                                 int &splits) 
     101                                                                int &splits, bool storePolys) 
    97102{ 
    98103        while (!polys->empty()) 
     
    110115                { 
    111116                        case Polygon3::COINCIDENT: 
     117                                // same sides => discard 
     118                                if (DotProd(poly->GetSupportingPlane().mNormal, mPlane.mNormal) > 0)  
     119                                { 
     120                                        if (storePolys) 
     121                                                mPolygons.push_back(poly); 
     122                                        else 
     123                                                DEL_PTR(poly); 
     124                                } 
     125                                else 
     126                                        backPolys->push_back(poly); 
    112127                                break; // TODO: compare normals 
    113128                        case Polygon3::FRONT_SIDE: 
     
    127142                                backPolys->push_back(back_piece); 
    128143                                 
     144                                if (storePolys) 
     145                                        mPolygons.push_back(poly); 
     146                                else 
     147                                        DEL_PTR(poly); 
    129148#ifdef _DEBUG 
    130                                 //                              Debug << "split " << poly << endl << front << endl << back << endl; 
     149                                Debug << "split " << poly << endl << front << endl << back << endl; 
    131150#endif 
    132                                 // don't need polygon anymore 
    133                                 DEL_PTR(poly); 
    134  
    135151                                break; 
    136152                        default: 
    137                                 Debug << "SHOULD NEVER COME HERE\n"; 
     153                Debug << "SHOULD NEVER COME HERE\n"; 
    138154                                break; 
    139155                } 
    140156        } 
     157 
     158        // contains nothing 
     159        delete polys; 
    141160} 
    142161 
     
    154173} 
    155174 
     175void BspLeaf::SetViewCell(ViewCell *viewCell) 
     176{ 
     177        mViewCell = viewCell; 
     178} 
     179 
    156180bool BspLeaf::IsLeaf() const  
    157181{  
     
    159183} 
    160184 
    161  
     185void BspLeaf::AddPolygons(PolygonContainer *polys) 
     186{ 
     187        while (!polys->empty()) 
     188        { 
     189                mPolygons.push_back(polys->back()); 
     190                polys->pop_back(); 
     191        } 
     192} 
    162193/****************************************************************/ 
    163194/*                  class BspTree implementation                */ 
    164195/****************************************************************/ 
    165196 
    166 BspTree::BspTree(): mTermMaxPolygons(0), mTermMaxDepth(0), mRoot(NULL) 
     197BspTree::BspTree():  
     198mTermMaxPolygons(0),  
     199mTermMaxDepth(0),  
     200mRoot(NULL),  
     201mIsIncremential(false), 
     202mStorePolys(false) 
    167203{ 
    168204        Randomize(); // initialise random generator for heuristics 
     
    243279            tStack.pop(); 
    244280         
     281                /// if we store 
     282                if (mStorePolys) 
     283                        Polygon3::DeletePolygons(&node->mPolygons); 
     284 
    245285                if (!node->IsLeaf()) 
    246286                { 
     
    248288 
    249289                        // push the children on the stack (there are always two children) 
    250                         interior->GetBack()->mParent = NULL; 
    251                         interior->GetFront()->mParent = NULL; 
    252  
    253290                        tStack.push(interior->GetBack()); 
    254291                        tStack.push(interior->GetFront()); 
     
    268305        // copy polygon information to guide the split process 
    269306        AddMesh2Polygons(viewCell->GetMesh(), polys); 
    270         mBox.Include(viewCell->GetBox()); // also add to BSP root box 
     307        mBox.Include(viewCell->GetBox()); // add to BSP aabb 
    271308 
    272309        BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); // traverse tree or create new one 
     
    292329                        // split viecell polygons with respect to split plane 
    293330                        interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits); 
     331 
    294332                        mStat.splits += splits; 
    295333 
    296334                        // push the children on the stack 
    297                         if (frontPolys->size() > 0) // if polygons on this side of bsp tree 
     335                        if (frontPolys->size() > 0) // if polygons on front side of bsp tree 
     336                        { 
    298337                                tStack.push(BspTraversalData(interior->GetFront(), interior->GetParent(),  
    299338                                                        frontPolys, tData.mDepth + 1)); 
    300                         else 
     339                        } 
     340                        else // front side polygons empty 
    301341                                delete frontPolys; 
    302342 
    303                         if (backPolys->size() > 0) // if polygons on this side of bsp tree 
     343                        if (backPolys->size() > 0) // if polygons on backc side of bsp tree 
     344                        { 
    304345                                tStack.push(BspTraversalData(interior->GetBack(), interior->GetParent(),  
    305346                                                        backPolys, tData.mDepth + 1)); 
    306                         else 
     347                        } 
     348                        else // back side polygons empty 
    307349                                delete backPolys; 
    308350                } 
    309351                else // reached leaf => subdivide current viewcell 
    310352                { 
    311                         BspNode *root = Subdivide(tStack, tData, NULL); 
    312  
    313                         if (!mRoot) // take as root if there is none yet 
     353                        BspNode *root = Subdivide(tStack, tData, viewCell); 
     354 
     355            // tree empty => new root 
     356                        if (!mRoot) 
    314357                                mRoot = root;                            
    315358                } 
     
    317360} 
    318361 
    319 void BspTree::Construct(const ViewCellContainer &viewCells) 
    320 { 
    321         // for this type of construction we split until no polygons is left 
    322         mTermMaxPolygons = 0; 
    323         mTermMaxDepth = sTermMaxDepth; 
    324  
     362void BspTree::InitTree(int maxPolygons, int maxDepth) 
     363{ 
     364        mTermMaxPolygons = maxPolygons; 
     365        mTermMaxDepth = maxDepth; 
    325366        mStat.nodes = 1; 
    326  
    327         // insert all viewcells 
    328         ViewCellContainer::const_iterator it; 
    329  
    330         for (it = viewCells.begin(); it != viewCells.end(); ++ it) 
    331         { 
    332                 InsertViewCell(*it); 
    333         } 
    334 } 
     367        mBox.Initialize();      // initialise bsp tree bounding box 
     368} 
     369 
     370 
    335371 
    336372void BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys) 
     
    346382} 
    347383 
    348 void BspTree::Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 
    349 { 
    350         ObjectContainer::const_iterator it, it_end = objects.end(); 
    351  
    352         int limit = (maxObjects > 0) ? Min((int)objects.size(), maxObjects) : (int)objects.size(); 
    353          
    354         // initialise bounding box 
    355         mBox.Initialize(); 
     384void BspTree::Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 
     385{ 
     386        int limit = (maxObjects > 0) ? Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 
    356387   
    357388        for (int i = 0; i < limit; ++i) 
    358389        { 
     390                if (viewCells[i]->GetMesh()) // copy the mesh data to polygons 
     391                { 
     392                        mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 
     393                        AddMesh2Polygons(viewCells[i]->GetMesh(), polys); 
     394                } 
     395        } 
     396} 
     397 
     398void BspTree::Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 
     399{ 
     400        int limit = (maxObjects > 0) ? Min((int)objects.size(), maxObjects) : (int)objects.size(); 
     401   
     402        for (int i = 0; i < limit; ++i) 
     403        { 
    359404                Intersectable *object = objects[i];//*it; 
    360405                Mesh *mesh = NULL; 
    361406 
    362                 // extract the meshes 
    363                 switch (object->Type()) 
     407                switch (object->Type()) // extract the meshes 
    364408                { 
    365409                case Intersectable::MESH_INSTANCE: 
     
    376420        if (mesh) // copy the mesh data to polygons 
    377421                { 
    378                         mBox.Include(object->GetBox()); // also add to BSP root box 
     422                        mBox.Include(object->GetBox()); // add to BSP tree aabb 
    379423                        AddMesh2Polygons(mesh, polys); 
    380424                } 
    381425        } 
    382426 
    383         Debug << "Number of polygons: " << polys.size() << ", BSP root box: " << mBox << endl; 
    384 } 
    385  
    386 void BspTree::Construct(const ObjectContainer &objects) 
    387 { 
     427        Debug << "Number of polygons: " << (int)polys.size() << ", BSP root box: " << mBox << endl; 
     428} 
     429 
     430void BspTree::Construct(const ViewCellContainer &viewCells) 
     431{ 
     432        //-- Construct tree using the given viewcells 
     433         
     434        /* for this type of construction we filter all viewcells down the  
     435         * tree until there is no polygon left. The split of the last polygon  
     436         * decides inside or outside of the viewcell. 
     437    */ 
     438        const int maxPolygons = 0; 
     439        const int maxDepth = 99999; 
     440        InitTree(maxPolygons, maxDepth); 
     441         
     442 
     443        // tree is completely constructed before  
     444        // view cells are not inserted one after another => better tree behaviour 
     445        if (!mIsIncremential) 
     446        { 
     447                // copy view cell meshes into one big polygon soup 
     448                PolygonContainer *polys = new PolygonContainer(); 
     449                Copy2PolygonSoup(viewCells, *polys, sMaxCandidates); 
     450 
     451                // construct tree from viewcell polygons 
     452                Construct(polys); 
     453        } 
     454 
     455        // insert all viewcells 
     456        ViewCellContainer::const_iterator it; 
     457 
     458        for (it = viewCells.begin(); it != viewCells.end(); ++ it) 
     459        { 
     460                InsertViewCell(*it); 
     461        } 
     462} 
     463 
     464 
     465ViewCellContainer *BspTree::Construct(const ObjectContainer &objects) 
     466{ 
     467#ifdef _DEBUG 
    388468        Debug << "Constructing tree using object container\n"; 
    389  
    390         mTermMaxPolygons = sTermMaxPolygons; 
    391         mTermMaxDepth = sTermMaxDepth; 
    392  
    393         mStat.nodes = 1; 
    394  
     469#endif 
     470        // take termination criteria from globals 
     471        InitTree(mTermMaxPolygons, mTermMaxDepth); 
     472 
     473        PolygonContainer *polys = new PolygonContainer(); 
     474         
     475        // copy mesh instance polygons into one big polygon soup 
     476        Copy2PolygonSoup(objects, *polys, sMaxCandidates); 
     477 
     478        // construct tree from polygon soup 
     479        Construct(polys); 
     480 
     481        return NULL;// TODO 
     482} 
     483 
     484ViewCellContainer *BspTree::Construct(const RayContainer &rays) 
     485{ 
     486        // TODO 
     487        return NULL; 
     488} 
     489 
     490void BspTree::Construct(PolygonContainer *polys) 
     491{ 
    395492        std::stack<BspTraversalData> tStack; 
    396         PolygonContainer *polys = new PolygonContainer(); 
    397          
    398         // copy mesh instance polygons into one big polygon soup 
    399         Copy2PolygonSoup(objects, *polys, 100); 
    400  
    401         BspTraversalData tData(new BspLeaf(), mRoot->GetParent(), polys, 0); // new root corresponding to unbounded space 
     493        // new root corresponding to unbounded space 
     494        BspTraversalData tData(new BspLeaf(), mRoot->GetParent(), polys, 0); 
    402495 
    403496        tStack.push(tData); 
     
    411504                BspNode *root = Subdivide(tStack, tData); 
    412505 
    413                 if (!mRoot) 
     506                if (!mRoot) // empty tree => new root 
    414507                        mRoot = root; 
    415508        } 
    416509} 
    417510 
    418 BspNode * BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell) 
     511 
     512BspNode * BspTree::Subdivide(BspTraversalStack &tStack,  
     513                                                         BspTraversalData &tData,  
     514                                                         ViewCell *viewCell) 
    419515{ 
    420516        PolygonContainer *backPolys = new PolygonContainer(); 
     
    425521                                                                  tData.mPolygons, 
    426522                                                                  tData.mDepth, 
    427                                                                   viewCell, 
    428523                                                                  frontPolys, 
    429524                                                                  backPolys); 
     
    440535        { 
    441536                EvaluateLeafStats(tData); 
    442                 // don't need to store polygon information => delete polygons 
    443                 Polygon3::DeletePolygons(tData.mPolygons); 
    444         } 
    445  
     537 
     538                // add view cell if in positive halfspace 
     539                if (!tData.mParent || (node == tData.mParent->GetFront())) 
     540                        dynamic_cast<BspLeaf *>(node)->SetViewCell(viewCell); 
     541        } 
     542 
     543        return node; 
     544} 
     545 
     546BspNode *BspTree::SubdivideNode(BspLeaf *leaf,  
     547                                                                BspInterior *parent,  
     548                                                                PolygonContainer *polys,  
     549                                                                const int depth,  
     550                                                                PolygonContainer *frontPolys,  
     551                                                                PolygonContainer *backPolys) 
     552{ 
     553        // terminate traversal 
     554        if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 
     555        { 
     556                // add or delete remaining polygons 
     557                if (mStorePolys) 
     558                        leaf->AddPolygons(polys); 
     559                else 
     560                        Polygon3::DeletePolygons(polys); 
     561 
     562                delete polys; 
     563 
     564                return leaf; 
     565        } 
     566 
     567         mStat.nodes += 2; 
     568 
     569        // add the new nodes to the tree + select subdivision plane 
     570        BspInterior *node = new BspInterior(SelectPlane(polys));  
     571 
     572#ifdef _DEBUG 
     573        Debug << node << endl; 
     574#endif 
     575        // split polygon according to current plane 
     576        int splits = 0; 
     577                 
     578        node->SplitPolygons(polys, frontPolys, backPolys, splits, mStorePolys); 
     579         
     580        mStat.splits += splits; 
     581 
     582        // two new leaves 
     583        BspLeaf *back = new BspLeaf(); 
     584        BspLeaf *front = new BspLeaf(); 
     585 
     586        // replace a link from node's parent 
     587        if (parent) 
     588        { 
     589                parent->ReplaceChildLink(leaf, node); 
     590        } 
     591 
     592        // and setup child links 
     593        node->SetupChildLinks(back, front); 
     594 
     595        delete leaf; // leaf not member of tree anymore 
     596         
    446597        return node; 
    447598} 
     
    455606        } 
    456607         
     608        // use heuristics to find appropriate plane 
    457609        return SelectPlaneHeuristics(polygons, sMaxCandidates); 
    458610} 
     
    511663int BspTree::EvalForBalancedTree(const int classification) 
    512664{ 
     665        // there should be roughly the same number of front and back polygons 
    513666        if (classification == Polygon3::FRONT_SIDE) 
    514667                return 1; 
     
    527680} 
    528681 
    529 BspNode *BspTree::SubdivideNode(BspLeaf *leaf,  
    530                                                                 BspInterior *parent,  
    531                                                                 PolygonContainer *polys,  
    532                                                                 const int depth,  
    533                                                                 ViewCell *viewCell, 
    534                                                                 PolygonContainer *frontPolys,  
    535                                                                 PolygonContainer *backPolys) 
    536 { 
    537         // terminate traversal 
    538         if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 
    539         { 
    540                 return leaf; 
    541         } 
    542  
    543          mStat.nodes += 2; 
    544  
    545         // add the new nodes to the tree + select subdivision plane 
    546         BspInterior *node = new BspInterior(SelectPlane(polys));  
    547  
    548 #ifdef _DEBUG 
    549         Debug << node << endl; 
    550 #endif 
    551         // split polygon according to current plane 
    552         int splits = 0; 
    553         int polySize = polys->size(); 
    554          
    555         node->SplitPolygons(polys, frontPolys, backPolys, splits); 
    556          
    557         mStat.splits += splits; 
    558  
    559         // two new leaves 
    560         BspLeaf *back = new BspLeaf(); 
    561         BspLeaf *front = new BspLeaf(viewCell); 
    562  
    563         // replace a link from node's parent 
    564         if (parent) 
    565         { 
    566                 parent->ReplaceChildLink(leaf, node); 
    567         } 
    568  
    569         // and setup child links 
    570         node->SetupChildLinks(back, front); 
    571  
    572         DEL_PTR(leaf); // leaf not member of tree anymore 
    573  
    574         return node; 
    575 } 
    576682 
    577683void BspTree::ParseEnvironment() 
     
    648754                        if (!viewcell->Mailed())  
    649755                        { 
    650                                 viewcell->Mail(); 
     756                                viewcell->Mail(); // what does mail mean? 
    651757                                         
    652758                                // add this node to pvs of all nodes it can see 
     
    686792} 
    687793 
     794bool BspTree::StorePolys() const 
     795{ 
     796        return mStorePolys; 
     797} 
    688798void BspTree::EvaluateLeafStats(const BspTraversalData &data) 
    689799{ 
     
    696806        } 
    697807 
    698         // record maximal depth 
     808        // store maximal depth 
    699809        if (data.mDepth > mStat.maxDepth) 
    700810                mStat.maxDepth = data.mDepth; 
     
    732842        BspNode *farChild; 
    733843         
    734         float position; 
    735          
    736         while (1) // endless loop 
     844        while (1) 
    737845        { 
    738846                if (!node->IsLeaf())  
     
    781889                        // find intersection with plane between ray origin and exit point 
    782890                        extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 
     891 
    783892                } else // compute intersections with objects in leaf 
    784893                { 
     
    816925                        tStack.pop(); 
    817926                } 
    818  
    819                 return hits; 
    820         } 
     927        } 
     928 
     929        return hits; 
    821930} 
    822931 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r242 r260  
    1313class Polygon3; 
    1414class AxisAlignedBox3; 
    15  
     15class Ray; 
    1616 
    1717//namespace GtpVisibilityPreprocessor { 
     
    1919/** Container storing a soup of polygons used during BSP tree construction 
    2020*/ 
    21 typedef std::vector<Polygon3 *> PolygonContainer; 
     21typedef vector<Polygon3 *> PolygonContainer; 
     22typedef vector<Ray *> RayContainer; 
    2223 
    2324struct BspRayTraversalData  
     
    125126        void SetParent(BspInterior *parent); 
    126127 
     128        PolygonContainer *GetPolygons(); 
     129 
    127130protected: 
    128131 
    129132        /// parent of this node 
    130133        BspInterior *mParent; 
     134 
     135        PolygonContainer mPolygons; 
    131136}; 
    132137 
     
    158163        */ 
    159164        void SplitPolygons(PolygonContainer *polys, PolygonContainer *frontPolys,  
    160                                            PolygonContainer *backPolys, int &splits); 
     165                                           PolygonContainer *backPolys, int &splits, bool storePolys = false); 
    161166 
    162167        friend ostream &operator<<(ostream &s, const BspInterior &A) 
     
    180185class BspLeaf : public BspNode  
    181186{ 
     187        friend BspTree; 
     188 
    182189public: 
    183190        BspLeaf(ViewCell *viewCell = NULL); 
    184191 
    185         /** @return true since it is an interior node */ 
     192        /** @return true since it is an interior node  
     193        */ 
    186194        bool IsLeaf() const; 
     195        /** Returns pointer from view cell. 
     196        */ 
    187197        ViewCell *GetViewCell(); 
     198        /** Sets pointer to view cell. 
     199        */ 
     200        void SetViewCell(ViewCell *viewCell); 
    188201 
    189202protected: 
     203 
     204        /** Helper function used to add remaining polygons to leaf. 
     205        */ 
     206        void AddPolygons(PolygonContainer *polys); 
    190207 
    191208        /// polygonal representation of this viewcell 
     
    222239 
    223240        /// BSP tree construction type 
    224         enum {VIEWCELLS, SCENE_GEOMETRY}; 
     241        enum {VIEWCELLS, SCENE_GEOMETRY, RAYS}; 
    225242 
    226243        /** Default constructor creating an empty tree. 
     
    232249        const BspTreeStatistics &GetStatistics() const;  
    233250   
    234         /** Constructs tree using the given list of viewcells. 
    235             A pointer to the appropriate viewcell is stored within each leaf.  
     251        /** Constructs tree using the given list of view cells. 
     252            A pointer to the appropriate view cell is stored within each leaf.  
    236253                Many leafs can point to the same viewcell. 
    237254        */ 
    238255        void Construct(const ViewCellContainer &viewCells); 
    239         /** Constructs tree using the given list of objects. Each leaf is taken as viewcell. 
    240             No objects are treated as viewcells explicitly. 
     256 
     257        /** Constructs tree using the given list of objects.  
     258            Note that the objects are not taken as view cells, but the view cells are 
     259                constructed from the subdivision: Each leaf is taken as one viewcell; 
    241260 
    242261                @param objects list of objects 
    243         */ 
    244         void Construct(const ObjectContainer &objects); 
     262                @returns list of view cells. 
     263        */ 
     264        ViewCellContainer *Construct(const ObjectContainer &objects); 
     265 
     266        /** Constructs tree using the given number of rays 
     267            @param objects list of objects 
     268                @returns list of view cells. 
     269        */ 
     270        ViewCellContainer *Construct(const RayContainer &rays); 
    245271 
    246272        int CollectLeafPvs(); 
     
    255281        */ 
    256282        BspNode *GetRoot() const; 
     283 
     284        /** If the view cell polygons are stored in the nodes. 
     285        */ 
     286        bool StorePolys() const; 
    257287 
    258288protected: 
    259289         
     290        /** Initialises BSP tree. 
     291                @param maxPolygons the maximal polygon count before termination of  
     292                subdivision 
     293                @param maxDepth the maximal depth before termination of  
     294                subdivision 
     295        */ 
     296        void InitTree(int maxPolygons, int maxDepth); 
     297 
     298        /** Constructs the tree from the given list of polygons. 
     299        */ 
     300        void Construct(PolygonContainer *polys); 
     301 
    260302        /** Evaluates plane classification with respect to the plane's  
    261303                contribution for a balanced tree. 
     
    301343                @param backPolys the polygons of the back child node as a result from splitting 
    302344        */ 
    303         BspNode *SubdivideNode(BspLeaf *leaf, BspInterior *parent,  
    304                                                         PolygonContainer *polys, const int depth,  
    305                                                         ViewCell *viewCell, 
    306                                                         PolygonContainer *frontPolys, PolygonContainer *backPolys); 
     345        BspNode *SubdivideNode(BspLeaf *leaf,  
     346                                                   BspInterior *parent,  
     347                                                   PolygonContainer *polys,  
     348                                                   const int depth,  
     349                                                   PolygonContainer *frontPolys,  
     350                                                   PolygonContainer *backPolys); 
    307351 
    308352        /** Filters polygons down the tree. 
     
    321365        Plane3 SelectPlaneHeuristics(PolygonContainer *polygons, int maxTests) const; 
    322366 
    323         /** Extracts the meshes of the objects and copies them into the mesh. Also calculcates the bounding box of the tree. 
     367        /** Extracts the meshes of the objects and copies them into the mesh.  
     368                Adds object aabb to the aabb of the tree. 
    324369                @param maxPolys the maximal number of objects to be stored as polygons 
    325370        */ 
    326371        void Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects); 
     372        /** Extracts the meshes of the view cells and copies them into the mesh.  
     373                Adds view cell aabb to the aabb of the tree. 
     374                @param maxPolys the maximal number of objects to be stored as polygons 
     375        */ 
     376        void Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects); 
    327377 
    328378        /** Add this mesh as polygons to polygon container. 
     
    353403        /// box around the whole view domain 
    354404        AxisAlignedBox3 mBox; 
     405 
     406                /// if view cell calculation is incremential 
     407        bool mIsIncremential; 
     408 
     409        /// if polygons should be stored in the tree 
     410        bool mStorePolys; 
    355411 
    356412public: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r242 r260  
    77#include "ViewCellBsp.h" 
    88#include "ViewCell.h" 
    9 #include "Polygon3.h"; 
     9#include "Polygon3.h" 
    1010 
    1111 
     
    296296        Mesh *mesh = new Mesh; 
    297297 
    298         AxisAlignedBox3 box = tree.GetBoundingBox(); 
    299         ExportBox(box); 
    300  
    301         while (!tStack.empty())  
     298        //AxisAlignedBox3 box = tree.GetBoundingBox(); 
     299        //ExportBox(box); 
     300          
     301        while (!tStack.empty())  
    302302        { 
    303303                BspNode *node = tStack.top(); 
     
    305305                tStack.pop(); 
    306306         
     307                if (tree.StorePolys()) // extract the polygons 
     308                { 
     309                        PolygonContainer::const_iterator it; 
     310                        PolygonContainer::const_iterator it_end = node->GetPolygons()->end(); 
     311 
     312                        for (it = node->GetPolygons()->begin(); it != it_end; ++ it) 
     313                                ExportPolygon(*it); 
     314                } 
     315 
    307316                if (!node->IsLeaf())  
    308317                { 
     
    311320                        tStack.push(interior->GetFront()); 
    312321                        tStack.push(interior->GetBack()); 
     322 
    313323                } 
    314324                else 
    315325                { 
    316326                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
    317                         // NOTE: could also export polygons to see if splits work 
    318                         if (leaf->GetViewCell()) 
     327                        // export view cell geometry 
     328                        if (!tree.StorePolys() && leaf->GetViewCell()) 
    319329                                ExportViewCell(leaf->GetViewCell()); 
    320330                } 
    321331  } 
    322332   
    323   ExportMesh(mesh); 
    324   delete mesh; 
    325333  return true; 
    326334} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r242 r260  
    4747   
    4848  virtual void  
    49         ExportPolygon(Polygon3 *poly); 
     49  ExportPolygon(Polygon3 *poly); 
    5050 
    5151  virtual bool 
     
    6161  ExportMesh(Mesh *mesh); 
    6262 
    63   virtual void ExportViewCell(ViewCell *viewCell); 
     63  virtual void  
     64  ExportViewCell(ViewCell *viewCell); 
    6465 
    6566protected: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp

    r182 r260  
    374374 
    375375 
     376 
     377/*********************************************************** 
     378 *         class X3dViewCellsParser implemenation          * 
     379 ***********************************************************/ 
     380 
     381 
     382// --------------------------------------------------------------------------- 
     383//  StdInParseHandlers: Constructors and Destructor 
     384// --------------------------------------------------------------------------- 
     385X3dViewCellsParser::X3dViewCellsParser(ViewCellContainer *viewCells) : 
     386  mElementCount(0) 
     387  , mAttrCount(0) 
     388  , mCharacterCount(0) 
     389  , mSpaceCount(0) 
     390  , mViewCells(viewCells) 
     391{ 
     392} 
     393 
     394X3dViewCellsParser::~X3dViewCellsParser() 
     395{ 
     396} 
     397 
     398 
     399// --------------------------------------------------------------------------- 
     400//  StdInParseHandlers: Implementation of the SAX DocumentHandler interface 
     401// --------------------------------------------------------------------------- 
     402void X3dViewCellsParser::endElement(const XMLCh* const name) 
     403{ 
     404  StrX lname(name); 
     405  string element(lname.LocalForm()); 
     406  if (element == "Shape") 
     407    EndShape(); 
     408} 
     409 
     410void 
     411X3dViewCellsParser::EndShape() 
     412{ 
     413} 
     414 
     415void 
     416X3dViewCellsParser::StartIndexedFaceSet( 
     417                                      AttributeList&  attributes) 
     418{ 
     419        int len = attributes.getLength(); 
     420        int i; 
     421        VertexIndexContainer vertices; 
     422 
     423        for (i=0; i < len; i++)  
     424        { 
     425                string attrName(StrX(attributes.getName(i)).LocalForm()); 
     426             
     427                if (attrName == "coordIndex")  
     428                { 
     429                        StrX attrValue(attributes.getValue(i)); 
     430                         
     431                        // handle coordIndex 
     432                        vertices.clear(); 
     433                        const char *ptr = attrValue.LocalForm(); 
     434                        char *endptr; 
     435                 
     436                        while(1) 
     437                        { 
     438                                int index = strtol(ptr, &endptr, 10); 
     439                                 
     440                                if (ptr == endptr || index == -1)  
     441                                { 
     442                                        if (vertices.size() > 2)  
     443                                        { 
     444                                                // the base of all view cells is a triangle. 
     445                                                Face *face = new Face(vertices); 
     446                                                 
     447                                                mViewCells->push_back(ViewCell::Convert2ViewCell(face));                                                 
     448                                        } 
     449                                        vertices.clear(); 
     450                                         
     451                                        if (ptr == endptr) 
     452                                                break; 
     453                                }  
     454                                else  
     455                                { 
     456                                        vertices.push_back(index); 
     457                                } 
     458                     
     459                                ptr = endptr; 
     460                        } 
     461                } 
     462        } 
     463} 
     464 
     465 
     466void 
     467X3dViewCellsParser::StartCoordinate( 
     468                                  AttributeList&  attributes) 
     469{ 
     470        int len = attributes.getLength(); 
     471         
     472        VertexContainer vertices; 
     473 
     474        for (int i=0; i < len; i++)  
     475        { 
     476                string attrName(StrX(attributes.getName(i)).LocalForm()); 
     477                 
     478                if (attrName == "point")  
     479                { 
     480                        StrX attrValue(attributes.getValue(i)); 
     481                         
     482                        const char *ptr = attrValue.LocalForm(); 
     483                         
     484                        char *endptr; 
     485                         
     486                        while (1)  
     487                        { 
     488                                float x = strtod(ptr, &endptr); 
     489                 
     490                                if (ptr == endptr) 
     491                                        break; 
     492                                ptr = endptr; 
     493                                 
     494                                float y = strtod(ptr, &endptr); 
     495 
     496                                 
     497                                if (ptr == endptr) 
     498                                        break; 
     499                                ptr = endptr; 
     500 
     501                                float z = strtod(ptr, &endptr); 
     502 
     503                                if (ptr == endptr) 
     504                                        break; 
     505 
     506                                ptr = endptr; 
     507                                if (*ptr == ',') 
     508                                        ptr++; 
     509 
     510                                Vector3 v(x, y, z); 
     511                                vertices.push_back(v); 
     512                        } 
     513                        mCurrentMesh->mVertices = vertices; 
     514                } 
     515        } 
     516} 
     517 
     518 
     519void 
     520X3dViewCellsParser::startElement(const XMLCh* const name, 
     521                               AttributeList&  attributes) 
     522{ 
     523  StrX lname(name); 
     524  string element(lname.LocalForm()); 
     525   
     526  if (element == "IndexedFaceSet") { 
     527    // create a new mesh node in the scene graph 
     528    StartIndexedFaceSet(attributes); 
     529  } 
     530 
     531  if (element == "Shape") { 
     532    cout<<"+"; 
     533    mCurrentMesh = new Mesh; 
     534  } 
     535   
     536  if (element == "Coordinate") { 
     537    if (mCurrentMesh) 
     538      StartCoordinate(attributes); 
     539  } 
     540   
     541  if (element == "Material") { 
     542    StartMaterial(attributes); 
     543  } 
     544 
     545  mElementCount++; 
     546  mAttrCount += attributes.getLength(); 
     547} 
     548 
     549void 
     550X3dViewCellsParser::characters(const XMLCh* const chars, 
     551                             const unsigned int length) 
     552{ 
     553  mCharacterCount += length; 
     554} 
     555 
     556void 
     557X3dViewCellsParser::ignorableWhitespace(const XMLCh* const chars, 
     558                                      const unsigned int length) 
     559{ 
     560  mSpaceCount += length; 
     561} 
     562 
     563void 
     564X3dViewCellsParser::resetDocument() 
     565{ 
     566  mAttrCount = 0; 
     567  mCharacterCount = 0; 
     568  mElementCount = 0; 
     569  mSpaceCount = 0; 
     570} 
     571 
     572 
     573 
     574// --------------------------------------------------------------------------- 
     575//  StdInParseHandlers: Overrides of the SAX ErrorHandler interface 
     576// --------------------------------------------------------------------------- 
     577void 
     578X3dViewCellsParser::error(const SAXParseException& e) 
     579{ 
     580  XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId()) 
     581                            << ", line " << e.getLineNumber() 
     582                            << ", char " << e.getColumnNumber() 
     583                            << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; 
     584} 
     585 
     586void 
     587X3dViewCellsParser::fatalError(const SAXParseException& e) 
     588{ 
     589  XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId()) 
     590                            << ", line " << e.getLineNumber() 
     591                            << ", char " << e.getColumnNumber() 
     592                            << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; 
     593} 
     594 
     595void 
     596X3dViewCellsParser::warning(const SAXParseException& e) 
     597{ 
     598  XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId()) 
     599                            << ", line " << e.getLineNumber() 
     600                            << ", char " << e.getColumnNumber() 
     601                            << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; 
     602} 
     603 
     604 
     605bool 
     606X3dParser::ParseFile(const string filename, 
     607                     SceneGraphNode **root) 
     608{ 
     609  // Initialize the XML4C system 
     610  try { 
     611    XMLPlatformUtils::Initialize(); 
     612  } 
     613   
     614  catch (const XMLException& toCatch) 
     615    { 
     616      XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" 
     617                                << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; 
     618      return false; 
     619    } 
     620   
     621   
     622  // 
     623  //  Create a SAX parser object. Then, according to what we were told on 
     624  //  the command line, set the options. 
     625  // 
     626  SAXParser* parser = new SAXParser; 
     627  parser->setValidationScheme(valScheme); 
     628  parser->setDoNamespaces(doNamespaces); 
     629  parser->setDoSchema(doSchema); 
     630  parser->setValidationSchemaFullChecking(schemaFullChecking); 
     631   
     632 
     633  // 
     634  //  Create our SAX handler object and install it on the parser, as the 
     635  //  document and error handler. We are responsible for cleaning them 
     636  //  up, but since its just stack based here, there's nothing special 
     637  //  to do. 
     638  // 
     639  *root = new SceneGraphNode; 
     640  X3dViewCellsParser handler(*root); 
     641  parser->setDocumentHandler(&handler); 
     642  parser->setErrorHandler(&handler); 
     643   
     644  unsigned long duration; 
     645  int errorCount = 0; 
     646  // create a faux scope so that 'src' destructor is called before 
     647  // XMLPlatformUtils::Terminate 
     648  { 
     649    // 
     650    //  Kick off the parse and catch any exceptions. Create a standard 
     651    //  input input source and tell the parser to parse from that. 
     652    // 
     653    //    StdInInputSource src; 
     654    try 
     655      { 
     656        const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); 
     657        parser->parse(filename.c_str()); 
     658        const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); 
     659        duration = endMillis - startMillis; 
     660        errorCount = parser->getErrorCount(); 
     661      } 
     662    catch (const OutOfMemoryException&) 
     663      { 
     664        XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; 
     665        errorCount = 2; 
     666        return false; 
     667      } 
     668    catch (const XMLException& e) 
     669      { 
     670        XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n" 
     671                                  << StrX(e.getMessage()) 
     672                                  << "\n" << XERCES_STD_QUALIFIER endl; 
     673        errorCount = 1; 
     674        return false; 
     675      } 
     676 
     677     
     678    // Print out the stats that we collected and time taken 
     679    if (!errorCount) { 
     680      XERCES_STD_QUALIFIER cout << filename << ": " << duration << " ms (" 
     681                                << handler.GetElementCount() << " elems, " 
     682                                << handler.GetAttrCount() << " attrs, " 
     683                                << handler.GetSpaceCount() << " spaces, " 
     684                                << handler.GetCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl; 
     685    } 
     686  } 
     687   
     688  // 
     689  //  Delete the parser itself.  Must be done prior to calling Terminate, below. 
     690  // 
     691  delete parser; 
     692   
     693  XMLPlatformUtils::Terminate(); 
     694   
     695  if (errorCount > 0) 
     696    return false; 
     697  else 
     698    return true; 
     699} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.h

    r170 r260  
    33 
    44#include "Parser.h" 
    5  
     5#include "ViewCells.h" 
    66 
    77class X3dParser : public Parser 
     
    1111   
    1212  bool ParseFile(const string filename, SceneGraphNode **root); 
    13    
     13  bool ParseViewCells(const string filename, ViewCellContainer *viewCells); 
    1414}; 
    1515 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h

    r180 r260  
    105105}; 
    106106 
     107/** Parser handlers for view cell x3d files. 
     108*/ 
     109class X3dViewCellsParseHandlers : public HandlerBase 
     110{ 
     111public: 
     112  // ----------------------------------------------------------------------- 
     113  //  Constructors and Destructor 
     114  // ----------------------------------------------------------------------- 
     115  X3dViewCellsParseHandlers(ViewCellContainer *mViewCells;); 
     116  ~X3dViewCellsParseHandlers(); 
     117   
     118   
     119  // ----------------------------------------------------------------------- 
     120  //  Getter methods 
     121  // ----------------------------------------------------------------------- 
     122  unsigned int GetElementCount() 
     123  { 
     124    return mElementCount; 
     125  } 
     126   
     127  unsigned int GetAttrCount() 
     128  { 
     129    return mAttrCount; 
     130  } 
     131   
     132  unsigned int GetCharacterCount() 
     133  { 
     134    return mCharacterCount; 
     135  } 
     136   
     137  unsigned int GetSpaceCount() 
     138  { 
     139    return mSpaceCount; 
     140  } 
     141 
     142 
     143  // ----------------------------------------------------------------------- 
     144  //  Handlers for the SAX DocumentHandler interface 
     145  // ----------------------------------------------------------------------- 
     146  void endElement(const XMLCh* const name); 
     147  void startElement(const XMLCh* const name, AttributeList& attributes); 
     148  void characters(const XMLCh* const chars, const unsigned int length); 
     149  void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); 
     150  void resetDocument(); 
     151 
     152  ViewCellContainer *mViewCells; 
     153   
     154  // Handlers for X3D 
     155  void 
     156  StartIndexedFaceSet( 
     157                      AttributeList&  attributes); 
     158   
     159  void 
     160  EndShape(); 
     161 
     162  void 
     163  StartCoordinate( 
     164                  AttributeList&  attributes); 
     165 
     166  void 
     167  StartMaterial( 
     168                AttributeList&  attributes); 
     169   
     170   
     171  // ----------------------------------------------------------------------- 
     172  //  Handlers for the SAX ErrorHandler interface 
     173  // ----------------------------------------------------------------------- 
     174  void warning(const SAXParseException& exc); 
     175  void error(const SAXParseException& exc); 
     176  void fatalError(const SAXParseException& exc); 
     177   
     178   
     179private: 
     180  // ----------------------------------------------------------------------- 
     181  //  Private data members 
     182  // 
     183  //  fAttrCount 
     184  //  fCharacterCount 
     185  //  fElementCount 
     186  //  fSpaceCount 
     187  //      These are just counters that are run upwards based on the input 
     188  //      from the document handlers. 
     189  // ----------------------------------------------------------------------- 
     190  unsigned int    mAttrCount; 
     191  unsigned int    mCharacterCount; 
     192  unsigned int    mElementCount; 
     193  unsigned int    mSpaceCount; 
     194}; 
     195 
    107196 
    108197// --------------------------------------------------------------------------- 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r242 r260  
    3131  p->BuildKdTree(); 
    3232  p->KdTreeStatistics(cout); 
     33 
    3334#ifdef TEST_BSP_VIEWCELLS 
     35  environment->GetStringValue("Scene.viewcells", buff); 
     36 
    3437  p->GenerateViewcells(); 
    3538  p->BspTreeStatistics(Debug); 
Note: See TracChangeset for help on using the changeset viewer.