Ignore:
Timestamp:
02/01/06 19:29:59 (18 years ago)
Author:
mattausch
Message:

implemented variance
started implementing merge history

File:
1 edited

Legend:

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

    r556 r580  
    3030// Static variables 
    3131int VspKdLeaf::sMailId = 0; 
    32 int MergeCandidate::sMaxPvsSize = 150; 
    33 float MergeCandidate::sOverallCost = Limits::Small; 
     32int VspKdMergeCandidate::sMaxPvsSize = 150; 
     33float VspKdMergeCandidate::sOverallCost = Limits::Small; 
    3434#define USE_FIXEDPOINT_T 0 
    3535 
     
    430430        environment->GetFloatValue("VspKdTree.PostProcess.maxCostRatio", mMergeMaxCostRatio); 
    431431        environment->GetIntValue("VspKdTree.PostProcess.maxPvsSize", 
    432                                                          MergeCandidate::sMaxPvsSize); 
     432                                                         VspKdMergeCandidate::sMaxPvsSize); 
    433433 
    434434        environment->GetBoolValue("VspKdTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 
     
    21732173        vc->SetArea(GetBBox(leaf).SurfaceArea()); 
    21742174 
    2175         vc->mLeaves.push_back(leaf); 
     2175        vc->mLeaf = leaf; 
    21762176 
    21772177        for (it = leaf->GetRays().begin(); it != it_end; ++ it) 
     
    22002200        // if merge was unsuccessful 
    22012201        if (!vc) return false; 
    2202  
     2202// TODO 
     2203#if VC_HISTORY 
    22032204        // set new size of view cell 
    22042205        vc->SetVolume(fVc->GetVolume() + bVc->GetVolume()); 
     
    22232224                vc->mLeaves.push_back(*it); 
    22242225        } 
    2225  
     2226#endif 
    22262227        vc->Mail(); 
    22272228 
     
    22352236void VspKdTree::CollectMergeCandidates() 
    22362237{ 
    2237         MergeCandidate::sOverallCost = 0; 
     2238        VspKdMergeCandidate::sOverallCost = 0; 
    22382239        vector<VspKdLeaf *> leaves; 
    22392240 
     
    22562257                // no leaf is part of two merge candidates 
    22572258                leaf->Mail(); 
    2258                 MergeCandidate::sOverallCost +=  
     2259                VspKdMergeCandidate::sOverallCost +=  
    22592260                        vc->GetVolume() * vc->GetPvs().GetSize(); 
    22602261                vector<VspKdLeaf *> neighbors; 
     
    22662267                for (nit = neighbors.begin(); nit != nit_end; ++ nit) 
    22672268                { 
    2268                         mMergeQueue.push(MergeCandidate(leaf, *nit)); 
     2269                        mMergeQueue.push(VspKdMergeCandidate(leaf, *nit)); 
    22692270                } 
    22702271        } 
     
    22732274void VspKdTree::CollectMergeCandidates(const vector<VspKdRay *> &rays) 
    22742275{ 
    2275         MergeCandidate::sOverallCost = 0; 
     2276        VspKdMergeCandidate::sOverallCost = 0; 
    22762277 
    22772278        vector<VspKdIntersection>::const_iterator iit; 
     
    22992300                        leaf->Mail 
    23002301                        // TODO: how to sort out doubles? 
    2301                         MergeCandidate mc = MergeCandidate(leaf, previousLeaf); 
     2302                        VspKdMergeCandidate mc = VspKdMergeCandidate(leaf, previousLeaf); 
    23022303                        mMergeQueue.push(mc); 
    23032304 
    2304                         MergeCandidate::sOverallCost += mc.GetLeaf1Cost(); 
    2305                         MergeCandidate::sOverallCost += mc.GetLeaf2Cost(); 
     2305                        VspKdMergeCandidate::sOverallCost += mc.GetLeaf1Cost(); 
     2306                        VspKdMergeCandidate::sOverallCost += mc.GetLeaf2Cost(); 
    23062307 
    23072308                        previousLeaf = leaf; 
     
    23212322        while (!mMergeQueue.empty() && (vcSize > mMergeMinViewCells) && 
    23222323                   (mMergeQueue.top().GetMergeCost() <  
    2323                     mMergeMaxCostRatio * MergeCandidate::sOverallCost)) 
     2324                    mMergeMaxCostRatio * VspKdMergeCandidate::sOverallCost)) 
    23242325        { 
    23252326                //Debug << "mergecost: " << mergeQueue.top().GetMergeCost() /  
    2326                 //MergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl; 
    2327                 MergeCandidate mc = mMergeQueue.top(); 
     2327                //VspKdMergeCandidate::sOverallCost << " " << mMergeMaxCostRatio << endl; 
     2328                VspKdMergeCandidate mc = mMergeQueue.top(); 
    23282329                mMergeQueue.pop(); 
    23292330 
     
    23402341                        -- vcSize; 
    23412342                        // increase absolute merge cost 
    2342                         MergeCandidate::sOverallCost += mc.GetMergeCost(); 
     2343                        VspKdMergeCandidate::sOverallCost += mc.GetMergeCost(); 
    23432344                } 
    23442345                // merge candidate not valid, because one of the leaves was already 
     
    23782379 
    23792380                        VspKdViewCell *viewCell = leaf->GetViewCell(); 
    2380  
     2381#if VC_HISTORY 
    23812382                        if (!viewCell->Mailed()) 
    23822383                        { 
     
    23862387 
    23872388                        viewCell->mLeaves.push_back(leaf); 
     2389#endif 
    23882390                } 
    23892391                else 
     
    24682470        while (!mMergeQueue.empty()) 
    24692471        { 
    2470                 MergeCandidate mc = mMergeQueue.top(); 
     2472                VspKdMergeCandidate mc = mMergeQueue.top(); 
    24712473                mMergeQueue.pop(); 
    24722474 
     
    25012503 
    25022504 
    2503 float GetShuffledVcCost(VspKdLeaf *leaf, VspKdViewCell *vc1, VspKdViewCell *vc2) 
     2505float EvalShuffleCost(VspKdLeaf *leaf, VspKdViewCell *vc1, VspKdViewCell *vc2) 
    25042506{ 
    25052507        const int pvs1 = SubtractedPvsSize(vc1->GetPvs(), *leaf->mPvs); 
     
    25212523{ 
    25222524        // compute new pvs and area 
     2525        //      TODO 
     2526#if VC_HISTORY 
    25232527        vc1->GetPvs().SubtractPvs(*leaf->mPvs); 
    25242528        vc2->GetPvs().AddPvs(*leaf->mPvs); 
     
    25372541 
    25382542        leaf->SetViewCell(vc2);  // finally change view cell 
     2543#endif 
    25392544} 
    25402545 
     
    25542559 
    25552560        // the view cell should not be empty after the shuffle 
    2556         if (vc1->mLeaves.size() > 1) 
    2557                 shuffledCost1 = GetShuffledVcCost(leaf1, vc1, vc2); 
     2561//todo 
     2562        /*      if (vc1->mLeaves.size() > 1) 
     2563                shuffledCost1 = EvalShuffleCost(leaf1, vc1, vc2); 
    25582564        if (vc2->mLeaves.size() > 1) 
    2559                 shuffledCost2 = GetShuffledVcCost(leaf2, vc2, vc1); 
    2560  
    2561         // shuffling unsuccessful 
     2565                shuffledCost2 = EvalShuffleCost(leaf2, vc2, vc1); 
     2566 
     2567*/      // shuffling unsuccessful 
    25622568        if ((oldCost <= shuffledCost1) && (oldCost <= shuffledCost2)) 
    25632569                return false; 
     
    25812587 
    25822588/*********************************************************************/ 
    2583 /*                MergeCandidate implementation                      */ 
     2589/*                VspKdMergeCandidate implementation                      */ 
    25842590/*********************************************************************/ 
    25852591 
    25862592 
    2587 MergeCandidate::MergeCandidate(VspKdLeaf *l1, VspKdLeaf *l2): 
     2593VspKdMergeCandidate::VspKdMergeCandidate(VspKdLeaf *l1, VspKdLeaf *l2): 
    25882594mMergeCost(0), 
    25892595mLeaf1(l1), 
     
    25952601} 
    25962602 
    2597 float MergeCandidate::GetLeaf1Cost() const 
     2603float VspKdMergeCandidate::GetLeaf1Cost() const 
    25982604{ 
    25992605        VspKdViewCell *vc = mLeaf1->GetViewCell(); 
     
    26012607} 
    26022608 
    2603 float MergeCandidate::GetLeaf2Cost() const 
     2609float VspKdMergeCandidate::GetLeaf2Cost() const 
    26042610{ 
    26052611        VspKdViewCell *vc = mLeaf2->GetViewCell(); 
     
    26072613} 
    26082614 
    2609 void MergeCandidate::EvalMergeCost() 
     2615void VspKdMergeCandidate::EvalMergeCost() 
    26102616{ 
    26112617        //-- compute pvs difference 
     
    26302636} 
    26312637 
    2632 void MergeCandidate::SetLeaf1(VspKdLeaf *l) 
     2638void VspKdMergeCandidate::SetLeaf1(VspKdLeaf *l) 
    26332639{ 
    26342640        mLeaf1 = l; 
    26352641} 
    26362642 
    2637 void MergeCandidate::SetLeaf2(VspKdLeaf *l) 
     2643void VspKdMergeCandidate::SetLeaf2(VspKdLeaf *l) 
    26382644{ 
    26392645        mLeaf2 = l; 
     
    26412647 
    26422648 
    2643 VspKdLeaf *MergeCandidate::GetLeaf1() 
     2649VspKdLeaf *VspKdMergeCandidate::GetLeaf1() 
    26442650{ 
    26452651        return mLeaf1; 
     
    26472653 
    26482654 
    2649 VspKdLeaf *MergeCandidate::GetLeaf2() 
     2655VspKdLeaf *VspKdMergeCandidate::GetLeaf2() 
    26502656{ 
    26512657        return mLeaf2; 
     
    26532659 
    26542660 
    2655 bool MergeCandidate::Valid() const 
     2661bool VspKdMergeCandidate::Valid() const 
    26562662{ 
    26572663        return 
     
    26612667 
    26622668 
    2663 float MergeCandidate::GetMergeCost() const 
     2669float VspKdMergeCandidate::GetMergeCost() const 
    26642670{ 
    26652671        return mMergeCost; 
     
    26672673 
    26682674 
    2669 void MergeCandidate::SetValid() 
     2675void VspKdMergeCandidate::SetValid() 
    26702676{ 
    26712677        mLeaf1Id = mLeaf1->GetViewCell()->mMailbox; 
Note: See TracChangeset for help on using the changeset viewer.