Ignore:
Timestamp:
01/21/07 00:40:56 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1999 r2003  
    2626#define USE_FIXEDPOINT_T 0 
    2727#define USE_VOLUMES_FOR_HEURISTICS 1 
    28  
    29   //int BvhNode::sMailId = 10000; //2147483647; 
    30   //int BvhNode::sReservedMailboxes = 1; 
     28#define TEST_POWERPLANT 0 
     29   
     30//int BvhNode::sMailId = 10000; 
     31//int BvhNode::sReservedMailboxes = 1; 
    3132 
    3233BvHierarchy *BvHierarchy::BvhSubdivisionCandidate::sBvHierarchy = NULL; 
     
    382383                                                                                BvhTraversalData &frontData, 
    383384                                                                                BvhTraversalData &backData) 
    384 { 
     385{  
    385386        const BvhTraversalData &tData = sc.mParentData; 
    386387        BvhLeaf *leaf = tData.mNode; 
     
    427428        ++ mBvhStats.splits; 
    428429 
    429  
     430  
    430431        //////////////////////////////////////// 
    431432        //-- fill front and back traversal data with the new values 
     
    446447        AssociateObjectsWithLeaf(back); 
    447448        AssociateObjectsWithLeaf(front); 
    448     
     449   
     450        //////////// 
    449451        //-- compute pvs correction to cope with undersampling 
     452 
    450453        frontData.mPvs = (float)CountViewCells(front->mObjects); 
    451454        backData.mPvs = (float)CountViewCells(back->mObjects); 
     
    453456        frontData.mCorrectedPvs = sc.mCorrectedFrontPvs; 
    454457        backData.mCorrectedPvs = sc.mCorrectedBackPvs; 
     458 
    455459 
    456460        // compute probability of this node being visible,  
     
    462466        backData.mCorrectedVolume = sc.mCorrectedBackVolume; 
    463467 
     468 
    464469    // how often was max cost ratio missed in this branch? 
    465470        frontData.mMaxCostMisses = sc.GetMaxCostMisses(); 
     
    468473        // set the time stamp so the order of traversal can be reconstructed 
    469474        node->SetTimeStamp(mHierarchyManager->mTimeStamp ++); 
    470                  
     475          
    471476        // assign the objects in sorted order 
    472         if (mUseGlobalSorting) 
     477        if (!TEST_POWERPLANT && mUseGlobalSorting) 
    473478        { 
    474479                AssignSortedObjects(sc, frontData, backData); 
     
    497502                BvhTraversalData tFrontData; 
    498503                BvhTraversalData tBackData; 
    499                          
     504                 
    500505                // create new interior node and two leaf node 
    501506                currentNode = SubdivideNode(*sc, tFrontData, tBackData); 
     
    628633        } 
    629634 
     635 
    630636        const BvhTraversalData &tData = splitCandidate.mParentData; 
    631637        BvhLeaf *leaf = tData.mNode; 
     
    671677 
    672678        if (0) 
    673         cout << "bvh volume cost" 
     679        { 
     680                cout << "bvh volume cost" 
    674681                 << " avg ray contri: " << avgRayContri << " ratio: " << oldRatio  
    675682                 << " parent: " << parentVol << " old vol: " << oldVolume  
    676683                 << " frontvol: " << frontVol << " corr. " << splitCandidate.mCorrectedFrontVolume  
    677684                 << " backvol: " << backVol << " corr. " << splitCandidate.mCorrectedBackVolume << endl; 
     685        } 
    678686 
    679687#ifdef GTP_DEBUG 
     
    849857 
    850858 
    851 #if 0 
     859#if 1 
    852860 
    853861/// compute object boundaries using spatial mid split 
     
    857865                                                                                        ObjectContainer &objectsBack) 
    858866{ 
    859         const float maxBox = tData.mBoundingBox.Max(axis); 
    860         const float minBox = tData.mBoundingBox.Min(axis); 
     867        AxisAlignedBox3 parentBox = tData.mNode->GetBoundingBox(); 
     868 
     869        const float maxBox = parentBox.Max(axis); 
     870        const float minBox = parentBox.Min(axis); 
    861871 
    862872        float midPoint = (maxBox + minBox) * 0.5f; 
     
    882892        } 
    883893 
    884         const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 
    885         const float newRenderCost = EvalRenderCost(objectsFront) * EvalRenderCost(objectsBack); 
     894        AxisAlignedBox3 fbox = EvalBoundingBox(objectsFront, &parentBox); 
     895        AxisAlignedBox3 bbox = EvalBoundingBox(objectsBack, &parentBox); 
     896 
     897        const float oldRenderCost = (float)tData.mNode->mObjects.size() * parentBox.SurfaceArea(); 
     898        const float newRenderCost = (float)objectsFront.size() * fbox.SurfaceArea() +  (float)objectsBack.size() * bbox.SurfaceArea(); 
    886899 
    887900        const float ratio = newRenderCost / oldRenderCost; 
     
    920933 
    921934#if 1 
     935        // hack: always take driving axis 
    922936        const float cost = (tData.mNode->GetBoundingBox().Size().DrivingAxis() == axis) ? -1.0f : 0.0f; 
    923937#else 
    924938        const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 
    925         const float newRenderCost = EvalRenderCost(objectsFront) * EvalRenderCost(objectsBack); 
     939        const float newRenderCost = EvalRenderCost(objectsFront) + EvalRenderCost(objectsBack); 
    926940 
    927941        const float cost = newRenderCost / oldRenderCost; 
     
    9861000        } 
    9871001 
    988         // temporary surface areas 
     1002        // record surface areas during the sweep 
    9891003        float al = 0; 
    9901004        float ar = boxArea; 
     
    13941408void BvHierarchy::CreateLocalSubdivisionCandidates(const ObjectContainer &objects,  
    13951409                                                                                                  SortableEntryContainer **subdivisionCandidates,  
    1396                                                                                                   const bool sort, 
     1410                                                                                                  const bool sortEntries, 
    13971411                                                                                                  const int axis) 
    13981412{ 
     
    14001414 
    14011415        // compute requested size and look if subdivision candidate has to be recomputed 
    1402         const int requestedSize = (int)objects.size() * 2; 
     1416        const int requestedSize = (int)objects.size(); 
    14031417         
    14041418        // creates a sorted split candidates array 
     
    14231437        } 
    14241438 
    1425         if (sort) 
     1439        if (sortEntries) 
    14261440        {       // no presorted candidate list 
    1427                 stable_sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 
     1441                //stable_sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 
     1442                sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 
    14281443        } 
    14291444} 
     
    22012216        // root and bounding box was already constructed 
    22022217        BvhLeaf *bvhLeaf = dynamic_cast<BvhLeaf *>(mRoot); 
    2203  
     2218         
    22042219        // only rays intersecting objects in node are interesting 
    22052220        const int nRays = AssociateObjectsWithRays(sampleRays); 
    22062221        //cout << "using " << nRays << " of " << (int)sampleRays.size() << " rays" << endl; 
    2207  
     2222         
    22082223        // probability that volume is "seen" from the view cells 
    22092224        const float prop = EvalViewCellsVolume(objects) / GetViewSpaceVolume(); 
     
    22132228         
    22142229        // create sorted object lists for the first data 
    2215         if (mUseGlobalSorting) 
     2230        if (!TEST_POWERPLANT && mUseGlobalSorting) 
    22162231        { 
    22172232                AssignInitialSortedObjectList(oData, objects); 
     
    22572272                        tQueue.Push(sCandidate); 
    22582273                } 
     2274 
     2275                cout << "size of initial bv subdivision: " << GetStatistics().Leaves() << endl; 
    22592276        } 
    22602277        else 
    2261         { 
     2278        {        
    22622279                // evaluate priority 
    22632280                EvalSubdivisionCandidate(*oSubdivisionCandidate); 
     
    22652282 
    22662283                tQueue.Push(oSubdivisionCandidate); 
    2267         } 
    2268                  
    2269         cout << "size of initial bv subdivision: " << GetStatistics().Leaves() << endl; 
     2284                cout << "size of initial bv subdivision: " << GetStatistics().Leaves() << endl; 
     2285        } 
    22702286} 
    22712287 
     
    23042320 
    23052321        *(tData.mSortedObjects[3]) = objects; 
    2306         stable_sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 
     2322        //stable_sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 
     2323        sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 
    23072324} 
    23082325 
     
    23752392        BvhTraversalData oData(bvhLeaf, 0, prop, nRays); 
    23762393 
    2377         AssignInitialSortedObjectList(oData, objects); 
     2394        if (!TEST_POWERPLANT && mUseGlobalSorting) 
     2395                AssignInitialSortedObjectList(oData, objects); 
    23782396         
    23792397 
     
    26572675                        delete bsc; 
    26582676                } 
    2659                 else // initial preprocessing  finished for this candidate 
    2660                 { 
     2677                else  
     2678                { 
     2679                        // initial preprocessing  finished for this candidate 
    26612680                        // add to candidate container 
    26622681                        candidateContainer.push_back(bsc); 
Note: See TracChangeset for help on using the changeset viewer.