Ignore:
Timestamp:
09/16/05 19:24:10 (19 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
6 edited

Legend:

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

    r275 r286  
    88#       filename glasgow1.x3d 
    99#       filename vienna.x3d 
    10         filename ../data/atlanta/atlanta2.x3d 
     10        filename ../data/vienna/vienna-simple.x3d 
     11#       filename ../data/vienna/viewcells-25-sel.x3d 
     12#       filename ../data/atlanta/atlanta2.x3d 
    1113#       filename ../data/soda/soda.dat 
    1214#       filename ../data/soda/soda5.dat 
    1315#       viewcells ../data/atlanta/atlanta_viewcells_large.x3d 
    1416#viewcells ../data/atlanta/atlanta_viewcells_large2.x3d 
    15 #       viewcells ../data/vienna/viewcells-25-sel.x3d 
    16         viewcells ../data/vienna/viewcells-25.x3d 
     17        viewcells ../data/vienna/viewcells-25-sel.x3d 
     18#       viewcells ../data/vienna/viewcells-25.x3d 
    1719#       viewcells ../data/vienna/viewcells-large-sel.x3d 
    1820} 
     
    6870        splitPlaneStrategy combined 
    6971#       constructionMethod rays 
    70         constructionMethod viewCells 
    71 #       constructionMethod sceneGeometry 
     72#       constructionMethod viewCells 
     73        constructionMethod sceneGeometry 
    7274        maxCandidates 25 
    7375        maxViewCells 999999 
    7476        Termination { 
    75                 maxPolygons 0 
    76                 maxDepth 3000 
     77                maxPolygons 3 
     78                maxDepth 30 
    7779        } 
    7880} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r268 r286  
    22#include "Mesh.h" 
    33#include "ViewCellBsp.h" // TODO: erase this 
     4#include "Intersectable.h" 
     5 
    46// tolerance value for side relation 
    57#define SIDE_TOLERANCE 0.002f // TODO: Test different values 
    68 
    7 Polygon3::Polygon3(): mMaterial(NULL) 
     9Polygon3::Polygon3(): mMaterial(NULL), mParent(NULL) 
    810{} 
    911 
    10 Polygon3::Polygon3(const VertexContainer &vertices): mVertices(vertices), mMaterial(NULL) 
     12Polygon3::Polygon3(const VertexContainer &vertices): mVertices(vertices), mMaterial(NULL), mParent(NULL) 
    1113{} 
    1214 
    13 Polygon3::Polygon3(Face *face, Mesh *parent) 
     15Polygon3::Polygon3(Intersectable *parent): mMaterial(NULL), mParent(parent) 
     16{ 
     17} 
     18Polygon3::Polygon3(Face *face, Mesh *parentMesh) 
    1419{        
    1520        VertexIndexContainer::iterator it = face->mVertexIndices.begin(); 
    1621        for (; it != face->mVertexIndices.end();  ++it) 
    1722        { 
    18                 mVertices.push_back(parent->mVertices[*it]); 
    19                 mMaterial = parent->mMaterial; 
     23                mVertices.push_back(parentMesh->mVertices[*it]); 
     24                mMaterial = parentMesh->mMaterial; 
    2025                 
    21                 //Debug << parent->mVertices[*it] << endl; 
     26                //Debug << parentMesh->mVertices[*it] << endl; 
    2227        } 
    2328} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r270 r286  
    1313class Plane3; 
    1414class Face; 
    15  
     15class Intersectable; 
    1616 
    1717/** Class representing a general planar polygon in 3d. 
     
    2222        Polygon3(); 
    2323        Polygon3(const VertexContainer &vertices); 
     24        Polygon3(Intersectable *parent); 
    2425 
    2526        /** Copies all the vertices of the face. 
    2627        */ 
    27         Polygon3(Face *face, Mesh *parent); 
     28        Polygon3(Face *face, Mesh *parentMesh); 
    2829         
    2930        /** Returns supporting plane of this polygon. 
     
    6566        /// we can also store materials with polygons 
    6667        Material *mMaterial; 
    67  
    68         static int mLeastSplitTable[4]; 
    69         static int mBalancedTreeTable[4]; 
     68         
     69        /// pointer to the intersectable this polygon is derived from 
     70        Intersectable *mParent; 
    7071}; 
    7172 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r276 r286  
    3939/****************************************************************/ 
    4040 
    41 BspNode::BspNode(): mParent(NULL), mPolygons(NULL),mViewCellIdx(0) 
     41BspNode::BspNode(): mParent(NULL), mPolygons(NULL)//,mViewCellIdx(0) 
    4242{} 
    4343 
    44 BspNode::BspNode(BspInterior *parent): mParent(parent), mPolygons(NULL),mViewCellIdx(0) 
     44BspNode::BspNode(BspInterior *parent): mParent(parent), mPolygons(NULL)//,mViewCellIdx(0) 
    4545{} 
    4646 
     
    144144} 
    145145 
    146 bool BspInterior::SplitPolygons(PolygonContainer *polys,  
    147                                                                 PolygonContainer *frontPolys,  
    148                                                                 PolygonContainer *backPolys,  
    149                                                                 PolygonContainer *coincident,  
    150                                                                 int &splits, bool storePolys) 
    151 { 
     146Polygon3 *BspInterior::SplitPolygons(PolygonContainer *polys,  
     147                                                                        PolygonContainer *frontPolys,  
     148                                                                        PolygonContainer *backPolys,  
     149                                                                        int &splits, bool storePolys) 
     150{ 
     151        Polygon3 *splitPoly = NULL; 
    152152#ifdef _Debug 
    153153        if (BspTree::displayDebug)Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl; 
     
    169169                { 
    170170                        case Polygon3::COINCIDENT: 
     171                                //Debug << "coincident" << endl;         
    171172                                // same surface normal 
    172173                                if (DotProd(mPlane.mNormal, poly->GetSupportingPlane().mNormal) > 0) 
    173174                                { 
    174                                         coincident->push_back(poly); 
     175                                        if (!splitPoly) // store the split polygon if there is none 
     176                                                splitPoly = poly; 
     177                                        else //  discard it otherwise 
     178                                                ProcessPolygon(poly, storePolys); 
     179 
    175180                                        break; 
    176                                 } 
    177                                 //if (BspTree::displayDebug)    Debug << "coincident" << endl;                           
     181                                }                                                        
    178182                                 
    179183                        case Polygon3::FRONT_SIDE:       
    180                                 //if (BspTree::displayDebug)Debug << "front" << endl; 
     184                                //Debug << "front" << endl; 
    181185                                frontPolys->push_back(poly); 
    182186                                break; 
    183187                        case Polygon3::BACK_SIDE: 
    184                                 //if (BspTree::displayDebug)Debug << "back" << endl; 
     188                                //Debug << "back" << endl; 
    185189                                backPolys->push_back(poly); 
    186190                                break; 
    187191                        case Polygon3::SPLIT: 
    188                                 front_piece = new Polygon3(poly->GetParent()); 
    189                                 back_piece = new Polygon3(poly->GetParent()); 
     192                                front_piece = new Polygon3(poly->mParent); 
     193                                back_piece = new Polygon3(poly->mParent); 
    190194 
    191195                                //-- split polygon 
     
    196200 
    197201#ifdef _DEBUG 
    198                                 if (BspTree::displayDebug)Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 
     202                                Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 
    199203#endif 
    200204                                ProcessPolygon(poly, storePolys); 
     
    207211        } 
    208212        //if (BspTree::displayDebug) Debug << "inside: " << inside << endl; 
    209         // contains nothing 
    210         delete polys; 
     213         
     214        delete polys; // contains nothing 
     215        return splitPoly; 
    211216} 
    212217 
     
    252257mTermMaxDepth(0),  
    253258mRoot(NULL),  
    254 mIsIncremential(false), 
    255259//mStorePolys(true) 
    256260mStorePolys(false) 
     
    354358 
    355359 
    356 void BspTree::InsertViewCell(ViewCell *viewCell) 
     360/*void BspTree::InsertViewCell(ViewCell *viewCell) 
    357361{        
    358362        std::stack<BspTraversalData> tStack; 
     
    384388                                PolygonContainer *frontPolys = new PolygonContainer(); 
    385389                                PolygonContainer *backPolys = new PolygonContainer(); 
    386                                 PolygonContainer *coincident = new PolygonContainer(); 
     390                                Polygon3 *coincident = NULL; 
    387391 
    388392                                int splits = 0; 
     
    400404 
    401405                                // push the children on the stack 
    402                                 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1)); 
    403                                 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1)); 
     406                                tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, NULL)); 
     407                                tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, coincident)); 
    404408                         
    405409                        } 
     
    420424                } 
    421425        } 
    422 } 
     426}*/ 
    423427 
    424428void BspTree::InitTree(int maxPolygons, int maxDepth) 
     
    433437 
    434438 
    435 int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys) 
     439int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent) 
    436440{ 
    437441        FaceContainer::const_iterator fi; 
     
    442446        { 
    443447                Polygon3 *poly = new Polygon3((*fi), mesh); 
     448                poly->mParent = parent; // set parent intersectable 
    444449                polys.push_back(poly); 
    445450                //if (displayDebug)Debug << *poly << endl; 
    446                 polysNum ++; 
     451                ++ polysNum; 
    447452        } 
    448453        return polysNum; 
     
    458463                { 
    459464                        mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 
    460                         AddMesh2Polygons(viewCells[i]->GetMesh(), polys); 
     465                        AddMesh2Polygons(viewCells[i]->GetMesh(), polys, viewCells[i]); 
    461466                } 
    462467        } 
     
    507512        InitTree(sTermMaxPolygons, sTermMaxDepth); 
    508513 
    509     bool savedStorePolys = mStorePolys; 
    510  
    511         // tree is completely constructed once before  
    512         // view cells are inserted one after another =>  
    513         // global tree optimization possible 
    514         if (!mIsIncremential) // todo: not incremential does not work 
    515         { 
    516                 // copy view cell meshes into one big polygon soup 
    517                 PolygonContainer *polys = new PolygonContainer(); 
    518                 Copy2PolygonSoup(viewCells, *polys); 
    519  
    520                 // polygons are stored only during view cell insertion 
    521                 mStorePolys = false; 
    522  
    523                 // construct tree from viewcell polygons 
    524                 Construct(polys); 
    525                 //Export("bsp.x3d"); 
    526         } 
    527          
    528         //-- insert all viewcells one after another 
    529         ViewCellContainer::const_iterator it; 
    530  
    531         mStorePolys = savedStorePolys; 
    532         mStat.polys = 0; 
    533         mStat.splits = 0; 
    534         mStat.accumDepth = 0; 
    535  
    536         long startTime = GetTime(); 
    537 //displayDebug = true; 
    538         counter = 0; 
    539         Debug << "**** Starting view cell insertion ****" << endl; 
    540         for (it = viewCells.begin(); it != viewCells.end(); ++ it) 
    541         { 
    542                 //if ((counter == 12) || (counter == 14)){ 
    543                 //Debug << "** inserting view cell " << counter << " **" << endl; 
    544                 InsertViewCell(*it); 
    545         //}     counter ++; 
    546         } 
    547  
    548         Debug << "**** Finished view cell insertion ****" << endl; 
    549         Debug << "insertion time: "<< TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     514        // copy view cell meshes into one big polygon soup 
     515        PolygonContainer *polys = new PolygonContainer(); 
     516        Copy2PolygonSoup(viewCells, *polys); 
     517 
     518        // construct tree from viewcell polygons 
     519        Construct(polys); 
     520        //Export("bsp.x3d"); 
    550521} 
    551522 
     
    574545        std::stack<BspTraversalData> tStack; 
    575546         
    576         BspTraversalData tData(new BspLeaf(), polys, 0, true, viewCells); 
     547        BspTraversalData tData(new BspLeaf(), polys, 0, NULL); 
    577548 
    578549        tStack.push(tData); 
     
    585556            tStack.pop(); 
    586557 
    587                 //TODO 
    588                 ViewCell *viewCell = NULL; 
    589  
    590         /*if (viewCells) // generate new view cell in leaf 
    591                 { 
    592                         viewCell = new ViewCell(); 
    593                         viewCells->push_back(viewCell); 
    594                 }*/ 
    595  
    596558                // subdivide leaf node 
    597                 BspNode *root = Subdivide(tStack, tData, viewCell); 
     559                BspNode *root = Subdivide(tStack, tData, viewCells); 
    598560 
    599561                // empty tree => new root corresponding to unbounded space 
     
    608570 
    609571BspNode *BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData,  
    610                                                         ViewCell *viewCell) 
     572                                                        ViewCellContainer *viewCells) 
    611573{ 
    612574        //-- terminate traversal   
    613575        if ((tData.mPolygons->size() <= mTermMaxPolygons) || (tData.mDepth >= mTermMaxDepth)) 
    614                 // if there is another view cell associated with this leaf => subdivide further 
    615                 //&& !(viewCell && tData.mIsInside && dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell()))   
    616576        { 
    617577#ifdef _DEBUG 
    618                 if (displayDebug)Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " << (int)tData.mPolygons->size() << endl; 
     578                Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " << (int)tData.mPolygons->size() << endl; 
    619579#endif 
    620580 
    621581                EvaluateLeafStats(tData); 
    622582 
    623             // add view cell if inside object)  
    624                 if (viewCell && tData.mCoincident && (tData.mCoincident->size() > 0))) // || (tData.mGeometry->size() > 0) // or if there is still geometry left  
    625                 { 
    626                         BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 
    627  
     583                BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 
     584 
     585                //-- new viewcells are generated and added to each leaf 
     586                if (viewCells) 
     587                { 
     588                        ViewCell *viewCell = new ViewCell(); 
     589                        leaf->SetViewCell(viewCell); 
     590                        viewCells->push_back(viewCell); 
     591                        Debug << "creating new viewcell" << endl; 
     592                } 
     593                //-- add viewcell stored in split polygon 
     594                else if (tData.mSplitPoly && tData.mSplitPoly->mParent) 
     595                { 
    628596                        if (leaf->GetViewCell()) 
    629597                                Debug << "ERROR: leaf already has view cell " << endl;//leaf->mViewCellIdx << endl; 
    630598 
    631                         //leaf->mViewCellIdx = counter; 
    632                         //Debug << "insert view cell" << endl; 
    633  
    634                         leaf->SetViewCell(coincident[0]->GetParent()); 
    635                 } 
    636  
     599                        //leaf->mViewCellIdx = counter;Debug << "insert view cell" << endl; 
     600 
     601                        leaf->SetViewCell(dynamic_cast<ViewCell *>(tData.mSplitPoly->mParent)); 
     602 
     603                        // discard split polygon 
     604                        tData.mNode->GetParent()->ProcessPolygon(tData.mSplitPoly, mStorePolys); 
     605                } 
     606         
    637607                // add or delete remaining polygons 
    638608                tData.mNode->ProcessPolygons(tData.mPolygons, mStorePolys); 
    639                 tData.mNode->ProcessPolygons(tData.coincident, mStorePolys); 
    640  
     609                                 
    641610                return tData.mNode; 
    642611        } 
    643612 
    644         tData.mNode->ProcessPolygons(tData.coincident, mStorePolys); 
     613        // discard the split polygon (not needed if traversal continues) 
     614        if (tData.mSplitPoly) 
     615                tData.mNode->GetParent()->ProcessPolygon(tData.mSplitPoly, mStorePolys); 
    645616 
    646617        //-- create new subdivided node 
    647618        PolygonContainer *backPolys = new PolygonContainer(); 
    648619        PolygonContainer *frontPolys = new PolygonContainer(); 
    649         PolygonContainer *coincident = new PolygonContainer(); 
     620        Polygon3 *splitPoly = NULL; 
    650621         
    651622        BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 
     
    653624                                                                                  frontPolys, 
    654625                                                                                  backPolys,  
    655                                                                                   coincident); 
     626                                                                                  &splitPoly); 
    656627 
    657628        // push the children on the stack 
    658629        // inside information is only propagated with the back leaf 
    659         tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, coincident)); 
    660         tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1)); 
     630        tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, NULL)); 
     631        tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, splitPoly)); 
    661632 
    662633        return interior; 
     
    667638                                                                        PolygonContainer *polys,  
    668639                                                                        PolygonContainer *frontPolys, 
    669                                                                         PolygonContainer *coincident,  
    670                                                                         PolygonContainer *backPolys, bool &inside) 
     640                                                                        PolygonContainer *backPolys, Polygon3 **splitPoly) 
    671641{ 
    672642        mStat.nodes += 2; 
     
    682652        int splits = 0; 
    683653                 
    684         inside = interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStorePolys); 
     654        *splitPoly = interior->SplitPolygons(polys, frontPolys, backPolys, splits, mStorePolys); 
    685655         
    686656        mStat.splits += splits; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r271 r286  
    144144        */ 
    145145        PolygonContainer *GetPolygons(); 
    146 int mViewCellIdx; 
     146        /** Stores polygons in node or discards them according to storePolys. 
     147        */ 
     148        void ProcessPolygons(PolygonContainer *polys, const bool storePolys); 
     149 
     150//int mViewCellIdx; 
    147151protected: 
    148  
    149         /** Adds or discards polygons according to storePolys. 
    150         */ 
    151         void ProcessPolygons(PolygonContainer *polys, const bool storePolys); 
    152  
    153152 
    154153        /// parent of this node 
     
    184183                @param backPolys returns the polygons in the back of the split plane 
    185184                @param splits number of splits 
    186                 @returns true if one or more polygons are inside of the split plane 
    187         */ 
    188         bool SplitPolygons(PolygonContainer *polys, PolygonContainer *frontPolys,  
    189                                            PolygonContainer *backPolys, int &splits, bool storePolys = false); 
     185                @returns split polygon if there is a polygon coincident to the split plane, NULL otherwise 
     186        */ 
     187        Polygon3 *SplitPolygons(PolygonContainer *polys,  
     188                                                        PolygonContainer *frontPolys,  
     189                                                    PolygonContainer *backPolys,  
     190                                                        int &splits,  
     191                                                        bool storePolys = false); 
     192 
     193        /** Stores polygon in node or discards them according to storePolys. 
     194                @param polys the polygons 
     195                @param storePolys if the polygons should be stored or discarded 
     196        */ 
     197        void ProcessPolygon(Polygon3 *poly, const bool storePolys); 
    190198 
    191199        friend ostream &operator<<(ostream &s, const BspInterior &A) 
     
    194202        } 
    195203 
    196 protected: 
     204protected:       
    197205         
    198         /** Discards or stores polygon in node. 
    199                 @param polys the polygons 
    200                 @param storePolys if the polygons should be stored or discarded 
    201         */ 
    202         void ProcessPolygon(Polygon3 *poly, const bool storePolys); 
    203206 
    204207        /// Splitting plane corresponding to this node 
     
    255258                /// current depth 
    256259                int mDepth; 
     260                /// the polygon that drove the split plane computation 
     261                Polygon3 *mSplitPoly; 
    257262                /// if the node is an inside or outside node with respect to the parent plane 
    258                 bool mIsInside; 
     263                //bool mIsInside; 
    259264                BspTraversalData() {} 
    260265                 
    261                 BspTraversalData(BspNode *node, PolygonContainer *polys, const int depth, const bool inside):  
    262                 mNode(node), mPolygons(polys), mDepth(depth), mIsInside(inside) {} 
     266                BspTraversalData(BspNode *node, PolygonContainer *polys, const int depth, Polygon3 *splitPoly):  
     267                mNode(node), mPolygons(polys), mDepth(depth), mSplitPoly(splitPoly) {} 
    263268    }; 
    264269 
     
    345350            @param tStack current traversal stack 
    346351                @param tData traversal data also holding node to be subdivided 
    347                 @param viewCell the view cell that will be represented with this part of the Bsp tree. 
     352                @param viewCellContainer if not null, a new viewcell is created and stored in the container 
    348353                @returns new root of the subtree 
    349354        */ 
    350         BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell = NULL); 
     355        BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCellContainer *viewCells = NULL); 
    351356 
    352357        /** Selects a splitting plane.  
     
    358363                (i.e., possibly more than one leaf). 
    359364        */ 
    360         void InsertViewCell(ViewCell *viewCell); 
     365        //void InsertViewCell(ViewCell *viewCell); 
    361366         
    362367        /** Subdivide leaf. 
     
    365370                @param frontPolys the polygons of the front child node as a result from splitting 
    366371                @param backPolys the polygons of the back child node as a result from splitting 
    367                 @param if the polygons are outside or inside with respect to the interior node plane 
     372                @param splitPoly polygon that is coincident to the split plane, NULL if no such polygon 
    368373                @returns the root of the subdivision 
    369374        */ 
     
    371376                                                           PolygonContainer *polys,  
    372377                                                           PolygonContainer *frontPolys,  
    373                                                            PolygonContainer *backPolys, bool &inside); 
     378                                                           PolygonContainer *backPolys, Polygon3 **splitPoly); 
    374379 
    375380        /** Filters polygons down the tree. 
     
    402407 
    403408        /** Extract polygons of this mesh and add to polygon container. 
     409                @param mesh the mesh that drives the polygon construction 
     410                @param parent the parent intersectable this polygon is constructed from 
    404411                @returns number of polygons 
    405412        */ 
    406         int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys); 
     413        int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent = NULL); 
    407414 
    408415        /** A ray is cast possible intersecting the tree. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r275 r286  
    5353          else 
    5454                  p->GenerateViewCells(); 
    55  
    56           Debug << "Number of view cells: " << p->mViewCells.size() << endl; 
    5755  } 
    5856 
    5957  p->BuildBspTree(); 
    6058  p->BspTreeStatistics(Debug); 
     59  Debug << "Number of view cells: " << p->mViewCells.size() << endl; 
    6160  p->Export(filename + "-bsptree.x3d", false, false, true); 
    6261 
Note: See TracChangeset for help on using the changeset viewer.