Ignore:
Timestamp:
10/11/05 19:25:27 (19 years ago)
Author:
mattausch
Message:

VisibilityInfo?: query sort operators as templates
X3dExporter: Fixed polygon wire frame, bsp splits, and bsp split planes visualization
ViewCellBsp?: Added rays to split criteria (not finished yet)
OgreOctreeSceneManager?: fixed error (mNumOctants instead of mNumOctrees)

File:
1 edited

Legend:

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

    r313 r318  
    149149} 
    150150 
    151 void BspInterior::SplitPolygons(PolygonContainer *polys,  
    152                                                                 PolygonContainer *frontPolys,  
    153                                                                 PolygonContainer *backPolys,  
    154                                                                 PolygonContainer *coincident, 
     151void BspInterior::SplitPolygons(PolygonContainer &polys,  
     152                                                                PolygonContainer &frontPolys,  
     153                                                                PolygonContainer &backPolys,  
     154                                                                PolygonContainer &coincident, 
    155155                                                                int &splits,  
    156156                                                                bool storePolys) 
     
    160160        Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; 
    161161#endif 
    162         while (!polys->empty()) 
    163         { 
    164                 Polygon3 *poly = polys->back(); 
    165                 polys->pop_back(); 
     162        while (!polys.empty()) 
     163        { 
     164                Polygon3 *poly = polys.back(); 
     165                polys.pop_back(); 
    166166 
    167167                //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 
     
    179179                        case Polygon3::COINCIDENT: 
    180180                                //Debug << "coincident" << endl;         
    181                                 coincident->push_back(poly); 
     181                                coincident.push_back(poly); 
    182182                                break;                   
    183183                        case Polygon3::FRONT_SIDE:       
    184184                                //Debug << "front" << endl; 
    185                                 frontPolys->push_back(poly); 
     185                                frontPolys.push_back(poly); 
    186186                                break; 
    187187                        case Polygon3::BACK_SIDE: 
    188188                                //Debug << "back" << endl; 
    189                                 backPolys->push_back(poly); 
     189                                backPolys.push_back(poly); 
    190190                                break; 
    191191                        case Polygon3::SPLIT: 
     
    200200                                // check if polygons still valid  
    201201                                if (front_piece->Valid()) 
    202                                         frontPolys->push_back(front_piece); 
     202                                        frontPolys.push_back(front_piece); 
    203203                                else 
    204204                                        DEL_PTR(front_piece); 
    205205                                 
    206206                                if (back_piece->Valid()) 
    207                                         backPolys->push_back(back_piece); 
     207                                        backPolys.push_back(back_piece); 
    208208                                else                             
    209209                                        DEL_PTR(back_piece); 
     
    402402                 
    403403                                // split viewcell polygons with respect to split plane 
    404                                 interior->SplitPolygons(tData.mPolygons,  
    405                                                                                 frontPolys,  
    406                                                                                 backPolys, 
    407                                                                                 &coincident, 
     404                                interior->SplitPolygons(*tData.mPolygons,  
     405                                                                                *frontPolys,  
     406                                                                                *backPolys, 
     407                                                                                coincident, 
    408408                                                                                splits,  
    409409                                                                                mStoreSplitPolys); 
     
    475475} 
    476476 
    477 int BspTree::Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 
     477int BspTree::AddToPolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 
    478478{ 
    479479        int limit = (maxObjects > 0) ? Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 
     
    491491} 
    492492 
    493 int BspTree::Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 
     493int BspTree::AddToPolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 
    494494{ 
    495495        int limit = (maxObjects > 0) ? Min((int)objects.size(), maxObjects) : (int)objects.size(); 
     
    531531        // copy view cell meshes into one big polygon soup 
    532532        PolygonContainer *polys = new PolygonContainer(); 
    533         mStat.polys = Copy2PolygonSoup(viewCells, *polys); 
     533        mStat.polys = AddToPolygonSoup(viewCells, *polys); 
    534534 
    535535        // construct tree from viewcell polygons 
     
    546546         
    547547        // copy mesh instance polygons into one big polygon soup 
    548         mStat.polys = Copy2PolygonSoup(objects, *polys); 
     548        mStat.polys = AddToPolygonSoup(objects, *polys); 
    549549 
    550550        // construct tree from polygon soup 
     
    607607                leaf->SetViewCell(tData.mViewCell); 
    608608                 
     609                //-- clean up 
     610 
    609611                // remaining polygons are discarded or added to node 
    610612                leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); 
    611613                DEL_PTR(tData.mPolygons); 
     614 
     615        CLEAR_CONTAINER(*tData.mRays); 
     616                DEL_PTR(tData.mRays); 
    612617 
    613618                return leaf; 
     
    621626        // create new interior node and two leaf nodes 
    622627        BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 
    623                                                                                   tData.mPolygons, 
    624                                                                                   frontPolys, 
    625                                                                                   backPolys,  
    626                                                                                   &coincident); 
     628                                                                                  *tData.mPolygons, 
     629                                                                                  *frontPolys, 
     630                                                                                  *backPolys,  
     631                                                                                  coincident, 
     632                                                                                  *tData.mRays); 
    627633 
    628634        ViewCell *frontViewCell = mRootCell; 
     
    648654        interior->ProcessPolygons(&coincident, mStoreSplitPolys); 
    649655 
     656        // split rays 
     657        RayContainer *frontRays = NULL; 
     658        RayContainer *backRays = NULL; 
     659 
     660        if (tData.mRays->size() > 0) 
     661        { 
     662                RayContainer *frontRays = new RayContainer(); 
     663                RayContainer *backRays = new RayContainer(); 
     664 
     665                Plane3 plane; 
     666                SplitRays(plane, *tData.mRays, *frontRays, *backRays); 
     667        } 
     668 
    650669        // push the children on the stack 
    651         tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, backViewCell)); 
    652         tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, frontViewCell)); 
     670        tStack.push(BspTraversalData(interior->GetBack(),  
     671                                                                 backPolys,  
     672                                                                 tData.mDepth + 1,  
     673                                                                 backViewCell,  
     674                                                                 backRays)); 
     675 
     676        tStack.push(BspTraversalData(interior->GetFront(),  
     677                                                                 frontPolys,  
     678                                                                 tData.mDepth + 1,  
     679                                                                 frontViewCell,  
     680                                                                 frontRays)); 
    653681 
    654682        // cleanup 
    655683        DEL_PTR(tData.mNode); 
    656684        DEL_PTR(tData.mPolygons); 
     685        DEL_PTR(tData.mRays); 
    657686 
    658687        return interior; 
     
    684713                        foundFront = true; 
    685714                } 
    686                 //if (foundFront) Debug << "front viewCell: " << *frontViewCell << endl; 
    687                 //if (foundBack) Debug << "back viewCell: " << *backViewCell << endl; 
    688715        } 
    689716} 
    690717 
    691718BspInterior *BspTree::SubdivideNode(BspLeaf *leaf,  
    692                                                                         PolygonContainer *polys,  
    693                                                                         PolygonContainer *frontPolys, 
    694                                                                         PolygonContainer *backPolys,  
    695                                                                         PolygonContainer *coincident) 
     719                                                                        PolygonContainer &polys,  
     720                                                                        PolygonContainer &frontPolys, 
     721                                                                        PolygonContainer &backPolys,  
     722                                                                        PolygonContainer &coincident, 
     723                                                                        const RayContainer &rays) 
    696724{ 
    697725        mStat.nodes += 2; 
    698726 
    699727        // add the new nodes to the tree + select subdivision plane 
    700         BspInterior *interior = new BspInterior(SelectPlane(leaf, *polys));  
     728        BspInterior *interior = new BspInterior(SelectPlane(leaf, polys, rays));  
    701729 
    702730#ifdef _DEBUG 
     
    707735        int splits = 0; 
    708736         
    709         interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStoreSplitPolys); 
     737        interior->SplitPolygons(polys,  
     738                                                        frontPolys,  
     739                                                        backPolys,  
     740                                                        coincident,  
     741                                                        splits,  
     742                                                        mStoreSplitPolys); 
    710743         
    711744        mStat.splits += splits; 
     
    829862} 
    830863 
    831 Plane3 BspTree::SelectPlane(BspLeaf *leaf, PolygonContainer &polys) 
     864Plane3 BspTree::SelectPlane(BspLeaf *leaf,  
     865                                                        PolygonContainer &polys,  
     866                                                        const RayContainer &rays) 
    832867{ 
    833868        if (polys.size() == 0) 
     
    882917 
    883918        // use heuristics to find appropriate plane 
    884         return SelectPlaneHeuristics(polys, sMaxCandidates); 
    885 } 
    886  
    887 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, int maxTests) 
     919        return SelectPlaneHeuristics(polys, rays, sMaxCandidates); 
     920} 
     921 
     922Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, 
     923                                                                          const RayContainer &rays, 
     924                                                                          const int maxTests) 
    888925{ 
    889926        float lowestCost = MAX_FLOAT; 
     
    901938                 
    902939                // evaluate current candidate 
    903                 float candidateCost = EvalSplitPlane(polys, candidatePlane); 
     940                float candidateCost = EvalSplitPlane(polys, candidatePlane, rays); 
    904941                         
    905942                if (candidateCost < lowestCost) 
     
    928965} 
    929966 
    930 float BspTree::EvalSplitPlane(PolygonContainer &polys, const Plane3 &candidatePlane) 
     967float BspTree::EvalSplitPlane(PolygonContainer &polys,  
     968                                                          const Plane3 &candidatePlane,  
     969                                                          const RayContainer &rays) 
    931970{ 
    932971        float val = 0; 
     
    13181357        } 
    13191358} 
     1359 
     1360void BspTree::SplitRays(const Plane3 plane, 
     1361                                                RayContainer &rays,  
     1362                                                RayContainer &frontRays,  
     1363                                                RayContainer &backRays) 
     1364{ 
     1365        while (!rays.empty()) 
     1366        { 
     1367                //TODO 
     1368        } 
     1369} 
    13201370//} // GtpVisibilityPreprocessor 
Note: See TracChangeset for help on using the changeset viewer.