Ignore:
Timestamp:
07/12/06 00:52:51 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1111 r1121  
    2222 
    2323#define USE_FIXEDPOINT_T 0 
    24 #define COUNT_OBJECTS 1 
     24#define COUNT_OBJECTS 0 
    2525 
    2626//-- static members 
     
    5050void VspTreeStatistics::Print(ostream &app) const 
    5151{ 
    52         app << "===== VspTree statistics ===============\n"; 
     52        app << "=========== VspTree statistics ===============\n"; 
    5353 
    5454        app << setprecision(4); 
     
    9999        //app << "#N_PVS: " << pvs << endl; 
    100100 
    101         app << "===== END OF VspTree statistics ==========\n"; 
     101        app << "========== END OF VspTree statistics ==========\n"; 
    102102} 
    103103 
     
    352352        //-- partition criteria 
    353353        Environment::GetSingleton()->GetFloatValue("VspTree.Construction.epsilon", mEpsilon); 
     354        Environment::GetSingleton()->GetFloatValue("VspTree.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight); 
    354355 
    355356        // if only the driving axis is used for axis aligned split 
     
    392393        Debug << "use cost heuristics: " << mUseCostHeuristics << endl; 
    393394        Debug << "subdivision stats log: " << subdivisionStatsLog << endl; 
    394          
     395        Debug << "render cost decrease weight: " << mRenderCostDecreaseWeight << endl; 
     396 
    395397        Debug << "circulating axis: " << mCirculatingAxis << endl; 
    396398        Debug << "minband: " << mMinBand << endl; 
     
    598600                tBackData.mMaxCostMisses = maxCostMisses; 
    599601                         
    600                  
     602         
    601603                if (1) 
    602604                { 
     
    620622                } 
    621623 
    622          
     624 
    623625                //-- evaluate new split candidates for global greedy cost heuristics 
    624626                VspSplitCandidate *frontCandidate = new VspSplitCandidate(tFrontData); 
     
    630632                tQueue.Push(frontCandidate); 
    631633                tQueue.Push(backCandidate); 
    632  
     634                 
     635                // delete old view cell 
     636                delete tData.mNode->GetViewCell(); 
    633637                // delete old leaf node 
    634638                DEL_PTR(tData.mNode); 
     
    747751                parent->ReplaceChildLink(leaf, interior); 
    748752                interior->SetParent(parent); 
     753 
     754                // remove "parent" view cell from pvs of all objects (traverse trough rays) 
     755                RemoveParentViewCellReferences(tData.mNode->GetViewCell()); 
    749756        } 
    750757        else // new root 
     
    770777        CreateViewCell(backData); 
    771778 
    772         // TODO:  
     779         
    773780        // create front and back view cell 
    774         // remove "parent" view cell from pvs of all objects (traverse trough rays) 
    775781        // add front and back view cell to "Potentially Visbilie View Cells"  
    776782        // of the objects in front and back pvs 
    777         RemoveParentViewCellReferences(tData.mNode->GetViewCell()); 
    778783        AddViewCellReferences(frontLeaf->GetViewCell()); 
    779784        AddViewCellReferences(backLeaf->GetViewCell()); 
    780  
    781785 
    782786        interior->mTimeStamp = mTimeStamp ++; 
     
    11441148void VspTree::AddContriToPvs(KdLeaf *leaf, int &pvs) const 
    11451149{ 
    1146         if (!leaf->Mailed()) 
    1147         { 
    1148                 leaf->Mail(); 
    1149  
    1150                 // add objects without those which are part of several kd leaves 
    1151                 pvs += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 
    1152  
    1153                 //-- handle objects of several kd leaves separately 
    1154                 ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
    1155  
    1156                 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
    1157                 { 
    1158                         Intersectable *object = *oit; 
    1159  
    1160                         // object not previously in left pvs 
    1161                         if (!object->Mailed()) 
    1162                         { 
    1163                                 object->Mail(); 
    1164                                 ++ pvs; 
    1165                         } 
     1150        if (leaf->Mailed()) 
     1151                return; 
     1152         
     1153        leaf->Mail(); 
     1154 
     1155        // add objects without those which are part of several kd leaves 
     1156        pvs += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 
     1157 
     1158        //-- handle objects of several kd leaves separately 
     1159        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
     1160 
     1161        for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
     1162        { 
     1163                Intersectable *object = *oit; 
     1164 
     1165                // object not previously in left pvs 
     1166                if (!object->Mailed()) 
     1167                { 
     1168                        object->Mail(); 
     1169                        ++ pvs; 
    11661170                } 
    11671171        }                                        
     
    15131517        // take render cost of node into account  
    15141518        // otherwise danger of being stuck in a local minimum!! 
    1515         const float factor = 0.99f; 
     1519        const float factor = mRenderCostDecreaseWeight; 
    15161520 
    15171521        const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 
     
    25542558 
    25552559 
    2556  
    2557  
    25582560int VspTree::ComputeBoxIntersections(const AxisAlignedBox3 &box, 
    25592561                                                                         ViewCellContainer &viewCells) const 
     
    26062608 
    26072609 
     2610 
     2611void VspTree::CollectDirtyCandidates(VspSplitCandidate *sc,  
     2612                                                                         vector<SplitCandidate *> &dirtyList) 
     2613{ 
     2614        VspLeaf *node = sc->mParentData.mNode; 
     2615         
     2616    ViewCellLeaf *vc = node->GetViewCell(); 
     2617                 
     2618        ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 
     2619 
     2620        KdLeaf::NewMail(); 
     2621 
     2622        for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     2623        { 
     2624                Intersectable *obj = (*oit).first; 
     2625 
     2626                set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 
     2627 
     2628                for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 
     2629                { 
     2630                        KdLeaf *leaf = *kit; 
     2631 
     2632                        if (!leaf->Mailed()) 
     2633                        { 
     2634                                leaf->Mail(); 
     2635                                dirtyList.push_back(leaf->mSplitCandidate); 
     2636                        } 
     2637                } 
     2638        } 
     2639} 
     2640 
     2641 
    26082642/*****************************************************************/ 
    26092643/*                class OspTree implementation                   */ 
     
    26552689 
    26562690        Environment::GetSingleton()->GetFloatValue("OspTree.Construction.splitBorder", mSplitBorder); 
    2657         //mSplitBorder = 0.1f; 
    2658  
    2659  
     2691        Environment::GetSingleton()->GetFloatValue("OspTree.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight); 
     2692         
    26602693        //-- debug output 
    26612694 
     
    26792712         
    26802713        Debug << "split borders: " << mSplitBorder << endl; 
     2714        Debug << "render cost decrease weight: " << mRenderCostDecreaseWeight << endl; 
    26812715 
    26822716 
     
    27612795                const AxisAlignedBox3 box = (*mi)->GetBox(); 
    27622796                 
    2763                 if (box.Max(axis) > position)  
     2797                if (box.Max(axis) > position + mEpsilon)  
    27642798                        ++ objectsFront; 
    27652799     
    2766                 if (box.Min(axis) < position) 
     2800                if (box.Min(axis) < position - mEpsilon) 
    27672801                        ++ objectsBack; 
    27682802        } 
     
    28432877                // delete old leaf node 
    28442878                DEL_PTR(tData.mNode); 
    2845                 DEL_PTR(tData.mNode->mViewCell); 
    28462879        } 
    28472880 
     
    28922925{ 
    28932926        // matt: TODO 
    2894         Debug << "here888 " << mTermMaxLeaves << " " << mOspStats.Leaves() << endl; 
    28952927        return ( 
    28962928                (mOspStats.Leaves() >= mTermMaxLeaves) 
     
    29522984                                                                           int &objectsBack) 
    29532985{ 
    2954          
     2986        // sort so we can use a sweep 
    29552987        SortSplitCandidates(node, axis); 
    29562988   
     
    29843016 
    29853017        float sum = (float)pvsSize * sizeBox; 
     3018float dummy1 = 0; 
     3019float dummy2 = 0; 
    29863020 
    29873021        vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 
    2988  
     3022cout << "***********" << endl; 
    29893023        //-- traverse through visibility events 
    29903024        for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci) 
    29913025        { 
     3026                int pvslold = pvsl; 
    29923027                EvalPvsIncr(*ci, pvsl, pvsr); 
     3028 
     3029                cout << "incr: " << ci->mObject->mViewCellPvs.GetSize() << " obj id "  
     3030                         << ci->mObject->GetId() << endl; 
    29933031 
    29943032                // Note: sufficient to compare size of bounding boxes of front and back side? 
     
    29973035                        sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value); 
    29983036 
    2999                         //Debug  << "pos=" << (*ci).value << "\t pvs=(" <<  pvsl << "," << pvsr << ")" << "\t cost= " << sum << endl; 
     3037                        cout << "pos=" << (*ci).value << "\t pvs=(" <<  pvsl << ","  
     3038                                 << pvsr << ")" << "\t cost= " << sum << endl; 
    30003039 
    30013040                        if (sum < minSum) 
     
    30123051        } 
    30133052         
    3014          
    3015         // -- compute cost 
     3053        //-- compute cost 
    30163054 
    30173055        const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 
     
    30353073         
    30363074        //if (axis != 1) 
    3037         Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox) 
    3038               <<"\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl; 
     3075        Debug << "axis=" << axis << " costRatio=" << ratio << " pos="  
     3076                  << position << " t=" << (position - minBox) / (maxBox - minBox) 
     3077              << "\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl; 
    30393078 
    30403079        return ratio; 
    30413080} 
    30423081 
     3082 
    30433083void OspTree::SortSplitCandidates(KdLeaf *node, const int axis) 
    30443084{ 
    30453085        mSplitCandidates->clear(); 
    30463086 
    3047         int requestedSize = 2*(int)node->mObjects.size(); 
     3087        int requestedSize = 2 * (int)node->mObjects.size(); 
    30483088         
    30493089        // creates a sorted split candidates array 
     
    30743114        stable_sort(mSplitCandidates->begin(), mSplitCandidates->end()); 
    30753115} 
    3076  
    30773116 
    30783117 
     
    30853124        return object->mViewCellPvs.GetSize(); 
    30863125#endif 
     3126} 
     3127 
     3128 
     3129const OspTreeStatistics &OspTree::GetStatistics() const 
     3130{ 
     3131        return mOspStats; 
    30873132} 
    30883133 
     
    31243169                        break; 
    31253170        } 
     3171 
     3172        cout << "pvs left: " << pvsLeft << " pvs right " << pvsRight << endl; 
    31263173} 
    31273174 
     
    32413288float OspTree::EvalViewCellPvsIncr(Intersectable *object) const 
    32423289{ 
    3243         // TODO          
     3290#if COUNT_OBJECTS        
    32443291        return 1; 
     3292#else 
     3293        return (float)object->mViewCellPvs.GetSize(); 
     3294#endif 
    32453295} 
    32463296 
     
    32763326                const float pvsIncr = EvalViewCellPvsIncr(obj); 
    32773327                totalPvs += pvsIncr; 
     3328                cout << "totalpvs " << totalPvs << " incr " << pvsIncr << endl; 
    32783329 
    32793330                if (box.Max(candidatePlane.mAxis) > candidatePlane.mPosition) 
     
    33103361        const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 
    33113362 
    3312         Debug << "old: " << oldRenderCost << " new: " << newRenderCost << " decrease: " << oldRenderCost - newRenderCost << endl; 
     3363        Debug << "old: " << oldRenderCost << " new: " << newRenderCost << " decrease: "  
     3364                << oldRenderCost - newRenderCost << endl; 
    33133365        const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBoundingBox.GetVolume(); 
    33143366         
    33153367        // take render cost of node into account  
    33163368        // otherwise danger of being stuck in a local minimum!! 
    3317         const float factor = 0.99f; 
     3369        const float factor = mRenderCostDecreaseWeight; 
    33183370 
    33193371        const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 
    3320  
    33213372        return factor * renderCostDecrease + (1.0f - factor) * normalizedOldRenderCost; 
    33223373} 
     
    34293480 
    34303481 
     3482void OspTree::CollectViewCells(KdLeaf *leaf, ViewCellContainer &viewCells) 
     3483{ 
     3484        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     3485 
     3486        ViewCell::NewMail(); 
     3487 
     3488        // loop through all object and collect view cell pvs of this node 
     3489        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     3490        { 
     3491                Intersectable *obj = *oit; 
     3492 
     3493                ViewCellPvsMap::const_iterator vit, vit_end = obj->mViewCellPvs.mEntries.end(); 
     3494 
     3495                for (vit = obj->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 
     3496                { 
     3497            ViewCell *vc = (*vit).first; 
     3498 
     3499                        if (!vc->Mailed()) 
     3500                        { 
     3501                                vc->Mail(); 
     3502                                viewCells.push_back(vc); 
     3503                        } 
     3504                } 
     3505        } 
     3506 
     3507} 
     3508 
     3509 
     3510void OspTree::CollectDirtyCandidates(OspSplitCandidate *sc,  
     3511                                                                         vector<SplitCandidate *> &dirtyList) 
     3512{ 
     3513        KdLeaf *node = sc->mParentData.mNode; 
     3514 
     3515        ObjectContainer::const_iterator oit, oit_end = node->mObjects.end(); 
     3516 
     3517        ViewCellContainer viewCells; 
     3518 
     3519        CollectViewCells(node, viewCells); 
     3520 
     3521        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     3522 
     3523        // through split candidates corresponding to view cell pvs of this 
     3524        // node into dirty list 
     3525        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     3526        { 
     3527                VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
     3528 
     3529                VspLeaf *leaf = vc->mLeaf; 
     3530                dirtyList.push_back(leaf->GetSplitCandidate()); 
     3531        } 
     3532} 
     3533 
     3534 
     3535int OspTree::ComputePvsSize(const ObjectContainer &objects) const 
     3536{ 
     3537        int pvsSize = 0; 
     3538 
     3539        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     3540 
     3541        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     3542        { 
     3543                pvsSize += (*oit)->mViewCellPvs.GetSize(); 
     3544        } 
     3545 
     3546        return pvsSize; 
     3547} 
     3548 
     3549 
    34313550/********************************************************************/ 
    34323551/*               class HierarchyManager implementation              */ 
     
    34453564        SplitCandidate *splitCandidate = mTQueue.Top(); 
    34463565 
    3447         Debug << "next candidate: " << splitCandidate->Type() 
     3566        cout << "next candidate: " << splitCandidate->Type() 
    34483567                << ", priority: " << splitCandidate->GetPriority() << endl; 
    34493568 
     
    34543573 
    34553574 
    3456 void HierarchyManager::PrepareConstruction(const VssRayContainer &sampleRays, 
    3457                                                                                    const ObjectContainer &objects, 
    3458                                                                                    AxisAlignedBox3 *forcedViewSpace, 
    3459                                                                                    RayInfoContainer &rays) 
    3460 { 
    3461         mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 
     3575void HierarchyManager::ProcessRays(const VssRayContainer &sampleRays, 
     3576                                                                   RayInfoContainer &rays, 
     3577                                                                   ObjectContainer &sampledObjects) 
     3578{ 
     3579        VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
    34623580 
    34633581        long startTime = GetTime(); 
     
    34673585        Intersectable::NewMail(); 
    34683586 
    3469         VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
    3470  
    3471         //-- store rays 
     3587        //-- store rays and objects 
    34723588        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
    34733589        { 
    34743590                VssRay *ray = *rit; 
    3475  
    34763591                float minT, maxT; 
    3477  
    34783592                static Ray hray; 
     3593 
    34793594                hray.Init(*ray); 
    34803595                 
     
    34893604                        rays.push_back(RayInfo(ray, minT / len, maxT / len)); 
    34903605                } 
     3606 
     3607                // store objects 
     3608                if (ray->mTerminationObject && !ray->mTerminationObject->Mailed()) 
     3609                { 
     3610                        ray->mTerminationObject->Mail(); 
     3611                        sampledObjects.push_back(ray->mTerminationObject); 
     3612                } 
     3613 
     3614                if (ray->mOriginObject && !ray->mOriginObject->Mailed()) 
     3615                { 
     3616                        ray->mOriginObject->Mail(); 
     3617                        sampledObjects.push_back(ray->mOriginObject); 
     3618                } 
    34913619        } 
    34923620 
    34933621        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    3494  
    3495  
    3496         int pvsSize = mVspTree.ComputePvsSize(rays); 
    3497  
     3622} 
     3623 
     3624 
     3625void HierarchyManager::PrepareVsp(const VssRayContainer &sampleRays, 
     3626                                                                  AxisAlignedBox3 *forcedViewSpace, 
     3627                                                                  RayInfoContainer &rays) 
     3628{ 
     3629        // prepare bounding box 
     3630        mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 
     3631 
     3632        // get clipped rays 
     3633        ObjectContainer sampledObjects; 
     3634        ProcessRays(sampleRays, rays, sampledObjects); 
     3635 
     3636        //const int pvsSize = mVspTree.ComputePvsSize(rays); 
     3637        const int pvsSize = (int)sampledObjects.size(); 
     3638 
     3639        cout <<  "here450 pvs size: " << pvsSize << endl; 
    34983640        // -- prepare view space partition 
    34993641 
     
    35073649                                                                        0, 
    35083650                                                                        &rays, 
    3509                                                                         //(int)objects.size(), 
    35103651                                                                        pvsSize,         
    35113652                                                                        prop, 
     
    35133654 
    35143655 
     3656        // create first view cell 
     3657        mVspTree.CreateViewCell(vData); 
     3658                 
     3659        // add first view cell to all the objects view cell pvs 
     3660        ObjectPvsMap::const_iterator oit,  
     3661                oit_end = leaf->GetViewCell()->GetPvs().mEntries.end(); 
     3662 
     3663        cout << "here23 " << leaf->GetViewCell()->GetPvs().mEntries.size(); 
     3664 
     3665        for (oit = leaf->GetViewCell()->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     3666        { 
     3667                Intersectable *obj = (*oit).first; 
     3668                cout << "obj: " << obj->GetId() << endl; 
     3669                obj->mViewCellPvs.AddSample(leaf->GetViewCell(), 1); 
     3670        } 
     3671 
    35153672        // compute first split candidate 
    35163673        VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(vData); 
     
    35183675 
    35193676        mTQueue.Push(splitCandidate); 
    3520  
    3521  
    3522         //-- object space partition 
    3523  
     3677} 
     3678 
     3679 
     3680void HierarchyManager::PrepareOsp(const ObjectContainer &objects,                                                                                  
     3681                                                                  AxisAlignedBox3 *forcedViewSpace) 
     3682{ 
    35243683        mOspTree.PrepareConstruction(objects, forcedViewSpace); 
    35253684 
     
    35303689        mOspTree.mRoot = kdleaf; 
    35313690         
    3532  
     3691        // TODO matt: this is something different than pvs size. 
     3692        const int pvsSize = mOspTree.ComputePvsSize(objects); 
     3693        const float prop = mOspTree.mBoundingBox.GetVolume(); 
     3694 
     3695        cout <<  "here40 pvs size: " << pvsSize << endl; 
    35333696        // first osp traversal data 
    35343697        OspTree::OspTraversalData oData(kdleaf, 
     
    35423705 
    35433706        // compute first split candidate 
    3544         OspTree::OspSplitCandidate *oSplitCandidate = new OspTree::OspSplitCandidate(oData); 
     3707        OspTree::OspSplitCandidate *oSplitCandidate =  
     3708                new OspTree::OspSplitCandidate(oData); 
    35453709    mOspTree.EvalSplitCandidate(*oSplitCandidate); 
    35463710 
    3547         mTQueue.Push(splitCandidate); 
     3711        mTQueue.Push(oSplitCandidate); 
     3712} 
     3713 
     3714 
     3715void HierarchyManager::PrepareConstruction(const VssRayContainer &sampleRays, 
     3716                                                                                   const ObjectContainer &objects, 
     3717                                                                                   AxisAlignedBox3 *forcedViewSpace, 
     3718                                                                                   RayInfoContainer &rays) 
     3719{ 
     3720        PrepareVsp(sampleRays, forcedViewSpace, rays); 
     3721        PrepareOsp(objects, forcedViewSpace); 
    35483722} 
    35493723 
     
    35613735{ 
    35623736        RayInfoContainer *rays = new RayInfoContainer(); 
    3563  
    3564         mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 
     3737        PrepareVsp(sampleRays, forcedViewSpace, *rays); 
    35653738 
    35663739        long startTime = GetTime(); 
    3567  
    3568         cout << "storing rays ... "; 
    3569  
    3570         Intersectable::NewMail(); 
    3571  
    3572         VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
    3573  
    3574         //-- store rays 
    3575         for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
    3576         { 
    3577                 VssRay *ray = *rit; 
    3578  
    3579                 float minT, maxT; 
    3580  
    3581                 static Ray hray; 
    3582                 hray.Init(*ray); 
    3583                  
    3584                 // TODO: not very efficient to implictly cast between rays types 
    3585                 if (mVspTree.GetBoundingBox().GetRaySegment(hray, minT, maxT)) 
    3586                 { 
    3587                         float len = ray->Length(); 
    3588  
    3589                         if (!len) 
    3590                                 len = Limits::Small; 
    3591  
    3592                         rays->push_back(RayInfo(ray, minT / len, maxT / len)); 
    3593                 } 
    3594         } 
    3595  
    3596         cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    3597  
    3598         const int pvsSize = mVspTree.ComputePvsSize(*rays); 
    3599  
    3600  
    3601         // -- prepare view space partition 
    3602  
    3603         // add first candidate for view space partition 
    3604         VspLeaf *vspleaf = new VspLeaf(); 
    3605  
    3606         mVspTree.mRoot = vspleaf; 
    3607         const float prop = mVspTree.mBoundingBox.GetVolume(); 
    3608  
    3609         // first vsp traversal data 
    3610         VspTree::VspTraversalData vData(vspleaf, 
    3611                                                                         0, 
    3612                                                                         rays, 
    3613                                                                         pvsSize,         
    3614                                                                         prop, 
    3615                                                                         mVspTree.mBoundingBox); 
    3616  
    3617  
    3618         //-- compute first split candidate 
    3619         VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(vData); 
    3620     mVspTree.EvalSplitCandidate(*splitCandidate); 
    3621  
    3622         mTQueue.Push(splitCandidate); 
    3623  
     3740        cout << "starting vsp contruction ... " << endl; 
    36243741        int i = 0; 
    36253742 
     
    36313748                        GlobalTerminationCriteriaMet(splitCandidate); 
    36323749 
    3633                 //cout << "vsp nodes: " << i ++ << endl; 
     3750                cout << "vsp nodes: " << i ++ << endl; 
    36343751 
    36353752                // cost ratio of cost decrease / totalCost 
    36363753                const float costRatio = splitCandidate->GetPriority() / mTotalCost; 
    3637                 //Debug << "cost ratio: " << costRatio << endl; 
     3754                //cout << "cost ratio: " << costRatio << endl; 
    36383755 
    36393756                if (costRatio < mTermMinGlobalCostRatio) 
     
    36463763                        dynamic_cast<VspTree::VspSplitCandidate *>(splitCandidate); 
    36473764 
     3765         
    36483766                VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
    3649          
     3767 
    36503768                DEL_PTR(splitCandidate); 
    36513769        } 
     
    36543772        mVspTree.mVspStats.Stop(); 
    36553773         
    3656         Debug << "object space" << endl; 
     3774        startTime = GetTime(); 
     3775        cout << "starting osp contruction ... " << endl; 
    36573776 
    36583777        //-- object space partition 
    3659  
    3660         mOspTree.PrepareConstruction(objects, forcedViewSpace); 
    3661  
    3662         // add first candidate for view space partition 
    3663         KdLeaf *leaf = new KdLeaf(NULL, 0); 
    3664         leaf->mObjects = objects; 
    3665  
    3666         mOspTree.mRoot = leaf; 
    3667          
    3668  
    3669         //-- first osp traversal data 
    3670         OspTree::OspTraversalData oData(leaf, 
    3671                                                                         0, 
    3672                                                                         pvsSize, 
    3673                                                                         prop, 
    3674                                                                         mOspTree.mBoundingBox); 
    3675  
    3676                  
    3677         mOspTree.ProcessLeafObjects(leaf, NULL); 
    3678  
    3679         // compute first split candidate 
    3680         OspTree::OspSplitCandidate *oSplitCandidate = new OspTree::OspSplitCandidate(oData); 
    3681     mOspTree.EvalSplitCandidate(*oSplitCandidate); 
    3682  
    3683         mTQueue.Push(oSplitCandidate); 
     3778    PrepareOsp(objects, forcedViewSpace); 
    36843779 
    36853780        i = 0; 
     
    37333828        while (!FinishedConstruction()) 
    37343829        { 
    3735                 SplitCandidate *splitCandidate = NextSplitCandidate(); 
    3736              
     3830                mCurrentCandidate = NextSplitCandidate(); 
     3831            
    37373832                const bool globalTerminationCriteriaMet =  
    3738                         GlobalTerminationCriteriaMet(splitCandidate); 
     3833                        GlobalTerminationCriteriaMet(mCurrentCandidate); 
    37393834 
    37403835                cout << "view cells: " << i ++ << endl; 
    37413836 
    37423837                // cost ratio of cost decrease / totalCost 
    3743                 const float costRatio = splitCandidate->GetPriority() / mTotalCost; 
     3838                const float costRatio = mCurrentCandidate->GetPriority() / mTotalCost; 
    37443839                //Debug << "cost ratio: " << costRatio << endl; 
    37453840 
     
    37503845 
    37513846                // we have either a object space or view space split 
    3752                 if (splitCandidate->Type() == SplitCandidate::VIEW_SPACE) 
     3847                if (mCurrentCandidate->Type() == SplitCandidate::VIEW_SPACE) 
    37533848                { 
    37543849                        VspTree::VspSplitCandidate *sc =  
    3755                                 dynamic_cast<VspTree::VspSplitCandidate *>(splitCandidate); 
     3850                                dynamic_cast<VspTree::VspSplitCandidate *>(mCurrentCandidate); 
    37563851 
    37573852                        VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
     
    37603855                {                        
    37613856                        OspTree::OspSplitCandidate *sc =  
    3762                                 dynamic_cast<OspTree::OspSplitCandidate *>(splitCandidate); 
     3857                                dynamic_cast<OspTree::OspSplitCandidate *>(mCurrentCandidate); 
    37633858 
    37643859                        KdNode *r = mOspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 
    37653860                } 
    37663861 
    3767                 DEL_PTR(splitCandidate); 
     3862                // reevaluate affected candidates 
     3863                RepairQueue(); 
     3864 
     3865                DEL_PTR(mCurrentCandidate); 
    37683866        } 
    37693867 
     
    37803878 
    37813879 
    3782 void HierarchyManager::RepairQueue(const vector<SplitCandidate *> &dirtyList) 
     3880void HierarchyManager::CollectDirtyCandidates(vector<SplitCandidate *> &dirtyList) 
     3881{        
     3882        // we have either a object space or view space split 
     3883        if (mCurrentCandidate->Type() == SplitCandidate::VIEW_SPACE) 
     3884        { 
     3885                VspTree::VspSplitCandidate *sc =  
     3886                        dynamic_cast<VspTree::VspSplitCandidate *>(mCurrentCandidate); 
     3887 
     3888                mVspTree.CollectDirtyCandidates(sc, dirtyList); 
     3889        } 
     3890        else // object space split 
     3891        {                        
     3892                OspTree::OspSplitCandidate *sc =  
     3893                        dynamic_cast<OspTree::OspSplitCandidate *>(mCurrentCandidate); 
     3894 
     3895                mOspTree.CollectDirtyCandidates(sc, dirtyList); 
     3896        } 
     3897} 
     3898 
     3899 
     3900void HierarchyManager::RepairQueue() 
    37833901{ 
    37843902        // TODO 
     
    37993917        // split candidate 
    38003918 
     3919        // collect list of "dirty" candidates 
     3920        vector<SplitCandidate *> dirtyList; 
     3921        CollectDirtyCandidates(dirtyList); 
     3922         
     3923        //-- reevaluate the dirty list 
    38013924        vector<SplitCandidate *>::const_iterator sit, sit_end = dirtyList.end(); 
    38023925 
Note: See TracChangeset for help on using the changeset viewer.