Changeset 1287


Ignore:
Timestamp:
08/27/06 23:39:50 (18 years ago)
Author:
mattausch
Message:

implemented bv hierarchy

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
21 edited

Legend:

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

    r1286 r1287  
    2525 
    2626static float debugVol = 0; 
    27 int BvhNode::sMailId = 0; 
     27int BvhNode::sMailId = 2147483647; 
    2828BvHierarchy *BvHierarchy::BvhSubdivisionCandidate::sBvHierarchy = NULL; 
    2929 
     
    4444 
    4545BvhNode::BvhNode(const AxisAlignedBox3 &bbox): 
    46 mBoundingBox(bbox) 
     46mParent(NULL), mBoundingBox(bbox) 
    4747{ 
    4848} 
     
    9191 
    9292 
    93 BvhLeaf::BvhLeaf(const AxisAlignedBox3 &bbox, BvhInterior *parent, const int numObjects): 
     93BvhLeaf::BvhLeaf(const AxisAlignedBox3 &bbox,  
     94                                 BvhInterior *parent,  
     95                                 const int numObjects): 
    9496BvhNode(bbox, parent) 
    9597{ 
     
    115117 
    116118BvhInterior::BvhInterior(const AxisAlignedBox3 &bbox): 
    117 BvhNode(bbox) 
     119BvhNode(bbox), mFront(NULL), mBack(NULL) 
    118120{ 
    119121} 
     
    121123 
    122124BvhInterior::BvhInterior(const AxisAlignedBox3 &bbox, BvhInterior *parent): 
    123 BvhNode(bbox, parent) 
     125BvhNode(bbox, parent), mFront(NULL), mBack(NULL) 
    124126{ 
    125127} 
     
    197199        Environment::GetSingleton()->GetIntValue("OspTree.Termination.maxLeaves", mTermMaxLeaves); 
    198200        Environment::GetSingleton()->GetIntValue("OspTree.Termination.minObjects", mTermMinObjects); 
    199         Environment::GetSingleton()->GetFloatValue("OspTree.Termination.minProbability", mTermMinVolume); 
     201        Environment::GetSingleton()->GetFloatValue("OspTree.Termination.minProbability", mTermMinProbability); 
    200202         
    201203        Environment::GetSingleton()->GetIntValue("OspTree.Termination.missTolerance", mTermMissTolerance); 
     
    233235 
    234236    Debug << "max depth: " << mTermMaxDepth << endl; 
    235         Debug << "min probabiliy: " << mTermMinVolume<< endl; 
     237        Debug << "min probabiliy: " << mTermMinProbability<< endl; 
    236238        Debug << "min objects: " << mTermMinObjects << endl; 
    237239        Debug << "max cost ratio: " << mTermMaxCostRatio << endl; 
     
    278280        BvhInterior *node = new BvhInterior(tData.mBoundingBox, leaf->GetParent()); 
    279281 
     282        cout << "here55 " << tData.mBoundingBox << " | " << node->GetBoundingBox() << endl; 
    280283 
    281284        //-- the front and back traversal data is filled with the new values 
    282285 
    283286        frontData.mDepth = backData.mDepth = tData.mDepth + 1; 
    284                  
    285         // frontData.mRays = new RayInfoContainer(); 
    286         // backData.mRays = new RayInfoContainer(); 
    287  
    288         frontData.mBoundingBox = ComputeBoundingBox(frontObjects); 
    289         backData.mBoundingBox = ComputeBoundingBox(backObjects); 
     287 
     288        frontData.mBoundingBox = ComputeBoundingBox(frontObjects, &(tData.mBoundingBox)); 
     289        backData.mBoundingBox = ComputeBoundingBox(backObjects, &(tData.mBoundingBox)); 
    290290        //RemoveParentViewCellsPvs(leaf, *tData.mRays); 
    291  
    292291 
    293292        ///////////// 
    294293        //-- create front and back leaf 
    295294 
    296         BvhLeaf *back = new BvhLeaf(backData.mBoundingBox, node, (int)backObjects.size()); 
    297         BvhLeaf *front = new BvhLeaf(frontData.mBoundingBox, node, (int)frontObjects.size()); 
     295        BvhLeaf *back =  
     296                new BvhLeaf(backData.mBoundingBox, node, (int)backObjects.size()); 
     297        BvhLeaf *front =  
     298                new BvhLeaf(frontData.mBoundingBox, node, (int)frontObjects.size()); 
    298299 
    299300        BvhInterior *parent = leaf->GetParent(); 
     
    333334        AssociateObjectsWithLeaf(front); 
    334335    
    335  
    336336        // compute probability, i.e., volume of seen view cells 
    337         frontData.mVolume = frontData.mBoundingBox.GetVolume(); 
    338         backData.mVolume =  backData.mBoundingBox.GetVolume(); 
     337        frontData.mProbability = EvalViewCellsVolume(frontObjects); 
     338        backData.mProbability = EvalViewCellsVolume(backObjects); 
    339339 
    340340        return node; 
     
    371371                tBackData.mMaxCostMisses = maxCostMisses; 
    372372                 
     373                // decrease the weighted average cost of the subdivisoin 
    373374                mTotalCost -= sc->GetRenderCostDecrease(); 
    374375 
    375376                // subdivision statistics 
    376                 if (1) EvalSubdivisionStats(*sc); 
     377                if (1) PrintSubdivisionStats(*sc); 
    377378 
    378379                //-- push the new split candidates on the queue 
    379380                 
    380                 BvhSubdivisionCandidate *frontCandidate = new BvhSubdivisionCandidate(tFrontData); 
    381                 BvhSubdivisionCandidate *backCandidate = new BvhSubdivisionCandidate(tBackData); 
     381                BvhSubdivisionCandidate *frontCandidate =  
     382                        new BvhSubdivisionCandidate(tFrontData); 
     383                BvhSubdivisionCandidate *backCandidate =  
     384                        new BvhSubdivisionCandidate(tBackData); 
    382385 
    383386                EvalSubdivisionCandidate(*frontCandidate); 
     
    416419void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate) 
    417420{ 
    418         ObjectContainer frontObjects, backObjects; 
    419  
    420421        // compute best object partition 
    421         const float ratio = 
    422                 SelectObjectPartition(splitCandidate.mParentData, frontObjects, backObjects); 
    423  
     422        const float ratio =     SelectObjectPartition( 
     423                                                        splitCandidate.mParentData,  
     424                                                        splitCandidate.mFrontObjects,  
     425                                                        splitCandidate.mBackObjects); 
     426         
    424427        const bool success = ratio < mTermMaxCostRatio; 
    425428 
    426         float oldRenderCost; 
     429        BvhLeaf *leaf = splitCandidate.mParentData.mNode; 
     430 
     431        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     432 
     433        const float oldRenderCost =  
     434                splitCandidate.mParentData.mProbability * (float)leaf->mObjects.size() / viewSpaceVol; 
    427435 
    428436        // compute global decrease in render cost 
    429         const float renderCostDecr = EvalRenderCostDecrease(frontObjects,  
    430                                                                                                                 backObjects, 
    431                                                                                                                 splitCandidate.mParentData, 
    432                                                                                                                 oldRenderCost); 
    433  
     437        float newRenderCost = EvalRenderCost(splitCandidate.mParentData, 
     438                                                                             splitCandidate.mFrontObjects,  
     439                                                                                 splitCandidate.mBackObjects); 
     440 
     441        newRenderCost /=  viewSpaceVol; 
     442 
     443        const float renderCostDecr = oldRenderCost - newRenderCost; 
     444 
     445        Debug << "!!render cost decr: " << renderCostDecr << endl; 
    434446        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
    435447 
     
    488500        } 
    489501 
    490         if (data.mVolume <= mTermMinVolume) 
     502        if (data.mProbability <= mTermMinProbability) 
    491503                ++ mBvhStats.minProbabilityNodes; 
    492504         
     
    502514 
    503515 
     516float BvHierarchy::EvalLocalObjectPartition(const BvhTraversalData &tData, 
     517                                                                                        const int axis, 
     518                                                                                        ObjectContainer &objectsFront, 
     519                                                                                        ObjectContainer &objectsBack) 
     520{ 
     521        const float maxBox = tData.mBoundingBox.Max(axis); 
     522        const float minBox = tData.mBoundingBox.Min(axis); 
     523 
     524        float midPoint = (maxBox + minBox) * 0.5f; 
     525 
     526        ObjectContainer::const_iterator oit, oit_end = tData.mNode->mObjects.end(); 
     527         
     528        for (oit = tData.mNode->mObjects.begin(); oit != oit_end; ++ oit) 
     529        { 
     530                Intersectable *obj = *oit; 
     531                AxisAlignedBox3 box = obj->GetBox(); 
     532                const float objMid = (box.Max(axis) + box.Min(axis)) * 0.5; 
     533                // object mailed => belongs to back objects 
     534                if (objMid < midPoint)  
     535                        objectsBack.push_back(obj); 
     536                else 
     537                        objectsFront.push_back(obj); 
     538        } 
     539 
     540        const float oldRenderCost = tData.mProbability * (float)tData.mNode->mObjects.size(); 
     541        const float newRenderCost =  
     542                EvalRenderCost(tData, objectsFront, objectsBack); 
     543 
     544        const float ratio = newRenderCost / oldRenderCost; 
     545        return ratio; 
     546} 
     547 
     548 
    504549float BvHierarchy::EvalLocalCostHeuristics(const BvhTraversalData &tData, 
    505550                                                                                   const int axis, 
     
    507552                                                                                   ObjectContainer &objectsBack) 
    508553{ 
    509         // the relative cost ratio 
    510         float ratio = 99999999.0f; 
     554        // prepare the heuristics by setting mailboxes and counters. 
     555        const float totalVol = PrepareHeuristics(tData, axis); 
    511556 
    512557        // go through the lists, count the number of objects left and right 
    513         // and evaluate the following cost funcion: 
    514         // C = ct_div_ci  + (ol + or)/queries 
    515          
    516         const float minBox = tData.mBoundingBox.Min(axis); 
    517         const float maxBox = tData.mBoundingBox.Max(axis); 
    518  
    519         const float sizeBox = maxBox - minBox; 
    520  
    521         float minBand = minBox + mSplitBorder * (maxBox - minBox); 
    522         float maxBand = minBox + (1.0f - mSplitBorder) * (maxBox - minBox); 
    523  
    524         //-- sort so we can use a sweep 
    525         SortSubdivisionCandidates(tData, axis, minBand, maxBand); 
    526  
    527         float totalVol = PrepareHeuristics(tData); 
    528         float voll = 0; 
    529         float volr = totalVol; 
    530  
    531         /// this is kind of a reverse pvs 
    532         const int totalObjects = (int)tData.mNode->mObjects.size(); 
    533          
    534         int objectsl = 0; 
    535         int objectsr = totalObjects; 
    536  
    537         float sum = (float)totalVol * objectsr; 
    538  
    539  
    540         bool splitPlaneFound = false; 
     558        // and evaluate the cost funcion 
     559 
     560        // local helper variables 
     561        float volLeft = 0; 
     562        float volRight = totalVol; 
     563 
     564        int nObjectsLeft = 0; 
     565 
     566        const int nTotalObjects = (int)tData.mNode->mObjects.size(); 
     567        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     568 
     569        vector<SortableEntry>::const_iterator currentPos = 
     570                mSubdivisionCandidates->begin(); 
    541571 
    542572        ///////////////////////////////// 
    543573        // the parameters for the current optimum 
    544574 
    545         float volBack = voll; 
    546         float volFront = volr; 
    547  
    548         int nObjectsBack = objectsl; 
    549         int nObjectsFront = objectsr; 
    550          
    551         float minSum = 1e20f; 
    552  
    553         ///////////////////////////// 
    554  
    555         debugVol = 0; 
    556         const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     575        float volBack = volLeft; 
     576        float volFront = volRight; 
     577 
     578        float newRenderCost = nTotalObjects * totalVol; 
     579 
    557580 
    558581        ///////////////////////////// 
    559582        // the sweep heuristics 
    560  
    561         // mail the objects on the left side 
    562         Intersectable::NewMail(); 
    563583         
    564584        //-- traverse through events and find best split plane 
    565         vector<SortableEntry>::const_iterator ci, ci_end = mSubdivisionCandidates->end(); 
    566  
    567         for (ci = mSubdivisionCandidates->begin(); ci != ci_end; ++ ci) 
    568         { 
    569                 Intersectable *object = (*ci).mObject; 
    570  
    571                 EvalHeuristicsContribution(tData.mNode, *ci, voll, volr, objectsl); 
    572                 objectsr = totalObjects - objectsl; 
    573  
    574                 // Note: sufficient to compare size of bounding boxes of front and back side? 
    575  
    576                 if (((*ci).mPos >= minBand) && ((*ci).mPos <= maxBand)) 
     585 
     586        vector<SortableEntry>::const_iterator cit, cit_end = mSubdivisionCandidates->end(); 
     587 
     588        for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit) 
     589        { 
     590                Intersectable *object = (*cit).mObject; 
     591                 
     592                // evaluate change in l and r volume 
     593                // voll = view cells that see only left node (i.e., left pvs) 
     594                // volr = view cells that see only right node (i.e., right pvs) 
     595                EvalHeuristicsContribution(object, volLeft, volRight); 
     596 
     597                ++ nObjectsLeft; 
     598                 
     599                const int nObjectsRight = nTotalObjects - nObjectsLeft; 
     600 
     601                // view cells that see both child nodes 
     602                //const float volLeftAndRight = totalVol - volLeft - volRight; 
     603 
     604                // the heuristics 
     605            const float sum = volLeft * (float)nObjectsLeft +  
     606                                                  volRight * (float)nObjectsRight; 
     607                //                                volLeftAndRight * (float)nTotalObjects; 
     608 
     609                if (sum < newRenderCost) 
    577610                { 
    578                         // voll = view cells that see only left node (i.e., left pvs) 
    579                         // volr = view cells that see only right node (i.e., right pvs) 
    580                         // rest = view cells that see both nodes (i.e., total pvs) 
    581             sum = voll * objectsl + volr * objectsr + (totalVol - voll - volr) * totalObjects; 
    582  
    583                         float currentPos; 
    584                          
    585                         // HACK: current positition is BETWEEN visibility events 
    586                         if (1 && ((ci + 1) != ci_end)) 
    587                                 currentPos = ((*ci).mPos + (*(ci + 1)).mPos) * 0.5f; 
    588                         else 
    589                                 currentPos = (*ci).mPos;                         
    590  
    591                         if ((totalVol - voll - volr - debugVol) / viewSpaceVol > 0.0001) 
    592                                 Debug << "front and back volume: " << (totalVol - voll - volr) / viewSpaceVol << " error: " << (totalVol - voll - volr - debugVol) / viewSpaceVol << endl; 
    593 #if 0                            
    594                         Debug << "pos: " << currentPos  
    595                                  << "\t (pvsl: " << pvsl << ", pvsr: " << pvsr << ")" 
    596                                  << "\t (voll: " << voll << ", volr: " << volr << ")" 
    597                                  << "\t (vcl: " << vcl << ", vcr: " << vcr << ", nvc: " << numViewCells << ")" 
    598                                  << "\t sum: " << sum << endl; 
    599                                  
    600 #endif 
    601                         if (sum < minSum) 
    602                         { 
    603                                 splitPlaneFound = true; 
    604  
    605                                 minSum = sum; 
    606  
    607                                 nObjectsBack = objectsl; 
    608                                 nObjectsFront = objectsr; 
    609                                  
    610                                 volBack = voll; 
    611                                 volFront = volr; 
    612                         } 
     611                        newRenderCost = sum; 
     612 
     613                        volBack = volLeft; 
     614                        volFront = volRight; 
     615 
     616                        // objects belongs to left side now 
     617                        for (; currentPos != (cit + 1); ++ currentPos); 
    613618                } 
    614619        } 
    615          
    616         //-- compute cost 
    617         const float frontAndBackVol = totalVol - volFront - volBack; 
    618  
    619         const float oldRenderCost = (float)totalObjects * totalVol + Limits::Small; 
    620         const float newRenderCost = (float)nObjectsFront * volFront +  
    621                                                                 (float)nObjectsBack * volBack + 
    622                                                                 (float)totalObjects * frontAndBackVol; 
    623  
    624         if (splitPlaneFound) 
    625         { 
    626                 ratio = newRenderCost / oldRenderCost; 
    627         } 
    628  
    629         //Debug << "axis=" << axis << " costRatio=" << ratio << " pos="  
    630         //        << position << " t=" << (position - minBox) / (maxBox - minBox) 
    631         //      << "\t pb=(" << volBack << ")\t pf=(" << volFront << ")" << endl; 
     620 
     621        //-- assign object to front and back volume 
     622 
     623        // belongs to back bv 
     624        for (cit = mSubdivisionCandidates->begin(); cit != currentPos; ++ cit) 
     625                objectsBack.push_back((*cit).mObject); 
     626         
     627        // belongs to front bv 
     628        for (cit = currentPos; cit != cit_end; ++ cit) 
     629                objectsFront.push_back((*cit).mObject); 
     630 
     631        tData.mNode->mObjects.end(); 
     632 
     633        const float oldRenderCost = (float)nTotalObjects * totalVol + Limits::Small; 
     634        // the relative cost ratio 
     635        const float ratio = newRenderCost / oldRenderCost; 
    632636 
    633637        Debug << "\n§§§§ eval local cost §§§§" << endl 
    634                   << "back pvs: " << nObjectsBack << " front pvs: " << nObjectsFront << " total pvs: " << totalObjects << endl  
     638                  << "back pvs: " << (int)objectsBack.size() << " front pvs: " << objectsFront.size() << " total pvs: " << nTotalObjects << endl  
    635639                  << "back p: " << volBack / viewSpaceVol << " front p " << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl 
    636640                  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 
    637641                  << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl; 
    638642 
    639         if (oldRenderCost < newRenderCost) 
    640                 Debug << "\nwarning!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 
    641  
    642         // assign objects 
    643         ObjectContainer::const_iterator oit, oit_end = tData.mNode->mObjects.end(); 
    644  
    645         for (oit = tData.mNode->mObjects.begin(); oit != oit_end; ++ oit) 
    646         { 
    647                 Intersectable *obj = *oit; 
    648  
    649                 if (obj->Mailed()) // belongs to back objects 
    650                         objectsBack.push_back(obj); 
    651                 else 
    652                         objectsFront.push_back(obj); 
    653         } 
    654  
    655643        return ratio; 
    656644} 
     
    658646 
    659647void BvHierarchy::SortSubdivisionCandidates(const BvhTraversalData &tData, 
    660                                                                           const int axis,  
    661                                                                           float minBand,  
    662                                                                           float maxBand) 
    663  
     648                                                                                        const int axis)                                                                                  
    664649{ 
    665650        mSubdivisionCandidates->clear(); 
     
    669654 
    670655        // compute requested size 
    671         int requestedSize = 0; 
    672         ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    673         for (oit = leaf->mObjects.begin(); oit < oit_end; ++ oit) 
    674                 requestedSize += 2 + (int)(*oit)->mVssRays.size() * 2; 
     656        const int requestedSize = (int)leaf->mObjects.size() * 2; 
    675657         
    676658        // creates a sorted split candidates array 
     
    683665 
    684666        mSubdivisionCandidates->reserve(requestedSize); 
    685  
    686         float pos; 
    687667 
    688668        //-- insert object queries 
     
    691671        //-- there is no ray associated with these events!! 
    692672 
     673        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     674 
    693675        for (oit = leaf->mObjects.begin(); oit < oit_end; ++ oit) 
    694676        { 
     
    696678                 
    697679                Intersectable *object = *oit; 
    698                 const AxisAlignedBox3 box = object->GetBox(); 
    699  
    700                 mSubdivisionCandidates->push_back( 
    701                         SortableEntry(SortableEntry::OBJECT, 
    702                                                   box.Min(axis), 
    703                                                   object, 
    704                                                   NULL) 
    705                                                   ); 
    706  
    707  
    708                 //-- insert ray queries 
    709                 //-- we are intersested only in rays which intersect an object that 
    710                 //-- is part of the kd node because they can induce a change in view cell 
    711                 //-- volume on the left and the right part.  
    712                 //-- Note that they cannot induce a change in pvs size!! 
    713                  
    714                 VssRayContainer::const_iterator rit, rit_end = obj->mVssRays.end(); 
    715  
    716                 for (rit = obj->mVssRays.begin(); rit < rit_end; ++ rit) 
    717                 { 
    718                         VssRay *ray = (*rit); 
    719                         const bool positive = ray->HasPosDir(axis); 
    720          
    721                         pos = ray->mTermination[axis]; 
    722  
    723                         mSubdivisionCandidates->push_back( 
    724                                 SortableEntry(SortableEntry::VIEWCELLS,  
    725                                 pos,  
    726                                 ray->mTerminationObject,  
    727                                 ray) 
    728                                 ); 
    729                 } 
     680                const AxisAlignedBox3 &box = object->GetBox(); 
     681                const float midPt = (box.Min(axis) + box.Max(axis)) * 0.5f; 
     682 
     683                mSubdivisionCandidates->push_back(SortableEntry(object, midPt)); 
    730684        } 
    731685 
     
    740694 
    741695 
    742 void BvHierarchy::EvalRayContribution(const VssRay &ray,  
    743                                                                           float &volLeft,  
    744                                                                           float &volRight) 
    745 { 
     696float BvHierarchy::PrepareHeuristics(const BvhTraversalData &tData, const int axis) 
     697{        
     698        //-- sort so we can use a sweep from right to left 
     699        SortSubdivisionCandidates(tData, axis); 
     700 
     701        float vol = 0; 
     702        BvhLeaf *leaf = tData.mNode; 
     703 
     704        // collect and mark the view cells as belonging to front pvs 
    746705        ViewCellContainer viewCells; 
    747         mVspTree->GetViewCells(ray, viewCells); 
     706        CollectViewCells(tData.mNode->mObjects, viewCells, true); 
     707 
     708    ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     709 
     710        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     711        { 
     712                vol += (*vit)->GetVolume(); 
     713        } 
     714 
     715        // mail view cells on the left side 
     716        ViewCell::NewMail(); 
     717         
     718        // mail the objects on the left side 
     719        Intersectable::NewMail(); 
     720 
     721        return vol; 
     722} 
     723/////////////////////////////////////////////////////////// 
     724 
     725 
     726void BvHierarchy::EvalHeuristicsContribution(Intersectable *obj, 
     727                                                                                         float &volLeft,  
     728                                                                                         float &volRight) 
     729{ 
     730        // collect all view cells associated with this objects  
     731        // (also multiple times, if they are pierced by several rays) 
     732 
     733        ViewCellContainer viewCells; 
     734         
     735        const bool useMailboxing = false; 
     736        CollectViewCells(obj, viewCells, useMailboxing); 
     737 
    748738 
    749739        /// classify view cells and compute volume contri accordingly 
     
    766756 
    767757                        // we now see view cell from both nodes  
    768                         // => remove ref to right child node 
    769                         volRight -= vol; 
    770                         debugVol += vol; 
     758                        // => add volume to left node 
     759                        volLeft += vol; 
     760                        //volRight -= vol; 
    771761                } 
    772762 
     
    775765                { 
    776766                        // view cell was previously seen from both nodes  => 
    777                         // contributes only to left node now 
    778                         volLeft += vol; 
    779                         debugVol -= vol; 
     767                        // remove volume from right node 
     768                        volRight -= vol; 
    780769                } 
    781770        } 
    782 } 
    783  
    784  
    785 float BvHierarchy::PrepareHeuristics(const VssRay &ray) 
    786 { 
    787         float vol = 0; 
    788  
    789         ViewCellContainer viewCells; 
    790         mVspTree->GetViewCells(ray, viewCells); 
    791          
    792         ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    793  
    794         for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    795         { 
    796                 ViewCell *vc = (*vit); 
    797  
    798                 if (!vc->Mailed()) 
    799                 { 
    800                         //Debug << "single vol: "<< vc->GetVolume() << endl; 
    801                         vc->Mail(); 
    802                         vc->mCounter = 0; 
    803                         vol += vc->GetVolume(); 
    804                 } 
    805                  
    806                 // view cell volume already added => just increase counter 
    807                 ++ vc->mCounter; 
    808         } 
    809  
    810         return vol; 
    811 } 
    812  
    813  
    814 float BvHierarchy::PrepareHeuristics(const BvhTraversalData &tData) 
    815 {        
    816         float vol = 0; 
    817         debugVol = 0; 
    818          
    819         ViewCell::NewMail(); 
    820  
    821         BvhLeaf *leaf = tData.mNode; 
    822  
    823         VssRayContainer rays; 
    824         CollectRays(leaf->mObjects, rays); 
    825  
    826         VssRayContainer::const_iterator rit, rit_end = rays.end(); 
    827  
    828         for (rit = rays.begin(); rit < rit_end; ++ rit) 
    829         { 
    830                 VssRay *ray = (*rit); 
    831  
    832                 const float volContri = PrepareHeuristics(*ray); 
    833  
    834                 // if hitpoint with one of the objects is inside this node, we 
    835                 // evaluate the volume of the view cells seen by this ray 
    836                 if (ray->mTerminationObject) 
    837                 { 
    838             vol += volContri; 
    839                 } 
    840  
    841                 // count double if both hit points are within the kd node 
    842                 if (0 && ray->mOriginObject) 
    843                 { 
    844                         vol += volContri; 
    845                 } 
    846         } 
    847  
    848         return vol; 
    849 } 
    850 /////////////////////////////////////////////////////////// 
    851  
    852  
    853 void BvHierarchy::EvalHeuristicsContribution(BvhLeaf *leaf, 
    854                                                                                          const SortableEntry &ci, 
    855                                                                                          float &volLeft,  
    856                                                                                          float &volRight,  
    857                                                                                          int &objectsLeft) 
    858 { 
    859         Intersectable *obj = ci.mObject; 
    860         VssRay *ray = ci.mRay; 
    861  
    862         // switch between different types of events 
    863         switch (ci.mType)  
    864         { 
    865                 case SortableEntry::OBJECT: 
    866                         cout << "o"; 
    867                         ci.mObject->Mail(); 
    868                         ++ objectsLeft; 
    869                         break; 
    870  
    871                 // compute volume contribution from view cells 
    872                 case SortableEntry::VIEWCELLS: 
    873                         cout << "v"; 
    874                         // process ray if the hit point with termination / origin object  
    875                         // is inside this kd leaf 
    876                         EvalRayContribution(*ray, volLeft, volRight); 
    877                         break; 
    878  
    879                 default: 
    880                         cout << "should not come here" << endl; 
    881                         break; 
    882         } 
    883         //cout << "vol left: " << volLeft << " vol right " << volRight << endl; 
    884771} 
    885772 
     
    923810                if (!mOnlyDrivingAxis || (axis == sAxis)) 
    924811                { 
    925                         if (1 || mUseCostHeuristics) 
     812                        if (mUseCostHeuristics) 
    926813                        { 
    927814                                //-- partition objects using heuristics 
    928                                  
    929815                                nCostRatio[axis] = 
    930816                                        EvalLocalCostHeuristics( 
     
    932818                                                                                        axis, 
    933819                                                                                        nFrontObjects[axis], 
    934                                                                                         nBackObjects[axis]);                     
     820                                                                                        nBackObjects[axis]); 
    935821                        } 
     822                        else 
     823                        { 
     824                                nCostRatio[axis] = 
     825                                        EvalLocalObjectPartition( 
     826                                                                                         tData, 
     827                                                                                         axis, 
     828                                                                                         nFrontObjects[axis], 
     829                                                                                         nBackObjects[axis]); 
     830                        } 
     831 
    936832                        if (bestAxis == -1) 
    937833                        { 
     
    946842 
    947843        //-- assign values 
    948          
     844 
    949845        frontObjects = nFrontObjects[bestAxis]; 
    950         backObjects = nFrontObjects[bestAxis]; 
     846        backObjects = nBackObjects[bestAxis]; 
    951847 
    952848        Debug << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl; 
     
    977873 
    978874 
    979 void BvHierarchy::EvalSubdivisionStats(const SubdivisionCandidate &sc) 
    980 { 
    981         const float costDecr = sc.GetRenderCostDecrease(); 
    982  
    983         AddSubdivisionStats(mBvhStats.Leaves(), 
    984                                                 costDecr, 
    985                                                 mTotalCost 
    986                                                 ); 
    987 } 
    988  
    989  
    990 void BvHierarchy::AddSubdivisionStats(const int leaves, 
    991                                                                           const float renderCostDecr, 
    992                                                                           const float totalRenderCost) 
    993 { 
     875void BvHierarchy::PrintSubdivisionStats(const SubdivisionCandidate &sc) 
     876{ 
     877        const float costDecr = sc.GetRenderCostDecrease();       
     878 
    994879        mSubdivisionStats  
    995                         << "#Leaves\n" << leaves << endl 
    996                         << "#RenderCostDecrease\n" << renderCostDecr << endl  
    997                         << "#TotalRenderCost\n" << totalRenderCost << endl; 
     880                        << "#Leaves\n" << mBvhStats.Leaves() 
     881                        << "#RenderCostDecrease\n" << costDecr << endl  
     882                        << "#TotalRenderCost\n" << mTotalCost << endl; 
    998883                        //<< "#AvgRenderCost\n" << avgRenderCost << endl; 
    999884} 
     
    1029914 
    1030915 
    1031 void BvHierarchy::MailViewCells(const ObjectContainer &objects,  
    1032                                                                 const bool isFront, 
    1033                                                                 ViewCellContainer &collectedViewCells) const 
    1034 { 
    1035         VssRayContainer rays; 
    1036         CollectRays(objects, rays); 
    1037          
    1038         VssRayContainer::const_iterator rit, rit_end = rays.end(); 
    1039  
    1040         for (rit = rays.begin(); rit < rit_end; ++ rit) 
    1041         { 
    1042                 VssRay *ray = (*rit); 
    1043  
    1044                 // view cell is assigned to left and / or right child 
    1045                 ViewCellContainer viewCells; 
    1046                 mVspTree->GetViewCells(*ray, viewCells); 
    1047                          
    1048                 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    1049  
    1050                 // mail view cell 
    1051                 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     916void BvHierarchy::ClassifyViewCells(const ViewCellContainer &viewCells,  
     917                                                                        const bool isFront) const 
     918{ 
     919        int mailed = 0; 
     920        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     921 
     922        // mail view cell 
     923        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     924        { 
     925                ViewCell *vc = *vit; 
     926 
     927                if (isFront) 
    1052928                { 
    1053                         ViewCell *vc = *vit; 
    1054  
    1055                         if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 
    1056                                 collectedViewCells.push_back(vc); 
    1057  
    1058                         if (isFront) 
     929                        if (!vc->Mailed()) 
    1059930                        { 
    1060                                 if (!vc->Mailed()) 
    1061                                         vc->Mail(); 
     931                                vc->Mail(); 
     932                                //Debug << " " << vc->mMailBox << endl; 
     933                                ++ mailed; 
    1062934                        } 
    1063                         else 
     935                } 
     936                else 
     937                { 
     938                        if (vc->Mailed()) 
    1064939                        { 
    1065                                 if (!vc->Mailed()) 
    1066                                         vc->Mail(1); 
    1067                                 else 
    1068                                         vc->Mail(2); 
     940                                vc->Mail(2); 
     941                                //Debug << " " << vc->mMailBox << endl; 
     942                                ++ mailed; 
    1069943                        } 
    1070                 }                                
    1071         } 
    1072 } 
    1073  
    1074  
    1075 float BvHierarchy::EvalRenderCostDecrease(const ObjectContainer &objectsFront, 
     944                        else if (!vc->Mailed(1) && !vc->Mailed(2)) 
     945                        { 
     946                                vc->Mail(1); 
     947                                //Debug << " " << vc->mMailBox << endl; 
     948                                ++ mailed; 
     949                        } 
     950 
     951                } 
     952        }                                
     953 
     954        Debug << "mailed " << mailed << " view cells " << endl; 
     955} 
     956 
     957 
     958float BvHierarchy::EvalRenderCost(const BvhTraversalData &tData, 
     959                                                                  const ObjectContainer &objectsFront, 
     960                                                                  const ObjectContainer &objectsBack) const 
     961{ 
     962        BvhLeaf *leaf = tData.mNode; 
     963 
     964        // probability that view point lies in a view cell which sees this node 
     965        const float pFront = EvalViewCellsVolume(objectsFront); 
     966        const float pBack = EvalViewCellsVolume(objectsBack); 
     967                 
     968        const int totalObjects = (int)leaf->mObjects.size(); 
     969        const int nObjectsFront = (int)objectsFront.size(); 
     970        const int nObjectsBack = (int)objectsBack.size(); 
     971 
     972        //-- pvs rendering heuristics 
     973        const float newRenderCost = nObjectsFront * pFront +  
     974                                                                nObjectsBack * pBack; 
     975 
     976        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     977        Debug << "\n***** eval render cost *********\n"  
     978                  << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << endl 
     979                  << "new rc: " << newRenderCost / viewSpaceVol << endl; 
     980                  
     981 
     982        return newRenderCost; 
     983} 
     984 
     985 
     986/*float BvHierarchy::EvalRenderCostDecrease(const BvhTraversalData &tData, 
     987                                                                                  const ObjectContainer &objectsFront, 
    1076988                                                                                  const ObjectContainer &objectsBack, 
    1077                                                                                   const BvhTraversalData &tData, 
    1078989                                                                                  float &normalizedOldRenderCost) const 
    1079990{ 
    1080         // probability that view point lies in back / front node 
     991        BvhLeaf *leaf = tData.mNode; 
     992 
     993        // probability that view point lies in a view cell which sees this node 
    1081994        float pOverall = 0; 
    1082995        float pFront = 0; 
     
    1085998 
    1086999        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
    1087  
    1088         BvhLeaf *leaf = tData.mNode; 
    1089          
     1000         
     1001        ViewCellContainer collectedViewCells; 
     1002        ViewCellContainer viewCellsFront, viewCellsBack; 
     1003 
     1004        // the view cells seen from the front bv 
     1005         
     1006    CollectViewCells(objectsFront, viewCellsFront); 
     1007        // the view cells seen from the back bv 
     1008        CollectViewCells(objectsBack, viewCellsBack); 
     1009        // the view cells seen from both bvs 
     1010        // note: could be evaluated simpler 
     1011        CollectViewCells(leaf->mObjects, collectedViewCells); 
     1012 
     1013 
    10901014        // sum up volume seen from the objects of left and right children 
    10911015        // => the volume is the weight for the render cost equation 
     1016         
    10921017        ViewCell::NewMail(3); 
    1093  
    1094         ViewCellContainer collectedViewCells; 
    1095         MailViewCells(objectsFront, true, collectedViewCells); 
    1096         MailViewCells(objectsBack, false, collectedViewCells); 
     1018        ClassifyViewCells(viewCellsFront, true); 
     1019        ClassifyViewCells(viewCellsBack, false); 
    10971020 
    10981021        ViewCellContainer::const_iterator vit, vit_end = collectedViewCells.end(); 
     
    11011024        for (vit = collectedViewCells.begin(); vit != vit_end; ++ vit) 
    11021025        { 
    1103                 AddViewCellVolumeContri(*vit, pFront, pBack, pFrontAndBack); 
     1026                ViewCell *vc = *vit; 
     1027                if (vc->Mailed()) 
     1028                        pFront += vc->GetVolume(); 
     1029                else if (vc->Mailed(1)) 
     1030                        pBack += vc->GetVolume(); 
     1031                else if (vc->Mailed(2)) 
     1032                        pFrontAndBack += vc->GetVolume(); 
    11041033        } 
    11051034 
     
    11131042        //-- pvs rendering heuristics 
    11141043        const float oldRenderCost = pOverall * totalObjects; 
    1115         const float newRenderCost = nObjectsFront * pFront + nObjectsBack * pBack + totalObjects * pFrontAndBack; 
     1044        const float newRenderCost = nObjectsFront * pFront +  
     1045                                                                nObjectsBack * pBack +  
     1046                                                                totalObjects * pFrontAndBack; 
    11161047 
    11171048        // normalize volume with view space volume 
     
    11271058        normalizedOldRenderCost = oldRenderCost / viewSpaceVol; 
    11281059 
    1129         if (oldRenderCost < newRenderCost * 0.99) 
    1130                 Debug << "\nwarning2!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 
    1131          
    11321060        return renderCostDecrease; 
    1133 } 
    1134  
    1135  
    1136 AxisAlignedBox3 BvHierarchy::ComputeBoundingBox(const ObjectContainer &objects) 
    1137 { 
     1061}*/ 
     1062 
     1063 
     1064AxisAlignedBox3 BvHierarchy::ComputeBoundingBox(const ObjectContainer &objects, 
     1065                                                                                                const AxisAlignedBox3 *parentBox) 
     1066{ 
     1067        if (parentBox && objects.empty()) 
     1068                return *parentBox; 
     1069 
    11381070        AxisAlignedBox3 box; 
    11391071        box.Initialize(); 
     
    11471079 
    11481080                // compute bounding box of view space 
    1149                 mBoundingBox.Include(obj->GetBox()); 
    1150         } 
     1081                box.Include(obj->GetBox()); 
     1082        } 
     1083 
    11511084        return box; 
    1152          
    11531085} 
    11541086 
     
    11631095                BvhNode *node = nodeStack.top(); 
    11641096                nodeStack.pop(); 
     1097 
    11651098                if (node->IsLeaf())  
    11661099                { 
     
    11851118 
    11861119 
    1187 void BvHierarchy::CollectViewCells(BvhLeaf *leaf, ViewCellContainer &viewCells) 
    1188 { 
    1189         ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    1190  
     1120void BvHierarchy::CollectViewCells(const ObjectContainer &objects,  
     1121                                                                   ViewCellContainer &viewCells, 
     1122                                                                   const bool setCounter) const 
     1123{ 
    11911124        ViewCell::NewMail(); 
     1125        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    11921126 
    11931127        // loop through all object and collect view cell pvs of this node 
    1194         for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
    1195         { 
    1196                 Intersectable *obj = *oit; 
    1197  
    1198                 ViewCellPvsMap::const_iterator vit, vit_end = obj->mViewCellPvs.mEntries.end(); 
    1199  
    1200                 for (vit = obj->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 
    1201                 { 
    1202             ViewCell *vc = (*vit).first; 
    1203  
    1204                         if (!vc->Mailed()) 
    1205                         { 
    1206                                 vc->Mail(); 
    1207                                 viewCells.push_back(vc); 
    1208                         } 
    1209                 } 
    1210         } 
    1211 } 
    1212  
    1213  
    1214 void BvHierarchy::CollectDirtyCandidates(BvhSubdivisionCandidate *sc,  
    1215                                                                                  vector<SubdivisionCandidate *> &dirtyList) 
    1216 { 
    1217         BvhTraversalData &tData = sc->mParentData; 
    1218         BvhLeaf *node = tData.mNode; 
    1219          
    1220         ViewCell::NewMail(); 
    1221  
    1222         ViewCellContainer viewCells; 
    1223         ViewCellContainer tmpViewCells; 
    1224  
    1225         VssRayContainer rays; 
    1226         CollectRays(node->mObjects, rays); 
    1227  
    1228         VssRayContainer::const_iterator rit, rit_end = rays.end(); 
    1229  
    1230         // find all view cells associated with the rays, add them to view cells 
    1231         for (rit = rays.begin(); rit != rit_end; ++ rit) 
     1128        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     1129        { 
     1130                CollectViewCells(*oit, viewCells, true, setCounter); 
     1131        } 
     1132} 
     1133 
     1134 
     1135void BvHierarchy::CollectViewCells(Intersectable *obj,  
     1136                                                                   ViewCellContainer &viewCells, 
     1137                                                                   const bool useMailBoxing, 
     1138                                                                   const bool setCounter) const 
     1139{ 
     1140        VssRayContainer::const_iterator rit, rit_end = obj->mVssRays.end(); 
     1141 
     1142        for (rit = obj->mVssRays.begin(); rit < rit_end; ++ rit) 
    12321143        { 
    12331144                VssRay *ray = (*rit); 
     1145                ViewCellContainer tmpViewCells; 
     1146         
    12341147                mVspTree->GetViewCells(*ray, tmpViewCells); 
    12351148 
     
    12401153                        VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
    12411154 
    1242                         if (!vc->Mailed()) 
     1155                        // store view cells 
     1156                        if (!useMailBoxing || !vc->Mailed()) 
    12431157                        { 
    1244                                 vc->Mail(); 
     1158                                if (useMailBoxing) 
     1159                                { 
     1160                                        vc->Mail(); 
     1161                                        if (setCounter) 
     1162                                                vc->mCounter = 0; 
     1163                                } 
     1164                                 
    12451165                                viewCells.push_back(vc); 
    12461166                        } 
     1167                         
     1168                        if (setCounter) 
     1169                        { 
     1170                                ++ vc->mCounter; 
     1171                        } 
    12471172                } 
    12481173        } 
    1249  
    1250  
    1251         // split candidates holding this view cells  
    1252         // are thrown into dirty list 
     1174} 
     1175 
     1176 
     1177void BvHierarchy::CollectDirtyCandidates(BvhSubdivisionCandidate *sc,  
     1178                                                                                 vector<SubdivisionCandidate *> &dirtyList) 
     1179{ 
     1180        BvhTraversalData &tData = sc->mParentData; 
     1181        BvhLeaf *node = tData.mNode; 
     1182         
     1183        ViewCellContainer viewCells; 
     1184        CollectViewCells(node->mObjects, viewCells); 
     1185 
     1186        // split candidates handling  
     1187        // these view cells  are thrown into dirty list 
    12531188        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    12541189 
     
    13581293 
    13591294 
    1360 void BvHierarchy::AddViewCellVolumeContri(ViewCell *vc, 
    1361                                                                                   float &frontVol, 
    1362                                                                                   float &backVol, 
    1363                                                                                   float &frontAndBackVol) const 
    1364 { 
    1365         if (vc->Mailed()) 
    1366         { 
    1367                 frontVol += vc->GetVolume(); 
    1368         } 
    1369         else if (vc->Mailed(1)) 
    1370         { 
    1371                 backVol += vc->GetVolume(); 
    1372         } 
    1373         else if (vc->Mailed(2)) 
    1374         { 
    1375                 frontAndBackVol += vc->GetVolume(); 
    1376         } 
    1377 } 
    1378  
    13791295/* 
    13801296int BvHierarchy::UpdateViewCellsPvs(BvhLeaf *leaf,  
     
    14691385        { 
    14701386                BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 
    1471  
     1387                const AxisAlignedBox3 box = leaf->GetBoundingBox(); 
    14721388                stream << "<Leaf" 
    1473                            << " min=\"" << leaf->GetBoundingBox().Min() 
    1474                            << " max=\"" << leaf->GetBoundingBox().Max()  
     1389                           << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
     1390                           << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\"" 
    14751391                           << " objects=\""; 
    14761392                 
     
    14831399        {        
    14841400                BvhInterior *interior = dynamic_cast<BvhInterior *>(node); 
    1485          
     1401                const AxisAlignedBox3 box = interior->GetBoundingBox(); 
     1402 
    14861403                stream << "<Interior" 
    1487                            << " min=\"" << interior->GetBoundingBox().Min() 
    1488                            << " max=\"" << interior->GetBoundingBox().Max() 
     1404                           << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
     1405                           << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z 
    14891406                           << "\">" << endl; 
    14901407 
     
    14971414 
    14981415 
    1499 float BvHierarchy::EvalViewCellsVolume(BvhLeaf *leaf) const 
     1416float BvHierarchy::EvalViewCellsVolume(const ObjectContainer &objects) const 
    15001417{ 
    15011418        float vol = 0; 
    15021419 
    1503         VssRayContainer rays; 
    1504         CollectRays(leaf->mObjects, rays); 
    1505  
    1506         ViewCell::NewMail(); 
    1507  
    1508         VssRayContainer::const_iterator rit, rit_end = rays.end(); 
    1509  
    1510         for (rit = rays.begin(); rit < rit_end; ++ rit) 
    1511         { 
    1512                 VssRay *ray = (*rit); 
    1513          
    1514                 ViewCellContainer viewCells; 
    1515                 mVspTree->GetViewCells(*ray, viewCells); 
    1516          
    1517                 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    1518  
    1519                 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    1520                 { 
    1521                         ViewCell *vc = (*vit); 
    1522  
    1523                         if (!vc->Mailed()) 
    1524                         { 
    1525                                 //Debug << "single vol: "<< vc->GetVolume() << endl; 
    1526                                 vc->Mail(); 
    1527                                 vol += vc->GetVolume(); 
    1528                         } 
    1529                 } 
     1420        ViewCellContainer viewCells; 
     1421        CollectViewCells(objects, viewCells); 
     1422 
     1423        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     1424 
     1425        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     1426        { 
     1427                vol += (*vit)->GetVolume(); 
    15301428        } 
    15311429 
     
    15351433 
    15361434SubdivisionCandidate *BvHierarchy::PrepareConstruction(const VssRayContainer &sampleRays, 
    1537                                                                                                            ObjectContainer &objects, 
    1538                                                                                                            AxisAlignedBox3 *forcedObjectSpace 
    1539                                                                                                            //, RayInfoContainer &rays 
     1435                                                                                                           const ObjectContainer &objects 
     1436                                                                                                           //,AxisAlignedBox3 *forcedObjectSpace 
    15401437                                                                                                           ) 
    15411438{ 
     1439        // note matt: we assume that we have objects sorted by their id 
     1440 
    15421441        // store pointer to this tree 
    15431442        BvhSubdivisionCandidate::sBvHierarchy = this; 
     
    15451444 
    15461445        // compute bounding box from objects 
    1547         if (forcedObjectSpace) 
    1548                 mBoundingBox = *forcedObjectSpace; 
    1549         else 
    1550                 mBoundingBox = ComputeBoundingBox(objects); 
    1551  
    1552         mTermMinVolume *= mBoundingBox.GetVolume(); 
     1446        mBoundingBox = ComputeBoundingBox(objects); 
     1447 
     1448        mTermMinProbability *= mBoundingBox.GetVolume(); 
    15531449        mGlobalCostMisses = 0; 
    1554  
    1555         // sort objects by id in order to have sorted objects in 
    1556         // the leaf nodes 
    1557         stable_sort(objects.begin(), objects.end(), ilt); 
    1558  
     1450         
    15591451        //-- create new root 
    15601452 
     
    15691461 
    15701462        //-- add first candidate for object space partition 
     1463         
     1464        // probabilty is voume of all "seen" view cells 
     1465#if 1 
     1466        const float prop = EvalViewCellsVolume(bvhleaf->mObjects); 
     1467#else 
     1468        const float prop = GetBoundingBox().GetVolume(); 
     1469#endif 
    15711470 
    15721471        // create osp traversal data 
    1573         BvhTraversalData oData(bvhleaf, 0, mBoundingBox.GetVolume()); 
     1472        BvhTraversalData oData(bvhleaf, 0, mBoundingBox, prop); 
    15741473 
    15751474        //-- first split candidate 
     
    15811480        EvalSubdivisionCandidate(*oSubdivisionCandidate); 
    15821481 
    1583 // probabilty is voume of all "seen" view cells 
    1584 #if 1 
    1585         const float prop = EvalViewCellsVolume(bvhleaf); 
    1586 #else 
    1587         const float prop = GetBoundingBox().GetVolume(); 
    1588 #endif 
    1589         mTotalCost = (float)objects.size() * prop /  
    1590                 mVspTree->GetBoundingBox().GetVolume(); 
    1591  
    1592         EvalSubdivisionStats(*oSubdivisionCandidate); 
     1482        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     1483        mTotalCost = (float)objects.size() * prop / viewSpaceVol; 
     1484 
     1485        PrintSubdivisionStats(*oSubdivisionCandidate); 
    15931486 
    15941487        return oSubdivisionCandidate; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1286 r1287  
    261261        /// universal counter 
    262262        int mCounter; 
     263 
     264 
    263265protected: 
    264266 
     
    289291                /// current depth 
    290292                int mDepth; 
    291                 /// rays piercing this node 
    292                 //RayInfoContainer *mRays; 
    293                 /// the volume of this node 
    294                 float mVolume; 
     293                /// the probability that this node is seen 
     294                float mProbability; 
    295295                /// the bounding box of the node 
    296296                AxisAlignedBox3 mBoundingBox; 
     
    305305                BvhTraversalData(): 
    306306                mNode(NULL), 
    307                 //mRays(NULL), 
    308307                mDepth(0), 
    309                 mVolume(0.0), 
     308                mProbability(0.0), 
    310309                mMaxCostMisses(0),  
    311310                mPriority(0), 
     
    315314                BvhTraversalData(BvhLeaf *node,  
    316315                                                 const int depth, 
    317                          //RayInfoContainer *rays, 
     316                                                 const AxisAlignedBox3 &box, 
    318317                                                 const float v): 
    319318                mNode(node),  
    320319                mDepth(depth), 
    321                 //mRays(rays), 
    322                 mVolume(v), 
     320                mBoundingBox(box), 
     321                mProbability(v), 
    323322                mMaxCostMisses(0), 
    324323                mPriority(0), 
     
    326325                {} 
    327326 
    328                 BvhTraversalData( 
    329                         const int depth 
    330                         //,RayInfoContainer *rays 
    331                         ):  
    332                 mNode(NULL),  
    333                 mDepth(depth), 
    334                 //mRays(rays), 
    335                 mVolume(0), 
    336                 mMaxCostMisses(0), 
    337                 mAxis(0) 
    338                 {} 
    339327 
    340328                /** Returns cost of the traversal data. 
     
    531519        bool GlobalTerminationCriteriaMet(const BvhTraversalData &data) const; 
    532520 
    533         // -------------------------------------------------------------- 
    534         // For sorting objects 
    535         // -------------------------------------------------------------- 
     521        /** For sorting the objects during the heuristics 
     522        */ 
    536523        struct SortableEntry 
    537524        { 
    538                 /** There is a 3th "event" for rays which intersect a 
    539                         box in the middle. These "events" don't induce a change in 
    540                         pvs size, but may induce a change in view cell volume. 
    541                 */ 
    542                 enum EType  
    543                 { 
    544                         OBJECT, 
    545                         VIEWCELLS 
    546                 }; 
    547  
    548                 int mType; 
     525                Intersectable *mObject; 
    549526                float mPos; 
    550527 
    551                 VssRay *mRay; 
    552                 Intersectable *mObject; 
    553  
    554528                SortableEntry() {} 
    555529 
    556                 SortableEntry( 
    557                         const int type, 
    558                         const float pos, 
    559                         Intersectable *obj, 
    560                         VssRay *ray): 
    561                 mType(type),   
    562                 mPos(pos),  
    563                 mObject(obj), 
    564                 mRay(ray) 
     530                SortableEntry(Intersectable *obj, const float pos):  
     531                mObject(obj), mPos(pos) 
    565532                {} 
    566533 
     
    571538        }; 
    572539  
    573         /** faster evaluation of split plane cost for kd axis aligned cells. 
    574         */ 
    575         float EvalLocalSplitCost(const BvhTraversalData &data, 
    576                                                          const AxisAlignedBox3 &box, 
    577                                                          const int axis, 
    578                                                          const float &position, 
    579                                                          float &pFront, 
    580                                                          float &pBack) const; 
     540        /** Evaluate balanced object partition. 
     541        */ 
     542        float EvalLocalObjectPartition( 
     543                const BvhTraversalData &tData, 
     544                const int axis, 
     545                ObjectContainer &objectsFront, 
     546                ObjectContainer &objectsBack); 
    581547 
    582548        /** Computes priority of the traversal data and stores it in tData. 
     
    584550        void EvalPriority(BvhTraversalData &tData) const; 
    585551 
    586         /** Evaluates render cost decrease of next split. 
    587         */ 
    588         float EvalRenderCostDecrease( 
     552        /** Evaluates render cost of next split. 
     553        */ 
     554        float EvalRenderCost( 
     555                const BvhTraversalData &tData, 
    589556                const ObjectContainer &objectsLeft, 
    590                 const ObjectContainer &objectsRight, 
    591                 const BvhTraversalData &tData, 
    592                 float &normalizedOldRenderCost) const; 
     557                const ObjectContainer &objectsRight) const; 
    593558 
    594559        /** Evaluates tree stats in the BSP tree leafs. 
     
    658623        void SortSubdivisionCandidates( 
    659624                const BvhTraversalData &data, 
    660                 const int axis,  
    661                 float minBand,  
    662                 float maxBand); 
     625                const int axis); 
    663626 
    664627        /** Computes best cost for axis aligned planes. 
     
    670633                ObjectContainer &objectsFBack); 
    671634 
    672         /** Evaluate the volume of view cells seeing the left and right child cell. 
    673         */ 
    674         void EvalRayContribution(const VssRay &ray, float &volLeft, float &volRight); 
    675  
    676  
    677         /** Evaluates the influence on the pvs of the event. 
    678                 @param ve the visibility event 
    679                 @param pvsLeft updates the left pvs 
    680                 @param rightPvs updates the right pvs 
     635        /** Evaluates the contribution to the front and back volume 
     636                when this object is changing sides in the bvs. 
     637 
     638                @param object the object 
     639                @param volLeft updates the left pvs 
     640                @param volPvs updates the right pvs 
    681641        */ 
    682642        void EvalHeuristicsContribution( 
    683                 BvhLeaf *leaf, 
    684                 const SortableEntry &ci, 
     643                Intersectable *obj, 
    685644                float &volLeft,  
    686                 float &volRight, 
    687                 int &objectsLeft); 
     645                float &volRight); 
    688646 
    689647        /** Prepares objects for the cost heuristics. 
    690648                @returns sum of volume of associated view cells 
    691649        */ 
    692         float PrepareHeuristics(const BvhTraversalData &tData); 
    693  
    694         /** Prepares heuristics for a particular ray. 
    695         */ 
    696         float PrepareHeuristics(const VssRay &ray); 
    697  
    698         void AddViewCellVolumeContri( 
    699                 ViewCell *vc,  
    700                 float &frontVol,  
    701                 float &backVol, 
    702                 float &frontAndBackVol) const; 
    703  
    704          
     650        float PrepareHeuristics(const BvhTraversalData &tData, const int axis); 
     651         
     652 
    705653        //////////////////////////////////////////////// 
    706654 
     
    708656        /** Prepares construction for vsp and osp trees. 
    709657        */ 
    710         AxisAlignedBox3 ComputeBoundingBox(const ObjectContainer &objects); 
    711  
    712         void CollectDirtyCandidates(BvhSubdivisionCandidate *sc, 
     658        AxisAlignedBox3 ComputeBoundingBox( 
     659                const ObjectContainer &objects,  
     660                const AxisAlignedBox3 *parentBox = NULL); 
     661 
     662        void CollectDirtyCandidates( 
     663                BvhSubdivisionCandidate *sc, 
    713664                vector<SubdivisionCandidate *> &dirtyList); 
    714665 
    715         /** Collect view cells which see this kd leaf. 
    716         */ 
    717         void CollectViewCells(BvhLeaf *leaf, ViewCellContainer &viewCells); 
     666        /** Collect view cells which see this bvh leaf. 
     667        */ 
     668        void CollectViewCells( 
     669                const ObjectContainer &objects,  
     670                ViewCellContainer &viewCells, 
     671                const bool setCounter = false) const; 
     672 
     673        /** Collects view cells which see an object. 
     674        */ 
     675        void CollectViewCells( 
     676                Intersectable *object,  
     677                ViewCellContainer &viewCells,  
     678                const bool useMailBoxing, 
     679                const bool setCounter = false) const; 
    718680 
    719681        /** Rays will be clipped to the bounding box. 
     
    724686                RayInfoContainer &rays); 
    725687 
    726  
    727         void EvalSubdivisionStats(const SubdivisionCandidate &tData); 
     688        /** Print the subdivision stats in the subdivison log. 
     689        */ 
     690        void PrintSubdivisionStats(const SubdivisionCandidate &tData); 
    728691 
    729692        void AddSubdivisionStats( 
     
    734697        void AssociateObjectsWithRays(const VssRayContainer &rays); 
    735698 
    736         //float EvalViewCellsVolume(BvhLeaf *leaf) const; 
    737          
    738 /*      int RemoveParentViewCellsPvs(BvhLeaf *leaf, const RayInfoContainer &rays) const; 
    739         int UpdateViewCellsPvs(BvhLeaf *leaf, const RayInfoContainer &rays) const; 
    740         bool AddViewCellToObjectPvs( 
    741                 Intersectable *obj, 
    742                 ViewCell *vc,  
    743                 float &contribution, 
    744                 bool onlyMailed) const; 
    745 */ 
    746  
    747699        bool IsObjectInLeaf(BvhLeaf *, Intersectable *object) const; 
    748700 
    749         void MailViewCells( 
    750                 const ObjectContainer &objects,  
    751                 const bool isFront, 
    752                 ViewCellContainer &collectedViewCells) const; 
    753  
    754         SubdivisionCandidate *PrepareConstruction(const VssRayContainer &sampleRays, 
    755                                                                                           ObjectContainer &objects, 
    756                                                                                           AxisAlignedBox3 *forcedObjectSpace 
    757                                                                                           //, RayInfoContainer &rays 
    758                                                                                           ); 
    759  
    760         float EvalViewCellsVolume(BvhLeaf *leaf) const; 
     701        /** Classifies view cells using the mail id. 
     702                0 = front bv, 1 = back bv, 2 = both bvs 
     703        */ 
     704        void ClassifyViewCells( 
     705                const ViewCellContainer &objects,  
     706                const bool isFront) const; 
     707 
     708        SubdivisionCandidate *PrepareConstruction( 
     709                const VssRayContainer &sampleRays, 
     710                const ObjectContainer &objects 
     711                //,AxisAlignedBox3 *forcedObjectSpace 
     712                ); 
     713 
     714        float EvalViewCellsVolume(const ObjectContainer &objects) const; 
    761715 
    762716 
    763717protected: 
    764  
    765718         
    766719        /// pointer to the hierarchy of view cells 
     
    790743        int mTermMaxDepth; 
    791744        /// mininum probability 
    792         float mTermMinVolume; 
     745        float mTermMinProbability; 
    793746        /// minimal number of objects 
    794747        int mTermMinObjects; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1221 r1287  
    23112311                optBool, 
    23122312                "osp_use_cost_heuristics=", 
    2313                 "false"); 
     2313                "true"); 
    23142314 
    23152315        RegisterOption("OspTree.subdivisionStats", 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp

    r1233 r1287  
    44#include "KdTree.h" 
    55#include "KdIntersectable.h" 
     6#include "BvHierarchy.h" 
    67 
    78 
     
    6768                } 
    6869 
    69                 ExportGeometry(leaf->mObjects);  
     70                if (0) ExportGeometry(leaf->mObjects);   
    7071        } 
    7172 
     
    102103 
    103104 
     105bool Exporter::ExportBvHierarchy(const BvHierarchy &bvHierarchy,  
     106                                                                 const int maxPvs) 
     107{ 
     108        vector<BvhLeaf *> leaves; 
     109        bvHierarchy.CollectLeaves(leaves); 
     110 
     111        mUseForcedMaterial = true; 
     112 
     113        vector<BvhLeaf *>::const_iterator it, it_end = leaves.end(); 
     114 
     115        Material white;  
     116        white.mDiffuseColor.r = 1; 
     117        white.mDiffuseColor.g = 1; 
     118        white.mDiffuseColor.b = 1; 
     119        int objSize = 0; 
     120 
     121        for (it = leaves.begin(); it != it_end; ++ it) 
     122        { 
     123                BvhLeaf *leaf = *it; 
     124 
     125                SetWireframe(); 
     126                SetForcedMaterial(white); 
     127                ExportBox(leaf->GetBoundingBox()); 
     128                 
     129                SetFilled(); 
     130 
     131                if (maxPvs) // color code pvs 
     132                { 
     133                        mForcedMaterial.mDiffuseColor.b = 1.0f; 
     134                        const float importance = (float)leaf->mObjects.size() / (float)maxPvs; 
     135 
     136                        mForcedMaterial.mDiffuseColor.r = importance; 
     137                        mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 
     138                } 
     139                else 
     140                { 
     141                        SetForcedMaterial(RandomMaterial()); 
     142                } 
     143 
     144                if (1)  
     145                { 
     146                        SetFilled(); 
     147                        ExportGeometry(leaf->mObjects); 
     148                        objSize += leaf->mObjects.size(); 
     149                } 
     150        } 
     151 
     152        return true; 
    104153} 
     154 
     155 
     156} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h

    r1197 r1287  
    2929class OspTree; 
    3030class KdIntersectable; 
    31  
     31class BvHierarchy; 
    3232 
    3333class Exporter 
     
    149149 
    150150  void ExportKdIntersectable(const KdIntersectable &kdObj); 
     151  bool ExportBvHierarchy(const BvHierarchy &bvHierarchy, const int maxPvs); 
    151152}; 
    152153  
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1286 r1287  
    135135 
    136136        SubdivisionCandidate *osc =  
    137                 mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace, objectSpaceRays); 
     137                mOspTree->PrepareConstruction(sampleRays, objects, objectSpaceRays); 
    138138 
    139139        mTQueue.Push(osc); 
     
    145145        const float costDecr = tData.GetRenderCostDecrease(); 
    146146 
    147         //mTotalCost -= costDecr; 
    148         //mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 
    149  
    150         AddSubdivisionStats(mOspTree->mOspStats.Leaves() + mVspTree->mVspStats.Leaves(), 
    151                                                 costDecr, 
    152                                                 mTotalCost 
    153                                                 ); 
     147        switch (mObjectSpaceSubdivisonType) 
     148        { 
     149        case KD_BASED_OBJ_SUBDIV: 
     150                AddSubdivisionStats(mOspTree->mOspStats.Leaves() + mVspTree->mVspStats.Leaves(), 
     151                                                        costDecr, 
     152                                                        mTotalCost 
     153                                                        ); 
     154                break; 
     155        case BV_BASED_OBJ_SUBDIV: 
     156                AddSubdivisionStats(mBvHierarchy->mBvhStats.Leaves() + mVspTree->mVspStats.Leaves(), 
     157                                                        costDecr, 
     158                                                        mTotalCost 
     159                                                        ); 
     160                break; 
     161        default: 
     162                AddSubdivisionStats(mVspTree->mVspStats.Leaves(), 
     163                                                        costDecr, 
     164                                                        mTotalCost 
     165                                                        ); 
     166                break; 
     167        } 
    154168} 
    155169 
     
    198212 
    199213 
    200 bool HierarchyManager::SubdivideSubdivisionCandidate(SubdivisionCandidate *sc) 
     214bool HierarchyManager::ApplySubdivisionCandidate(SubdivisionCandidate *sc) 
    201215{ 
    202216        const bool globalTerminationCriteriaMet =  
     
    211225        else 
    212226        { 
    213                 KdNode *n = mOspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
     227                if (mObjectSpaceSubdivisonType == KD_BASED_OBJ_SUBDIV) 
     228                { 
     229                        KdNode *n = mOspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
     230                } 
     231                else if (mObjectSpaceSubdivisonType == BV_BASED_OBJ_SUBDIV) 
     232                { 
     233                        BvhNode *n = mBvHierarchy->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
     234                } 
    214235        } 
    215236         
     
    241262                //-- subdivide leaf node 
    242263 
    243                 if (SubdivideSubdivisionCandidate(splitCandidate)) 
     264                if (ApplySubdivisionCandidate(splitCandidate)) 
    244265                { 
    245266                        // subdivision successful 
     
    249270                        // for view space splits, this would be object space splits 
    250271                        // and other way round 
    251                         if (repair) 
    252                                 RepairQueue(); 
     272                        if (repair) RepairQueue(); 
    253273 
    254274                        cout << "candidate: " << splitCandidate->Type() << ", priority: " << splitCandidate->GetPriority() << endl; 
     
    455475 
    456476 
    457 void HierarchyManager::ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const 
     477void HierarchyManager::ExportObjectSpaceHierarchy(Exporter *exporter, 
     478                                                                                                  const ObjectContainer &objects) const 
    458479{ 
    459480        switch (mObjectSpaceSubdivisonType) 
     
    461482        case KD_BASED_OBJ_SUBDIV: 
    462483                { 
    463                         ExportOspTreeForViz(objects); 
    464                         break; 
    465                 } 
    466         case BV_BASED_OBJ_SUBDIV: 
    467                 { 
    468                         ExportBvhForViz(objects); 
     484                        ExportOspTree(exporter, objects); 
     485                        break; 
     486                } 
     487        case BV_BASED_OBJ_SUBDIV: 
     488                { 
     489                        ExportBvHierarchy(exporter, objects); 
    469490                        break; 
    470491                } 
     
    475496 
    476497 
    477 void HierarchyManager::ExportBvhForViz(const ObjectContainer &objects) const 
    478 { 
    479 } 
    480  
    481  
    482 void HierarchyManager::ExportOspTreeForViz(const ObjectContainer &objects) const 
    483 { 
    484         //-- export final object partition 
    485         Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 
    486                  
    487         if (exporter) 
    488         { 
    489                 cout << "exporting object space partition ... "; 
    490  
    491                 if (1) exporter->ExportGeometry(objects); 
     498void HierarchyManager::ExportBvHierarchy(Exporter *exporter,  
     499                                                                                 const ObjectContainer &objects) const 
     500{ 
     501        exporter->SetWireframe(); 
     502        exporter->ExportBvHierarchy(*mBvHierarchy, 0); 
     503} 
     504 
     505 
     506void HierarchyManager::ExportOspTree(Exporter *exporter,  
     507                                                                         const ObjectContainer &objects) const 
     508{ 
     509        if (0) exporter->ExportGeometry(objects); 
    492510                         
    493 #if 0            
    494                 // export rays 
    495                 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
    496 #endif 
    497                 exporter->SetWireframe(); 
    498          
    499                 const int colorCode = 0; 
    500                 const int maxPvs = 0;//mOspTree.GetStatistics().maxPvs; 
    501  
    502                 exporter->ExportOspTree(*mOspTree, 0); 
    503                 delete exporter; 
    504  
    505                 cout << "finished" << endl; 
    506         } 
     511        exporter->SetWireframe(); 
     512        const int maxPvs = 0;//mOspTree.GetStatistics().maxPvs; 
     513 
     514        exporter->ExportOspTree(*mOspTree, 0); 
    507515} 
    508516 
     
    561569        case KD_BASED_OBJ_SUBDIV: 
    562570                { 
    563                         ConstructOspTree(sampleRays, objects, forcedViewSpace); 
    564                         break; 
    565                 } 
    566         case BV_BASED_OBJ_SUBDIV: 
    567                 { 
    568                         ConstructBvHierarchy(sampleRays, objects, forcedViewSpace); 
     571                        ConstructOspTree(sampleRays, objects); 
     572                        break; 
     573                } 
     574        case BV_BASED_OBJ_SUBDIV: 
     575                { 
     576                        ConstructBvHierarchy(sampleRays, objects); 
    569577                        break; 
    570578                } 
     
    576584 
    577585void HierarchyManager::ConstructBvHierarchy(const VssRayContainer &sampleRays, 
    578                                                                                         const ObjectContainer &objects, 
    579                                                                                         AxisAlignedBox3 *forcedViewSpace)  
     586                                                                                        const ObjectContainer &objects 
     587                                                                                        //,AxisAlignedBox3 *forcedViewSpace 
     588                                                                                        )  
    580589 
    581590{ 
     
    583592        cout << "starting bv hierarchy construction ... " << endl; 
    584593 
     594        //ObjectContainer obj = objects; 
     595 
     596        // compute first candidate 
     597        SubdivisionCandidate *sc = 
     598                mBvHierarchy->PrepareConstruction(sampleRays, objects); 
     599 
     600        mTotalCost = mBvHierarchy->mTotalCost; 
     601        Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
     602         
     603    mTQueue.Push(sc); 
     604 
     605        mBvHierarchy->mBvhStats.Reset(); 
     606        mBvHierarchy->mBvhStats.Start(); 
     607 
     608        const long startTime = GetTime(); 
     609        const bool repairQueue = false; 
     610 
     611        // process object space candidates 
     612        RunConstruction(repairQueue); 
     613         
     614        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     615 
     616        mBvHierarchy->mBvhStats.Stop(); 
     617} 
     618 
     619 
     620void HierarchyManager::ConstructOspTree(const VssRayContainer &sampleRays, 
     621                                                                                const ObjectContainer &objects)  
     622 
     623{ 
     624        RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 
     625 
     626        Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 
     627        cout << "starting osp tree construction ... " << endl; 
     628 
    585629        // start with one big kd cell - all objects can be seen from everywhere 
    586630        // note: only true for view space = object space 
    587631 
    588         ObjectContainer obj = objects; 
    589  
    590632        // compute first candidate 
    591         SubdivisionCandidate *sc = 
    592                 mBvHierarchy->PrepareConstruction(sampleRays, obj, forcedViewSpace); 
    593  
     633        SubdivisionCandidate *osc = 
     634                mOspTree->PrepareConstruction(sampleRays, objects, *objectSpaceRays); 
     635 
     636        mTotalCost = mOspTree->mTotalCost; 
    594637        Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
    595         mTotalCost = mOspTree->mTotalCost; 
    596  
    597     mTQueue.Push(sc); 
     638         
     639    mTQueue.Push(osc); 
    598640 
    599641        mOspTree->mOspStats.Reset(); 
     
    602644        const long startTime = GetTime(); 
    603645        const bool repairQueue = false; 
    604  
     646         
    605647        // process object space candidates 
    606648        RunConstruction(repairQueue); 
     
    618660} 
    619661 
    620  
    621 void HierarchyManager::ConstructOspTree(const VssRayContainer &sampleRays, 
    622                                                                                 const ObjectContainer &objects, 
    623                                                                                 AxisAlignedBox3 *forcedViewSpace)  
    624  
    625 { 
    626         RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 
    627  
    628         Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 
    629         cout << "starting osp tree construction ... " << endl; 
    630  
    631         // start with one big kd cell - all objects can be seen from everywhere 
    632         // note: only true for view space = object space 
    633  
    634         // compute first candidate 
    635         SubdivisionCandidate *osc = 
    636                 mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 
    637  
    638         Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
    639         mTotalCost = mOspTree->mTotalCost; 
    640  
    641     mTQueue.Push(osc); 
    642  
    643         mOspTree->mOspStats.Reset(); 
    644         mOspTree->mOspStats.Start(); 
    645  
    646         const long startTime = GetTime(); 
    647         const bool repairQueue = false; 
    648          
    649         // process object space candidates 
    650         RunConstruction(repairQueue); 
    651          
    652         cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    653  
    654         mOspTree->mOspStats.Stop(); 
    655  
    656         ////////////////////////// 
    657         // matt: only for debugging purpose 
    658  
    659         const float rc = mOspTree->EvalRenderCost(sampleRays); 
    660  
    661         Debug << "My render cost evalulation: " << rc << endl; 
    662 } 
    663  
    664 } 
     662} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1286 r1287  
    4040class KdTreeStatistics; 
    4141class BvHierarchy; 
    42  
     42class Exporter; 
    4343 
    4444#if 0 
     
    154154        VspTree *GetVspTree() { return mVspTree; } 
    155155 
    156         void ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const; 
     156        void ExportObjectSpaceHierarchy( 
     157                Exporter *exporter,  
     158                const ObjectContainer &objects) const; 
    157159 
    158160 
     
    172174 
    173175        void RunConstruction(const bool repair); 
    174         bool SubdivideSubdivisionCandidate(SubdivisionCandidate *sc); 
     176        bool ApplySubdivisionCandidate(SubdivisionCandidate *sc); 
    175177 
    176178        bool FinishedConstruction() const; 
     
    199201        void CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList); 
    200202                 
    201         void ExportOspTreeForViz(const ObjectContainer &objects) const; 
    202         void ExportBvhForViz(const ObjectContainer &objects) const; 
     203        void ExportOspTree(Exporter *exporter, const ObjectContainer &objects) const; 
     204        void ExportBvHierarchy(Exporter *exporter, const ObjectContainer &objects) const; 
     205 
    203206 
    204207        void ConstructBvHierarchy( 
    205208                const VssRayContainer &sampleRays, 
    206                 const ObjectContainer &objects, 
    207                 AxisAlignedBox3 *forcedViewSpace); 
     209                const ObjectContainer &objects); 
    208210 
    209211        void ConstructOspTree( 
    210212                const VssRayContainer &sampleRays, 
    211                 const ObjectContainer &objects, 
    212                 AxisAlignedBox3 *forcedViewSpace); 
     213                const ObjectContainer &objects); 
    213214 
    214215protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r1199 r1287  
    99bool MeshDebug = false; 
    1010 
    11 int Intersectable::sMailId = 21843194198; 
     11int Intersectable::sMailId = 2147483647; 
    1212int Intersectable::sReservedMailboxes = 1; 
    1313 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp

    r1286 r1287  
    397397        backData.mNode = back; 
    398398 
    399  
    400399        // compute probability, i.e., volume of seen view cells 
    401400        frontData.mProbability = EvalViewCellsVolume(front, *frontData.mRays); 
    402401        backData.mProbability =  EvalViewCellsVolume(back, *backData.mRays); 
    403  
    404402 
    405403        //delete leaf; 
     
    16481646 
    16491647 
    1650 void OspTree::ComputeBoundingBox(const ObjectContainer &objects, 
    1651                                                                  AxisAlignedBox3 *forcedBoundingBox)  
    1652 { 
    1653         if (forcedBoundingBox) 
    1654         { 
    1655                 mBoundingBox = *forcedBoundingBox; 
    1656         } 
    1657         else // compute vsp tree bounding box 
    1658         { 
    1659                 mBoundingBox.Initialize(); 
    1660  
    1661                 ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    1662  
    1663                 //-- compute bounding box 
    1664         for (oit = objects.begin(); oit != oit_end; ++ oit) 
    1665                 { 
    1666                         Intersectable *obj = *oit; 
    1667  
    1668                         // compute bounding box of view space 
    1669                         mBoundingBox.Include(obj->GetBox()); 
    1670                 } 
     1648void OspTree::ComputeBoundingBox(const ObjectContainer &objects)  
     1649{ 
     1650        mBoundingBox.Initialize(); 
     1651 
     1652        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     1653 
     1654        //-- compute bounding box 
     1655        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     1656        { 
     1657                Intersectable *obj = *oit; 
     1658 
     1659                // compute bounding box of view space 
     1660                mBoundingBox.Include(obj->GetBox()); 
    16711661        } 
    16721662} 
     
    26572647SubdivisionCandidate * OspTree::PrepareConstruction(const VssRayContainer &sampleRays, 
    26582648                                                                                                        const ObjectContainer &objects, 
    2659                                                                                                         AxisAlignedBox3 *forcedObjectSpace, 
    26602649                                                                                                        RayInfoContainer &rays) 
    26612650{ 
     
    26652654         
    26662655        // compute bounding box from objects 
    2667         ComputeBoundingBox(objects, forcedObjectSpace); 
     2656        ComputeBoundingBox(objects); 
    26682657 
    26692658        mTermMinProbability *= mBoundingBox.GetVolume(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h

    r1259 r1287  
    627627                @returns pvs size of the node 
    628628        */ 
    629         float PrepareHeuristics(const OspTraversalData &tData, ViewCellContainer &touchedViewCells); 
     629        float PrepareHeuristics( 
     630                const OspTraversalData &tData,  
     631                ViewCellContainer &touchedViewCells); 
    630632 
    631633        /** Prepares heuristics for a particular ray. 
    632634        */ 
    633         void PrepareHeuristics(const VssRay &ray, ViewCellContainer &touchedViewCells); 
     635        void PrepareHeuristics( 
     636                const VssRay &ray,  
     637                ViewCellContainer &touchedViewCells); 
    634638 
    635639        /** Prepares construction for vsp and osp trees. 
    636640        */ 
    637         void ComputeBoundingBox(const ObjectContainer &objects, 
    638                                                         AxisAlignedBox3 *forcedBoundingBox); 
     641        void ComputeBoundingBox(const ObjectContainer &objects); 
    639642 
    640643        void CollectDirtyCandidates(OspSubdivisionCandidate *sc, 
     
    727730                const VssRayContainer &sampleRays, 
    728731                const ObjectContainer &objects, 
    729                 AxisAlignedBox3 *forcedObjectSpace, 
    730732                RayInfoContainer &rays); 
    731733 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1286 r1287  
    1818#include "BvHierarchy.h" 
    1919#include "HierarchyManager.h" 
     20#include "VssRay.h" 
     21 
    2022 
    2123#ifdef GTP_INTERNAL 
     
    483485                const bool ishack = true; 
    484486 
    485                 if (ishack) 
    486                 { 
     487                /*if (ishack) 
    487488                        mHierarchyManager = new HierarchyManager(mVspTree, mKdTree); 
    488                 } 
    489489                else 
    490                 { 
    491490                        mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::KD_BASED_OBJ_SUBDIV); 
    492                 } 
     491                */ 
     492                mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::BV_BASED_OBJ_SUBDIV); 
    493493 
    494494                mViewCellsManager = new VspOspViewCellsManager(vcTree, mHierarchyManager); 
     
    831831                                                                objectB, 
    832832                                                                objectA, 
    833                                                                 probability, 
    834                                                                 mPass); 
     833                                                                mPass, 
     834                                                                probability 
     835                                                                ); 
    835836 
    836837                        vssRays.push_back(vssRay); 
     
    844845                                                                objectA, 
    845846                                                                objectB, 
    846                                                                 probability, 
    847                                                                 mPass); 
     847                                                                mPass, 
     848                                                                probability 
     849                                                                ); 
    848850 
    849851                        vssRays.push_back(vssRay); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1283 r1287  
    2828class BvHierarchy; 
    2929class Intersectable; 
     30class VssRay; 
    3031 
    3132/** Namespace for the external visibility preprocessor 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj

    r1286 r1287  
    2727                                RuntimeTypeInfo="TRUE" 
    2828                                UsePrecompiledHeader="0" 
     29                                BrowseInformation="1" 
    2930                                WarningLevel="3" 
    3031                                Detect64BitPortabilityProblems="TRUE" 
     
    6869                                OmitFramePointers="TRUE" 
    6970                                EnableFiberSafeOptimizations="TRUE" 
    70                                 OptimizeForProcessor="3" 
     71                                OptimizeForProcessor="0" 
    7172                                OptimizeForWindowsApplication="TRUE" 
    7273                                AdditionalIncludeDirectories="..\include;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj

    r1286 r1287  
    2626                                RuntimeLibrary="3" 
    2727                                UsePrecompiledHeader="0" 
     28                                BrowseInformation="1" 
    2829                                WarningLevel="3" 
    2930                                Detect64BitPortabilityProblems="TRUE" 
     
    7576                                EnableIntrinsicFunctions="TRUE" 
    7677                                FavorSizeOrSpeed="1" 
    77                                 OptimizeForProcessor="3" 
     78                                OptimizeForProcessor="0" 
    7879                                OptimizeForWindowsApplication="TRUE" 
    7980                                AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\MultiLevelRayTracing" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1286 r1287  
    3232                                           myless<vector<ViewCell *>::value_type> > TraversalQueue; 
    3333 
    34 int ViewCell::sMailId = 0;//21843194198; 
     34int ViewCell::sMailId = 2147483647; 
    3535int ViewCell::sReservedMailboxes = 1; 
    3636 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1286 r1287  
    51015101                        cout << "exporting view cells after post process ... "; 
    51025102 
    5103                         if (0) 
    5104                         { 
    5105                                 // export view space box 
    5106                                 exporter->SetWireframe(); 
    5107                                 exporter->ExportBox(mViewSpaceBox); 
    5108                                 exporter->SetFilled(); 
    5109                         } 
    5110  
    51115103                        if (mExportGeometry) 
    51125104                        { 
     
    51205112                        } 
    51215113 
    5122                         //exporter->SetFilled(); 
    5123  
    51245114                        // HACK: export without clip plane 
    51255115                        const bool b = mUseClipPlaneForViz; 
     
    51375127        } 
    51385128 
    5139         mHierarchyManager->ExportObjectSpaceHierarchyForViz(objects); 
    5140          
    5141         //-- export single view cells 
     5129        if (1) 
     5130        { 
     5131                // export final object partition 
     5132                Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 
     5133 
     5134                if (exporter) 
     5135                { 
     5136                        cout << "exporting object space hierarchy ... "; 
     5137                        mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects); 
     5138                 
     5139                        delete exporter; 
     5140                        cout << "finished" << endl; 
     5141                } 
     5142        } 
     5143         
     5144        // export pvss of some view cell 
    51425145        ExportPvs(objects, visRays); 
    51435146} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1286 r1287  
    159159        if (mObjectSpaceHierarchyType == OSP) 
    160160        { 
     161                // for a spatial subdivision, it is not necessary to store 
     162                // the objects with the leaves, they can be classified now 
    161163                mHierarchyManager->mOspTree->InsertObjects( 
    162164                        mHierarchyManager->mOspTree->mRoot, *mObjects); 
    163165        } 
     166        else 
     167                cout << "here209" << endl; 
     168 
    164169} 
    165170 
     
    279284 
    280285 
    281 void ViewCellsParseHandlers::StartHierarchy(AttributeList&  attributes) 
    282 { 
    283         int len = attributes.getLength(); 
    284    
    285         for (int i = 0; i < len; ++ i)  
    286         { 
    287                 string attrName(StrX(attributes.getName(i)).LocalForm()); 
    288                  
    289                 if (attrName == "name")  
    290                 { 
    291                         StrX attrValue(attributes.getValue(i)); 
    292                          
    293                         const char *ptr = attrValue.LocalForm(); 
    294                          
    295                         // the view cells manager is created here 
    296                         //CreateViewCellsManager(ptr); 
    297                 } 
    298         } 
    299 } 
    300  
    301  
    302286void ViewCellsParseHandlers::StartBspElement(string element, 
    303287                                                                                         AttributeList& attributes) 
     
    437421                // create new view cells hierarchy 
    438422                mViewCellsTree = new ViewCellsTree(); 
    439         } 
    440  
    441         // decides about the view cells manager type 
    442         if (element == "Hierarchy") 
    443         { 
    444                 cout << "parsing view cells manager type" << endl; 
    445                 StartHierarchy(attributes); 
    446423        } 
    447424 
     
    688665                const char *ptr = attrValue.LocalForm(); 
    689666 
    690  
    691667                if (attrName == "id") 
    692668                { 
     
    711687void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes) 
    712688{ 
    713         BspLeaf * leaf =  
    714                 new BspLeaf(dynamic_cast<BspInterior *>(mCurrentBspNode), NULL); 
     689        BspLeaf * leaf; 
    715690 
    716691        if (mCurrentBspNode) // replace front or (if not NULL) back child 
    717692        { 
    718                 dynamic_cast<BspInterior *>(mCurrentBspNode)->ReplaceChildLink(NULL, leaf); 
     693                BspInterior *interior = dynamic_cast<BspInterior *>(mCurrentBspNode); 
     694 
     695                leaf = new BspLeaf(interior); 
     696                interior->ReplaceChildLink(NULL, leaf); 
    719697        } 
    720698        else 
    721699        { 
     700                leaf = new BspLeaf(); 
    722701                mVspBspTree->mRoot = leaf; 
    723702        } 
     
    797776        if (mCurrentBspNode) // replace NULL child of parent with current node 
    798777        { 
    799                 BspInterior *current = dynamic_cast<BspInterior *>(mCurrentBspNode); 
    800  
    801                 current->ReplaceChildLink(NULL, interior); 
    802                 interior->SetParent(current); 
     778                BspInterior *parent = dynamic_cast<BspInterior *>(mCurrentBspNode); 
     779 
     780                parent->ReplaceChildLink(NULL, interior); 
     781                interior->SetParent(parent); 
    803782        } 
    804783        else 
     
    856835void ViewCellsParseHandlers::CreateViewSpaceHierarchy() 
    857836{ 
    858         ViewCellContainer::iterator it, it_end = mViewCells.end(); 
    859         cout << "\n====================" << endl << endl; 
    860         for (it = mViewCells.begin(); it != it_end; ++ it) 
    861         { 
    862                 cout << (*it)->GetId() << " "; 
    863         } 
    864 cout << endl; 
    865837        if (mViewSpaceHierarchyType == BSP) 
    866838        { 
     
    936908                } 
    937909        } 
    938         cout << "************************" << endl; 
    939         it_end = mViewCells.end(); 
    940         for (it = mViewCells.begin(); it != it_end; ++ it) 
    941         { 
    942                 cout << (*it)->GetId() << " "; 
    943         } 
    944         cout << endl; 
    945         cout << "\nview space box: " << mViewSpaceBox << endl; 
     910        //cout << "\nview space box: " << mViewSpaceBox << endl; 
    946911} 
    947912 
     
    992957void ViewCellsParseHandlers::StartVspLeaf(AttributeList& attributes) 
    993958{ 
    994         VspLeaf * leaf =  
    995                 new VspLeaf(dynamic_cast<VspInterior *>(mCurrentVspNode), NULL); 
    996  
     959        VspLeaf * leaf; 
     960                 
    997961        if (mCurrentVspNode) // replace front or (if not NULL) back child 
    998962        { 
    999                 dynamic_cast<VspInterior *>(mCurrentVspNode)->ReplaceChildLink(NULL, leaf); 
     963                VspInterior *interior = dynamic_cast<VspInterior *>(mCurrentVspNode); 
     964                leaf = new VspLeaf(interior); 
     965                interior->ReplaceChildLink(NULL, leaf); 
    1000966        } 
    1001967        else 
    1002968        { 
     969                leaf = new VspLeaf(); 
    1003970                mVspTree->mRoot = leaf; 
    1004971        } 
     
    1029996                dummyVc.SetId(viewCellId); 
    1030997 
    1031                 cout << "\nsearching view cell with id " << viewCellId << endl; 
     998                //cout << "\nsearching view cell with id " << viewCellId << endl; 
    1032999 
    10331000                ViewCellContainer::iterator vit = 
     
    10871054                AxisAlignedBox3 frontBox, backBox; 
    10881055 
    1089                 parent->GetBoundingBox().Split(parent->GetPlane().mAxis, parent->GetPlane().mPosition, frontBox, backBox); 
     1056                parent->GetBoundingBox().Split( 
     1057                        parent->GetPlane().mAxis,  
     1058                        parent->GetPlane().mPosition,  
     1059                        frontBox,  
     1060                        backBox); 
     1061 
    10901062                if (parent->GetFront() == interior) 
    10911063                        interior->SetBoundingBox(frontBox); 
     
    11341106 
    11351107                parent->mBox.Split(parent->mAxis, parent->mPosition, frontBox, backBox); 
     1108 
    11361109                if (parent->mFront == interior) 
    11371110                        interior->mBox = frontBox; 
     
    11801153                if (attrName == "min")  
    11811154                { 
    1182                         sscanf(ptr, "%f %f %f", &minBox); 
     1155                        sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z); 
    11831156                } 
    11841157                if (attrName == "max")  
    11851158                { 
    1186                         sscanf(ptr, "%f %f %f", &maxBox); 
     1159                        sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z); 
    11871160                } 
    11881161                if (attrName == "objects") 
     
    11921165        } 
    11931166 
    1194         BvhLeaf * leaf =  
    1195                 new BvhLeaf(AxisAlignedBox3(minBox, maxBox),  
    1196                                         dynamic_cast<BvhInterior *>(mCurrentBvhNode), (int)objects.size()); 
     1167        AxisAlignedBox3 box = AxisAlignedBox3(minBox, maxBox); 
     1168 
     1169        BvhLeaf *leaf; 
     1170 
     1171        if (mCurrentBvhNode) // replace front or (if not NULL) back child 
     1172        { 
     1173                BvhInterior *interior = dynamic_cast<BvhInterior *>(mCurrentBvhNode); 
     1174                leaf = new BvhLeaf(box, interior, (int)objects.size()); 
     1175                interior->ReplaceChildLink(NULL, leaf); 
     1176        } 
     1177        else 
     1178        { 
     1179                leaf = new BvhLeaf(box, NULL, (int)objects.size()); 
     1180                mHierarchyManager->mBvHierarchy->mRoot = leaf; 
     1181        } 
    11971182 
    11981183        leaf->mObjects = objects; 
    1199  
    1200         if (mCurrentBvhNode) // replace front or (if not NULL) back child 
    1201         { 
    1202                 dynamic_cast<BvhInterior *>(mCurrentBvhNode)->ReplaceChildLink(NULL, leaf); 
    1203         } 
    1204         else 
    1205         { 
    1206                 mHierarchyManager->mBvHierarchy->mRoot = leaf; 
    1207         } 
    12081184} 
    12091185 
     
    12191195        { 
    12201196                const int index = strtol(ptr, &endptr, 10); 
    1221  
    12221197                if (ptr == endptr) break; 
    12231198 
    12241199                objIndices.push_back(index); 
    1225  
    12261200                ptr = endptr; 
    12271201        } 
     
    12391213 
    12401214                ObjectContainer::iterator oit = 
    1241                         lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt);       
     1215                        lower_bound(mObjects->begin(),  
     1216                                                mObjects->end(),  
     1217                                                (Intersectable *)&dummyInst,  
     1218                                                ilt);    
    12421219                                                         
    12431220                if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) 
     
    12601237        for (int i = 0; i < len; ++ i)  
    12611238        { 
     1239                cout << "here5" << endl; 
    12621240                string attrName(StrX(attributes.getName(i)).LocalForm()); 
    12631241                StrX attrValue(attributes.getValue(i)); 
     
    12651243 
    12661244                if (attrName == "min")  
    1267                 { 
    1268                         sscanf(ptr, "%f %f %f", &minBox); 
     1245                {cout << "here6" << endl; 
     1246                        sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z); 
    12691247                } 
    12701248                if (attrName == "max")  
    1271                 { 
    1272                         sscanf(ptr, "%f %f %f", &maxBox); 
     1249                {cout << "here7" << endl; 
     1250                        sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z); 
    12731251                } 
    12741252        } 
     
    12781256        if (mCurrentBvhNode) // replace NULL child of parent with current node 
    12791257        { 
     1258                cout << "here8" << endl; 
    12801259                BvhInterior *parent = dynamic_cast<BvhInterior *>(mCurrentBvhNode); 
    12811260                parent->ReplaceChildLink(NULL, interior); 
     
    12831262        } 
    12841263        else 
    1285         { 
    1286                 mBvHierarchy->mRoot = interior; 
    1287         } 
    1288  
     1264        {cout << "here18" << endl; 
     1265                mHierarchyManager->mBvHierarchy->mRoot = interior; 
     1266        } 
     1267cout << "here28" << endl; 
    12891268        mCurrentBvhNode = interior; 
    12901269} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h

    r1286 r1287  
    7777  VspBspTree *mVspBspTree; 
    7878  HierarchyManager *mHierarchyManager; 
    79   BvHierarchy *mBvHierarchy; 
     79  //vHierarchy *mBvHierarchy; 
    8080 
    8181  BspTree *mBspTree; 
     
    129129  void EndViewCells(); 
    130130  void EndBoundingBoxes(); 
    131          
    132   void StartHierarchy(AttributeList& attributes); 
    133131 
    134132  void StartBspElement(string element, AttributeList& attributes); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp

    r1233 r1287  
    11811181        } 
    11821182 
    1183         // hack: all object exported as one mesh 
     1183        /////////////////////////////////// 
     1184        // method 2 (hacky) 
     1185        // all object exported as one mesh 
    11841186        PolygonContainer polys; 
    11851187 
    11861188        for (oit = objects.begin(); oit != oit_end; ++ oit) 
    11871189        { 
    1188                 polys.push_back(new Polygon3(dynamic_cast<MeshInstance *>(*oit)->GetMesh()->mVertices)); 
     1190                MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 
     1191                polys.push_back(new Polygon3(mi->GetMesh()->mVertices)); 
    11891192        } 
    11901193 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1286 r1287  
    28542854void VspTree::GetViewCells(const VssRay &ray, ViewCellContainer &viewCells) 
    28552855{ 
    2856 #if 0  
     2856#if 1  
    28572857        // use view cells manager to compute view cells 
    2858         mViewCellsManager->ComputeSampleContribution(ray, false, true); 
    2859         viewCells = ray.mViewCells; 
    2860         ray.mViewCells.clear(); 
    2861          
     2858        VssRay vcRay(ray); 
     2859 
     2860        mViewCellsManager->ComputeSampleContribution(vcRay, false, true); 
     2861        viewCells = vcRay.mViewCells; 
    28622862#else 
    28632863        static Ray hray; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.h

    r1201 r1287  
    269269 
    270270 
    271  
     271/*inline int 
     272RandomValue(int a, int b) 
     273{ 
     274        int range = abs(a - b); 
     275        return (rand() * range) / RAND_MAX + ((a < b) ? a : b); 
     276}*/ 
    272277 
    273278inline Real sqr(Real a) 
     
    275280  return a*a; 
    276281} 
     282 
    277283 
    278284template <class T> 
Note: See TracChangeset for help on using the changeset viewer.