Ignore:
Timestamp:
04/26/06 08:11:30 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r810 r822  
    130130        environment->GetFloatValue("VspBspTree.Construction.minBand", mMinBand); 
    131131        environment->GetFloatValue("VspBspTree.Construction.maxBand", mMaxBand); 
     132        environment->GetBoolValue("VspBspTree.Construction.useDrivingAxisForMaxCost", mUseDrivingAxisForMaxCost); 
    132133 
    133134        //-- debug output 
     
    159160        Debug << "priority queue type: " << mNodePriorityQueueType << endl; 
    160161        Debug << "empty view cells merge: " << mEmptyViewCellsMergeAllowed << endl; 
    161         Debug << "octree: " << mCirculatingAxis << endl; 
     162        Debug << "circulating axis: " << mCirculatingAxis << endl; 
    162163        Debug << "minband: " << mMinBand << endl; 
    163164        Debug << "maxband: " << mMaxBand << endl; 
    164          
     165        Debug << "use driving axis for max cost: " << mUseDrivingAxisForMaxCost << endl; 
    165166 
    166167        Debug << "Split plane strategy: "; 
     
    728729                                ++ mBspStats.polySplits; 
    729730 
     731                        // if it was a kd node (i.e., a box) and the split axis is axis aligned, it is still a kd node 
    730732                        tFrontData.mIsKdNode = tBackData.mIsKdNode = (tData.mIsKdNode && (splitAxis < 3)); 
    731733                        tFrontData.mAxis = tBackData.mAxis = splitAxis; 
     
    12191221        const float minBox = box.Min(axis); 
    12201222        const float maxBox = box.Max(axis); 
     1223 
    12211224        const float sizeBox = maxBox - minBox; 
    12221225 
     
    12391242        float minSum = 1e20f; 
    12401243 
     1244         
    12411245        // if no border can be found, take mid split 
    12421246        position = minBox + 0.5f * sizeBox; 
     1247         
     1248        // the relative cost ratio 
     1249        float ratio = /*Limits::Infinity;*/99999999.0; 
     1250        bool splitPlaneFound = false; 
    12431251 
    12441252        Intersectable::NewMail(); 
     
    12821290        vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 
    12831291 
    1284         for (ci = mSplitCandidates->begin(); ci < ci_end; ++ ci) 
     1292        for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci) 
    12851293        { 
    12861294                VssRay *ray; 
     
    13251333                } 
    13261334 
     1335                 
     1336                 
    13271337                // Note: sufficient to compare size of bounding boxes of front and back side? 
    13281338                if (((*ci).value >= minBand) && ((*ci).value <= maxBand)) 
     
    13301340                        sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value); 
    13311341 
    1332                         //cout << "pos=" << (*ci).value << "\t pvs=(" <<  pvsl << "," << pvsr << ")" << endl; 
    1333                         //cout<<"cost= "<<sum<<endl; 
     1342                        //Debug << "pos=" << (*ci).value << "\t pvs=(" <<  pvsl << "," << pvsr << ")" << endl; 
     1343                        //Debug << "cost= " << sum << endl; 
    13341344 
    13351345                        if (sum < minSum) 
    13361346                        { 
     1347                                splitPlaneFound = true; 
     1348 
    13371349                                minSum = sum; 
    13381350                                position = (*ci).value; 
     
    13441356        } 
    13451357         
    1346         Debug << "pos: " << position << " sizebox: " << sizeBox << " pvs: " << pvsSize << endl; 
    1347  
     1358         
    13481359        // -- compute cost 
    13491360        const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 
     
    13621373        const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 
    13631374 
    1364         float ratio = mPvsFactor * newRenderCost / (oldRenderCost + Limits::Small); 
    1365  
    1366         //Debug << "costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox) 
    1367         //     <<"\t q=(" << queriesBack << "," << queriesFront << ")\t r=(" << raysBack << "," << raysFront << ")" << endl; 
     1375        if (splitPlaneFound) 
     1376        { 
     1377                ratio = mPvsFactor * newRenderCost / (oldRenderCost + Limits::Small); 
     1378        } 
     1379        //if (axis != 1) 
     1380        //Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox) 
     1381         //    <<"\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl; 
    13681382 
    13691383        return ratio; 
     
    13881402        BspNodeGeometry *nBackGeom[3]; 
    13891403 
     1404        // set to NULL, so I can find out which gemetry was stored 
    13901405        for (int i = 0; i < 3; ++ i) 
    13911406        { 
     
    13941409        } 
    13951410 
    1396         int bestAxis = -1; 
    1397  
    13981411        // create bounding box of node geometry 
    13991412        AxisAlignedBox3 box; 
     
    14021415        if (1) 
    14031416        { 
     1417                // get bounding box from geometry 
    14041418                tData.mGeometry->GetBoundingBox(box); 
    14051419        } 
     
    14141428 
    14151429        int sAxis = 0; 
     1430        int bestAxis; 
     1431 
     1432        if (mUseDrivingAxisForMaxCost) 
     1433                bestAxis = box.Size().DrivingAxis(); 
     1434        else 
     1435                bestAxis = -1; 
     1436 
     1437        // mximum cost ratio for axis to be valid: 
     1438        // if exceeded, spatial mid split is used instead 
     1439        const float maxCostRatio = 0.9f; 
     1440 
    14161441        // hack : subdivide along driving axis up to certain depth 
    14171442        int maxDepthForDrivingAxis = 0; 
     1443        const maxCostRatioForHeur = 0.99; 
    14181444 
    14191445    const bool useSpecialAxis = mOnlyDrivingAxis || mUseRandomAxis ||  
    1420                 mCirculatingAxis || (tData.mDepth < maxDepthForDrivingAxis); 
     1446                mCirculatingAxis; 
    14211447 
    14221448 
     
    14261452        else if (mCirculatingAxis) 
    14271453                sAxis = (tData.mAxis + 1) % 3; 
    1428         else if (mOnlyDrivingAxis || (tData.mDepth < maxDepthForDrivingAxis)) 
     1454        else if (mOnlyDrivingAxis) 
    14291455                sAxis = box.Size().DrivingAxis(); 
    14301456 
     
    14331459        //Debug << "axis: " << sAxis << " drivingaxis: " << box.Size().DrivingAxis(); 
    14341460 
    1435         for (axis = 0; axis < 3; ++ axis) 
     1461        for (axis = 0; axis < 3 ; ++ axis) 
    14361462        { 
    14371463                if (!useSpecialAxis || (axis == sAxis)) 
    14381464                { 
    1439                         if (!mUseCostHeuristics) 
    1440                         { 
     1465                        //-- place split plane using heuristics 
     1466 
     1467                        if (mUseCostHeuristics) 
     1468                        { 
     1469                                nCostRatio[axis] = 
     1470                                        BestCostRatioHeuristics(*tData.mRays, 
     1471                                                                                    box, 
     1472                                                                                        tData.mPvs, 
     1473                                                                                        axis, 
     1474                                                                                        nPosition[axis]);                        
     1475                        } 
     1476                         
     1477                        //-- split plane position is spatial median 
     1478                        //-- use median split if cost ratio very low as 
     1479                        //-- there are not enough visibility cues 
     1480 
     1481                        else //if (!mUseCostHeuristics || (nCostRatio[axis] > maxCostRatioForHeur)) 
     1482                        { 
     1483 
    14411484                                nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 
    14421485                                Vector3 normal(0,0,0); normal[axis] = 1.0f; 
    14431486 
    14441487                                // allows faster split because we have axis aligned kd tree boxes 
    1445                                 if (0 && isKdNode) 
     1488                                if (isKdNode) 
    14461489                                { 
    14471490                                        nCostRatio[axis] = EvalAxisAlignedSplitCost(tData, 
     
    14551498                                         
    14561499                                        // create back geometry from box 
     1500                                        // NOTE: the geometry is saved when possible 
    14571501                                        pos = box.Max(); pos[axis] = nPosition[axis]; 
    14581502                                        AxisAlignedBox3 bBox(box.Min(), pos); 
     
    14621506                                        nBackGeom[axis] = new BspNodeGeometry(fPolys); 
    14631507         
    1464                                         // create front geometry from box 
     1508                                        //-- create front geometry from box 
    14651509                                        pos = box.Min(); pos[axis] = nPosition[axis]; 
    14661510                                        AxisAlignedBox3 fBox(pos, box.Max()); 
     
    14811525                                } 
    14821526                        } 
    1483                         else 
    1484                         { 
    1485                                 nCostRatio[axis] = 
    1486                                         BestCostRatioHeuristics(*tData.mRays, 
    1487                                                                                     box, 
    1488                                                                                         tData.mPvs, 
    1489                                                                                         axis, 
    1490                                                                                         nPosition[axis]); 
    1491                         } 
    1492  
    1493                         if (bestAxis == -1) 
    1494                         { 
    1495                                 bestAxis = axis; 
    1496                         } 
    1497                         else if (nCostRatio[axis] < nCostRatio[bestAxis]) 
    1498                         { 
    1499                                 bestAxis = axis; 
    1500                         } 
    1501  
     1527                                                 
     1528 
     1529                        if (!mUseDrivingAxisForMaxCost) 
     1530                        { 
     1531                                if (bestAxis == -1) 
     1532                                { 
     1533                                        bestAxis = axis; 
     1534                                } 
     1535                                else if (nCostRatio[axis] < nCostRatio[bestAxis]) 
     1536                                { 
     1537                                        bestAxis = axis; 
     1538                                } 
     1539                        } 
     1540                        else  
     1541                        { 
     1542                                 // NOTE: takes longest axis split if cost ratio exceeds threshold 
     1543                                if (nCostRatio[axis] < min(maxCostRatio, nCostRatio[bestAxis])) 
     1544                                { 
     1545                                        bestAxis = axis; 
     1546                                } 
     1547                                //else if (nCostRatio[axis] < nCostRatio[bestAxis]) 
     1548                                //      Debug << "warning!! different path taken: " << axis << " " << bestAxis << endl; 
     1549                                 
     1550                        } 
    15021551                } 
    15031552        } 
     
    15201569        plane = Plane3(normal, nPosition[bestAxis]); 
    15211570 
     1571        //Debug << "best axis: " << bestAxis << " pos " << nPosition[bestAxis] << endl; 
     1572        //Debug << "!!!!!!!!!!!!!!" << endl; 
    15221573        return nCostRatio[bestAxis]; 
    15231574} 
Note: See TracChangeset for help on using the changeset viewer.