Ignore:
Timestamp:
11/17/05 18:47:53 (19 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
2 added
7 edited

Legend:

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

    r419 r420  
    6666        // surface area substitute for probability 
    6767        PolygonContainer geom; 
    68  
     68float overallarea = 0; 
    6969        for (it = viewCells.begin(); it != it_end; ++ it) 
    7070        { 
     
    7272                mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom); 
    7373                const float area = Polygon3::GetArea(geom); 
     74                if (area < 0.0001) 
     75                        Debug << "warning, area: " << area << endl; 
    7476                CLEAR_CONTAINER(geom); 
    7577 
     
    9294                // crossing the border of a view cell is also depending on the move speed 
    9395                loadPvsOverhead += pCrossVc * mVcOverhead; 
    94  
     96overallarea+=area; 
    9597                pInVcTotal += pInVc; 
    9698        } 
    97  
     99        Debug << "overall area: " << overallarea << endl; 
    98100         
    99101        renderTime /= pInVcTotal; 
     
    103105        mStat.avgRenderTime = renderTime + loadPvsOverhead; 
    104106         
     107        mStat.maxCost /= pInVcTotal; 
     108        mStat.minCost /= pInVcTotal; 
     109 
    105110        mStat.Stop(); 
    106111 
     
    183188    mStat.avgRtWithoutOverhead = renderTime; 
    184189        mStat.avgRenderTime = renderTime + loadPvsOverhead; 
    185         mStat.maxCost /= pCrossVcTotal; 
    186         mStat.minCost /= pCrossVcTotal; 
     190 
     191        mStat.maxCost /= pInVcTotal; 
     192        mStat.minCost /= pInVcTotal; 
    187193 
    188194        mStat.Stop(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r419 r420  
    6161        ObjectContainer objects; 
    6262         
    63         switch (BspTree::sConstructionMethod) 
     63        switch (mBspTree->mConstructionMethod) 
    6464        { 
    6565        case BspTree::FROM_INPUT_VIEW_CELLS: 
     
    181181        } 
    182182 
    183         if (ViewCell::sHierarchy == ViewCell::BSP) 
     183        switch(ViewCell::sHierarchy) 
    184184        { 
    185                 // cast ray to BSP tree to get intersection with view cells 
    186                 if (mBspTree) 
    187                 { 
    188                         mBspTree->CastRay(ray); 
    189                          
    190                         if (object) 
    191                                 sampleContributions += AddObjectSamples(object, ray); 
    192                          
    193                         if (!ray.intersections.empty()) // second intersection found 
    194                         { 
    195                                 sampleContributions +=  
    196                                         AddObjectSamples(ray.intersections[0].mObject, ray); 
    197                         } 
    198                 } 
    199         } 
    200         else { 
    201                 if (ray.kdLeaves.size()) { 
     185        case ViewCell::BSP: 
     186                 
     187                //-- cast ray to BSP tree to get intersection with view cells 
     188                if (!mBspTree) 
     189                        break; 
     190                 
     191                mBspTree->CastRay(ray); 
     192                         
     193                if (object) 
     194                        sampleContributions += AddObjectSamples(object, ray); 
     195                         
     196                if (!ray.intersections.empty()) // second intersection found 
     197                { 
     198                        sampleContributions +=  
     199                                AddObjectSamples(ray.intersections[0].mObject, ray); 
     200                } 
     201                break; 
     202        case ViewCell::KD: 
     203                if (ray.kdLeaves.size())  
     204                { 
    202205                        Intersectable *terminator = 
    203206                                ray.intersections.size() ? ray.intersections[0].mObject: NULL; 
    204207 
    205208                        sampleContributions += AddNodeSamples(ray, 
    206                                                                                                                                                                                 object, 
    207                                                                                                                                                                                 terminator); 
    208                 } 
    209         } 
    210          
     209                                                                                                                                                                        object, 
     210                                                                                                                                                                        terminator); 
     211                } 
     212                break; 
     213        case ViewCell::VSP: 
     214                // TODO: 
     215                break; 
     216        default: 
     217                Debug << "Should never come here" << endl; 
     218                break; 
     219        } 
     220 
    211221        return sampleContributions; 
    212222} 
     
    573583                        if (exporter) 
    574584                        { 
     585                                exporter->SetWireframe(); 
    575586                                exporter->ExportBspLeaves(*mBspTree, stat.maxPvs); 
    576587                                //exporter->ExportBspViewCellPartition(*mBspTree, 0); 
     588                                 
     589                                if (1) // export scene geometry 
     590                                { 
     591                                        Material m;//= RandomMaterial(); 
     592                                        m.mDiffuseColor = RgbColor(0, 1, 0); 
     593                                        exporter->SetForcedMaterial(m); 
     594                                        exporter->SetWireframe(); 
     595         
     596                                        for (int j = 0; j < objects.size(); ++ j) 
     597                                                exporter->ExportIntersectable(objects[j]); 
     598                                } 
     599                                         
    577600                                delete exporter; 
    578601                        } 
     
    756779        if (!mBspTree) 
    757780        { 
    758                 if ((BspTree::sConstructionMethod == BspTree::FROM_RAYS) && 
     781                if ((BspTree::mConstructionMethod == BspTree::FROM_RAYS) && 
    759782                        ((int)mSampleRays.size() < mBspConstructionSamples)) 
    760783                { 
     
    866889                                        outRays.push_back(mSampleRays[i]); 
    867890                        } 
    868                         if (BspTree::sConstructionMethod == BspTree::FROM_RAYS) 
     891                        if (BspTree::mConstructionMethod == BspTree::FROM_RAYS) 
    869892                        { 
    870893                                // export rays  
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r418 r420  
    1414#include "Plane3.h" 
    1515 
    16 int BspTree::sMaxPolyCandidates = 10; 
    17 int BspTree::sMaxRayCandidates = 10; 
    18 int BspTree::sSplitPlaneStrategy = BALANCED_POLYS;  
    19 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 
    20  
    21  
    22 int BspTree::sTermMaxPolygons = 10; 
    23 int BspTree::sTermMinPvs = 20; 
    24 int BspTree::sTermMaxDepth = 20; 
    25 float BspTree::sTermMinArea = 0.001f; 
    26 int BspTree::sTermMaxPolysForAxisAligned = 50; 
    27 int BspTree::sTermMaxObjectsForAxisAligned = 50; 
    28 int BspTree::sTermMaxRaysForAxisAligned = -1; 
    29 int BspTree::sTermMaxRays = -1; 
    30 float BspTree::sTermMaxRayContribution = 0.05f; 
    31 float BspTree::sTermMaxAccRayLength = 50; 
    32  
    33  
    34 int BspTree::sMinPvsDif = 10; 
    35 int BspTree::sMinPvs = 10; 
    36 int BspTree::sMaxPvs = 500; 
    37  
    38 float BspTree::sCt_div_ci = 1.0f; 
    39 float BspTree::sSplitBorder = 1.0f; 
    40 float BspTree::sMaxCostRatio = 0.9f; 
    41  
    42 //-- factors for bsp tree split plane heuristics 
    43  
    44 float BspTree::sLeastSplitsFactor = 1.0f; 
    45 float BspTree::sBalancedPolysFactor = 1.0f; 
    46 float BspTree::sBalancedViewCellsFactor = 1.0f; 
    47  
    48 // NOTE:  very important criterium for 2.5d scenes 
    49 float BspTree::sVerticalSplitsFactor = 1.0f; 
    50 float BspTree::sLargestPolyAreaFactor = 1.0f; 
    51 float BspTree::sBlockedRaysFactor = 1.0f; 
    52 float BspTree::sLeastRaySplitsFactor = 1.0f; 
    53 float BspTree::sBalancedRaysFactor = 1.0f; 
    54 float BspTree::sPvsFactor = 1.0f; 
    55  
    56 bool BspTree::sStoreLeavesWithRays = false; 
    5716int BspNode::mailID = 1; 
    5817 
     
    7433*/ 
    7534float BspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0}; 
    76  
    77 bool BspTree::sPvsUseArea = true; 
    7835 
    7936/****************************************************************/ 
     
    271228void BspLeaf::AddToPvs(const BoundedRayContainer &rays,  
    272229                                           int &sampleContributions, 
    273                                            int &contributingSamples) 
     230                                           int &contributingSamples, 
     231                                           bool storeLeavesWithRays) 
    274232{ 
    275233        sampleContributions = 0; 
     
    296254                } 
    297255                 
    298                 if (BspTree::sStoreLeavesWithRays) 
     256                if (storeLeavesWithRays) 
    299257                        // warning: intersections not ordered 
    300258                        ray->bspIntersections.push_back(Ray::BspIntersection((*it)->mMinT, this)); 
     
    308266 
    309267BspTree::BspTree(BspViewCell *viewCell):  
    310 mRootCell(viewCell), mRoot(NULL), mGenerateViewCells(false), 
    311 mStorePiercingRays(true) 
    312 { 
     268mRootCell(viewCell),  
     269mRoot(NULL),  
     270mGenerateViewCells(false), 
     271//-- factors for bsp tree split plane heuristics 
     272mVerticalSplitsFactor(1.0f), 
     273mLargestPolyAreaFactor(1.0f), 
     274mBlockedRaysFactor(1.0f), 
     275mLeastRaySplitsFactor(1.0f), 
     276mBalancedRaysFactor(1.0f), 
     277mPvsFactor(1.0f), 
     278mLeastSplitsFactor(1.0f), 
     279mBalancedPolysFactor(1.0f), 
     280mBalancedViewCellsFactor(1.0f), 
     281//------------------------------------ 
     282mStoreLeavesWithRays(false), 
     283mPvsUseArea(true) 
     284{ 
     285        ParseEnvironment(); 
    313286        Randomize(); // initialise random generator for heuristics 
    314287} 
     
    593566                        { 
    594567                                //store rays if needed for heuristics 
    595                                 if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     568                                if (mSplitPlaneStrategy & BLOCKED_RAYS) 
    596569                                        (*it).second->mPiercingRays.push_back(ray); 
    597570                        }  
     
    602575                                polys->push_back(poly); 
    603576 
    604                                 if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     577                                if (mSplitPlaneStrategy & BLOCKED_RAYS) 
    605578                                        poly->mPiercingRays.push_back(ray); 
    606579 
     
    664637} 
    665638 
    666 inline bool BspTree::TerminationCriteriaMet(const BspTraversalData &data) const 
     639bool BspTree::TerminationCriteriaMet(const BspTraversalData &data) const 
    667640{ 
    668641        return  
    669                 (((int)data.mPolygons->size() <= sTermMaxPolygons) ||  
    670                  ((int)data.mRays->size() <= sTermMaxRays) || 
    671                  (data.mPvs <= sTermMinPvs) || 
    672                  (data.mArea <= sTermMinArea) || 
    673                  (data.mDepth >= sTermMaxDepth) || 
    674                  (((float)data.mPvs / (float)data.mRays->size()) < sTermMaxRayContribution)); 
     642                (((int)data.mPolygons->size() <= mTermMaxPolygons) ||  
     643                 ((int)data.mRays->size() <= mTermMaxRays) || 
     644                 (data.mPvs <= mTermMinPvs) || 
     645                 (data.mArea <= mTermMinArea) || 
     646                 (data.mDepth >= mTermMaxDepth) || 
     647                 (((float)data.mPvs / ((float)data.mRays->size() + Limits::Small)) <  
     648                        mTermMaxRayContribution)); 
    675649} 
    676650 
     
    926900        float boxArea = box.SurfaceArea(); 
    927901   
    928         float minBand = minBox + sSplitBorder * (maxBox - minBox); 
    929         float maxBand = minBox + (1.0f - sSplitBorder) * (maxBox - minBox); 
     902        float minBand = minBox + mSplitBorder * (maxBox - minBox); 
     903        float maxBand = minBox + (1.0f - mSplitBorder) * (maxBox - minBox); 
    930904         
    931905        float minSum = 1e20f; 
     
    968942   
    969943        float oldCost = (float)polys.size(); 
    970         float newCost = sCt_div_ci + minSum / boxArea; 
     944        float newCost = mCt_div_ci + minSum / boxArea; 
    971945        float ratio = newCost / oldCost; 
    972946 
     
    1008982        } 
    1009983         
    1010         if (costRatio >= sMaxCostRatio) 
     984        if (costRatio >= mMaxCostRatio) 
    1011985                return false; 
    1012986 
     
    10371011        } 
    10381012         
    1039         if ((sSplitPlaneStrategy & AXIS_ALIGNED) && 
    1040                 ((int)data.mPolygons->size() > sTermMaxPolysForAxisAligned) && 
    1041                 ((int)data.mRays->size() > sTermMaxRaysForAxisAligned) && 
    1042                 ((sTermMaxObjectsForAxisAligned < 0) ||  
    1043                   (Polygon3::ParentObjectsSize(*data.mPolygons) > sTermMaxObjectsForAxisAligned))) 
     1013        if ((mSplitPlaneStrategy & AXIS_ALIGNED) && 
     1014                ((int)data.mPolygons->size() > mTermMaxPolysForAxisAligned) && 
     1015                ((int)data.mRays->size() > mTermMaxRaysForAxisAligned) && 
     1016                ((mTermMaxObjectsForAxisAligned < 0) ||  
     1017                  (Polygon3::ParentObjectsSize(*data.mPolygons) > mTermMaxObjectsForAxisAligned))) 
    10441018        { 
    10451019                Plane3 plane; 
     
    10491023 
    10501024        // simplest strategy: just take next polygon 
    1051         if (sSplitPlaneStrategy & RANDOM_POLYGON) 
     1025        if (mSplitPlaneStrategy & RANDOM_POLYGON) 
    10521026        { 
    10531027        if (!data.mPolygons->empty()) 
     
    10861060        Plane3 plane; 
    10871061 
    1088         int limit = Min((int)data.mPolygons->size(), sMaxPolyCandidates); 
     1062        int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 
    10891063         
    10901064        int candidateIdx = limit; 
     
    11161090        const BoundedRayContainer *rays = data.mRays; 
    11171091 
    1118         for (int i = 0; i < sMaxRayCandidates / 2; ++ i) 
     1092        for (int i = 0; i < mMaxRayCandidates / 2; ++ i) 
    11191093        { 
    11201094                candidateIdx = Random((int)rays->size()); 
     
    11431117 
    11441118        //Debug << "lowest: " << lowestCost << endl; 
    1145                  
    1146         for (int i = 0; i < sMaxRayCandidates / 2; ++ i) 
     1119        for (int i = 0; i < mMaxRayCandidates / 2; ++ i) 
    11471120        { 
    11481121                Vector3 pt[3]; 
     
    12281201                const int classification = (*it)->ClassifyPlane(candidatePlane); 
    12291202 
    1230                 if (sSplitPlaneStrategy & BALANCED_POLYS) 
     1203                if (mSplitPlaneStrategy & BALANCED_POLYS) 
    12311204                        sumBalancedPolys += sBalancedPolysTable[classification]; 
    12321205                 
    1233                 if (sSplitPlaneStrategy & LEAST_SPLITS) 
     1206                if (mSplitPlaneStrategy & LEAST_SPLITS) 
    12341207                        sumSplits += sLeastPolySplitsTable[classification]; 
    12351208 
    1236                 if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 
     1209                if (mSplitPlaneStrategy & LARGEST_POLY_AREA) 
    12371210                { 
    12381211                        if (classification == Polygon3::COINCIDENT) 
     
    12411214                } 
    12421215                 
    1243                 if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     1216                if (mSplitPlaneStrategy & BLOCKED_RAYS) 
    12441217                { 
    12451218                        const float blockedRays = (float)(*it)->mPiercingRays.size(); 
     
    12521225 
    12531226                // assign view cells to back or front according to classificaion 
    1254                 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
     1227                if (mSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
    12551228                { 
    12561229                        MeshInstance *viewCell = (*it)->mParent; 
     
    12911264        } 
    12921265 
     1266        const float polysSize = (float)polys.size() + Limits::Small; 
     1267 
    12931268        // all values should be approx. between 0 and 1 so they can be combined 
    12941269        // and scaled with the factors according to their importance 
    1295         if ((sSplitPlaneStrategy & BALANCED_POLYS) && (!polys.empty())) 
    1296                 val += sBalancedPolysFactor * fabs(sumBalancedPolys) / (float)polys.size(); 
    1297          
    1298         if ((sSplitPlaneStrategy & LEAST_SPLITS) && (!polys.empty()) 
    1299                 val += sLeastSplitsFactor * sumSplits / (float)polys.size(); 
    1300  
    1301         if (sSplitPlaneStrategy & LARGEST_POLY_AREA)  
     1270        if (mSplitPlaneStrategy & BALANCED_POLYS) 
     1271                val += sBalancedPolysFactor * fabs(sumBalancedPolys) / polysSize; 
     1272         
     1273        if (mSplitPlaneStrategy & LEAST_SPLITS 
     1274                val += sLeastSplitsFactor * sumSplits / polysSize; 
     1275 
     1276        if (mSplitPlaneStrategy & LARGEST_POLY_AREA)  
    13021277                // HACK: polys.size should be total area so scaling is between 0 and 1 
    13031278                val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; 
    13041279 
    1305         if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     1280        if (mSplitPlaneStrategy & BLOCKED_RAYS) 
    13061281                if (totalBlockedRays != 0) 
    13071282                        val += sBlockedRaysFactor * (totalBlockedRays - sumBlockedRays) / totalBlockedRays; 
    13081283 
    1309         if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
    1310                 if (totalViewCells != 0) 
    1311                         val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells) / (float)totalViewCells; 
     1284        if (mSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
     1285                val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells) /  
     1286                        ((float)totalViewCells + Limits::Small); 
    13121287         
    13131288        return val; 
     
    13601335        float pBack = 0; 
    13611336 
    1362         if (sSplitPlaneStrategy & PVS) 
     1337        if (mSplitPlaneStrategy & PVS) 
    13631338        { 
    13641339                // create three unique ids for pvs heuristics 
     
    13671342                Intersectable::NewMail(); frontAndBackId = ViewCell::sMailId; 
    13681343 
    1369                 if (sPvsUseArea) // use front and back cell areas to approximate volume 
     1344                if (mPvsUseArea) // use front and back cell areas to approximate volume 
    13701345                {        
    13711346                        // construct child geometry with regard to the candidate split plane 
     
    13951370                        ray->ClassifyPlane(candidatePlane, minT, maxT, entP, extP); 
    13961371 
    1397                 if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) 
     1372                if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 
    13981373                { 
    13991374                        sumBalancedRays += sBalancedRaysTable[cf]; 
    14001375                } 
    14011376                 
    1402                 if (sSplitPlaneStrategy & BALANCED_RAYS) 
     1377                if (mSplitPlaneStrategy & BALANCED_RAYS) 
    14031378                { 
    14041379                        sumRaySplits += sLeastRaySplitsTable[cf]; 
    14051380                } 
    14061381 
    1407                 if (sSplitPlaneStrategy & PVS) 
     1382                if (mSplitPlaneStrategy & PVS) 
    14081383                { 
    14091384                        if (!ray->intersections.empty()) 
     
    14231398                        } 
    14241399 
    1425                         if (!sPvsUseArea) // use front and back cell areas to approximate volume 
     1400                        if (!mPvsUseArea) // use front and back cell areas to approximate volume 
    14261401                        { 
    14271402                                float len = Distance(entP, extP); 
     
    14751450        } 
    14761451 
    1477         if ((sSplitPlaneStrategy & LEAST_RAY_SPLITS) && !rays.empty()) 
    1478                         val += sLeastRaySplitsFactor * sumRaySplits / (float)rays.size(); 
    1479  
    1480         if ((sSplitPlaneStrategy & BALANCED_RAYS) && !rays.empty()) 
    1481                         val += sBalancedRaysFactor * fabs(sumBalancedRays) / (float)rays.size(); 
    1482  
    1483         if ((sSplitPlaneStrategy & PVS) && area && pvs) 
    1484         { 
    1485                 val += sPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / 
    1486                            (pOverall * (float)pvs * 2); 
     1452        const float raysSize = (float)rays.size() + Limits::Small; 
     1453        if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 
     1454                val += sLeastRaySplitsFactor * sumRaySplits / raysSize; 
     1455 
     1456        if (mSplitPlaneStrategy & BALANCED_RAYS) 
     1457                val += sBalancedRaysFactor * fabs(sumBalancedRays) /  raysSize; 
     1458 
     1459        float denom = pOverall * (float)pvs * 2.0f + Limits::Small; 
     1460        if ((mSplitPlaneStrategy & PVS) && area && pvs) 
     1461        { 
     1462                val += sPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / denom; 
    14871463 
    14881464                // give penalty to unbalanced split 
     
    15571533        float val = 0; 
    15581534 
    1559         if (sSplitPlaneStrategy & VERTICAL_AXIS) 
     1535        if (mSplitPlaneStrategy & VERTICAL_AXIS) 
    15601536        { 
    15611537                Vector3 tinyAxis(0,0,0); tinyAxis[mBox.Size().TinyAxis()] = 1.0f; 
     
    15671543 
    15681544        // the following criteria loop over all polygons to find the cost value 
    1569         if ((sSplitPlaneStrategy & BALANCED_POLYS)      || 
    1570                 (sSplitPlaneStrategy & LEAST_SPLITS)        || 
    1571                 (sSplitPlaneStrategy & LARGEST_POLY_AREA)   || 
    1572                 (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) || 
    1573                 (sSplitPlaneStrategy & BLOCKED_RAYS)) 
     1545        if ((mSplitPlaneStrategy & BALANCED_POLYS)      || 
     1546                (mSplitPlaneStrategy & LEAST_SPLITS)        || 
     1547                (mSplitPlaneStrategy & LARGEST_POLY_AREA)   || 
     1548                (mSplitPlaneStrategy & BALANCED_VIEW_CELLS) || 
     1549                (mSplitPlaneStrategy & BLOCKED_RAYS)) 
    15741550        { 
    15751551                val += SplitPlaneCost(candidatePlane, *data.mPolygons); 
     
    15771553 
    15781554        // the following criteria loop over all rays to find the cost value 
    1579         if ((sSplitPlaneStrategy & BALANCED_RAYS)      || 
    1580                 (sSplitPlaneStrategy & LEAST_RAY_SPLITS)   || 
    1581                 (sSplitPlaneStrategy & PVS)) 
     1555        if ((mSplitPlaneStrategy & BALANCED_RAYS)      || 
     1556                (mSplitPlaneStrategy & LEAST_RAY_SPLITS)   || 
     1557                (mSplitPlaneStrategy & PVS)) 
    15821558        { 
    15831559                val += SplitPlaneCost(candidatePlane, *data.mRays, data.mPvs,  
     
    15921568{ 
    15931569        //-- parse bsp cell tree construction method 
    1594         char constructionMethodStr[60]; 
     1570        /*char constructionMethodStr[60]; 
    15951571         
    15961572        environment->GetStringValue("BspTree.Construction.input", constructionMethodStr); 
    15971573 
    1598         sConstructionMethod = FROM_INPUT_VIEW_CELLS; 
     1574        mConstructionMethod = FROM_INPUT_VIEW_CELLS; 
    15991575         
    16001576        if (strcmp(constructionMethodStr, "fromViewCells") == 0) 
    1601                 sConstructionMethod = FROM_INPUT_VIEW_CELLS; 
     1577                mConstructionMethod = FROM_INPUT_VIEW_CELLS; 
    16021578        else if (strcmp(constructionMethodStr, "fromSceneGeometry") == 0) 
    1603                 sConstructionMethod = FROM_SCENE_GEOMETRY; 
     1579                mConstructionMethod = FROM_SCENE_GEOMETRY; 
    16041580        else if (strcmp(constructionMethodStr, "fromRays") == 0) 
    1605                 sConstructionMethod = FROM_RAYS; 
     1581                mConstructionMethod = FROM_RAYS; 
    16061582        else  
    16071583        { 
     
    16111587 
    16121588        Debug << "Construction method: " << constructionMethodStr << endl; 
    1613  
     1589*/ 
    16141590        //-- termination criteria for autopartition 
    1615         environment->GetIntValue("BspTree.Termination.maxDepth", sTermMaxDepth); 
    1616         environment->GetIntValue("BspTree.Termination.minPvs", sTermMinPvs); 
    1617         environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons); 
    1618         environment->GetIntValue("BspTree.Termination.maxRays", sTermMaxRays); 
    1619         environment->GetFloatValue("BspTree.Termination.minArea", sTermMinArea);         
    1620         environment->GetFloatValue("BspTree.Termination.maxRayContribution", sTermMaxRayContribution); 
    1621         environment->GetFloatValue("BspTree.Termination.maxAccRayLenght", sTermMaxAccRayLength); 
     1591        environment->GetIntValue("BspTree.Termination.maxDepth", mTermMaxDepth); 
     1592        environment->GetIntValue("BspTree.Termination.minPvs", mTermMinPvs); 
     1593        environment->GetIntValue("BspTree.Termination.maxPolygons", mTermMaxPolygons); 
     1594        environment->GetIntValue("BspTree.Termination.maxRays", mTermMaxRays); 
     1595        environment->GetFloatValue("BspTree.Termination.minArea", mTermMinArea);         
     1596        environment->GetFloatValue("BspTree.Termination.maxRayContribution", mTermMaxRayContribution); 
     1597        environment->GetFloatValue("BspTree.Termination.maxAccRayLenght", mTermMaxAccRayLength); 
    16221598 
    16231599        //-- termination criteria for axis aligned split 
    1624         environment->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", sCt_div_ci); 
    1625         environment->GetFloatValue("BspTree.Termination.AxisAligned.maxCostRatio", sMaxCostRatio); 
     1600        environment->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", mCt_div_ci); 
     1601        environment->GetFloatValue("BspTree.Termination.AxisAligned.maxCostRatio", mMaxCostRatio); 
    16261602        environment->GetIntValue("BspTree.Termination.AxisAligned.maxPolys",  
    1627                                                          sTermMaxPolysForAxisAligned); 
     1603                                                         mTermMaxPolysForAxisAligned); 
    16281604        environment->GetIntValue("BspTree.Termination.AxisAligned.maxRays",  
    1629                                                          sTermMaxRaysForAxisAligned); 
     1605                                                         mTermMaxRaysForAxisAligned); 
    16301606        environment->GetIntValue("BspTree.Termination.AxisAligned.maxObjects",  
    1631                                                          sTermMaxObjectsForAxisAligned); 
     1607                                                         mTermMaxObjectsForAxisAligned); 
    16321608        //-- partition criteria 
    1633         environment->GetIntValue("BspTree.maxPolyCandidates", sMaxPolyCandidates); 
    1634         environment->GetIntValue("BspTree.maxRayCandidates", sMaxRayCandidates); 
    1635         environment->GetIntValue("BspTree.splitPlaneStrategy", sSplitPlaneStrategy); 
    1636         environment->GetFloatValue("BspTree.AxisAligned.splitBorder", sSplitBorder); 
     1609        environment->GetIntValue("BspTree.maxPolyCandidates", mMaxPolyCandidates); 
     1610        environment->GetIntValue("BspTree.maxRayCandidates", mMaxRayCandidates); 
     1611        environment->GetIntValue("BspTree.splitPlaneStrategy", mSplitPlaneStrategy); 
     1612        environment->GetFloatValue("BspTree.AxisAligned.splitBorder", mSplitBorder); 
    16371613 
    16381614        environment->GetFloatValue("BspTree.Construction.sideTolerance", Vector3::sDistTolerance); 
     
    16401616 
    16411617        // post processing stuff 
    1642         environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", sMinPvsDif); 
    1643         environment->GetIntValue("ViewCells.PostProcessing.minPvs", sMinPvs); 
    1644         environment->GetIntValue("ViewCells.PostProcessing.maxPvs", sMaxPvs); 
    1645  
    1646     Debug << "BSP max depth: " << sTermMaxDepth << endl; 
    1647         Debug << "BSP min PVS: " << sTermMinPvs << endl; 
    1648         Debug << "BSP min area: " << sTermMinArea << endl; 
    1649         Debug << "BSP max polys: " << sTermMaxPolygons << endl; 
    1650         Debug << "BSP max rays: " << sTermMaxRays << endl; 
    1651         Debug << "BSP max polygon candidates: " << sMaxPolyCandidates << endl; 
    1652         Debug << "BSP max plane candidates: " << sMaxRayCandidates << endl; 
     1618        environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", mMinPvsDif); 
     1619        environment->GetIntValue("ViewCells.PostProcessing.minPvs", mMinPvs); 
     1620        environment->GetIntValue("ViewCells.PostProcessing.maxPvs", mMaxPvs); 
     1621 
     1622    Debug << "BSP max depth: " << mTermMaxDepth << endl; 
     1623        Debug << "BSP min PVS: " << mTermMinPvs << endl; 
     1624        Debug << "BSP min area: " << mTermMinArea << endl; 
     1625        Debug << "BSP max polys: " << mTermMaxPolygons << endl; 
     1626        Debug << "BSP max rays: " << mTermMaxRays << endl; 
     1627        Debug << "BSP max polygon candidates: " << mMaxPolyCandidates << endl; 
     1628        Debug << "BSP max plane candidates: " << mMaxRayCandidates << endl; 
    16531629 
    16541630        Debug << "Split plane strategy: "; 
    1655         if (sSplitPlaneStrategy & RANDOM_POLYGON) 
     1631        if (mSplitPlaneStrategy & RANDOM_POLYGON) 
    16561632                Debug << "random polygon "; 
    1657         if (sSplitPlaneStrategy & AXIS_ALIGNED) 
     1633        if (mSplitPlaneStrategy & AXIS_ALIGNED) 
    16581634                Debug << "axis aligned "; 
    1659         if (sSplitPlaneStrategy & LEAST_SPLITS)      
     1635        if (mSplitPlaneStrategy & LEAST_SPLITS)      
    16601636                Debug << "least splits "; 
    1661         if (sSplitPlaneStrategy & BALANCED_POLYS) 
     1637        if (mSplitPlaneStrategy & BALANCED_POLYS) 
    16621638                Debug << "balanced polygons "; 
    1663         if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
     1639        if (mSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
    16641640                Debug << "balanced view cells "; 
    1665         if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 
     1641        if (mSplitPlaneStrategy & LARGEST_POLY_AREA) 
    16661642                Debug << "largest polygon area "; 
    1667         if (sSplitPlaneStrategy & VERTICAL_AXIS) 
     1643        if (mSplitPlaneStrategy & VERTICAL_AXIS) 
    16681644                Debug << "vertical axis "; 
    1669         if (sSplitPlaneStrategy & BLOCKED_RAYS) 
     1645        if (mSplitPlaneStrategy & BLOCKED_RAYS) 
    16701646                Debug << "blocked rays "; 
    1671         if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) 
     1647        if (mSplitPlaneStrategy & LEAST_RAY_SPLITS) 
    16721648                Debug << "least ray splits "; 
    1673         if (sSplitPlaneStrategy & BALANCED_RAYS) 
     1649        if (mSplitPlaneStrategy & BALANCED_RAYS) 
    16741650                Debug << "balanced rays "; 
    1675         if (sSplitPlaneStrategy & PVS) 
     1651        if (mSplitPlaneStrategy & PVS) 
    16761652                Debug << "pvs"; 
    16771653        Debug << endl; 
     
    17191695        BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 
    17201696 
    1721         if (data.mDepth >= sTermMaxDepth) 
     1697        if (data.mDepth >= mTermMaxDepth) 
    17221698                ++ mStat.maxDepthNodes; 
    17231699         
     
    17341710#ifdef _DEBUG 
    17351711        Debug << "BSP stats: " 
    1736                   << "Depth: " << data.mDepth << " (max: " << sTermMaxDepth << "), " 
    1737                   << "PVS: " << data.mPvs << " (min: " << sTermMinPvs << "), " 
    1738                   << "Area: " << data.mArea << " (min: " << sTermMinArea << "), " 
    1739                   << "#polygons: " << (int)data.mPolygons->size() << " (max: " << sTermMaxPolygons << "), " 
    1740                   << "#rays: " << (int)data.mRays->size() << " (max: " << sTermMaxRays << "), "  
     1712                  << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " 
     1713                  << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 
     1714                  << "Area: " << data.mArea << " (min: " << mTermMinArea << "), " 
     1715                  << "#polygons: " << (int)data.mPolygons->size() << " (max: " << mTermMaxPolygons << "), " 
     1716                  << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMaxRays << "), "  
    17411717                  << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "=, " 
    17421718                  << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 
     
    17951771                        } 
    17961772                        else // ray and plane are coincident 
    1797                         // WHAT TO DO IN THIS CASE ? 
    17981773                        { 
    1799                                 break; 
    1800                                 //node = in->GetFront(); 
    1801                                 //continue; 
     1774                                // WHAT TO DO IN THIS CASE ? 
     1775                                //break; 
     1776                                node = in->GetFront(); 
     1777                                continue; 
    18021778                        } 
    18031779 
     
    19901966        int fdiff = fvc->GetPvs().Diff(bvc->GetPvs()); 
    19911967 
    1992         if (fvc->GetPvs().GetSize() + fdiff < sMaxPvs) 
    1993         { 
    1994                 if ((fvc->GetPvs().GetSize() < sMinPvs) ||       
    1995                         (bvc->GetPvs().GetSize() < sMinPvs) || 
    1996                         ((fdiff < sMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < sMinPvsDif))) 
     1968        if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs) 
     1969        { 
     1970                if ((fvc->GetPvs().GetSize() < mMinPvs) ||       
     1971                        (bvc->GetPvs().GetSize() < mMinPvs) || 
     1972                        ((fdiff < mMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif))) 
    19971973                { 
    19981974                        return true; 
     
    20552031                { 
    20562032                case Ray::COINCIDENT: // TODO: should really discard ray? 
    2057                         //frontRays.push_back(bRay); 
    2058                         DEL_PTR(bRay); 
     2033                        frontRays.push_back(bRay); 
     2034                        //DEL_PTR(bRay); 
    20592035                        break; 
    20602036                case Ray::BACK: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r419 r420  
    316316        */ 
    317317        void AddToPvs(const BoundedRayContainer &rays, int &sampleContributions, 
    318                                   int &contributingSamples); 
     318                                  int &contributingSamples, bool storeLeavesWithRays = false); 
    319319 
    320320protected: 
     
    495495        void EvaluateViewCellsStats(BspViewCellsStatistics &stat) const; 
    496496 
     497        /// BSP tree construction method 
     498        int mConstructionMethod; 
     499 
    497500protected: 
    498501 
     
    733736        int ComputePvsSize(const BoundedRayContainer &rays) const; 
    734737 
    735         bool TerminationCriteriaMet(const BspTraversalData &data) const; 
     738        inline bool TerminationCriteriaMet(const BspTraversalData &data) const; 
    736739 
    737740        float AccumulatedRayLength(BoundedRayContainer &rays) const; 
     
    766769        bool mGenerateViewCells; 
    767770 
    768         /// if rays should be stored that are piercing this view cell 
    769         bool mStorePiercingRays; 
    770  
    771 public: 
    772         /** Parses the environment and stores the global BSP tree parameters 
    773         */ 
    774         static void ParseEnvironment(); 
     771                /** Parses the environment and stores the global BSP tree parameters 
     772        */ 
     773        void ParseEnvironment(); 
    775774 
    776775        /// maximal number of polygons before subdivision termination 
    777         static int sTermMaxPolygons; 
     776        int mTermMaxPolygons; 
    778777        /// maximal number of rays before subdivision termination 
    779         static int sTermMaxRays; 
     778        int mTermMaxRays; 
    780779        /// maximal possible depth 
    781         static int sTermMaxDepth; 
     780        int mTermMaxDepth; 
    782781        /// mininum area 
    783         static float sTermMinArea; 
     782        float mTermMinArea; 
    784783        /// mininum PVS 
    785         static int sTermMinPvs; 
     784        int mTermMinPvs; 
    786785        /// strategy to get the best split plane 
    787         static int sSplitPlaneStrategy; 
     786        int mSplitPlaneStrategy; 
    788787        /// number of candidates evaluated for the next split plane 
    789         static int sMaxPolyCandidates; 
    790         static int sMaxRayCandidates; 
    791         /// BSP tree construction method 
    792         static int sConstructionMethod; 
     788        int mMaxPolyCandidates; 
     789        /// number of candidates for split planes evaluated using the rays 
     790        int mMaxRayCandidates; 
     791         
    793792        /// maximal number of polygons for axis aligned split 
    794         static int sTermMaxPolysForAxisAligned; 
     793        int mTermMaxPolysForAxisAligned; 
    795794        /// maximal number of rays for axis aligned split 
    796         static int sTermMaxRaysForAxisAligned; 
     795        int mTermMaxRaysForAxisAligned; 
    797796        /// maximal number of objects for axis aligned split 
    798         static int sTermMaxObjectsForAxisAligned; 
    799  
    800         static float sTermMaxRayContribution; 
    801         static float sTermMaxAccRayLength; 
    802  
    803         static bool sStoreLeavesWithRays; 
     797        int mTermMaxObjectsForAxisAligned; 
     798        /// maximal contribution per ray 
     799        float mTermMaxRayContribution; 
     800        /// maximal accumulated ray length 
     801        float mTermMaxAccRayLength; 
     802 
     803        bool mStoreLeavesWithRays; 
    804804 
    805805        /// axis aligned split criteria 
    806         static float sCt_div_ci; 
    807         static float sSplitBorder; 
    808         static float sMaxCostRatio; 
     806        float mCt_div_ci; 
     807        float mSplitBorder; 
     808        float mMaxCostRatio; 
    809809 
    810810        // factors guiding the split plane heuristics 
    811         static float sLeastSplitsFactor; 
    812         static float sBalancedPolysFactor; 
    813         static float sBalancedViewCellsFactor; 
    814         static float sVerticalSplitsFactor; 
    815         static float sLargestPolyAreaFactor; 
    816         static float sBlockedRaysFactor; 
    817         static float sLeastRaySplitsFactor; 
    818         static float sBalancedRaysFactor; 
    819         static float sPvsFactor; 
    820  
    821         //-- thresholds used for view cells are merging 
    822         static int sMinPvsDif; 
    823         static int sMinPvs; 
    824         static int sMaxPvs; 
    825         static bool sPvsUseArea; 
     811        float sLeastSplitsFactor; 
     812        float sBalancedPolysFactor; 
     813        float sBalancedViewCellsFactor; 
     814        float sVerticalSplitsFactor; 
     815        float sLargestPolyAreaFactor; 
     816        float sBlockedRaysFactor; 
     817        float sLeastRaySplitsFactor; 
     818        float sBalancedRaysFactor; 
     819        float sPvsFactor; 
     820 
     821        //-- thresholds used for view cells merge 
     822        int mMinPvsDif; 
     823        int mMinPvs; 
     824        int mMaxPvs; 
     825        /// if area or accumulated ray lenght should be used for PVS heuristics 
     826        bool mPvsUseArea; 
    826827 
    827828private: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r419 r420  
    2424#include "Intersectable.h" 
    2525#include "Ray.h" 
     26#include "RayInfo.h" 
    2627 
    2728// Static variables 
     
    3435float VspKdTree::sTermMaxRayContribution = 0.1f; 
    3536 
    36  
    37  
     37/// Adds object to the pvs of the front and back node 
    3838inline void AddObject2Pvs(Intersectable *object, 
    3939                                                  const int side, 
     
    7171 
    7272/**************************************************************/ 
     73/*                class VspKdTreeNode implementation          */ 
     74/**************************************************************/ 
     75 
     76// Inline constructor 
     77VspKdTreeNode::VspKdTreeNode(VspKdTreeInterior *p): 
     78mParent(p), mAxis(-1), mDepth(p ? p->mDepth + 1 : 0)  
     79{} 
     80 
     81VspKdTreeNode::~VspKdTreeNode()  
     82{}; 
     83 
     84inline VspKdTreeInterior *VspKdTreeNode::GetParent() const 
     85{ 
     86        return mParent; 
     87} 
     88 
     89inline void VspKdTreeNode::SetParent(VspKdTreeInterior *p) 
     90{ 
     91        mParent = p; 
     92} 
     93 
     94bool VspKdTreeNode::IsLeaf() const  
     95{  
     96        return mAxis == -1;  
     97} 
     98   
     99int VspKdTreeNode::GetAccessTime()  
     100{ 
     101        return 0x7FFFFFF; 
     102} 
     103 
     104/**************************************************************/ 
    73105/*                VspKdTreeInterior implementation            */ 
    74106/**************************************************************/ 
     
    88120        mBack = b; 
    89121        mFront = f; 
    90         b->mParent = f->mParent = this; 
     122        b->SetParent(this); 
     123        f->SetParent(this); 
    91124} 
    92125 
     
    140173} 
    141174 
    142 /**************************************************/ 
    143 /*         class VspKdTree implementation         */ 
    144 /**************************************************/ 
     175 
     176/*********************************************************/ 
     177/*            class VspKdTreeLeaf implementation         */ 
     178/*********************************************************/ 
     179VspKdTreeLeaf::VspKdTreeLeaf(VspKdTreeInterior *p,      const int nRays): 
     180VspKdTreeNode(p), mRays(), mPvsSize(0), mValidPvs(false)  
     181{ 
     182        mRays.reserve(nRays); 
     183} 
     184 
     185VspKdTreeLeaf::~VspKdTreeLeaf()  
     186{} 
     187 
     188int VspKdTreeLeaf::Type() const   
     189{  
     190        return ELeaf;  
     191} 
     192 
     193void VspKdTreeLeaf::Print(ostream &s) const  
     194{ 
     195        s << endl << "L: r = " << (int)mRays.size() << endl; 
     196}; 
     197 
     198void VspKdTreeLeaf::AddRay(const RayInfo &data)  
     199{ 
     200        mValidPvs = false; 
     201        mRays.push_back(data); 
     202        data.mRay->Ref(); 
     203} 
     204 
     205int VspKdTreeLeaf::GetPvsSize() const  
     206{ 
     207        return mPvsSize; 
     208} 
     209 
     210void VspKdTreeLeaf::SetPvsSize(const int s)  
     211{ 
     212        mPvsSize = s; 
     213} 
     214 
     215void VspKdTreeLeaf::Mail() 
     216{  
     217        mMailbox = mailID;  
     218} 
     219 
     220void VspKdTreeLeaf::NewMail()  
     221{  
     222        ++ mailID;  
     223} 
     224 
     225bool VspKdTreeLeaf::Mailed() const  
     226{  
     227        return mMailbox == mailID;  
     228} 
     229 
     230bool VspKdTreeLeaf::Mailed(const int mail)  
     231{ 
     232        return mMailbox >= mailID + mail; 
     233} 
     234 
     235float VspKdTreeLeaf::GetAvgRayContribution() const  
     236{ 
     237        return GetPvsSize() / ((float)mRays.size() + Limits::Small); 
     238} 
     239 
     240float VspKdTreeLeaf::GetSqrRayContribution() const  
     241{ 
     242        return sqr(GetAvgRayContribution()); 
     243} 
     244 
     245/*********************************************************/ 
     246/*            class VspKdTree implementation             */ 
     247/*********************************************************/ 
     248 
     249 
    145250void VspKdTree::ParseEnvironment() 
    146251{ 
     
    271376                Intersectable::NewMail(); 
    272377                int pvsSize = 0; 
    273                 for(VspKdTreeNode::RayInfoContainer::iterator ri = rays.begin();  
    274                         ri != rays.end(); ++ ri) 
     378                for(RayInfoContainer::iterator ri = mRays.begin();  
     379                        ri != mRays.end(); ++ ri) 
    275380                { 
    276381                        if ((*ri).mRay->IsActive())  
     
    323428        for (VssRayContainer::const_iterator ri = rays.begin(); ri != rays.end(); ++ ri) 
    324429        { 
    325                 leaf->AddRay(VspKdTreeNode::RayInfo(*ri)); 
     430                leaf->AddRay(RayInfo(*ri)); 
    326431 
    327432                mBox.Include((*ri)->GetOrigin()); 
     
    334439        cout << "Bbox = " << mBox << endl; 
    335440         
    336         mStat.rays = (int)leaf->rays.size(); 
     441        mStat.rays = (int)leaf->mRays.size(); 
    337442        leaf->UpdatePvsSize(); 
    338443         
     
    467572        cout<< 
    468573                "pvs="<<leaf->mPvsSize<< 
    469                 " rays="<<leaf->rays.size()<< 
     574                " rays="<<leaf->mRays.size()<< 
    470575                " rc="<<leaf->GetAvgRayContribution()<< 
    471576                " axis="<<axis<<endl; 
     
    502607 
    503608        // this is the main ray classification loop! 
    504     for(VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    505                 ri != leaf->rays.end(); ri++) 
     609    for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 
     610                ri != leaf->mRays.end();        ri++) 
    506611        { 
    507612                if (!(*ri).mRay->IsActive())  
     
    533638         
    534639        //      cout<<axis<<" "<<pvsSize<<" "<<pvsBack<<" "<<pvsFront<<endl; 
    535         //  float oldCost = leaf->rays.size(); 
     640        //  float oldCost = leaf->mRays.size(); 
    536641        float oldCost = (float)pvsSize; 
    537642         
     
    616721        // C = ct_div_ci  + (ql*rl + qr*rr)/queries 
    617722         
    618         int rl=0, rr = (int)leaf->rays.size(); 
    619         int pl=0, pr = leaf->GetPvsSize(); 
     723        int rl = 0, rr = (int)leaf->mRays.size(); 
     724        int pl = 0, pr = leaf->GetPvsSize(); 
    620725        float minBox = box.Min(axis); 
    621726        float maxBox = box.Max(axis); 
     
    630735        Intersectable::NewMail(); 
    631736        // set all object as belonging to the fron pvs 
    632         for(VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    633                 ri != leaf->rays.end(); ++ ri) 
     737        for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 
     738                ri != leaf->mRays.end();        ++ ri) 
    634739        { 
    635740                if ((*ri).mRay->IsActive()) 
     
    724829        splitCandidates->clear(); 
    725830   
    726         int requestedSize = 2 * (int)(node->rays.size()); 
     831        int requestedSize = 2 * (int)(node->mRays.size()); 
    727832        // creates a sorted split candidates array 
    728833        if (splitCandidates->capacity() > 500000 && 
     
    736841 
    737842        // insert all queries  
    738         for(VspKdTreeNode::RayInfoContainer::const_iterator ri = node->rays.begin(); 
    739                 ri < node->rays.end(); ++ ri)  
     843        for(RayInfoContainer::const_iterator ri = node->mRays.begin(); 
     844                ri < node->mRays.end(); ++ ri)  
    740845        { 
    741846                bool positive = (*ri).mRay->HasPosDir(axis); 
     
    759864                ++ mStat.maxDepthNodes; 
    760865   
    761         //  if ( (int)(leaf->rays.size()) < termMinCost) 
     866        //  if ( (int)(leaf->mRays.size()) < termMinCost) 
    762867        //    stat.minCostNodes++; 
    763868        if (leaf->GetPvsSize() < sTermMinPvs) 
     
    773878                ++ mStat.minSizeNodes; 
    774879 
    775 //      if ((int)(leaf->rays.size()) > stat.maxRayRefs) 
    776 //              mStat.maxRayRefs = (int)leaf->rays.size(); 
     880//      if ((int)(leaf->mRays.size()) > stat.maxRayRefs) 
     881//              mStat.maxRayRefs = (int)leaf->mRays.size(); 
    777882} 
    778883 
     
    784889                                                                                AxisAlignedBox3 &frontBBox) 
    785890{ 
    786         if ( (leaf->GetPvsSize() < sTermMinPvs) || (leaf->rays.size() < sTermMinRays) || 
     891        if ( (leaf->GetPvsSize() < sTermMinPvs) || (leaf->mRays.size() < sTermMinRays) || 
    787892        // (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 
    788893       (leaf->mDepth >= sTermMaxDepth) || SqrMagnitude(box.Size()) <= sTermMinSize )  
     
    791896#if 0 
    792897                if (leaf->mDepth >= termMaxDepth) { 
    793                         cout<<"Warning: max depth reached depth="<<(int)leaf->mDepth<<" rays="<<leaf->rays.size()<<endl; 
     898                        cout<<"Warning: max depth reached depth="<<(int)leaf->mDepth<<" rays="<<leaf->mRays.size()<<endl; 
    794899                        cout<<"Bbox: "<<GetBBox(leaf)<<" dirbbox:"<<GetDirBBox(leaf)<<endl; 
    795900                } 
     
    846951                frontBBox.SetMin(axis, position); 
    847952                 
    848                 for(VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    849                                 ri != leaf->rays.end(); ri++)  
     953                for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 
     954                                ri != leaf->mRays.end(); ++ ri)  
    850955                { 
    851956                        if ((*ri).mRay->IsActive())  
     
    861966                                        if ((*ri).mRay->HasPosDir(axis))  
    862967                                        { 
    863                                                 back->AddRay(VspKdTreeNode::RayInfo((*ri).mRay, 
    864                                                                                                                         (*ri).mMinT, 
    865                                                                                                                         (*ri).mRay->mT)); 
    866                                                 front->AddRay(VspKdTreeNode::RayInfo((*ri).mRay, 
    867                                                                                                                         (*ri).mRay->mT, 
    868                                                                                                                         (*ri).mMaxT)); 
     968                                                back->AddRay(RayInfo((*ri).mRay, 
     969                                                                                         (*ri).mMinT, 
     970                                                                                         (*ri).mRay->mT)); 
     971                                                front->AddRay(RayInfo((*ri).mRay, 
     972                                                                                          (*ri).mRay->mT, 
     973                                                                                          (*ri).mMaxT)); 
    869974                                        }  
    870975                                        else  
    871976                                        { 
    872                                                 back->AddRay(VspKdTreeNode::RayInfo((*ri).mRay, 
    873                                                                                                                         (*ri).mRay->mT, 
    874                                                                                                                         (*ri).mMaxT)); 
    875                                                 front->AddRay(VspKdTreeNode::RayInfo((*ri).mRay, 
    876                                                                                                                         (*ri).mMinT, 
    877                                                                                                                         (*ri).mRay->mT)); 
     977                                                back->AddRay(RayInfo((*ri).mRay, 
     978                                                                                         (*ri).mRay->mT, 
     979                                                                                         (*ri).mMaxT)); 
     980                                                front->AddRay(RayInfo((*ri).mRay, 
     981                                                                                          (*ri).mMinT, 
     982                                                                                          (*ri).mRay->mT)); 
    878983                                        } 
    879984                                }  
     
    891996                // rays front/back 
    892997     
    893         for(VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    894                         ri != leaf->rays.end(); ++ ri)  
     998        for (RayInfoContainer::iterator ri = leaf->mRays.begin(); 
     999                        ri != leaf->mRays.end(); ++ ri)  
    8951000                { 
    8961001                        if ((*ri).mRay->IsActive())  
     
    9161021         
    9171022        // update stats 
    918         mStat.rayRefs -= (int)leaf->rays.size(); 
     1023        mStat.rayRefs -= (int)leaf->mRays.size(); 
    9191024        mStat.rayRefs += raysBack + raysFront; 
    9201025 
    921         delete leaf; 
     1026        DEL_PTR(leaf); 
     1027 
    9221028        return node; 
    9231029} 
     
    9291035        // find a node in the tree which subtree will be collapsed 
    9301036        int maxAccessTime = time - accessTimeThreshold; 
    931         int released; 
     1037        int released = 0; 
    9321038 
    9331039        tstack.push(mRoot); 
     
    9471053                                break; 
    9481054                        } 
    949                         if (in->GetBack()->GetAccessTime() <  in->GetFront()->GetAccessTime())  
     1055                        if (in->GetBack()->GetAccessTime() < in->GetFront()->GetAccessTime())  
    9501056                        { 
    9511057                                tstack.push(in->GetFront()); 
     
    9841090         
    9851091        // check if we should perform a dynamic subdivision of the leaf 
    986         if (// leaf->rays.size() > (unsigned)termMinCost && 
     1092        if (// leaf->mRays.size() > (unsigned)termMinCost && 
    9871093                (leaf->GetPvsSize() >= sTermMinPvs) &&  
    9881094                (SqrMagnitude(leafBBox.Size()) > sizeThreshold) ) 
     
    10421148        stack<RayTraversalData> tstack; 
    10431149 
    1044         tstack.push(RayTraversalData(mRoot, VspKdTreeNode::RayInfo(ray))); 
     1150        tstack.push(RayTraversalData(mRoot, RayInfo(ray))); 
    10451151   
    10461152        RayTraversalData data; 
     
    10561162                        // split the set of rays in two groups intersecting the 
    10571163                        // two subtrees 
    1058  
    10591164                        TraverseInternalNode(data, tstack); 
    10601165        }  
     
    10741179                                if (removeAllScheduledRays)  
    10751180                                { 
    1076                                         int tail = (int)leaf->rays.size() - 1; 
    1077  
    1078                                         for (int i=0; i < (int)(leaf->rays.size()); ++ i)  
     1181                                        int tail = (int)leaf->mRays.size() - 1; 
     1182 
     1183                                        for (int i=0; i < (int)(leaf->mRays.size()); ++ i)  
    10791184                                        { 
    1080                                                 if (leaf->rays[i].mRay->ScheduledForRemoval())  
     1185                                                if (leaf->mRays[i].mRay->ScheduledForRemoval())  
    10811186                                                { 
    10821187                                                        // find a ray to replace it with 
    1083                                                         while (tail >= i && leaf->rays[tail].mRay->ScheduledForRemoval())  
     1188                                                        while (tail >= i && leaf->mRays[tail].mRay->ScheduledForRemoval())  
    10841189                                                        { 
    10851190                                                                ++ mStat.removedRayRefs; 
    1086                                                                 leaf->rays[tail].mRay->Unref(); 
    1087                                                                 leaf->rays.pop_back(); 
     1191                                                                leaf->mRays[tail].mRay->Unref(); 
     1192                                                                leaf->mRays.pop_back(); 
    10881193                                                                 
    10891194                                                                -- tail; 
     
    10951200                                                        ++ mStat.removedRayRefs; 
    10961201               
    1097                                                         leaf->rays[i].mRay->Unref(); 
    1098                                                         leaf->rays[i] = leaf->rays[tail]; 
    1099                                                         leaf->rays.pop_back(); 
     1202                                                        leaf->mRays[i].mRay->Unref(); 
     1203                                                        leaf->mRays[i] = leaf->mRays[tail]; 
     1204                                                        leaf->mRays.pop_back(); 
    11001205                                                        -- tail; 
    11011206                                                } 
     
    11051210       
    11061211                        if (!removeAllScheduledRays) 
    1107                                 for (int i=0; i < (int)leaf->rays.size(); i++)  
     1212                                for (int i=0; i < (int)leaf->mRays.size(); i++)  
    11081213                                { 
    1109                                         if (leaf->rays[i].mRay == ray)  
     1214                                        if (leaf->mRays[i].mRay == ray)  
    11101215                                        { 
    11111216                                                ++ mStat.removedRayRefs; 
    11121217                                                ray->Unref(); 
    1113                                                 leaf->rays[i] = leaf->rays[leaf->rays.size() - 1]; 
    1114                                                 leaf->rays.pop_back(); 
     1218                                                leaf->mRays[i] = leaf->mRays[leaf->mRays.size() - 1]; 
     1219                                                leaf->mRays.pop_back(); 
    11151220                                            // check this ray again 
    11161221                                                break; 
     
    11321237        stack<RayTraversalData> tstack; 
    11331238   
    1134         tstack.push(RayTraversalData(mRoot, VspKdTreeNode::RayInfo(ray))); 
     1239        tstack.push(RayTraversalData(mRoot, RayInfo(ray))); 
    11351240   
    11361241        RayTraversalData data; 
     
    11481253                { 
    11491254                        // remove the ray from the leaf 
    1150                         // find the ray in the leaf and swap it with the last ray... 
    1151                         VspKdTreeLeaf *leaf = (VspKdTreeLeaf *)data.mNode; 
     1255                        // find the ray in the leaf and swap it with the last ray 
     1256                        VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(data.mNode); 
    11521257                        leaf->AddRay(data.mRayData); 
    11531258                        ++ mStat.addedRayRefs; 
     
    11711276                { 
    11721277                        tstack.push(RayTraversalData(in->GetBack(),  
    1173                                                 VspKdTreeNode::RayInfo(data.mRayData.mRay, data.mRayData.mMinT,  
    1174                                                                                            data.mRayData.mRay->mT))); 
     1278                                                RayInfo(data.mRayData.mRay, data.mRayData.mMinT, data.mRayData.mRay->mT))); 
    11751279                                 
    11761280                        tstack.push(RayTraversalData(in->GetFront(), 
    1177                                                 VspKdTreeNode::RayInfo(data.mRayData.mRay, data.mRayData.mRay->mT,  
    1178                                                                                            data.mRayData.mMaxT))); 
     1281                                                RayInfo(data.mRayData.mRay, data.mRayData.mRay->mT, data.mRayData.mMaxT))); 
    11791282         
    11801283                }  
     
    11821285                { 
    11831286                        tstack.push(RayTraversalData(in->GetBack(), 
    1184                                                                                  VspKdTreeNode::RayInfo(data.mRayData.mRay, 
    1185                                                                                                                                 data.mRayData.mRay->mT, 
    1186                                                                                                                                 data.mRayData.mMaxT))); 
     1287                                                                                 RayInfo(data.mRayData.mRay, 
     1288                                                                                                 data.mRayData.mRay->mT, 
     1289                                                                                                 data.mRayData.mMaxT))); 
    11871290                        tstack.push(RayTraversalData(in->GetFront(), 
    1188                                                                                  VspKdTreeNode::RayInfo(data.mRayData.mRay, 
    1189                                                                                                                                 data.mRayData.mMinT, 
    1190                                                                                                                                 data.mRayData.mRay->mT))); 
     1291                                                                                 RayInfo(data.mRayData.mRay, 
     1292                                                                                                 data.mRayData.mMinT, 
     1293                                                                                                 data.mRayData.mRay->mT))); 
    11911294                } 
    11921295          }  
     
    12191322 
    12201323#if DEBUG_COLLAPSE 
    1221         cout<<"Collapsing subtree"<<endl; 
    1222         cout<<"acessTime="<<sroot->GetAccessTime()<<endl; 
    1223         cout<<"depth="<<(int)sroot->depth<<endl; 
     1324        cout << "Collapsing subtree" << endl; 
     1325        cout << "acessTime=" << sroot->GetAccessTime() << endl; 
     1326        cout << "depth=" << (int)sroot->depth << endl; 
    12241327#endif 
    12251328 
     
    12401343                        VspKdTreeLeaf *leaf = (VspKdTreeLeaf *) node; 
    12411344                         
    1242                         for(VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    1243                                         ri != leaf->rays.end(); ++ ri)  
     1345                        for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 
     1346                                        ri != leaf->mRays.end(); ++ ri)  
    12441347                        { 
    12451348                                ++ totalRayCount; 
     
    12781381                        VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(node); 
    12791382 
    1280                         for(VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    1281                                         ri != leaf->rays.end(); ++ ri)  
     1383                        for(RayInfoContainer::iterator ri = leaf->mRays.begin(); 
     1384                                        ri != leaf->mRays.end(); ++ ri)  
    12821385                        { 
    12831386                                // unref this ray from the old node              
     
    13051408   
    13061409        // delete the node and all its children 
    1307         delete sroot; 
    1308    
    1309         // for(VspKdTreeNode::SRayContainer::iterator ri = newLeaf->rays.begin(); 
    1310     //      ri != newLeaf->rays.end(); ++ ri) 
     1410        DEL_PTR(sroot); 
     1411   
     1412        // for(VspKdTreeNode::SRayContainer::iterator ri = newleaf->mRays.begin(); 
     1413    //      ri != newleaf->mRays.end(); ++ ri) 
    13111414        //     (*ri).ray->UnMail(2); 
    13121415 
     
    13471450                { 
    13481451                        VspKdTreeLeaf *leaf = (VspKdTreeLeaf *)node; 
    1349                         for (VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 
    1350                                 ri != leaf->rays.end(); ++ ri) 
     1452                        for (RayInfoContainer::iterator ri = leaf->mRays.begin(); 
     1453                                 ri != leaf->mRays.end(); ++ ri) 
    13511454                        { 
    13521455                                if ((*ri).mRay->IsActive())  
     
    15481651        return mStat; 
    15491652} 
     1653 
     1654void VspKdTree::AddRays(VssRayContainer &add) 
     1655{ 
     1656        VssRayContainer remove; 
     1657        UpdateRays(remove, add); 
     1658} 
     1659  
     1660// return memory usage in MB 
     1661float VspKdTree::GetMemUsage() const  
     1662{ 
     1663        return  
     1664                (sizeof(VspKdTree) +  
     1665                 mStat.Leaves() * sizeof(VspKdTreeLeaf) + 
     1666                 mStat.Interior() * sizeof(VspKdTreeInterior) + 
     1667                 mStat.rayRefs * sizeof(RayInfo)) / (1024.0f * 1024.0f); 
     1668} 
     1669         
     1670float VspKdTree::GetRayMemUsage() const  
     1671{ 
     1672        return mStat.rays * (sizeof(VssRay))/(1024.0f * 1024.0f); 
     1673} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h

    r419 r420  
    3131#include "Ray.h" 
    3232 
    33 // -------------------------------------------------------------- 
    34 // Static statistics for kd-tree search 
    35 // -------------------------------------------------------------- 
     33#include "RayInfo.h" 
     34 
     35 
     36/** 
     37        Static statistics for vsp kd-tree search 
     38*/ 
    3639class VspKdStatistics:  public StatisticsBase 
    3740{ 
    3841public:   
    39   // total number of nodes 
    40   int nodes; 
    41   // number of splits along each of the axes 
    42   int splits[7]; 
    43   // totals number of rays 
    44   int rays; 
     42        // total number of nodes 
     43        int nodes; 
     44        // number of splits along each of the axes 
     45        int splits[7]; 
     46        // totals number of rays 
     47        int rays; 
    4548        // initial size of the pvs 
    46   int initialPvsSize; 
     49        int initialPvsSize; 
    4750        // total number of query domains 
    48   int queryDomains; 
    49   // total number of ray references 
    50   int rayRefs; 
     51        int queryDomains; 
     52        // total number of ray references 
     53        int rayRefs; 
    5154 
    5255        // max depth nodes 
    53   int maxDepthNodes; 
    54   // max depth nodes 
    55   int minPvsNodes; 
    56   int minRaysNodes; 
     56        int maxDepthNodes; 
     57        // max depth nodes 
     58        int minPvsNodes; 
     59        int minRaysNodes; 
    5760        // max ray contribution nodes 
    58   int maxRayContribNodes; 
     61        int maxRayContribNodes; 
    5962        // max depth nodes 
    60   int minSizeNodes; 
    61          
    62   // max number of rays per node 
    63   int maxRayRefs; 
    64   // number of dynamically added ray refs 
    65   int addedRayRefs; 
    66   // number of dynamically removed ray refs 
    67   int removedRayRefs; 
    68    
    69   // Constructor 
    70   VspKdStatistics()  
    71   { 
    72           Reset(); 
    73   } 
    74  
    75   int Nodes() const {return nodes;} 
    76   int Interior() const { return nodes/2; } 
    77   int Leaves() const { return (nodes/2) + 1; } 
    78  
    79   void Reset()  
    80   { 
    81           nodes = 0; 
    82           for (int i=0; i<7; i++) 
    83                   splits[i] = 0; 
    84           rays = queryDomains = 0; 
    85           rayRefs = 0; 
    86           maxDepthNodes = 0; 
    87           minPvsNodes = 0; 
    88           minRaysNodes = 0;  
    89           maxRayRefs = 0; 
    90           addedRayRefs = removedRayRefs = 0; 
    91           initialPvsSize = 0; 
    92           maxRayContribNodes = 0; 
    93           minSizeNodes = 0; 
    94   } 
    95    
    96   void 
    97   Print(ostream &app) const; 
    98  
    99   friend ostream &operator<<(ostream &s, const VspKdStatistics &stat) { 
    100     stat.Print(s); 
    101     return s; 
    102   } 
    103    
     63        int minSizeNodes; 
     64         
     65        // max number of rays per node 
     66        int maxRayRefs; 
     67        // number of dynamically added ray refs 
     68        int addedRayRefs; 
     69        // number of dynamically removed ray refs 
     70        int removedRayRefs; 
     71   
     72        /** Default constructor. 
     73        */ 
     74        VspKdStatistics() {     Reset(); } 
     75        int Nodes() const { return nodes; } 
     76        int Interior() const { return nodes / 2; } 
     77        int Leaves() const { return (nodes / 2) + 1; } 
     78 
     79        void Reset()  
     80        { 
     81                nodes = 0; 
     82 
     83                for (int i=0; i<7; i++) 
     84                        splits[i] = 0; 
     85 
     86                rays = queryDomains = 0; 
     87                rayRefs = 0; 
     88                maxDepthNodes = 0; 
     89                minPvsNodes = 0; 
     90                minRaysNodes = 0;  
     91                maxRayRefs = 0; 
     92                addedRayRefs = removedRayRefs = 0; 
     93                initialPvsSize = 0; 
     94                maxRayContribNodes = 0; 
     95                minSizeNodes = 0; 
     96        } 
     97 
     98        void Print(ostream &app) const; 
     99        friend ostream &operator<<(ostream &s, const VspKdStatistics &stat)  
     100        { 
     101            stat.Print(s); 
     102            return s; 
     103        }   
    104104}; 
    105105 
     
    108108 
    109109 
    110 // -------------------------------------------------------------- 
    111 // KD-tree node - abstract class 
    112 // -------------------------------------------------------------- 
     110/** Abstract superclass of Vsp-Kd-Tree nodes. 
     111*/ 
    113112class VspKdTreeNode 
    114113{ 
     
    118117#define USE_FIXEDPOINT_T 1 
    119118 
    120 struct RayInfo 
    121 { 
    122         // pointer to the actual ray 
    123         VssRay *mRay; 
    124          
    125         // endpoints  - do we need them? 
    126 #if USE_FIXEDPOINT_T 
    127         short mMinT, mMaxT; 
    128 #else 
    129         float mMinT, mMaxT; 
    130 #endif 
    131          
    132         RayInfo():mRay(NULL) {} 
    133          
    134         RayInfo(VssRay *r):mRay(r), mMinT(0), 
    135 #if USE_FIXEDPOINT_T 
    136 #define FIXEDPOINT_ONE 0x7FFE 
    137         // mMaxT(0xFFFF) 
    138                 mMaxT(FIXEDPOINT_ONE) 
    139 #else 
    140                 mMaxT(1.0f) 
    141 #endif 
    142         {} 
    143          
    144         RayInfo(VssRay *r, 
    145                         const float _min, 
    146                         const float _max 
    147                         ):mRay(r)  
    148         { 
    149                 SetMinT(_min); 
    150                 SetMaxT(_max); 
    151         } 
    152          
    153         RayInfo(VssRay *r, 
    154                         const short _min, 
    155                         const float _max):mRay(r), mMinT(_min)  
    156         { 
    157                 SetMaxT(_max); 
    158         } 
    159          
    160         RayInfo(VssRay *r, 
    161                         const float _min, 
    162                         const short _max): 
    163         mRay(r), mMaxT(_max)  
    164         { 
    165                 SetMinT(_min); 
    166         } 
    167          
    168         friend bool operator<(const RayInfo &a, const RayInfo &b) { 
    169                 return a.mRay < b.mRay; 
    170         } 
    171    
    172          
    173         float ExtrapOrigin(const int axis) const { 
    174                 return mRay->GetOrigin(axis) + GetMinT()*mRay->GetDir(axis); 
    175         } 
    176          
    177         float ExtrapTermination(const int axis) const { 
    178                 return mRay->GetOrigin(axis) + GetMaxT()*mRay->GetDir(axis); 
    179         } 
    180          
    181 #if USE_FIXEDPOINT_T 
    182         float GetMinT () const { return mMinT/(float)(FIXEDPOINT_ONE); } 
    183         float GetMaxT () const { return mMaxT/(float)(FIXEDPOINT_ONE); } 
    184          
    185         void SetMinT (const float t) { 
    186                 mMinT = (short) (t*(float)(FIXEDPOINT_ONE)); 
    187         } 
    188          
    189         void SetMaxT (const float t) { 
    190                 mMaxT = (short) (t*(float)(FIXEDPOINT_ONE)); 
    191                 mMaxT++; 
    192                 //      if (mMaxT!=0xFFFF) 
    193                 //      mMaxT++; 
    194         } 
    195 #else 
    196         float GetMinT () const { return mMinT; } 
    197         float GetMaxT () const { return mMaxT; } 
    198          
    199         void SetMinT (const float t) { mMinT = t; } 
    200         void SetMaxT (const float t) { mMaxT = t; } 
    201 #endif  
    202  
    203  
    204         int ComputeRayIntersection(const int axis, const float position, float &t) const  
    205         {                
    206                 // intersect the ray with the plane 
    207                 float denom = mRay->GetDir(axis); 
    208      
    209                 if (fabs(denom) < 1e-20) 
    210                         //if (denom == 0.0f) 
    211                         return (mRay->GetOrigin(axis) > position) ? 1 : -1; 
    212      
    213                 t = (position - mRay->GetOrigin(axis))/denom; 
    214  
    215                 if (t < GetMinT()) 
    216                         return (denom > 0) ? 1 : -1; 
    217  
    218                 if (t > GetMaxT()) 
    219                         return (denom > 0) ? -1 : 1; 
    220  
    221                 return 0; 
    222         } 
    223  
    224  
    225 }; 
    226  
    227  
    228 typedef vector<RayInfo> RayInfoContainer; 
    229  
    230 enum {EInterior, ELeaf}; 
    231  
    232   ///////////////////////////////// 
    233   // The actual data goes here 
    234    
    235   // link to the parent 
    236   VspKdTreeInterior *mParent; 
    237  
    238   enum {SPLIT_X=0, SPLIT_Y, SPLIT_Z, SPLIT_DIRX, SPLIT_DIRY, SPLIT_DIRZ}; 
    239    
    240   // splitting axis 
    241   char mAxis; 
    242          
    243   // depth 
    244   unsigned char mDepth; 
    245    
    246   //  short depth; 
    247   // 
    248   ///////////////////////////////// 
    249    
    250   inline VspKdTreeNode(VspKdTreeInterior *p); 
    251  
    252    
    253   virtual ~VspKdTreeNode() {}; 
    254   virtual int Type() const = 0; 
    255    
    256  
    257   bool IsLeaf() const { return mAxis == -1; } 
    258    
    259   virtual void Print(ostream &s) const = 0; 
    260  
    261   virtual int GetAccessTime()  
    262   { 
    263           return 0x7FFFFFF; 
    264   } 
    265  
    266    
    267          
     119        enum {EInterior, ELeaf}; 
     120 
     121        /** Constructs new interior node from the parent node. 
     122        */ 
     123        inline VspKdTreeNode(VspKdTreeInterior *p); 
     124 
     125        /** Destroys this node and the subtree. 
     126        */ 
     127        virtual ~VspKdTreeNode(); 
     128 
     129        /** Type of the node (Einterior or ELeaf) 
     130        */ 
     131        virtual int Type() const = 0; 
     132  
     133        /** Returns true if this node is a leaf. 
     134        */ 
     135        bool IsLeaf() const; 
     136         
     137        /** Prints node stats. 
     138        */ 
     139        virtual void Print(ostream &s) const = 0; 
     140 
     141        /** Returns time needed to access this node. 
     142        */ 
     143        virtual int GetAccessTime(); // NOTE: don't really know how it is used! 
     144 
     145        /** Returns parent node. 
     146        */ 
     147        VspKdTreeInterior *GetParent() const; 
     148        /** Sets parent node. 
     149        */ 
     150        void SetParent(VspKdTreeInterior *p); 
     151 
     152protected: 
     153        ///////////////////////////////// 
     154        // The actual data goes here 
     155   
     156        /// link to the parent 
     157        VspKdTreeInterior *mParent; 
     158 
     159        enum {SPLIT_X = 0, SPLIT_Y, SPLIT_Z, SPLIT_DIRX, SPLIT_DIRY, SPLIT_DIRZ}; 
     160   
     161        /// splitting axis 
     162        char mAxis; 
     163         
     164        /// depth 
     165        unsigned char mDepth; 
    268166}; 
    269167 
     
    276174        friend class VspKdTree; 
    277175 
     176        /** Constructs new interior node from parent node. 
     177        */ 
    278178        VspKdTreeInterior(VspKdTreeInterior *p); 
    279179                         
     
    286186        virtual void Print(ostream &s) const; 
    287187 
     188        /** Returns back child. 
     189        */ 
    288190        inline VspKdTreeNode *GetBack() const; 
     191        /** Returns front child. 
     192        */ 
    289193        inline VspKdTreeNode *GetFront() const; 
    290194 
    291195protected: 
    292196 
     197        /** Sets pointers to back child and front child. 
     198        */ 
    293199        void SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f); 
    294   
     200 
     201        /** Replaces the pointer to oldChild with a pointer to newChild. 
     202        */ 
    295203        void ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild); 
    296204  
     205        /** Computes intersection of the ray with the node boundaries. 
     206        */ 
    297207        int ComputeRayIntersection(const RayInfo &rayData, float &t); 
    298208 
     
    321231        friend class VspKdTree; 
    322232 
     233        /** Constructs leaf from parent node. 
     234                @param p the parent node 
     235                @param nRays preallocates memory to store this number of rays 
     236        */ 
     237        VspKdTreeLeaf(VspKdTreeInterior *p,     const int nRays); 
     238         
     239        virtual ~VspKdTreeLeaf(); 
     240 
     241        virtual int Type() const;   
     242 
     243        virtual void Print(ostream &s) const; 
     244   
     245        /** Adds a ray to the leaf ray container. 
     246        */ 
     247        void AddRay(const RayInfo &data); 
     248        /** Returns size of the leaf PVS as induced by the rays 
     249                @note returns precomputed PVS size, which may not be valid 
     250                anymore. Run UpdatePvsSize to get a valid PVS. 
     251        */ 
     252        int GetPvsSize() const; 
     253        void SetPvsSize(const int s); 
     254 
     255        /** If PVS is not valid, this function recomputes the leaf  
     256                PVS as induced by the rays. 
     257        */ 
     258        void UpdatePvsSize(); 
     259 
     260        void Mail(); 
     261 
     262        bool Mailed() const; 
     263   
     264        bool Mailed(const int mail); 
     265 
     266        /** Returns average contribution of a ray to the PVS 
     267        */ 
     268        inline float GetAvgRayContribution() const; 
     269        /** Returns square of average contribution of a ray. 
     270        */ 
     271        inline float GetSqrRayContribution() const; 
     272 
     273        static void NewMail(); 
     274 
    323275        static int mailID; 
    324         int mailbox; 
    325    
    326         RayInfoContainer rays; 
     276 
     277protected: 
     278         
     279        int mMailbox; 
     280   
     281        RayInfoContainer mRays; 
    327282        bool mValidPvs; 
    328283         
    329         VspKdTreeLeaf(VspKdTreeInterior *p,     const int nRays): 
    330         VspKdTreeNode(p), rays(), mPvsSize(0), mValidPvs(false)  
    331         { 
    332                 rays.reserve(nRays); 
    333         } 
    334          
    335         virtual ~VspKdTreeLeaf() { } 
    336  
    337         virtual int Type() const   
    338         {  
    339                 return ELeaf;  
    340         } 
    341  
    342         virtual void Print(ostream &s) const  
    343         { 
    344                 s << endl << "L: r = " << (int)rays.size() << endl; 
    345         }; 
    346    
    347         void AddRay(const RayInfo &data)  
    348         { 
    349                 mValidPvs = false; 
    350                 rays.push_back(data); 
    351                 data.mRay->Ref(); 
    352         } 
    353          
    354         int GetPvsSize() const  
    355         { 
    356                 return mPvsSize; 
    357         } 
    358         void SetPvsSize(const int s)  
    359         { 
    360                 mPvsSize = s; 
    361         } 
    362  
    363         void UpdatePvsSize(); 
    364  
    365         void Mail()  
    366         {  
    367                 mailbox = mailID;  
    368         } 
    369    
    370         static void NewMail()  
    371         {  
    372                 ++ mailID;  
    373         } 
    374    
    375         bool Mailed() const  
    376         {  
    377                 return mailbox == mailID;  
    378         } 
    379    
    380         bool Mailed(const int mail)  
    381         { 
    382                 return mailbox >= mailID + mail; 
    383         } 
    384  
    385         float GetAvgRayContribution() const  
    386         { 
    387                 return GetPvsSize()/((float)rays.size() + Limits::Small); 
    388         } 
    389  
    390         float GetSqrRayContribution() const  
    391         { 
    392                 return sqr(GetPvsSize()/((float)rays.size() + Limits::Small)); 
    393         } 
    394284private: 
    395285        int mPvsSize; 
    396286}; 
    397  
    398 // Inline functions 
    399 inline VspKdTreeNode::VspKdTreeNode(VspKdTreeInterior *p): 
    400 mParent(p), mAxis(-1), mDepth(p ? p->mDepth + 1 : 0)  
    401 {} 
    402287 
    403288 
     
    501386  }; 
    502387   
    503   // simplified data for ray traversal only... 
    504  
     388  /** Simplified data for ray traversal only. 
     389  */ 
    505390  struct RayTraversalData  
    506391  { 
    507           VspKdTreeNode::RayInfo mRayData; 
     392          RayInfo mRayData; 
    508393          VspKdTreeNode *mNode; 
    509394       
    510395          RayTraversalData() {} 
    511396           
    512           RayTraversalData(VspKdTreeNode *n, const VspKdTreeNode::RayInfo &data): 
     397          RayTraversalData(VspKdTreeNode *n, const RayInfo &data): 
    513398          mRayData(data), mNode(n) {} 
    514399  }; 
     
    521406        virtual void Construct(VssRayContainer &rays, 
    522407                                                   AxisAlignedBox3 *forcedBoundingBox = NULL); 
    523          
    524         // incemental construction 
     408 
     409        /** Returns bounding box of the specified node. 
     410        */ 
     411        AxisAlignedBox3 GetBBox(VspKdTreeNode *node) const; 
     412 
     413        const VspKdStatistics &GetStatistics() const; 
     414 
     415        /** Get the root of the tree. 
     416        */ 
     417        VspKdTreeNode *GetRoot() const; 
     418 
     419        /** Returns average PVS size in tree. 
     420        */ 
     421        float GetAvgPvsSize(); 
     422 
     423        /** Parses the environment and stores the global VspKd tree parameters 
     424        */ 
     425        static void ParseEnvironment(); 
     426 
     427        ///////////////////////////// 
     428        // Construction parameters 
     429 
     430        /// max depth of the tree 
     431        static int sTermMaxDepth; 
     432 
     433        /// minimal ratio of the volume of the cell and the query volume 
     434        static float sTermMinSize; 
     435 
     436        /// minimal pvs per node to still get subdivided 
     437        static int sTermMinPvs; 
     438 
     439        /// minimal ray number per node to still get subdivided 
     440        static int sTermMinRays; 
     441         
     442        /// maximal cost ration to subdivide a node 
     443        static float sTermMaxCostRatio; 
     444         
     445        /// maximal contribution per ray to subdivide the node 
     446        static float sTermMaxRayContribution; 
     447 
     448        /** Returns memory usage in MB. 
     449        */ 
     450        float GetMemUsage() const; 
     451         
     452        float GetRayMemUsage() const; 
     453 
     454protected: 
     455        // incremental construction 
    525456        virtual void UpdateRays(VssRayContainer &remove, VssRayContainer &add); 
    526457 
    527         virtual void AddRays(VssRayContainer &add) 
    528         { 
    529                 VssRayContainer remove; 
    530                 UpdateRays(remove, add); 
    531         } 
     458        virtual void AddRays(VssRayContainer &add); 
    532459 
    533460        VspKdTreeNode *Locate(const Vector3 &v); 
     
    549476 
    550477        void SortSplitCandidates(VspKdTreeLeaf *node, 
    551                                                          const int axis); 
    552          
    553    
    554         // return memory usage in MB 
    555         float GetMemUsage() const  
    556         { 
    557                 return  
    558                         (sizeof(VspKdTree) +  
    559                          mStat.Leaves() * sizeof(VspKdTreeLeaf) + 
    560                          mStat.Interior() * sizeof(VspKdTreeInterior) + 
    561                          mStat.rayRefs * sizeof(VspKdTreeNode::RayInfo)) / (1024.0f*1024.0f); 
    562         } 
    563          
    564         float GetRayMemUsage() const  
    565         { 
    566                 return mStat.rays * (sizeof(VssRay))/(1024.0f * 1024.0f); 
    567         } 
     478                                                         const int axis);        
    568479   
    569480        float BestCostRatioHeuristic(VspKdTreeLeaf *node, 
     
    591502                                                int &pvsFront); 
    592503 
    593         AxisAlignedBox3 GetBBox(VspKdTreeNode *node) const;      
    594504 
    595505        VspKdTreeNode * SubdivideLeaf(VspKdTreeLeaf *leaf, 
     
    619529                                         SimpleRayContainer &rays); 
    620530 
    621         float GetAvgPvsSize(); 
    622  
    623         /** Get the root of the tree. 
    624         */ 
    625         VspKdTreeNode *GetRoot() const; 
    626  
    627531        int CollapseSubtree(VspKdTreeNode *sroot, const int time); 
    628  
    629         const VspKdStatistics &GetStatistics() const; 
    630532         
    631533        int ReleaseMemory(const int time); 
    632  
    633         /** Parses the environment and stores the global BSP tree parameters 
    634         */ 
    635         static void ParseEnvironment(); 
    636  
    637         ///////////////////////////// 
    638         // Construction parameters 
    639  
    640         // max depth of the tree 
    641         static int sTermMaxDepth; 
    642  
    643         // minimal ratio of the volume of the cell and the query volume 
    644         static float sTermMinSize; 
    645  
    646         // minimal pvs per node to still get subdivided 
    647         static int sTermMinPvs; 
    648  
    649         // minimal ray number per node to still get subdivided 
    650         static int sTermMinRays; 
    651          
    652         // maximal cost ration to subdivide a node 
    653         static float sTermMaxCostRatio; 
    654          
    655         // maximal contribution per ray to subdivide the node 
    656         static float sTermMaxRayContribution; 
    657534 
    658535protected: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r419 r420  
    2323  environment->Parse(argc, argv, USE_EXE_PATH); 
    2424  MeshKdTree::ParseEnvironment(); 
    25   BspTree::ParseEnvironment(); 
     25   
    2626  VspKdTree::ParseEnvironment(); 
    2727 
     
    6363  // a certain number of rays collected 
    6464  if (ViewCell::sHierarchy == ViewCell::BSP && 
    65           !(BspTree::sConstructionMethod == BspTree::FROM_RAYS))  
     65          !(BspTree::mConstructionMethod == BspTree::FROM_RAYS))  
    6666  { 
    67           if (BspTree::sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS) 
     67          if (BspTree::mConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS) 
    6868          { 
    6969                  // view cells input file name 
Note: See TracChangeset for help on using the changeset viewer.