Ignore:
Timestamp:
11/25/05 22:31:30 (19 years ago)
Author:
mattausch
Message:

detected leak in BspTree?
added specialised fast view cell bsp tree called VspBspTree?

File:
1 edited

Legend:

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

    r436 r437  
    124124                                                           PolygonContainer &coincident) 
    125125{ 
    126         Polygon3 *splitPoly = NULL; 
    127  
    128126        int splits = 0; 
    129127 
     
    140138                // classify polygon 
    141139                const int cf = poly->ClassifyPlane(mPlane); 
    142  
    143                 Polygon3 *front_piece = NULL; 
    144                 Polygon3 *back_piece = NULL; 
    145140 
    146141                switch (cf) 
     
    156151                                break; 
    157152                        case Polygon3::SPLIT: 
    158                                 front_piece = new Polygon3(poly->mParent); 
    159                                 back_piece = new Polygon3(poly->mParent); 
    160  
    161                                 //-- split polygon into front and back part 
    162                                 poly->Split(mPlane,  
    163                                                         *front_piece,  
    164                                                         *back_piece); 
     153                                { 
     154                                        Polygon3 *front_piece = new Polygon3(poly->mParent); 
     155                                        Polygon3 *back_piece = new Polygon3(poly->mParent); 
     156 
     157                                        //-- split polygon into front and back part 
     158                                        poly->Split(mPlane, *front_piece, *back_piece); 
    165159                                         
    166                                 ++ splits; // increase number of splits 
    167  
    168                                 //-- inherit rays from parent polygon for blocked ray criterium 
    169                                 poly->InheritRays(*front_piece, *back_piece); 
    170                                 //Debug << "p: " << poly->mPiercingRays.size() << " f: " << front_piece->mPiercingRays.size() << " b: " << back_piece->mPiercingRays.size() << endl; 
     160                                        ++ splits; // increase number of splits 
     161 
     162                                        //-- inherit rays from parent polygon for blocked ray criterium 
     163                                        poly->InheritRays(*front_piece, *back_piece); 
     164                                        //Debug << "p: " << poly->mPiercingRays.size() << " f: " << front_piece->mPiercingRays.size() << " b: " << back_piece->mPiercingRays.size() << endl; 
    171165                                 
    172                                 // check if polygons still valid  
    173                                 if (front_piece->Valid()) 
    174                                         frontPolys.push_back(front_piece); 
    175                                 else 
    176                                         DEL_PTR(front_piece); 
     166                                        // check if polygons still valid  
     167                                        if (front_piece->Valid()) 
     168                                                frontPolys.push_back(front_piece); 
     169                                        else 
     170                                                DEL_PTR(front_piece); 
    177171                                 
    178                                 if (back_piece->Valid()) 
    179                                         backPolys.push_back(back_piece); 
    180                                 else                             
    181                                         DEL_PTR(back_piece); 
     172                                        if (back_piece->Valid()) 
     173                                                backPolys.push_back(back_piece); 
     174                                        else                             
     175                                                DEL_PTR(back_piece); 
    182176                                 
    183177#ifdef _DEBUG 
    184                                 Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 
     178                                        Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 
    185179#endif 
    186                                 DEL_PTR(poly);                   
     180                                        DEL_PTR(poly); 
     181                                } 
    187182                                break; 
    188183                        default: 
     
    273268mRootCell(viewCell),  
    274269mRoot(NULL),  
    275 mGenerateViewCells(false), 
    276270mStoreLeavesWithRays(false), 
    277 mPvsUseArea(true) 
     271mPvsUseArea(true), 
     272mGenerateViewCells(true) 
    278273{ 
    279274        Randomize(); // initialise random generator for heuristics 
     
    447442        PolygonContainer *polys = new PolygonContainer(); 
    448443 
     444        // don't generate new view cell, insert this one 
     445        mGenerateViewCells = false; 
    449446        // extract polygons that guide the split process 
    450447        mStat.polys += AddMeshToPolygons(viewCell->GetMesh(), *polys, viewCell); 
     
    457454{        
    458455        std::stack<BspTraversalData> tStack; 
    459          
     456 
    460457        // traverse existing tree or create new tree 
    461458    if (!mRoot) 
     
    624621        mStat.polys = AddToPolygonSoup(viewCells, *polys); 
    625622 
     623        // view cells are given 
     624        mGenerateViewCells = false; 
    626625        // construct tree from the view cell polygons 
    627626        Construct(polys, new BoundedRayContainer()); 
     
    635634         
    636635        PolygonContainer *polys = new PolygonContainer(); 
    637          
     636 
     637        mGenerateViewCells = true; 
    638638        // copy mesh instance polygons into one big polygon soup 
    639639        mStat.polys = AddToPolygonSoup(objects, *polys); 
     
    652652 
    653653        RayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     654 
     655        // generate view cells 
     656        mGenerateViewCells = false; 
    654657 
    655658        long startTime = GetTime(); 
     
    726729        PolygonContainer *polys = new PolygonContainer(); 
    727730         
     731        mGenerateViewCells = true; 
     732 
    728733        // copy mesh instance polygons into one big polygon soup 
    729734        mStat.polys = AddToPolygonSoup(objects, *polys); 
     
    844849        PolygonContainer coincident; 
    845850         
    846         PolygonContainer *frontPolys = new PolygonContainer(); 
    847         PolygonContainer *backPolys = new PolygonContainer(); 
    848  
    849         BoundedRayContainer *frontRays = new BoundedRayContainer(); 
    850         BoundedRayContainer *backRays = new BoundedRayContainer(); 
    851          
    852851        BspTraversalData tFrontData(NULL, new PolygonContainer(), tData.mDepth + 1, mRootCell,  
    853852                                                                new BoundedRayContainer(), 0, 0, new BspNodeGeometry()); 
     
    856855 
    857856        // create new interior node and two leaf nodes 
    858         BspInterior *interior = SubdivideNode(tData, 
    859                                                                                   tFrontData, 
    860                                                                                   tBackData, 
    861                                                                                   coincident); 
     857        BspInterior *interior =  
     858                SubdivideNode(tData, tFrontData, tBackData, coincident); 
    862859 
    863860#ifdef _DEBUG    
     
    897894                                                           BspTraversalData &backData,  
    898895                                                           const PolygonContainer &coincident, 
    899                                                            const Plane3 splitPlane) const 
     896                                                           const Plane3 &splitPlane) const 
    900897{ 
    901898        // if not empty, tree is further subdivided => don't have to find view cell 
     
    15341531                         
    15351532                        // add the termination object 
    1536                         AddObjToPvs(ray->intersections[0].mObject, cf, frontPvs, backPvs); 
     1533                        if (!ray->intersections.empty()) 
     1534                                AddObjToPvs(ray->intersections[0].mObject, cf, frontPvs, backPvs); 
    15371535                         
    15381536                        // add the source object 
     
    15921590 
    15931591        const float raysSize = (float)rays.size() + Limits::Small; 
     1592 
    15941593        if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 
    15951594                val += mLeastRaySplitsFactor * sumRaySplits / raysSize; 
     
    16041603 
    16051604                // give penalty to unbalanced split 
    1606                 if (1) 
     1605                if (0) 
    16071606                if (((pFront * 0.2 + Limits::Small) > pBack) || (pFront < (pBack * 0.2 + Limits::Small))) 
    16081607                        val += 0.5; 
     
    16141613                  << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl; 
    16151614#endif 
     1615         
    16161616        return val; 
    16171617} 
     
    20362036} 
    20372037 
    2038 void BspTree::SetGenerateViewCells(int generateViewCells) 
    2039 { 
    2040         mGenerateViewCells = generateViewCells; 
    2041 } 
    20422038 
    20432039BspTreeStatistics &BspTree::GetStat() 
Note: See TracChangeset for help on using the changeset viewer.