Changeset 289 for trunk/VUT


Ignore:
Timestamp:
09/19/05 03:07:07 (19 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
8 edited

Legend:

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

    r286 r289  
    1414#       filename ../data/soda/soda5.dat 
    1515#       viewcells ../data/atlanta/atlanta_viewcells_large.x3d 
    16 #viewcells ../data/atlanta/atlanta_viewcells_large2.x3d 
    17         viewcells ../data/vienna/viewcells-25-sel.x3d 
    18 #       viewcells ../data/vienna/viewcells-25.x3d 
     16#       viewcells ../data/atlanta/atlanta_viewcells_large2.x3d 
     17#       viewcells ../data/vienna/viewcells-25-sel.x3d 
     18        viewcells ../data/vienna/viewcells-25.x3d 
    1919#       viewcells ../data/vienna/viewcells-large-sel.x3d 
    2020} 
     
    7070        splitPlaneStrategy combined 
    7171#       constructionMethod rays 
    72 #       constructionMethod viewCells 
    73         constructionMethod sceneGeometry 
     72        constructionMethod viewCells 
     73#       constructionMethod sceneGeometry 
    7474        maxCandidates 25 
    7575        maxViewCells 999999 
    7676        Termination { 
    77                 maxPolygons 3 
    78                 maxDepth 30 
     77                maxPolygons 0 
     78                maxDepth 100 
    7979        } 
    8080} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h

    r270 r289  
    4444  { 
    4545    const Vector3 v = b - a; // line from A to B 
    46     float dv = DotProd(mNormal, v); 
     46    float dv = DotProd(v, mNormal); 
    4747     
    4848    if (signum(dv) == 0) 
     
    5050                if (coplanar)  
    5151                        (*coplanar) = true;      
    52                 Debug << "signum is zero" << endl; 
     52         
    5353                return a; 
    5454        } 
     
    6363     
    6464    //return a - Distance(a) * b / dv + Distance(a) * a / dv; // NOTE: gives better precision than calclulating a + u * v 
    65     return a + (u * v); 
     65    return a + u * v; 
    6666  } 
    6767   
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r286 r289  
    66// tolerance value for side relation 
    77#define SIDE_TOLERANCE 0.002f // TODO: Test different values 
     8#define SIDE_TOLERANCE_SQRD 0.000004f 
    89 
    910Polygon3::Polygon3(): mMaterial(NULL), mParent(NULL) 
     
    3839} 
    3940 
    40 void Polygon3::Split(Plane3 *partition, Polygon3 *front, Polygon3 *back, int &splits) 
    41 { 
    42         splits = 0; 
    43         Vector3 ptA = mVertices[mVertices.size() - 1]; 
     41void Polygon3::Split(Plane3 *partition, Polygon3 *front, Polygon3 *back) 
     42{ 
     43        Vector3 ptA = mVertices.back(); 
    4444         
    4545        int sideA = partition->Side(ptA, SIDE_TOLERANCE); 
    4646         
    4747        VertexContainer::const_iterator it; 
     48        bool foundSplit = false; 
     49 
     50        Vector3 prevSplitPt(ptA); 
    4851 
    4952        // find line - plane intersections 
    5053        for (it = mVertices.begin(); it != mVertices.end(); ++ it) 
    5154        { 
    52                 Vector3 ptB = (*it); 
     55                Vector3 ptB = *it; 
    5356                int sideB = partition->Side(ptB, SIDE_TOLERANCE); 
    5457         
     
    6063                                //-- plane - line intersection 
    6164                                Vector3 splitPt = partition->FindIntersection(ptA, ptB); 
    62                          
    63                                 // add vertex to both polygons 
    64                                 front->mVertices.push_back(splitPt); 
    65                                 back->mVertices.push_back(splitPt); 
    66                          
    67                                 ++ splits; 
     65                                Debug << "front split pt " << splitPt << " ptA " << ptA << " ptB " << ptB << " side " << sideB << endl; 
     66                                if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 
     67                                { 
     68                                        // add vertex to both polygons 
     69                                        front->mVertices.push_back(splitPt); 
     70                                        back->mVertices.push_back(splitPt); 
     71 
     72                                        foundSplit = true; 
     73                                        prevSplitPt = splitPt; 
     74                                } 
    6875                        } 
    6976                        front->mVertices.push_back(ptB); 
     
    7582                                //-- plane - line intersection 
    7683                                Vector3 splitPt = partition->FindIntersection(ptA, ptB); 
    77                          
    78                                 // add vertex to both polygons 
    79                                 front->mVertices.push_back(splitPt); 
    80                                 back->mVertices.push_back(splitPt); 
    81  
    82                                 ++ splits; 
     84                        //      if (foundSplit) Debug << "back split pt " << splitPt << " prev " << prevSplitPt << endl; 
     85                                if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 
     86                                { 
     87                                        //Debug << "add back split vertex " << splitPt << endl; 
     88                                        // add vertex to both polygons 
     89                                        front->mVertices.push_back(splitPt); 
     90                                        back->mVertices.push_back(splitPt); 
     91 
     92                                        foundSplit = true; 
     93                                        prevSplitPt = splitPt; 
     94                                }//else Debug << "reject back split vertex " << splitPt << endl;         
    8395                        } 
    8496                        back->mVertices.push_back(ptB); 
     
    120132        { 
    121133                int side = plane.Side(*it, SIDE_TOLERANCE); 
    122                 if (BspTree::displayDebug) Debug << "side: " << side << " " << plane.Distance(*it) << endl; 
     134                //Debug << "side: " << side << " " << plane.Distance(*it) << endl; 
    123135 
    124136                if (side > 0) 
     
    134146                // 3 vertices enough to decide coincident 
    135147                else if (((++ count) >= 3) && !onFrontSide && !onBackSide)  
    136                         return COINCIDENT; 
     148                { 
     149                        // Decide if plane and surface normal are same 
     150                        if (DotProd(plane.mNormal, GetSupportingPlane().mNormal) > 0) 
     151                                return COINCIDENT; 
     152                        else  
     153                                return FRONT_SIDE; 
     154                } 
    137155        } 
    138156 
     
    159177                sum += mVertices[i]; 
    160178         
    161         return sum/i; 
     179        return sum/(float)i; 
    162180} 
    163181 
     
    172190        } 
    173191} 
     192 
     193bool Polygon3::CheckValid() const 
     194{ 
     195        if (mVertices.size() < 3) 
     196                return false; 
     197 
     198        Vector3 vtx = mVertices.back(); 
     199        VertexContainer::const_iterator it, it_end = mVertices.end(); 
     200 
     201        for (it = mVertices.begin(); it != it_end; ++it) 
     202        { 
     203                if (!(SqrDistance(vtx, *it) > SIDE_TOLERANCE_SQRD)) 
     204                { 
     205                        Debug << "Malformed vertices:\n" << *this << endl; 
     206                        return false; 
     207                } 
     208                vtx = *it; 
     209        } 
     210         
     211        return true; 
     212} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r286 r289  
    1515class Intersectable; 
    1616 
    17 /** Class representing a general planar polygon in 3d. 
     17//typedef Vertex3 Vector3; 
     18 
     19/** Class representing a planar convex polygon in 3d. 
    1820*/ 
    1921class Polygon3 
     
    3638                @param front the front polygon 
    3739                @param back the back polygon 
    38                 @param splits number of splits 
    3940        */ 
    40         void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back, int &splits); 
     41        void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back); 
    4142 
    4243        enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; 
     
    5960         */ 
    6061        Vector3 Center() const; 
     62        /** Checks if the polygon is valid, i.e., not degenerated. 
     63                @returns true if polygon is valid. 
     64        */ 
     65        bool CheckValid() const;  
    6166 
    62                  
    6367        /// vertices are connected in counterclockwise order. 
    6468        VertexContainer mVertices; 
     
    7781        VertexContainer::const_iterator it; 
    7882 
    79         s << setprecision(6) << "Polygon:\n"; 
    80          
     83        //s << setprecision(6) << "Polygon:\n"; 
    8184        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it) 
    8285                s << *it << endl; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r286 r289  
    3333const int FACTOR_LEAST_SPLITS = 1; 
    3434 
    35 int counter = 0; 
    36 bool BspTree::displayDebug = false; 
     35//int counter = 0; 
     36//bool BspTree::displayDebug = false; 
    3737/****************************************************************/ 
    3838/*                  class BspNode implementation                */ 
     
    8888        } 
    8989        else CLEAR_CONTAINER(*polys); 
    90  
    91         delete polys; 
    9290} 
    9391 
     
    136134} 
    137135 
    138 void BspInterior::ProcessPolygon(Polygon3 *poly, const bool storePolys) 
     136void BspInterior::ProcessPolygon(Polygon3 **poly, const bool storePolys) 
    139137{ 
    140138        if (storePolys)  
    141                 GetPolygons()->push_back(poly); 
     139                GetPolygons()->push_back(*poly); 
    142140        else 
    143                 delete poly; 
    144 } 
    145  
    146 Polygon3 *BspInterior::SplitPolygons(PolygonContainer *polys,  
    147                                                                         PolygonContainer *frontPolys,  
    148                                                                         PolygonContainer *backPolys,  
    149                                                                         int &splits, bool storePolys) 
     141                DEL_PTR(*poly); 
     142} 
     143 
     144void BspInterior::SplitPolygons(PolygonContainer *polys,  
     145                                                                PolygonContainer *frontPolys,  
     146                                                                PolygonContainer *backPolys,  
     147                                                                PolygonContainer *coincident, 
     148                                                                int &splits,  
     149                                                                bool storePolys) 
    150150{ 
    151151        Polygon3 *splitPoly = NULL; 
    152152#ifdef _Debug 
    153         if (BspTree::displayDebug)Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl; 
     153        Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl; 
    154154#endif 
    155155        while (!polys->empty()) 
     
    158158                polys->pop_back(); 
    159159 
    160                 //if (BspTree::displayDebug) Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 
     160                //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 
    161161 
    162162                // test if split is neccessary 
     
    170170                        case Polygon3::COINCIDENT: 
    171171                                //Debug << "coincident" << endl;         
    172                                 // same surface normal 
    173                                 if (DotProd(mPlane.mNormal, poly->GetSupportingPlane().mNormal) > 0) 
    174                                 { 
    175                                         if (!splitPoly) // store the split polygon if there is none 
    176                                                 splitPoly = poly; 
    177                                         else //  discard it otherwise 
    178                                                 ProcessPolygon(poly, storePolys); 
    179  
    180                                         break; 
    181                                 }                                                        
    182                                  
     172                                coincident->push_back(poly); 
     173                                break;                   
    183174                        case Polygon3::FRONT_SIDE:       
    184175                                //Debug << "front" << endl; 
     
    192183                                front_piece = new Polygon3(poly->mParent); 
    193184                                back_piece = new Polygon3(poly->mParent); 
    194  
     185Debug << "*************\n"; 
     186Debug << "initial poly\n" << *poly << endl; 
    195187                                //-- split polygon 
    196                                 poly->Split(&mPlane, front_piece, back_piece, splits); 
    197  
    198                                 frontPolys->push_back(front_piece); 
    199                                 backPolys->push_back(back_piece); 
    200  
     188                                poly->Split(&mPlane, front_piece, back_piece); 
     189                                ++ splits; 
     190                         
     191                                //Debug << "poly\n" << *poly << "split front piece not valid\n" << *front_piece << endl; 
     192                                //Debug << "poly\n" << *poly << "split back piece not valid\n" << *back_piece << endl; 
     193 
     194                                if (front_piece->CheckValid()) 
     195                                        frontPolys->push_back(front_piece); 
     196                                else 
     197                                        DEL_PTR(front_piece); 
     198                                 
     199                                //if (back_piece->CheckValid()) 
     200                                        backPolys->push_back(back_piece); 
     201                                //else 
     202                                //      DEL_PTR(back_piece); 
     203Debug << "*************\n"; 
    201204#ifdef _DEBUG 
    202205                                Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 
    203206#endif 
    204                                 ProcessPolygon(poly, storePolys); 
     207                                ProcessPolygon(&poly, storePolys); 
    205208                                 
    206209                                break; 
     
    210213                } 
    211214        } 
    212         //if (BspTree::displayDebug) Debug << "inside: " << inside << endl; 
    213          
    214         delete polys; // contains nothing 
    215         return splitPoly; 
     215        //Debug << "inside: " << inside << endl; 
    216216} 
    217217 
     
    357357} 
    358358 
    359  
    360 /*void BspTree::InsertViewCell(ViewCell *viewCell) 
    361 {        
    362         std::stack<BspTraversalData> tStack; 
    363          
     359void BspTree::InsertViewCell(ViewCell *viewCell) 
     360{ 
    364361        PolygonContainer *polys = new PolygonContainer(); 
    365362 
     
    368365        mBox.Include(viewCell->GetBox()); // add to BSP aabb 
    369366 
    370          // traverse tree or create new one 
     367        InsertPolygons(polys); 
     368} 
     369 
     370void BspTree::InsertPolygons(PolygonContainer *polys, ViewCellContainer *viewCells) 
     371{        
     372        std::stack<BspTraversalData> tStack; 
     373                 
     374        // traverse tree or create new one 
    371375        BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 
    372376 
    373         tStack.push(BspTraversalData(firstNode, polys, 0, true)); 
     377        tStack.push(BspTraversalData(firstNode, polys, 0, NULL)); 
    374378 
    375379        while (!tStack.empty()) 
     
    388392                                PolygonContainer *frontPolys = new PolygonContainer(); 
    389393                                PolygonContainer *backPolys = new PolygonContainer(); 
    390                                 Polygon3 *coincident = NULL; 
     394                                PolygonContainer coincident; 
    391395 
    392396                                int splits = 0; 
    393397                 
    394398                                // split viecell polygons with respect to split plane 
    395                                 bool inside = interior->SplitPolygons(tData.mPolygons,  
    396                                                                                                           frontPolys,  
    397                                                                                                           backPolys, 
    398                                                                                                           coincident, 
    399                                                                                                           splits,  
    400                                                                                                           mStorePolys); 
     399                                interior->SplitPolygons(tData.mPolygons,  
     400                                                                                frontPolys,  
     401                                                                                backPolys, 
     402                                                                                &coincident, 
     403                                                                                splits,  
     404                                                                                mStorePolys); 
    401405                                 
     406                                // get view cell associated with the split polygon 
     407                                ViewCell *viewCell = (coincident.size() > 0) ?  
     408                                        dynamic_cast<ViewCell *>(coincident.front()->mParent) : NULL; 
     409                                interior->ProcessPolygons(&coincident, mStorePolys); 
     410 
    402411                                //Debug << "split node on level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl; 
    403412                                mStat.splits += splits; 
     
    405414                                // push the children on the stack 
    406415                                tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, NULL)); 
    407                                 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, coincident)); 
    408                          
     416                                tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, viewCell)); 
    409417                        } 
    410                         else // stop traversal 
    411                         { 
    412                                 DEL_PTR(tData.mPolygons); 
    413                         } 
     418 
     419                        // cleanup 
     420                        DEL_PTR(tData.mPolygons); 
    414421                } 
    415422                else // reached leaf => subdivide current viewcell 
    416423                { 
    417424                        if (tData.mPolygons->size() > 0) 
    418                                 Debug << "WARNING (should not come here): polygon size: " << (int)tData.mPolygons->size() << " inside: " << tData.mIsInside << endl; 
    419  
    420                         BspNode *root = Subdivide(tStack, tData, viewCell);              
     425                                Debug << "Subdividing further: polygon size: " << (int)tData.mPolygons->size() << ", view cell: " << tData.mViewCell << endl; 
     426 
     427                        BspNode *root = Subdivide(tStack, tData, viewCells);             
    421428 
    422429                        if (!mRoot) // tree empty => new root 
     
    424431                } 
    425432        } 
    426 }*/ 
     433} 
    427434 
    428435void BspTree::InitTree(int maxPolygons, int maxDepth) 
     
    448455                poly->mParent = parent; // set parent intersectable 
    449456                polys.push_back(poly); 
    450                 //if (displayDebug)Debug << *poly << endl; 
     457 
     458                if (!poly->CheckValid()) 
     459                        Debug << "Input polygon not valid: " << *poly << endl; 
     460 
    451461                ++ polysNum; 
    452462        } 
     
    504514void BspTree::Construct(const ViewCellContainer &viewCells) 
    505515{ 
    506         //-- Construct tree using the given viewcells 
    507          
    508         /* for this type of construction we filter all viewcells down the  
    509          * tree. If there is no polygon left, the last split plane 
    510          * decides inside or outside of the viewcell. 
    511     */ 
    512516        InitTree(sTermMaxPolygons, sTermMaxDepth); 
    513517 
     
    592596                } 
    593597                //-- add viewcell stored in split polygon 
    594                 else if (tData.mSplitPoly && tData.mSplitPoly->mParent) 
     598                else if (tData.mViewCell) 
    595599                { 
    596600                        if (leaf->GetViewCell()) 
    597601                                Debug << "ERROR: leaf already has view cell " << endl;//leaf->mViewCellIdx << endl; 
    598602 
    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          
    607                 // add or delete remaining polygons 
     603                        //leaf->mViewCellIdx = counter; 
     604                        Debug << "insert view cell" << endl; 
     605 
     606                        leaf->SetViewCell(dynamic_cast<ViewCell *>(tData.mViewCell)); 
     607                } 
     608         
     609                // remaining polygons are discarded or added to node 
    608610                tData.mNode->ProcessPolygons(tData.mPolygons, mStorePolys); 
    609                                  
     611                DEL_PTR(tData.mPolygons); 
     612 
    610613                return tData.mNode; 
    611614        } 
    612615 
    613         // discard the split polygon (not needed if traversal continues) 
    614         if (tData.mSplitPoly) 
    615                 tData.mNode->GetParent()->ProcessPolygon(tData.mSplitPoly, mStorePolys); 
    616  
    617         //-- create new subdivided node 
     616        //-- continue subdivision 
    618617        PolygonContainer *backPolys = new PolygonContainer(); 
    619618        PolygonContainer *frontPolys = new PolygonContainer(); 
    620         Polygon3 *splitPoly = NULL; 
    621          
     619        PolygonContainer coincident; 
     620         
     621        // create new interior node and two leaf nodes 
    622622        BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 
    623623                                                                                  tData.mPolygons, 
    624624                                                                                  frontPolys, 
    625625                                                                                  backPolys,  
    626                                                                                   &splitPoly); 
     626                                                                                  &coincident); 
     627 
     628        if (coincident.size() == 0)  
     629        { 
     630                Debug << "size is zero at depth " << tData.mDepth << ", #back polys: " << (int)backPolys->size() << ", #front polys: " << (int)frontPolys->size() << endl; 
     631                if (frontPolys) Debug << "front poly: " << *frontPolys->back() << endl; 
     632        } 
     633        //Debug << "coincident size: " << coincident.size() << endl; 
     634 
     635        // get view cell associated with the first split polygon 
     636        ViewCell *viewCell = (coincident.size() > 0) ?  
     637                                        dynamic_cast<ViewCell *>(coincident.front()->mParent) : NULL; 
     638        interior->ProcessPolygons(&coincident, mStorePolys); 
    627639 
    628640        // push the children on the stack 
    629         // inside information is only propagated with the back leaf 
     641        // split polygon is only needed in the back leaf 
    630642        tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, NULL)); 
    631         tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, splitPoly)); 
     643        tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, viewCell)); 
     644 
     645        // cleanup 
     646        DEL_PTR(tData.mNode); 
     647        DEL_PTR(tData.mPolygons); 
    632648 
    633649        return interior; 
     
    638654                                                                        PolygonContainer *polys,  
    639655                                                                        PolygonContainer *frontPolys, 
    640                                                                         PolygonContainer *backPolys, Polygon3 **splitPoly) 
     656                                                                        PolygonContainer *backPolys,  
     657                                                                        PolygonContainer *coincident) 
    641658{ 
    642659        mStat.nodes += 2; 
     
    651668        // split polygon according to current plane 
    652669        int splits = 0; 
    653                  
    654         *splitPoly = interior->SplitPolygons(polys, frontPolys, backPolys, splits, mStorePolys); 
     670         
     671        interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStorePolys); 
    655672         
    656673        mStat.splits += splits; 
     
    666683 
    667684        // and setup child links 
    668         //interior->SetupChildLinks(new BspLeaf(interior), new BspLeaf(interior, leaf->mViewCell)); 
    669685        interior->SetupChildLinks(new BspLeaf(interior), new BspLeaf(interior)); 
    670686         
    671         delete leaf; // leaf not member of tree anymore 
    672  
    673687        return interior; 
    674688} 
     
    10381052        { 
    10391053                exporter->ExportBspTree(*this); 
    1040                 delete exporter; 
    1041  
    10421054                return true; 
    10431055        }        
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r286 r289  
    182182                @param frontPolys returns the polygons in the front of the split plane 
    183183                @param backPolys returns the polygons in the back of the split plane 
    184                 @param splits number of splits 
    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); 
     184                @param coincident returns the polygons coincident to the split plane 
     185                @param splits returns the splits number of splits        
     186                @param storePolys if the polygons should be stored in the node 
     187        */ 
     188        void SplitPolygons(PolygonContainer *polys,  
     189                                           PolygonContainer *frontPolys,  
     190                                           PolygonContainer *backPolys,  
     191                                           PolygonContainer *coincident,  
     192                                           int &splits,  
     193                                           bool storePolys = false); 
    192194 
    193195        /** Stores polygon in node or discards them according to storePolys. 
     
    195197                @param storePolys if the polygons should be stored or discarded 
    196198        */ 
    197         void ProcessPolygon(Polygon3 *poly, const bool storePolys); 
     199        void ProcessPolygon(Polygon3 **poly, const bool storePolys); 
    198200 
    199201        friend ostream &operator<<(ostream &s, const BspInterior &A) 
     
    204206protected:       
    205207         
    206  
    207208        /// Splitting plane corresponding to this node 
    208209        Plane3 mPlane; 
     
    258259                /// current depth 
    259260                int mDepth; 
    260                 /// the polygon that drove the split plane computation 
    261                 Polygon3 *mSplitPoly; 
     261                /// the view cell associated with this subdivsion 
     262                ViewCell *mViewCell; 
    262263                /// if the node is an inside or outside node with respect to the parent plane 
    263264                //bool mIsInside; 
    264265                BspTraversalData() {} 
    265266                 
    266                 BspTraversalData(BspNode *node, PolygonContainer *polys, const int depth, Polygon3 *splitPoly):  
    267                 mNode(node), mPolygons(polys), mDepth(depth), mSplitPoly(splitPoly) {} 
     267                BspTraversalData(BspNode *node, PolygonContainer *polys, const int depth, ViewCell *viewCell):  
     268                mNode(node), mPolygons(polys), mDepth(depth), mViewCell(viewCell) {} 
    268269    }; 
    269270 
     
    282283   
    283284        /** Constructs tree using the given list of view cells. 
    284             A pointer to the appropriate view cell is stored within each leaf.  
     285            For this type of construction we filter all view cells down the  
     286                tree. If there is no polygon left, the last split plane 
     287            decides inside or outside of the viewcell. A pointer to the  
     288                appropriate view cell is stored within each leaf.  
    285289                Many leafs can point to the same viewcell. 
    286290        */ 
     
    322326        bool Export(const string filename); 
    323327 
    324 static bool displayDebug; 
     328        //static bool displayDebug; 
    325329protected: 
    326330         
     
    360364        Plane3 SelectPlane(PolygonContainer *polys) const; 
    361365 
    362         /** Filters next viewcell down the tree and inserts it into the appropriate leaves 
     366        /** Filters next view cell down the tree and inserts it into the appropriate leaves 
    363367                (i.e., possibly more than one leaf). 
    364368        */ 
    365         //void InsertViewCell(ViewCell *viewCell); 
    366          
     369        void InsertViewCell(ViewCell *viewCell); 
     370        /** Inserts polygons down the tree. The polygons are filtered until a leaf is reached, 
     371                then further subdivided. 
     372                @param viewCellContainer if not null, a new viewcell is created and stored in the container 
     373        */ 
     374        void InsertPolygons(PolygonContainer *polys, ViewCellContainer *viewCells = NULL); 
     375 
    367376        /** Subdivide leaf. 
    368377                @param leaf the leaf to be subdivided 
    369378                @param polys the input polygons 
    370                 @param frontPolys the polygons of the front child node as a result from splitting 
    371                 @param backPolys the polygons of the back child node as a result from splitting 
    372                 @param splitPoly polygon that is coincident to the split plane, NULL if no such polygon 
     379                @param frontPolys returns the polygons in the front of the split plane 
     380                @param backPolys returns the polygons in the back of the split plane 
     381                @param coincident returns the polygons coincident to the split plane 
    373382                @returns the root of the subdivision 
    374383        */ 
     
    376385                                                           PolygonContainer *polys,  
    377386                                                           PolygonContainer *frontPolys,  
    378                                                            PolygonContainer *backPolys, Polygon3 **splitPoly); 
     387                                                           PolygonContainer *backPolys,  
     388                                                           PolygonContainer *coincident); 
    379389 
    380390        /** Filters polygons down the tree. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r265 r289  
    352352  Mesh *mesh = new Mesh; 
    353353  // add 6 vertices of the box 
    354   int index = mesh->mVertices.size(); 
     354  int index = (int)mesh->mVertices.size(); 
    355355  for (int i=0; i < 8; i++) { 
    356356    Vector3 v; 
     
    397397        ViewCellContainer mFoundViewCells; 
    398398 
    399         while (!tStack.empty())  
    400         { 
    401                 BspNode *node = tStack.top(); 
     399        if (tree.StorePolys()) 
     400        { 
     401                while (!tStack.empty())  
     402                { 
     403            BspNode *node = tStack.top(); 
    402404     
    403                 tStack.pop(); 
    404          
    405                 if (tree.StorePolys()) // extract the polygons 
     405                        tStack.pop(); 
     406         
     407                        if (tree.StorePolys()) // extract the polygons 
     408                        { 
     409                                PolygonContainer::const_iterator it; 
     410                                PolygonContainer::const_iterator it_end = node->GetPolygons()->end(); 
     411 
     412                                for (it = node->GetPolygons()->begin(); it != it_end; ++ it) 
     413                                        ExportPolygon(*it); 
     414                        } 
     415 
     416                        if (!node->IsLeaf())  
     417                        { 
     418                                BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     419       
     420                                tStack.push(interior->GetFront()); 
     421                                tStack.push(interior->GetBack()); 
     422 
     423                        } 
     424                } 
     425        } 
     426        else // export view cells 
     427        { 
     428                while (!tStack.empty())  
    406429                { 
    407                         PolygonContainer::const_iterator it; 
    408                         PolygonContainer::const_iterator it_end = node->GetPolygons()->end(); 
    409  
    410                         for (it = node->GetPolygons()->begin(); it != it_end; ++ it) 
    411                                 ExportPolygon(*it); 
     430            BspNode *node = tStack.top(); 
     431     
     432                        tStack.pop(); 
     433         
     434                        if (node->IsLeaf())  
     435                        { 
     436                                ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
     437                                if (viewCell) 
     438                                        mFoundViewCells.push_back(viewCell); 
     439                        } 
     440                        else 
     441                        { 
     442                                BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     443       
     444                                tStack.push(interior->GetFront()); 
     445                                tStack.push(interior->GetBack()); 
     446                        } 
    412447                } 
    413448 
    414                 if (!node->IsLeaf())  
    415                 { 
    416                         BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    417        
    418                         tStack.push(interior->GetFront()); 
    419                         tStack.push(interior->GetBack()); 
    420  
    421                 } 
    422                 else if (!tree.StorePolys()) 
    423                 { 
    424                         ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
    425                          
    426                         if (viewCell) 
    427                                 mFoundViewCells.push_back(viewCell); 
    428                 } 
    429         } 
    430          
    431         if (!tree.StorePolys()) 
    432         { 
    433                 //move consecutive duplicates past the end; store new end 
     449                Debug << "Number of view cells with dublicates: " << (int)mFoundViewCells.size() << endl; 
     450 
     451        //-- erase dublicates 
     452                sort(mFoundViewCells.begin(), mFoundViewCells.end()); 
    434453                ViewCellContainer::iterator new_end = unique(mFoundViewCells.begin(), mFoundViewCells.end()); 
    435                 // delete all elements past new_end  
    436454                mFoundViewCells.erase(new_end, mFoundViewCells.end()); 
    437455                ExportViewCells(&mFoundViewCells); 
     456 
     457                Debug << "Number of view cells after erasing dublicates: " << (int)mFoundViewCells.size() << endl; 
    438458        } 
    439459 
     
    458478    AxisAlignedBox3 box = tree.GetBox(node); 
    459479    // add 6 vertices of the box 
    460     int index = mesh->mVertices.size(); 
     480    int index = (int)mesh->mVertices.size(); 
    461481    for (int i=0; i < 8; i++) { 
    462482      Vector3 v; 
     
    513533       
    514534      // add 6 vertices of the box 
    515       int index = mesh->mVertices.size(); 
     535      int index = (int)mesh->mVertices.size(); 
    516536      for (int i=0; i < 8; i++) { 
    517537        Vector3 v; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r286 r289  
    4242  { 
    4343          if (vcFilename != "") 
    44           { 
    4544          p->LoadViewCells(vcFilename); 
    46                    
    47                   Exporter *exporter = Exporter::GetExporter("viewcells.x3d"); 
    48                   if (exporter)  
    49                   {       exporter->ExportViewCells(&p->mViewCells); 
    50                           delete exporter;   
    51                   } 
    52           } 
    5345          else 
    5446                  p->GenerateViewCells(); 
     47 
     48          Exporter *exporter = Exporter::GetExporter("viewcells.x3d"); 
     49          if (exporter)  
     50          {      
     51          exporter->ExportViewCells(&p->mViewCells); // export view cells 
     52                  delete exporter; 
     53          } 
     54          Debug << "Viewcells loaded / generated. Number of view cells: " << p->mViewCells.size() << endl; 
    5555  } 
    5656 
    5757  p->BuildBspTree(); 
    5858  p->BspTreeStatistics(Debug); 
    59   Debug << "Number of view cells: " << p->mViewCells.size() << endl; 
    60   p->Export(filename + "-bsptree.x3d", false, false, true); 
     59  p->Export("vc_bsptree.x3d", false, false, true); 
    6160 
    6261#endif 
Note: See TracChangeset for help on using the changeset viewer.