Changeset 1323


Ignore:
Timestamp:
09/05/06 09:51:56 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
4 edited

Legend:

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

    r1314 r1323  
    580580 
    581581        const float oldProp = EvalViewCellsVolume(tData.mNode->mObjects); 
    582         //const float oldProp2 = tData.mProbability; Debug << "here65 " << oldProp - oldProp2 << endl; 
     582        //const float oldProp2 = tData.mProbability; 
    583583 
    584584        const float oldRenderCost = oldProp * (float)tData.mNode->mObjects.size(); 
     
    591591 
    592592 
    593 float BvHierarchy::EvalLocalCostHeuristics(const BvhTraversalData &tData, 
    594                                                                                    const int axis, 
    595                                                                                    ObjectContainer &objectsFront, 
    596                                                                                    ObjectContainer &objectsBack) 
    597 { 
    598         // prepare the heuristics by setting mailboxes and counters. 
    599         const float totalVol = PrepareHeuristics(tData, axis); 
    600  
     593float BvHierarchy::EvalSah(const BvhTraversalData &tData, 
     594                                                   const int axis, 
     595                                                   ObjectContainer &objectsFront, 
     596                                                   ObjectContainer &objectsBack) 
     597{ 
     598        SortSubdivisionCandidates(tData, axis); 
     599   
    601600        // go through the lists, count the number of objects left and right 
    602         // and evaluate the cost funcion 
    603  
    604         // local helper variables 
    605         float volLeft = 0; 
    606         float volRight = totalVol; 
    607  
    608         int nObjectsLeft = 0; 
    609  
    610         const int nTotalObjects = (int)tData.mNode->mObjects.size(); 
    611         const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     601        // and evaluate the following cost funcion: 
     602        // C = ct_div_ci  + (ol + or)/queries 
     603        int objectsLeft = 0, objectsRight = (int)tData.mNode->mObjects.size(); 
     604   
     605        AxisAlignedBox3 box = tData.mNode->GetBoundingBox(); 
     606 
     607        float minBox = box.Min(axis); 
     608        float maxBox = box.Max(axis); 
     609        float boxArea = box.SurfaceArea(); 
     610 
     611        float minSum = 1e20f; 
     612   
     613        vector<float> bordersRight; 
     614        bordersRight.resize(mSubdivisionCandidates->size()); 
     615 
     616        float minBorder = maxBox; 
     617        float maxBorder = minBox; 
    612618 
    613619        vector<SortableEntry>::const_iterator currentPos = 
    614620                mSubdivisionCandidates->begin(); 
    615621 
    616         ///////////////////////////////// 
    617         // the parameters for the current optimum 
    618  
    619         float volBack = volLeft; 
    620         float volFront = volRight; 
    621         float newRenderCost = nTotalObjects * totalVol; 
    622  
    623 #ifdef _DEBUG 
    624         const int leaves = mBvhStats.Leaves(); 
    625         const bool printStats = ((axis == 0) && (leaves > 0) && (leaves < 90)); 
    626          
    627         ofstream sumStats; 
    628         ofstream vollStats; 
    629         ofstream volrStats; 
    630  
    631         if (printStats) 
     622        vector<SortableEntry>::reverse_iterator rcit =  
     623                mSubdivisionCandidates->rbegin(), rcit_end = mSubdivisionCandidates->rend(); 
     624                 
     625        vector<float>::reverse_iterator rbit = bordersRight.rbegin(); 
     626         
     627        for (; rcit != rcit_end; ++ rcit, ++ rbit)  
     628        { 
     629                Intersectable *obj = (*rcit).mObject; 
     630                const AxisAlignedBox3 box = obj->GetBox(); 
     631 
     632                if (box.Min() < minBorder) 
     633                        minBorder = box.Min(axis); 
     634                 
     635                (*rbit) = minBorder; 
     636        } 
     637 
     638        vector<float>::const_iterator bit = bordersRight.begin(); 
     639 
     640        vector<SortableEntry>::const_iterator cit, cit_end = mSubdivisionCandidates->end(); 
     641        for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit, ++ bit)  
     642        { 
     643                Intersectable *obj = (*cit).mObject; 
     644 
     645                ++ objectsLeft; 
     646                -- objectsRight; 
     647 
     648                AxisAlignedBox3 lbox = box; 
     649                AxisAlignedBox3 rbox = box; 
     650         
     651                const AxisAlignedBox3 obox = obj->GetBox(); 
     652 
     653                if (obox.Max(axis) > maxBorder) 
     654                        maxBorder = obox.Max(axis); 
     655 
     656        lbox.SetMax(axis, maxBorder); 
     657                rbox.SetMin(axis, *bit); 
     658         
     659                const float sum = objectsLeft * lbox.SurfaceArea() + objectsRight * rbox.SurfaceArea(); 
     660       
     661            // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 
     662            // cout<<"cost= "<<sum<<endl; 
     663       
     664                if (sum < minSum)  
     665                { 
     666                        minSum = sum;    
     667                        // objects belongs to left side now 
     668                        for (; currentPos != (cit + 1); ++ currentPos); 
     669                } 
     670        } 
     671 
     672        //-- assign object to front and back volume 
     673 
     674        // belongs to back bv 
     675        for (cit = mSubdivisionCandidates->begin(); cit != currentPos; ++ cit) 
     676                objectsBack.push_back((*cit).mObject); 
     677         
     678        // belongs to front bv 
     679        for (cit = currentPos; cit != cit_end; ++ cit) 
     680                objectsFront.push_back((*cit).mObject); 
     681 
     682        float oldCost = (float)tData.mNode->mObjects.size(); 
     683        float newCost = minSum / boxArea; 
     684        float ratio = newCost / oldCost; 
     685   
     686#if 0 
     687  cout<<"===================="<<endl; 
     688  cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox) 
     689      <<"\t o=("<<objectsBack<<","<<objectsFront<<")"<<endl; 
     690#endif 
     691  return ratio; 
     692} 
     693 
     694 
     695static bool PrepareOutput(const int axis, 
     696                                                  const int leaves, 
     697                                                  ofstream &sumStats,  
     698                                                  ofstream &vollStats,  
     699                                                  ofstream &volrStats) 
     700{ 
     701        if ((axis == 0) && (leaves > 0) && (leaves < 90)) 
    632702        { 
    633703                char str[64];    
     
    639709                volrStats.open(str); 
    640710        } 
     711 
     712        return sumStats.is_open() && vollStats.is_open() && volrStats.is_open(); 
     713} 
     714 
     715 
     716static void PrintHeuristics(const int objectsRight, 
     717                                                        const float sum, 
     718                                                        const float volLeft, 
     719                                                        const float volRight, 
     720                                                        const float viewSpaceVol, 
     721                                                        ofstream &sumStats,  
     722                                                        ofstream &vollStats,  
     723                                                        ofstream &volrStats) 
     724{ 
     725        sumStats 
     726                << "#Position\n" << objectsRight << endl 
     727                << "#Sum\n" << sum / viewSpaceVol << endl 
     728                << "#Vol\n" << (volLeft +  volRight) / viewSpaceVol << endl; 
     729 
     730        vollStats 
     731                << "#Position\n" << objectsRight << endl 
     732                << "#Vol\n" << volLeft / viewSpaceVol << endl; 
     733 
     734        volrStats 
     735                << "#Position\n" << objectsRight << endl 
     736                << "#Vol\n" << volRight / viewSpaceVol << endl; 
     737} 
     738 
     739 
     740float BvHierarchy::EvalLocalCostHeuristics(const BvhTraversalData &tData, 
     741                                                                                   const int axis, 
     742                                                                                   ObjectContainer &objectsFront, 
     743                                                                                   ObjectContainer &objectsBack) 
     744{ 
     745        // prepare the heuristics by setting mailboxes and counters. 
     746        const float totalVol = PrepareHeuristics(tData, axis); 
     747 
     748        // go through the lists, count the number of objects left and right 
     749        // and evaluate the cost funcion 
     750 
     751        // local helper variables 
     752        float volLeft = 0; 
     753        float volRight = totalVol; 
     754 
     755        int nObjectsLeft = 0; 
     756 
     757        const int nTotalObjects = (int)tData.mNode->mObjects.size(); 
     758        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     759 
     760        vector<SortableEntry>::const_iterator currentPos = 
     761                mSubdivisionCandidates->begin(); 
     762 
     763        ///////////////////////////////// 
     764        // the parameters for the current optimum 
     765 
     766        float volBack = volLeft; 
     767        float volFront = volRight; 
     768        float newRenderCost = nTotalObjects * totalVol; 
     769 
     770#ifdef _DEBUG 
     771        ofstream sumStats; 
     772        ofstream vollStats; 
     773        ofstream volrStats; 
     774 
     775        const bool printStats = 
     776                PrepareOutput(axis, mBvhStats.Leaves(), sumStats, vollStats, volrStats); 
     777         
    641778#endif 
    642779 
     
    666803 
    667804#ifdef _DEBUG 
    668                  
    669805                if (printStats) 
    670                 { 
    671                         sumStats 
    672                                 << "#Position\n" << nObjectsRight << endl 
    673                                 << "#Sum\n" << sum / viewSpaceVol << endl 
    674                                 << "#Vol\n" << (volLeft +  volRight) / viewSpaceVol << endl; 
    675  
    676                         vollStats 
    677                                 << "#Position\n" << nObjectsRight << endl 
    678                                 << "#Vol\n" << volLeft / viewSpaceVol << endl; 
    679  
    680                         volrStats 
    681                                 << "#Position\n" << nObjectsRight << endl 
    682                                 << "#Vol\n" << volRight / viewSpaceVol << endl; 
    683                 } 
     806                        PrintHeuristics(nObjectsRight, sum, volLeft, volRight, viewSpaceVol, 
     807                                                        sumStats, vollStats, volrStats); 
    684808#endif 
    685809 
     
    705829        for (cit = currentPos; cit != cit_end; ++ cit) 
    706830                objectsFront.push_back((*cit).mObject); 
    707  
    708         tData.mNode->mObjects.end(); 
    709831 
    710832        const float oldRenderCost = (float)nTotalObjects * totalVol + Limits::Small; 
     
    775897float BvHierarchy::PrepareHeuristics(const BvhTraversalData &tData, const int axis) 
    776898{        
    777         //-- sort so we can use a sweep from right to left 
     899        BvhLeaf *leaf = tData.mNode; 
     900        float vol = 0; 
     901 
     902        // sort so we can use a sweep from right to left 
    778903        SortSubdivisionCandidates(tData, axis); 
    779  
    780         float vol = 0; 
    781         BvhLeaf *leaf = tData.mNode; 
    782904 
    783905        // collect and mark the view cells as belonging to front pvs 
    784906        ViewCellContainer viewCells; 
    785907        CollectViewCells(tData.mNode->mObjects, viewCells, true); 
    786  
    787     ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    788  
     908                         
     909        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    789910        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    790911        { 
     
    792913        } 
    793914 
     915        // mail the objects on the left side 
     916        Intersectable::NewMail(); 
    794917        // mail view cells on the left side 
    795918        ViewCell::NewMail(); 
    796         // mail the objects on the left side 
    797         Intersectable::NewMail(); 
    798  
     919         
    799920        return vol; 
    800921} 
     
    808929        // collect all view cells associated with this objects  
    809930        // (also multiple times, if they are pierced by several rays) 
    810  
    811931        ViewCellContainer viewCells; 
    812          
    813932        const bool useMailboxing = false; 
     933 
    814934        CollectViewCells(obj, viewCells, useMailboxing); 
    815  
    816935 
    817936        /// classify view cells and compute volume contri accordingly 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1315 r1323  
    553553                ObjectContainer &objectsBack); 
    554554 
     555        float EvalSah( 
     556                const BvhTraversalData &tData, 
     557                const int axis, 
     558                ObjectContainer &objectsFront, 
     559                ObjectContainer &objectsBack); 
     560 
    555561        /** Computes priority of the traversal data and stores it in tData. 
    556562        */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1315 r1323  
    4646                mOspTree = new OspTree(); 
    4747                mOspTree->mVspTree = mVspTree; 
    48                 //mOspTree->mHierarchyManager = this; 
     48                 
    4949                Debug << "creating osp tree" << endl; 
    5050                break; 
     
    5252        mBvHierarchy = new BvHierarchy(); 
    5353                mBvHierarchy->mVspTree = mVspTree; 
    54                 //mBvHierarchy->mHierarchyManager = this; 
     54                 
    5555                Debug << "creating bv hierachy" << endl; 
    5656                break; 
     
    7474        mOspTree->mVspTree = mVspTree; 
    7575 
    76         //mOspTree->mHierarchyManager = this; 
    7776        Debug << "creating osp tree" << endl; 
    7877 
     
    216215        cout << "Constructing view space / object space tree ... \n"; 
    217216         
     217        // use objects for evaluating vsp tree construction in the first levels 
     218        // of the subdivision 
     219        mSavedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 
     220        mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV; 
     221 
     222        // start with view space subdivison: prepare vsp tree for traversal 
     223        PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace); 
     224 
     225        // start object space subdivision immediately? 
     226        if (StartObjectSpaceSubdivision()) 
     227        { 
     228                mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
     229                PrepareObjectSpaceSubdivision(sampleRays, objects); 
     230        } 
     231 
    218232        // process object space candidates 
    219233        RunConstruction(sampleRays, objects, forcedViewSpace); 
     
    328342        const bool ospDepthReached =  
    329343                (mMinDepthForObjectSpaceSubdivion <= mVspTree->mVspStats.maxDepth); 
    330         const bool stillNotOsp = (mObjectSpaceSubdivisionType == NO_OBJ_SUBDIV); 
    331344     
    332         return stillNotOsp && (mTQueue.Empty() || ((mConstructionType == 1) && ospDepthReached)); 
     345        return !ObjectSpaceSubdivisionConstructed() &&  
     346                   (mTQueue.Empty() || ((mConstructionType == INTERLEAVED) && ospDepthReached)); 
    333347} 
    334348 
     
    340354        mHierarchyStats.nodes = 0; 
    341355        mGlobalCostMisses = 0; 
    342  
    343         // use objects for evaluating vsp tree construction in the first levels 
    344         // of the subdivision 
    345         const int savedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 
    346         mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV; 
    347  
    348         // start with view space subdivison: prepare vsp tree for traversal 
    349         PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace); 
    350  
    351         // start object space subdivision immediately? 
    352         if (StartObjectSpaceSubdivision()) 
    353         {cout << "here1155 "; 
    354                 mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType; 
    355                 PrepareObjectSpaceSubdivision(sampleRays, objects); 
    356         } 
    357356 
    358357        int i = 0; 
     
    389388                if (StartObjectSpaceSubdivision()) 
    390389                { 
    391                         mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType; 
     390                        mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
    392391 
    393392                        cout << "starting object space subdivision at maximal view space subdivison depth " << mVspTree->mVspStats.maxDepth << " (" << mMinDepthForObjectSpaceSubdivion << ") " << endl; 
     
    401400                DEL_PTR(mCurrentCandidate); 
    402401        } 
    403          
    404         mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType; 
     402 
     403        mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
    405404} 
    406405 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1314 r1323  
    265265protected: 
    266266 
     267        enum {SEQUENTIAL, INTERLEAVED}; 
    267268        int mObjectSpaceSubdivisionType; 
     269        /// the original osp type 
     270        int mSavedObjectSpaceSubdivisionType; 
     271 
    268272        int mConstructionType; 
    269273 
Note: See TracChangeset for help on using the changeset viewer.