Changeset 276 for trunk/VUT


Ignore:
Timestamp:
09/16/05 08:27:42 (19 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r275 r276  
    147147                                                                PolygonContainer *frontPolys,  
    148148                                                                PolygonContainer *backPolys,  
     149                                                                PolygonContainer *coincident,  
    149150                                                                int &splits, bool storePolys) 
    150151{ 
    151152#ifdef _Debug 
    152         //if (BspTree::displayDebug)Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl; 
     153        if (BspTree::displayDebug)Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl; 
    153154#endif 
    154         bool inside = false; 
    155  
    156155        while (!polys->empty()) 
    157156        { 
     
    170169                { 
    171170                        case Polygon3::COINCIDENT: 
    172  
    173                                 if (!inside) 
    174                                         // same surface normal 
    175                                         inside = (DotProd(mPlane.mNormal, poly->GetSupportingPlane().mNormal) > 0); 
    176                                         //if (BspTree::displayDebug)    Debug << "coincident" << endl; 
    177                                 // discard polygons or saves them in node 
    178                                 ProcessPolygon(poly, storePolys); 
    179                                 break; 
     171                                // same surface normal 
     172                                if (DotProd(mPlane.mNormal, poly->GetSupportingPlane().mNormal) > 0) 
     173                                { 
     174                                        coincident->push_back(poly); 
     175                                        break; 
     176                                } 
     177                                //if (BspTree::displayDebug)    Debug << "coincident" << endl;                           
     178                                 
    180179                        case Polygon3::FRONT_SIDE:       
    181180                                //if (BspTree::displayDebug)Debug << "front" << endl; 
     
    183182                                break; 
    184183                        case Polygon3::BACK_SIDE: 
    185                                 inside = true;  //if (BspTree::displayDebug)Debug << "back" << endl; 
     184                                //if (BspTree::displayDebug)Debug << "back" << endl; 
    186185                                backPolys->push_back(poly); 
    187186                                break; 
    188187                        case Polygon3::SPLIT: 
    189                                 inside = true;                           
    190  
    191                                 front_piece = new Polygon3(); 
    192                                 back_piece = new Polygon3(); 
     188                                front_piece = new Polygon3(poly->GetParent()); 
     189                                back_piece = new Polygon3(poly->GetParent()); 
    193190 
    194191                                //-- split polygon 
     
    201198                                if (BspTree::displayDebug)Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 
    202199#endif 
    203                                 // save or discard polygons 
    204200                                ProcessPolygon(poly, storePolys); 
    205201                                 
     
    213209        // contains nothing 
    214210        delete polys; 
    215  
    216         return inside; 
    217211} 
    218212 
     
    390384                                PolygonContainer *frontPolys = new PolygonContainer(); 
    391385                                PolygonContainer *backPolys = new PolygonContainer(); 
     386                                PolygonContainer *coincident = new PolygonContainer(); 
    392387 
    393388                                int splits = 0; 
     
    396391                                bool inside = interior->SplitPolygons(tData.mPolygons,  
    397392                                                                                                          frontPolys,  
    398                                                                                                           backPolys,  
     393                                                                                                          backPolys, 
     394                                                                                                          coincident, 
    399395                                                                                                          splits,  
    400396                                                                                                          mStorePolys); 
    401  
     397                                 
    402398                                //Debug << "split node on level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl; 
    403399                                mStat.splits += splits; 
    404400 
    405401                                // push the children on the stack 
    406                                 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, false)); 
    407                                 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, inside)); 
     402                                tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1)); 
     403                                tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1)); 
    408404                         
    409405                        } 
     
    578574        std::stack<BspTraversalData> tStack; 
    579575         
    580         BspTraversalData tData(new BspLeaf(), polys, 0, true); 
     576        BspTraversalData tData(new BspLeaf(), polys, 0, true, viewCells); 
    581577 
    582578        tStack.push(tData); 
     
    589585            tStack.pop(); 
    590586 
     587                //TODO 
    591588                ViewCell *viewCell = NULL; 
    592589 
    593         if (viewCells) // generate new view cell in leaf 
     590        /*if (viewCells) // generate new view cell in leaf 
    594591                { 
    595592                        viewCell = new ViewCell(); 
    596593                        viewCells->push_back(viewCell); 
    597                 } 
     594                }*/ 
    598595 
    599596                // subdivide leaf node 
     
    625622 
    626623            // add view cell if inside object)  
    627                 if (viewCell && tData.mIsInside) // || (tData.mGeometry->size() > 0) // or if there is still geometry left  
     624                if (viewCell && tData.mCoincident && (tData.mCoincident->size() > 0))) // || (tData.mGeometry->size() > 0) // or if there is still geometry left  
    628625                { 
    629626                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 
     
    634631                        //leaf->mViewCellIdx = counter; 
    635632                        //Debug << "insert view cell" << endl; 
    636                         leaf->SetViewCell(viewCell); 
     633 
     634                        leaf->SetViewCell(coincident[0]->GetParent()); 
    637635                } 
    638636 
    639637                // add or delete remaining polygons 
    640638                tData.mNode->ProcessPolygons(tData.mPolygons, mStorePolys); 
     639                tData.mNode->ProcessPolygons(tData.coincident, mStorePolys); 
    641640 
    642641                return tData.mNode; 
    643642        } 
     643 
     644        tData.mNode->ProcessPolygons(tData.coincident, mStorePolys); 
    644645 
    645646        //-- create new subdivided node 
    646647        PolygonContainer *backPolys = new PolygonContainer(); 
    647648        PolygonContainer *frontPolys = new PolygonContainer(); 
    648  
    649         bool inside = false; 
    650  
     649        PolygonContainer *coincident = new PolygonContainer(); 
     650         
    651651        BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 
    652652                                                                                  tData.mPolygons, 
    653653                                                                                  frontPolys, 
    654                                                                                   backPolys, inside); 
     654                                                                                  backPolys,  
     655                                                                                  coincident); 
    655656 
    656657        // push the children on the stack 
    657658        // inside information is only propagated with the back leaf 
    658         tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, inside)); 
    659         tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, false)); 
     659        tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, coincident)); 
     660        tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1)); 
    660661 
    661662        return interior; 
     
    665666BspInterior *BspTree::SubdivideNode(BspLeaf *leaf,  
    666667                                                                        PolygonContainer *polys,  
    667                                                                         PolygonContainer *frontPolys,  
     668                                                                        PolygonContainer *frontPolys, 
     669                                                                        PolygonContainer *coincident,  
    668670                                                                        PolygonContainer *backPolys, bool &inside) 
    669671{ 
     
    680682        int splits = 0; 
    681683                 
    682         inside = interior->SplitPolygons(polys, frontPolys, backPolys, splits, mStorePolys); 
     684        inside = interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStorePolys); 
    683685         
    684686        mStat.splits += splits; 
Note: See TracChangeset for help on using the changeset viewer.