Changeset 1633


Ignore:
Timestamp:
10/17/06 20:32:06 (18 years ago)
Author:
mattausch
Message:

worked on gradient method for vsposp

Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
3 added
18 edited

Legend:

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

    r1624 r1633  
    509509 
    510510        const float renderCostDecr = oldRenderCost - newRenderCost; 
    511         const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate); 
    512  
     511         
    513512#ifdef _DEBUG 
    514513        Debug << "old render cost: " << oldRenderCost << endl; 
     
    516515        Debug << "render cost decrease: " << renderCostDecr << endl; 
    517516#endif 
    518  
    519         splitCandidate.SetRenderCostDecrease(renderCostDecr); 
    520         splitCandidate.SetPvsEntriesIncr(EvalPvsEntriesIncr(splitCandidate)); 
    521517 
    522518#if 1 
     
    529525#endif 
    530526 
     527        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
     528 
     529        // increase in pvs entries 
     530        const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate); 
     531        splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 
     532 
    531533        // compute global decrease in render cost 
    532534        splitCandidate.SetPriority(priority); 
     535} 
     536 
     537 
     538float BvHierarchy::EvalPriority(const BvhSubdivisionCandidate &splitCandidate) const 
     539{ 
     540        BvhLeaf *leaf = splitCandidate.mParentData.mNode; 
     541 
     542        const float oldRenderCost = EvalRenderCost(leaf->mObjects); 
     543 
     544        // compute global decrease in render cost 
     545        const float newRenderCost =  
     546                EvalRenderCost(splitCandidate.mFrontObjects) + 
     547                EvalRenderCost(splitCandidate.mBackObjects); 
     548 
     549        const float renderCostDecr = oldRenderCost - newRenderCost; 
     550 
     551#ifdef _DEBUG 
     552        Debug << "old render cost: " << oldRenderCost << endl; 
     553        Debug << "new render cost: " << newRenderCost << endl; 
     554        Debug << "render cost decrease: " << renderCostDecr << endl; 
     555#endif 
     556 
     557#if 1 
     558        // take render cost of node into account  
     559        // otherwise danger of being stuck in a local minimum!! 
     560        const float factor = mRenderCostDecreaseWeight; 
     561        const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost; 
     562#else 
     563        const float priority = (float)-splitCandidate.mParentData.mDepth; 
     564#endif 
     565 
     566        return priority; 
    533567} 
    534568 
     
    569603                ); 
    570604 
    571         if (1 && terminationCriteriaMet) 
     605#ifdef _DEBUG 
     606        if (terminationCriteriaMet) 
    572607        { 
    573608                Debug << "bvh global termination criteria met:" << endl; 
     
    575610                Debug << "leaves: " << mBvhStats.Leaves() << " " << mTermMaxLeaves << endl; 
    576611        } 
    577  
     612#endif 
    578613        return terminationCriteriaMet;  
    579614} 
     
    15291564 
    15301565void BvHierarchy::CollectDirtyCandidates(BvhSubdivisionCandidate *sc,  
    1531                                                                                  vector<SubdivisionCandidate *> &dirtyList) 
     1566                                                                                 vector<SubdivisionCandidate *> &dirtyList,  
     1567                                                                                 const bool onlyUnmailed) 
    15321568{ 
    15331569        BvhTraversalData &tData = sc->mParentData; 
     
    15351571         
    15361572        ViewCellContainer viewCells; 
    1537         CollectViewCells(node->mObjects, viewCells); 
     1573        ViewCell::NewMail(); 
     1574        CollectViewCells(node->mObjects, viewCells, true); 
     1575 
    15381576        if (0) cout << "collected " << (int)viewCells.size() << " dirty candidates" << endl; 
    1539  
     1577         
    15401578        // split candidates handling  
    15411579        // these view cells  are thrown into dirty list 
     
    15441582        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    15451583        { 
    1546                 VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
     1584        VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
    15471585                VspLeaf *leaf = vc->mLeaves[0]; 
     1586         
    15481587                SubdivisionCandidate *candidate = leaf->GetSubdivisionCandidate(); 
    15491588                 
    1550                 if (candidate) // is this leaf still a split candidate? 
    1551                 { 
     1589                // is this leaf still a split candidate? 
     1590                if (candidate && (!onlyUnmailed || !candidate->Mailed())) 
     1591                { 
     1592                        candidate->Mail(); 
    15521593                        dirtyList.push_back(candidate); 
    15531594                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1632 r1633  
    403403                int Type() const { return OBJECT_SPACE; } 
    404404         
    405                 void EvalPriority() 
     405                void EvalPriority(bool computeSplitplane = true) 
    406406                { 
    407                         sBvHierarchy->EvalSubdivisionCandidate(*this);   
     407                        if (computeSplitplane) 
     408                                sBvHierarchy->EvalSubdivisionCandidate(*this);   
     409                        else 
     410                                mPriority = sBvHierarchy->EvalPriority(*this); 
    408411                } 
    409412 
    410                 /*bool Apply(SplitQueue *queue, bool terminationCriteriaMet) 
     413                bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet) 
    411414                { 
    412415                        BvhNode *n = sBvHierarchy->Subdivide(splitQueue, this, terminationCriteriaMet); 
    413416                        // local or global termination criteria failed 
    414417                        return !n->IsLeaf();             
    415                 }*/ 
     418                } 
     419 
     420                void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList, 
     421                                                                        const bool onlyUnmailed) 
     422                { 
     423                        sBvHierarchy->CollectDirtyCandidates(this, dirtyList, onlyUnmailed); 
     424                } 
    416425 
    417426                bool GlobalTerminationCriteriaMet() const 
     
    710719        float PrepareHeuristics(const BvhTraversalData &tData, const int axis); 
    711720         
     721        /** Reevaluates the priority of this split candidate 
     722                @returns priority 
     723        */ 
     724        float EvalPriority(const BvhSubdivisionCandidate &splitCandidate) const; 
     725 
    712726        //////////////////////////////////////////////// 
    713727 
     
    725739        void CollectDirtyCandidates( 
    726740                BvhSubdivisionCandidate *sc, 
    727                 vector<SubdivisionCandidate *> &dirtyList); 
     741                vector<SubdivisionCandidate *> &dirtyList, 
     742                const bool onlyUnmailed); 
    728743 
    729744        /** Collect view cells which see this bvh leaf. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1613 r1633  
    25262526                                        "4"); 
    25272527 
     2528         
     2529        RegisterOption("Hierarchy.Construction.recomputeSplitPlaneOnRepair", 
     2530                                        optBool, 
     2531                                        "hierarchy_construction_recompute_split_on_repair=", 
     2532                                        "true"); 
     2533 
    25282534        ///////////////////////////////////////////////////////////////// 
    25292535} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1632 r1633  
    113113        mSubdivisionStats.open(subdivisionStatsLog); 
    114114 
    115         //mMinRenderCostDecrease = -1; 
     115        Environment::GetSingleton()->GetBoolValue( 
     116                "Hierarchy.Construction.recomputeSplitPlaneOnRepair", mRecomputeSplitPlaneOnRepair); 
    116117 
    117118        Debug << "******** Hierachy Manager Parameters ***********" << endl; 
     
    122123        Debug << "repair queue: " << mRepairQueue << endl; 
    123124        Debug << "number of multilevels: " << mNumMultiLevels << endl; 
     125        Debug << "recompute split plane on repair: " << mRecomputeSplitPlaneOnRepair << endl; 
    124126 
    125127        switch (mConstructionType) 
     
    259261                (0 
    260262                || (mHierarchyStats.Leaves() >= mTermMaxLeaves)  
    261                 || (mHierarchyStats.mGlobalCostMisses >= mTermGlobalCostMissTolerance) 
     263                //|| (mHierarchyStats.mGlobalCostMisses >= mTermGlobalCostMissTolerance) 
    262264                || (candidate->GlobalTerminationCriteriaMet()) 
    263265                //|| (mHierarchyStats.mRenderCostDecrease < mMinRenderCostDecrease) 
     
    316318        // compute view space bounding box 
    317319        mVspTree->ComputeBoundingBox(sampleRays, forcedViewSpace); 
     320 
     321        SplitQueue objectSpaceQueue; 
     322        SplitQueue viewSpaceQueue; 
    318323 
    319324        // use sah for evaluating osp tree construction  
     
    324329        mSavedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 
    325330 
    326         SplitQueue objectSpaceQueue; 
    327         SplitQueue viewSpaceQueue; 
    328  
    329331        // number of initial splits 
    330332        int maxSteps = 200; 
    331333        float renderCostDecr = 0; 
     334 
     335        SubdivisionCandidate *osc =  
     336                PrepareObjectSpaceSubdivision(sampleRays, objects); 
     337         
     338        objectSpaceQueue.Push(osc); 
     339 
     340        ///////////////////////// 
     341        // calulcate initial object space splits 
     342         
     343        SubdivisionCandidateContainer dirtyVspList; 
     344 
     345        // subdivide object space first 
     346        // for first round, use sah splits. Once view space partition 
     347        // has started, use render cost heuristics instead 
     348        const int ospSteps =  
     349                RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, maxSteps); 
     350 
     351        cout << ospSteps << " object space partition steps taken" << endl; 
     352 
     353        SubdivisionCandidate *vsc =  
     354                        PrepareViewSpaceSubdivision(sampleRays, objects); 
     355 
     356        viewSpaceQueue.Push(vsc); 
     357 
     358        // view space subdivision was constructed 
     359        mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 
     360 
     361        // don't terminate on max steps 
     362        //maxSteps = mTermMaxLeaves; 
    332363 
    333364        // This method subdivides view space / object space  
     
    337368        // and vice versa until iteration depth is reached. 
    338369 
    339         while (1) 
    340         { 
    341                 // subdivide object space first 
    342                 // for first round, use sah splits. Once view space partition 
    343                 // has started, use render cost heuristics instead 
    344                 SubdivisionCandidate *osc =  
    345                         ResetObjectSpaceSubdivision(sampleRays, objects); 
    346                 objectSpaceQueue.Push(osc); 
    347  
    348                 // process object space candidates using render queue for  
    349                 // objects until slope of previous subdivision is reached 
    350                 SubdivisionCandidateContainer ospContainer; 
    351  
    352                 const int ospSteps =  
    353                         RunConstruction(objectSpaceQueue, ospContainer, renderCostDecr, maxSteps); 
    354             cout << ospSteps << " object space partition steps taken" << endl; 
    355  
    356                 // use splits of one kind until rendercost slope is reached 
    357                 renderCostDecr = mHierarchyStats.mRenderCostDecrease; 
     370        while (!(viewSpaceQueue.Empty() && objectSpaceQueue.Empty())) 
     371        { 
     372                // should view or object space be subdivided further? 
     373                if (viewSpaceQueue.Empty() || 
     374                        (!objectSpaceQueue.Empty() && 
     375                        (objectSpaceQueue.Top()->GetPriority() > viewSpaceQueue.Top()->GetPriority()))) 
     376                { 
     377                        // use splits of one kind until rendercost slope is reached 
     378                        renderCostDecr = mHierarchyStats.mRenderCostDecrease; 
     379 
     380                        // dirtied view space candidates 
     381                        SubdivisionCandidateContainer dirtyVspList; 
     382 
     383                        // subdivide object space first 
     384                        // for first round, use sah splits. Once view space partition 
     385                        // has started, use render cost heuristics instead 
     386                        const int ospSteps =  
     387                                RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, maxSteps); 
     388 
     389                        cout << ospSteps << " object space partition steps taken" << endl; 
    358390                 
    359                 // object space subdivision constructed 
    360                 mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
    361  
    362                 /// Repair split queue 
    363                 cout << "repairing queue ... " << endl; 
    364                  
    365                 vector<SubdivisionCandidate *> dirtyList; 
    366  
    367                 CollectDirtyCandidates(ospContainer, dirtyList); 
    368                 //RepairQueue(dirtyList, viewSpaceQueue); 
    369  
    370                 cout << "finished repairing queue ... " << endl; 
    371                  
    372                 CLEAR_CONTAINER(ospContainer); 
    373  
    374                 ///////////////// 
    375                 // subdivide view space with respect to the objects 
    376  
    377                 SubdivisionCandidate *vsc =  
    378                         ResetViewSpaceSubdivision(sampleRays, objects); 
    379                 viewSpaceQueue.Push(vsc); 
    380  
    381                 SubdivisionCandidateContainer vspContainer; 
    382                 // process view space candidates 
    383                 const int vspSteps =  
    384                         RunConstruction(viewSpaceQueue, vspContainer, renderCostDecr, maxSteps); 
    385  
    386                 cout << vspSteps << " view space partition steps taken" << endl; 
    387  
    388                 // view space subdivision constructed 
    389                 mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 
    390  
    391                 // use splits of one kind until rendercost slope is reached 
    392                 renderCostDecr = mHierarchyStats.mRenderCostDecrease; 
    393  
    394                 /// Repair split queue 
    395                 cout << "repairing queue ... " << endl; 
    396                  
    397                 CollectDirtyCandidates(vspContainer, dirtyList); 
    398                 //RepairQueue(dirtyList, objectSpaceQueue); 
    399  
    400                 cout << "finished repairing queue ... " << endl; 
    401  
    402                 CLEAR_CONTAINER(vspContainer); 
    403         } 
    404          
     391                        // object space subdivision constructed 
     392                        mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
     393 
     394                        /// Repair split queue 
     395                        cout << "repairing queue ... " << endl; 
     396                        RepairQueue(dirtyVspList, viewSpaceQueue, true); 
     397                        cout << "repaired " << dirtyVspList.size() << " candidates" << endl; 
     398                } 
     399                else 
     400                { 
     401                        // use splits of one kind until rendercost slope is reached 
     402                        renderCostDecr = mHierarchyStats.mRenderCostDecrease; 
     403 
     404                        ///////////////// 
     405                        // subdivide view space with respect to the objects 
     406 
     407                        SubdivisionCandidateContainer dirtyOspList; 
     408 
     409                        // process view space candidates 
     410                        const int vspSteps =  
     411                                RunConstruction(viewSpaceQueue, dirtyOspList, renderCostDecr, maxSteps); 
     412 
     413                        cout << vspSteps << " view space partition steps taken" << endl; 
     414 
     415                        // view space subdivision constructed 
     416                        mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 
     417 
     418                        /// Repair split queue 
     419                        cout << "repairing queue ... " << endl; 
     420                        RepairQueue(dirtyOspList, objectSpaceQueue, true); 
     421                        cout << "repaired " << dirtyOspList.size() << " candidates" << endl; 
     422                } 
     423        } 
     424 
    405425        cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    406426 
     
    432452        mVspTree->ComputeBoundingBox(sampleRays, forcedViewSpace); 
    433453 
    434         // use objects for evaluating vsp tree construction in the first levels 
    435         // of the subdivision 
     454        // use objects for evaluating vsp tree construction in the  
     455        // first levels of the subdivision 
    436456        mSavedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 
    437457        mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV; 
     
    557577                                                                                                 const bool repairQueue) 
    558578{ 
    559         // test if global termination criteria were met before this split 
    560579        const bool terminationCriteriaMet = GlobalTerminationCriteriaMet(sc); 
    561         const bool vspSplit = (sc->Type() == SubdivisionCandidate::VIEW_SPACE); 
    562  
    563         bool success = false; 
    564  
    565         switch (sc->Type()) 
    566         { 
    567         case SubdivisionCandidate::VIEW_SPACE: 
    568                 { 
    569                         VspNode *n = mVspTree->Subdivide(splitQueue, sc, terminationCriteriaMet); 
    570  
    571                         // check if terminated 
    572                         success = !n->IsLeaf(); 
    573                 } 
    574                 break; 
    575         case SubdivisionCandidate::OBJECT_SPACE: 
    576                 { 
    577                         if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV) 
    578                         { 
    579                                 KdNode *n = mOspTree->Subdivide(splitQueue, sc, terminationCriteriaMet); 
    580  
    581                                 // local or global termination criteria failed 
    582                                 success = !n->IsLeaf(); 
    583                         } 
    584                         else if (mObjectSpaceSubdivisionType == BV_BASED_OBJ_SUBDIV) 
    585                         { 
    586                                 BvhNode *n = mBvHierarchy->Subdivide(splitQueue, sc, terminationCriteriaMet); 
    587  
    588                                 // local or global termination criteria failed 
    589                                 success = !n->IsLeaf();                                  
    590                         } 
    591                 } 
    592                 break; 
    593         default: 
    594                 cerr << "unknown subdivision type" << endl; 
    595                 break; 
    596         } 
     580 
     581        const bool success = sc->Apply(splitQueue, terminationCriteriaMet); 
    597582 
    598583        if (!success) // split was not taken 
     
    635620                // this would be object space splits and other way round 
    636621                vector<SubdivisionCandidate *> dirtyList; 
    637                 CollectDirtyCandidates(sc, dirtyList); 
    638  
    639                 RepairQueue(dirtyList, splitQueue); 
     622                sc->CollectDirtyCandidates(dirtyList, false); 
     623 
     624                RepairQueue(dirtyList, splitQueue, mRecomputeSplitPlaneOnRepair); 
    640625        } 
    641626 
     
    766751                //////// 
    767752                //-- subdivide leaf node of either type 
    768  
    769753                ApplySubdivisionCandidate(sc, mTQueue, repairQueue); 
    770  
    771754                DEL_PTR(sc); 
    772755        } 
     
    775758 
    776759int HierarchyManager::RunConstruction(SplitQueue &splitQueue, 
    777                                                                           SubdivisionCandidateContainer &chosenCandidates, 
     760                                                                          SubdivisionCandidateContainer &dirtyCandidates, 
    778761                                                                          const float minRenderCostDecr, 
    779762                                                                          const int maxSteps) 
    780763{ 
    781764        int steps = 0; 
     765        SubdivisionCandidate::NewMail(); 
    782766 
    783767        // main loop 
    784         while (!splitQueue.Empty() && ((steps ++) < maxSteps)) 
     768        while (!splitQueue.Empty() && (steps < maxSteps)) 
    785769        { 
    786770                SubdivisionCandidate *sc = NextSubdivisionCandidate(splitQueue);  
    787771                 
    788772                // minimum slope reached 
    789                 if (sc->GetRenderCostDecrease() < minRenderCostDecr) 
    790                         break; 
     773                //if (sc->GetRenderCostDecrease() < minRenderCostDecr)  break; 
    791774 
    792775                //////// 
     
    794777 
    795778                const bool repairQueue = false; 
    796                 bool success = ApplySubdivisionCandidate(sc, splitQueue, repairQueue); 
     779                const bool success = ApplySubdivisionCandidate(sc, splitQueue, repairQueue); 
    797780 
    798781                if (success) 
    799782                { 
    800                         chosenCandidates.push_back(sc); 
     783                        sc->CollectDirtyCandidates(dirtyCandidates, true); 
     784                        //cout << "collected " << dirtyCandidates.size() << "dirty candidates" << endl; 
     785                        ++ steps; 
    801786                } 
    802787        } 
     
    826811         
    827812                        firstCandidate = mBvHierarchy->Reset(sampleRays, objects); 
    828                         cout << "here4" << endl; 
     813                 
    829814                        mHierarchyStats.mTotalCost = mBvHierarchy->mTotalCost; 
    830815 
     
    835820                        // evaluate stats before first subdivision 
    836821                        EvalSubdivisionStats(); 
    837                         cout << "here5" << endl; 
    838822                } 
    839823                break; 
     
    845829                break; 
    846830        } 
    847 cout << "here6" << endl; 
     831 
    848832        return firstCandidate; 
    849833} 
     
    990974 
    991975 
    992 void HierarchyManager::CollectObjectSpaceDirtyList(SubdivisionCandidate *sc, 
    993                                                                                                    SubdivisionCandidateContainer &dirtyList) 
    994 { 
    995         switch (mObjectSpaceSubdivisionType) 
    996         { 
    997         case KD_BASED_OBJ_SUBDIV: 
    998                 { 
    999                         OspTree::OspSubdivisionCandidate *ospSc =  
    1000                                 dynamic_cast<OspTree::OspSubdivisionCandidate *>(sc); 
    1001  
    1002                         mOspTree->CollectDirtyCandidates(ospSc, dirtyList); 
    1003                         break; 
    1004                 } 
    1005         case BV_BASED_OBJ_SUBDIV: 
    1006                 { 
    1007                         BvHierarchy::BvhSubdivisionCandidate *bvhSc =  
    1008                                 dynamic_cast<BvHierarchy::BvhSubdivisionCandidate *>(sc); 
    1009  
    1010                         mBvHierarchy->CollectDirtyCandidates(bvhSc, dirtyList); 
    1011                         break; 
    1012                 } 
    1013         default: 
    1014                 break; 
    1015         } 
    1016 } 
    1017  
    1018  
    1019 void HierarchyManager::CollectViewSpaceDirtyList(SubdivisionCandidate *sc,  
    1020                                                                                                  SubdivisionCandidateContainer &dirtyList) 
    1021 { 
    1022         VspTree::VspSubdivisionCandidate *vspSc =  
    1023                 dynamic_cast<VspTree::VspSubdivisionCandidate *>(sc); 
    1024  
    1025         mVspTree->CollectDirtyCandidates(vspSc, dirtyList); 
    1026 } 
    1027  
    1028  
    1029 void HierarchyManager::CollectDirtyCandidates(SubdivisionCandidate *sc,  
    1030                                                                                           SubdivisionCandidateContainer &dirtyList) 
    1031 { 
    1032         // we have either a object space or view space split 
    1033         if (sc->Type() == SubdivisionCandidate::VIEW_SPACE) 
    1034         { 
    1035                 CollectViewSpaceDirtyList(sc, dirtyList); 
    1036         } 
    1037         else // object space split 
    1038         { 
    1039                 CollectObjectSpaceDirtyList(sc, dirtyList); 
    1040         } 
    1041 } 
    1042  
    1043  
    1044976void HierarchyManager::CollectDirtyCandidates(const SubdivisionCandidateContainer &chosenCandidates,  
    1045977                                                                                          SubdivisionCandidateContainer &dirtyList) 
    1046978{ 
    1047979        SubdivisionCandidateContainer::const_iterator sit, sit_end = chosenCandidates.end(); 
     980        SubdivisionCandidate::NewMail(); 
    1048981 
    1049982        for (sit = chosenCandidates.begin(); sit != sit_end; ++ sit) 
    1050983        { 
    1051                 // we have either a object space or view space split 
    1052                 if ((*sit)->Type() == SubdivisionCandidate::VIEW_SPACE) 
    1053                 { 
    1054                         CollectViewSpaceDirtyList(*sit, dirtyList); 
    1055                 } 
    1056                 else // object space split 
    1057                 { 
    1058                         CollectObjectSpaceDirtyList(*sit, dirtyList); 
    1059                 } 
    1060         } 
    1061 } 
    1062  
    1063  
    1064 void HierarchyManager::RepairQueue(const vector<SubdivisionCandidate *> &dirtyList,  
    1065                                                                    SplitQueue &splitQueue) 
     984                (*sit)->CollectDirtyCandidates(dirtyList, true); 
     985        } 
     986} 
     987 
     988 
     989void HierarchyManager::RepairQueue(const SubdivisionCandidateContainer &dirtyList,  
     990                                                                   SplitQueue &splitQueue, 
     991                                                                   const bool recomputeSplitPlaneOnRepair) 
    1066992{ 
    1067993        // for each update of the view space partition: 
     
    10971023                 
    10981024                splitQueue.Erase(sc); // erase from queue 
    1099                 sc->EvalPriority(); // reevaluate 
     1025                sc->EvalPriority(recomputeSplitPlaneOnRepair); // reevaluate 
    11001026                 
    11011027#ifdef _DEBUG 
     
    11131039        mHierarchyStats.mRepairTime += timeDiff; 
    11141040 
    1115         if (1) cout << "repaired in " << timeDiff * 1e-3f << " secs" << endl; 
     1041        if (0) cout << "repaired in " << timeDiff * 1e-3f << " secs" << endl; 
    11161042} 
    11171043 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1627 r1633  
    106106 
    107107 
    108 typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue; 
    109  
    110108/** This class implements a structure holding two different hierarchies, 
    111109        one for object space partitioning and one for view space partitioning. 
     
    290288                list of entries is given in the dirty list. 
    291289        */ 
    292         void RepairQueue(const vector<SubdivisionCandidate *> &dirtyList, SplitQueue &splitQueue); 
     290        void RepairQueue(const SubdivisionCandidateContainer &dirtyList,  
     291                                         SplitQueue &splitQueue, 
     292                                         const bool recomputeSplitPlaneOnRepair); 
    293293 
    294294        /** Collect subdivision candidates which were affected by the splits from the 
     
    297297        void CollectDirtyCandidates(const SubdivisionCandidateContainer &chosenCandidates,  
    298298                                                                SubdivisionCandidateContainer &dirtyList); 
    299  
    300         /** Collect the list of dirty candidates after the current  
    301                 subdivision candidate split. 
    302         */ 
    303         void CollectDirtyCandidates(SubdivisionCandidate *sc, 
    304                                                                 vector<SubdivisionCandidate *> &dirtyList); 
    305299 
    306300        /** Evaluate subdivision stats for log. 
     
    497491        /// number of iteration steps for multilevel approach    
    498492        int mNumMultiLevels; 
     493        /** if split plane should be recomputed for the repair. 
     494                Otherwise only the priority is recomputed, the 
     495                split plane itself stays the same 
     496        */ 
     497        bool mRecomputeSplitPlaneOnRepair; 
    499498}; 
    500499 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1594 r1633  
    12001200 
    12011201        MeshInstance dummyInst(NULL); 
    1202         //Debug << "objects size: " << size << endl; 
    1203  
     1202         
    12041203        // read object ids 
     1204        // note: could also do this geometrically 
    12051205        for (int i = 0; i < size; ++ i) 
    12061206        {        
     
    13311331        /////////////////////////// 
    13321332        //-- compute bounding box of object space 
     1333 
    13331334    for (oit = objects.begin(); oit != oit_end; ++ oit) 
    13341335        { 
     
    14331434 
    14341435 
    1435 } 
     1436void KdTree::InsertObjects(KdNode *node, const ObjectContainer &objects) 
     1437{/* 
     1438        stack<KdObjectsTraversalData> tStack; 
     1439 
     1440        while (!tStack.empty()) 
     1441        { 
     1442                KdObjectsTraversalData tData = tStack.top(); 
     1443        tStack.pop(); 
     1444 
     1445                KdNode *node = tData.node; 
     1446                 
     1447                if (node->IsLeaf()) 
     1448                { 
     1449                        KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 
     1450 
     1451                        ObjectContainer::const_iterator oit, oit_end = tData.objects->end(); 
     1452 
     1453                        for (oit = tData.objects->begin(); oit != oit_end; ++ oit) 
     1454                        { 
     1455                                leaf->mObjects.push_back(*oit); 
     1456                        } 
     1457                } 
     1458                else // interior 
     1459                { 
     1460                        KdObjectsTraversalData frontData, backData; 
     1461                        KdInterior *interior = dynamic_cast<KdInterior *>(node); 
     1462 
     1463                        frontData.objects = new ObjectContainer(); 
     1464                        backData.objects = new ObjectContainer(); 
     1465 
     1466                        ObjectContainer::const_iterator oit, oit_end = tData.objects->end(); 
     1467                         
     1468                    for (oit = tData.objects->begin(); oit != oit_end; ++ oit)  
     1469                        { 
     1470                                Intersectable *object = *oit; 
     1471                 
     1472                                // determine the side of this ray with respect to the plane 
     1473                                const AxisAlignedBox3 box = object->GetBox(); 
     1474 
     1475                                if (box.Max(interior->mAxis) >= interior->mPosition) 
     1476                                { 
     1477                                        frontData.objects->push_back(object); 
     1478                                } 
     1479 
     1480                                if (box.Min(interior->mAxis) < interior->mPosition) 
     1481                                { 
     1482                                        backData.objects->push_back(object); 
     1483                                } 
     1484                        } 
     1485 
     1486                        tStack.push(backData); 
     1487                        tStack.push(frontData); 
     1488                } 
     1489 
     1490                DEL_PTR(tData.objects); 
     1491        }*/ 
     1492} 
     1493 
     1494} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r1614 r1633  
    575575        KdInterior *ImportBinInterior(IN_STREAM  &stream, KdInterior *parent); 
    576576        KdNode *LoadNextNode(IN_STREAM  &stream, KdInterior *parent, const ObjectContainer &objects); 
     577         
     578        /** Adds this objects to the kd leaf objects. 
     579                @warning: Can corrupt the tree 
     580        */ 
     581        void InsertObjects(KdNode *node, const ObjectContainer &objects); 
    577582 
    578583  int mTermMaxNodes; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp

    r1615 r1633  
    15471547 
    15481548void OspTree::CollectDirtyCandidates(OspSubdivisionCandidate *sc,  
    1549                                                                          vector<SubdivisionCandidate *> &dirtyList) 
     1549                                                                         vector<SubdivisionCandidate *> &dirtyList, 
     1550                                                                         const bool onlyUnmailed) 
    15501551{ 
    15511552        OspTraversalData &tData = sc->mParentData; 
     
    15781579        } 
    15791580 
    1580  
    1581         // split candidates holding this view cells  
    1582         // are thrown into dirty list 
     1581        // andidates holding this view cells are thrown into dirty list 
    15831582        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    15841583 
     
    15881587 
    15891588                VspLeaf *leaf = vc->mLeaves[0]; 
    1590                 dirtyList.push_back(leaf->GetSubdivisionCandidate()); 
     1589 
     1590                SubdivisionCandidate *dsc = leaf->GetSubdivisionCandidate(); 
     1591                if (dsc && (!onlyUnmailed || !dsc->Mailed())) 
     1592                { 
     1593                        dsc->Mail(); 
     1594                        dirtyList.push_back(dsc); 
     1595                } 
    15911596        } 
    15921597} 
     
    19681973                                                                         ViewCell *vc,  
    19691974                                                                         float &contribution, 
    1970                                                                          bool onlyMailed) const 
     1975                                                                         bool onlyUnmailed) const 
    19711976{        
    19721977        contribution = 0; // todo 
     
    19771982                vdata = obj->mViewCellPvs.AddSample2(vc, 1); 
    19781983        } 
    1979         else if (!onlyMailed || !vdata->Mailed()) 
     1984        else if (!onlyUnmailed || !vdata->Mailed()) 
    19801985        { 
    19811986                obj->mViewCellPvs.AddSample(vc, 1); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h

    r1594 r1633  
    1212#include "SubdivisionCandidate.h" 
    1313#include "IntersectableWrapper.h" 
     14#include "KdTree.h" 
    1415 
    1516 
     
    3940class SubdivisionCandidate; 
    4041class HierarchyManager; 
    41  
     42class KdNode; 
    4243 
    4344 
     
    136137 
    137138 
    138  
    139  
    140 /** View Space Partitioning tree. 
     139/** Object Space Partitioning Kd tree. 
    141140*/ 
    142141class OspTree  
     
    251250                int Type() const { return OBJECT_SPACE; } 
    252251         
    253                 void EvalPriority() 
     252                void EvalPriority(bool computeSplitplane = true) 
    254253                { 
    255                         sOspTree->EvalSubdivisionCandidate(*this);       
     254                        if (computeSplitplane) 
     255                                sOspTree->EvalSubdivisionCandidate(*this);       
     256                        // else TODO 
    256257                } 
    257258 
     
    261262                } 
    262263 
     264                bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet) 
     265                { 
     266                        KdNode *n = sOspTree->Subdivide(splitQueue ,this,  terminationCriteriaMet); 
     267 
     268                        // local or global termination criteria failed 
     269                        return !n->IsLeaf();             
     270                } 
     271 
     272                void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList, 
     273                                                                        const bool onlyUnmailed) 
     274                { 
     275                        sOspTree->CollectDirtyCandidates(this, dirtyList, onlyUnmailed); 
     276                } 
    263277 
    264278                OspSubdivisionCandidate(const AxisAlignedPlane &plane, const OspTraversalData &tData):  
     
    643657 
    644658        void CollectDirtyCandidates(OspSubdivisionCandidate *sc, 
    645                 vector<SubdivisionCandidate *> &dirtyList); 
     659                                                                vector<SubdivisionCandidate *> &dirtyList, 
     660                                                                const bool onlyUnmailed); 
    646661 
    647662        /** Collect view cells which see this kd leaf. 
     
    703718                ViewCell *vc,  
    704719                float &contribution, 
    705                 bool onlyMailed) const; 
     720                bool onlyUnmailed) const; 
    706721 
    707722        int ClassifyRays( 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1627 r1633  
    617617{ 
    618618        mKdTree = new KdTree(); 
     619 
    619620        return mKdTree->LoadBinTree(filename.c_str(), mObjects); 
    620621} 
     
    820821bool Preprocessor::InitRayCast(const string externKdTree, const string internKdTree) 
    821822{ 
     823        // always try to load the kd tree 
    822824        bool loadKdTree = true; 
    823825        //Environment::GetSingleton()->GetBoolValue("Preprocessor.loadKdTree", loadKdTree); 
    824          
    825          
     826                 
    826827        if (!loadKdTree) 
    827         {       ///////// 
    828                 //-- build new kd tree from scene geometry 
    829  
     828        {        
     829                // build new kd tree from scene geometry 
    830830                BuildKdTree(); 
    831                 KdTreeStatistics(cout); 
    832831        } 
    833832        else 
    834833        { 
    835                 long startTime = GetTime(); 
    836834                cout << "loading kd tree file " << internKdTree << " ... "; 
    837835 
    838836                if (!LoadKdTree(internKdTree)) 
    839837                { 
    840                         cout << "error loading kd tree with filename " << internKdTree << ", rebuilding it instead ..." << endl; 
    841  
     838                        cout << "error loading kd tree with filename " << internKdTree << ", rebuilding it instead ... " << endl; 
    842839                        BuildKdTree(); 
    843                         KdTreeStatistics(cout); 
    844                 } 
    845  
    846                 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    847  
    848                 if (0) 
    849                 { 
    850                         Exporter *exporter = Exporter::GetExporter("dummykd.x3d"); 
     840                } 
     841 
     842                // export kd tree? 
     843                const long startTime = GetTime(); 
     844                cout << "exporting kd tree ... "; 
     845 
     846                if (!ExportKdTree(internKdTree)) 
     847                { 
     848                        cout << " error exporting kd tree with filename " << internKdTree << endl; 
     849                } 
     850                else 
     851                { 
     852                        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     853                } 
     854        } 
     855         
     856        KdTreeStatistics(cout); 
     857        cout << mKdTree->GetBox() << endl; 
     858 
     859        if (0) 
     860        { 
     861                Exporter *exporter = Exporter::GetExporter("dummykd.x3d"); 
    851862                         
    852                         if (exporter) 
    853                         { 
    854                                 exporter->ExportKdTree(*mKdTree, true); 
    855                                 delete exporter; 
    856                         } 
    857                 } 
    858  
    859                 // export kd tree? 
    860                 startTime = GetTime(); 
    861                 cout << "exporting kd tree ... "; 
    862  
    863                 if (!ExportKdTree(internKdTree)) 
    864                 { 
    865                         cout << " error exporting kd tree with filename " << internKdTree << endl; 
    866                 } 
    867                 else 
    868                 { 
    869                         cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    870                 } 
    871         } 
     863                if (exporter) 
     864                { 
     865                        exporter->ExportKdTree(*mKdTree, true); 
     866                        delete exporter; 
     867                } 
     868 
     869                /*ofstream objstr("objects.txt"); 
     870 
     871                vector<KdLeaf *> leaves; 
     872                mKdTree->CollectLeaves(leaves); 
     873 
     874                vector<KdLeaf *>::const_iterator lit, lit_end = leaves.end(); 
     875                for (lit = leaves.begin(); lit != lit_end; ++ lit) 
     876                { 
     877                        objstr << "objects: " << (*lit)->mObjects.size() << " bb " << mKdTree->GetBox(*lit) << endl; 
     878                }*/ 
     879        } 
     880 
    872881 
    873882        int rayCastMethod; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj

    r1545 r1633  
    647647                        </File> 
    648648                        <File 
     649                                RelativePath=".\SubdivisionCandidate.cpp"> 
     650                        </File> 
     651                        <File 
    649652                                RelativePath=".\SubdivisionCandidate.h"> 
    650653                        </File> 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h

    r1632 r1633  
    88 
    99namespace GtpVisibilityPreprocessor { 
     10 
     11class SubdivisionCandidate; 
     12 
     13typedef vector<SubdivisionCandidate *> SubdivisionCandidateContainer; 
     14typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue; 
    1015 
    1116/** Candidate for a view space / object space split. 
     
    2025 
    2126        virtual ~SubdivisionCandidate() {}; 
    22         virtual void EvalPriority() = 0; 
     27        virtual void EvalPriority(bool computeSplitplane = true) = 0; 
    2328        virtual int Type() const = 0; 
    24         //virtual bool Apply() = 0; 
     29        virtual bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet) = 0; 
    2530        virtual bool GlobalTerminationCriteriaMet() const = 0; 
     31 
     32        virtual void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList, 
     33                                                                                const bool onlyUnmailed) = 0; 
    2634 
    2735        /** Set render cost decrease achieved through this split. 
     
    7078        } 
    7179 
     80        ////////// 
     81        //-- mailing stuff 
     82 
     83        static void NewMail(const int reserve = 1)  
     84        { 
     85                sMailId += sReservedMailboxes; 
     86                sReservedMailboxes = reserve; 
     87        } 
     88 
     89        void Mail() { mMailbox = sMailId; } 
     90        bool Mailed() const { return mMailbox == sMailId; } 
     91 
     92        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
     93        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
     94 
     95        int IncMail() { return ++ mMailbox - sMailId; } 
     96 
     97 
     98        // last mail id -> warning not thread safe! 
     99        // both mailId and mailbox should be unique for each thread!!! 
     100        static int sMailId; 
     101        static int sReservedMailboxes; 
     102 
    72103protected: 
    73104 
     
    80111        /// the decrease of the number of pvs entries 
    81112        int mPvsEntriesIncr; 
     113 
     114        int mMailbox; 
    82115}; 
    83116 
    84 typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue; 
    85 typedef vector<SubdivisionCandidate *> SubdivisionCandidateContainer; 
    86117 
    87118} 
    88119 
    89 // FLEXIBLEHEAP_H 
     120// SUBDIVISIONCANDIDATE_H 
    90121#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1622 r1633  
    3434                                           myless<vector<ViewCell *>::value_type> > TraversalQueue; 
    3535 
    36 int ViewCell::sMailId = 1;//2147483647; 
     36int ViewCell::sMailId = 10000;//2147483647; 
    3737int ViewCell::sReservedMailboxes = 1; 
    3838 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1632 r1633  
    264264{ 
    265265        SimpleRayContainer simpleRays; 
    266         const long startTime = GetTime(); 
     266        long startTime = GetTime(); 
    267267 
    268268        mPreprocessor->GenerateRays(samplesPerPass, sampleType, simpleRays); 
    269         Debug << "generated " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    270  
     269        cout << "generated " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     270 
     271        startTime = GetTime(); 
    271272        // shoot simple ray and add it to importance samples 
    272273        mPreprocessor->CastRays(simpleRays, passSamples, true); 
    273         Debug << "cast " <<  samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     274        cout << "cast " <<  samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    274275 
    275276        return (int)passSamples.size(); 
     
    323324         
    324325        long startTime = GetTime(); 
    325         cout << "view cell construction: casting " << mInitialSamples << " initial samples ... "; 
     326        cout << "view cell construction: casting " << mInitialSamples << " initial samples ... " << endl; 
    326327 
    327328        // cast initial samples 
     
    482483        if (mShowVisualization) 
    483484        { 
    484                 VssRayContainer visualizationSamples; 
    485  
    486                 //////// 
     485                /////////////// 
    487486                //-- visualization rays, e.g., to show some samples in the scene 
    488                 CastPassSamples(mVisualizationSamples, 
    489                                             SamplingStrategy::DIRECTION_BASED_DISTRIBUTION,  
    490                                                 visualizationSamples); 
     487                 
     488                VssRayContainer visSamples; 
     489                int numSamples = CastPassSamples(mVisualizationSamples, 
     490                                                                                 mSamplingType,  
     491                                                                                 visSamples); 
    491492 
    492493                if (SAMPLE_AFTER_SUBDIVISION) 
    493                         ComputeSampleContributions(visualizationSamples, true, storeViewCells); 
     494                        ComputeSampleContributions(visSamples, true, storeViewCells); 
    494495 
    495496                // various visualizations 
    496                 Visualize(preprocessor->mObjects, visualizationSamples); 
    497  
    498                 disposeRays(visualizationSamples, outRays); 
     497                Visualize(preprocessor->mObjects, visSamples); 
     498 
     499                disposeRays(visSamples, outRays); 
    499500        } 
    500501 
     
    51285129        GetRaySets(sampleRays, mVisualizationSamples, visRays); 
    51295130 
    5130         if (1)  
    5131         {        
    5132                 //////////// 
    5133                 //-- export final view cells 
    5134  
     5131        //////////// 
     5132        //-- export final view cells 
     5133 
     5134        Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl"); 
     5135 
     5136        if (exporter) 
     5137        { 
    51355138                // hack color code (show pvs size) 
    51365139                const int savedColorCode = mColorCode; 
    51375140                mColorCode = 0; 
    5138          
    5139                 Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl"); 
    5140                  
    5141                 if (exporter) 
    5142                 { 
    5143                         const long starttime = GetTime(); 
    5144                         cout << "exporting final view cells (after initial construction + post process) ... "; 
    5145  
    5146                         // matt: hack for clamping scene 
    5147                         AxisAlignedBox3 bbox = mViewSpaceBox; 
    5148                         bbox.Scale(Vector3(0.5, 1, 0.5)); 
    5149                         if (CLAMP_TO_BOX) 
    5150                         {        
    5151                                 exporter->SetWireframe();  
    5152                                 exporter->ExportBox(bbox); 
    5153                                 exporter->SetFilled();  
    5154                         } 
    5155                                  
    5156                         if (0 && mExportGeometry) 
    5157                         { 
    5158                                 exporter->ExportGeometry(objects, true, CLAMP_TO_BOX ? &bbox : NULL); 
    5159                         } 
    5160                          
    5161                         if (0 && mExportRays) 
    5162                         {        
    5163                                 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
    5164                         } 
    5165                  
    5166                         mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, CLAMP_TO_BOX ? &bbox : NULL, false); 
    5167                         ExportViewCellsForViz(exporter, CLAMP_TO_BOX ? &bbox : NULL, GetClipPlane()); 
    5168  
    5169                         delete exporter; 
    5170                         cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl; 
    5171                 } 
    5172  
     5141 
     5142                const long starttime = GetTime(); 
     5143                cout << "exporting final view cells (after initial construction + post process) ... "; 
     5144 
     5145                // matt: hack for clamping scene 
     5146                AxisAlignedBox3 bbox = mViewSpaceBox; 
     5147                bbox.Scale(Vector3(0.5, 1, 0.5)); 
     5148                if (CLAMP_TO_BOX) 
     5149                {        
     5150                        exporter->SetWireframe();  
     5151                        exporter->ExportBox(bbox); 
     5152                        exporter->SetFilled();  
     5153                } 
     5154 
     5155                if (0 && mExportGeometry) 
     5156                { 
     5157                        exporter->ExportGeometry(objects, true, CLAMP_TO_BOX ? &bbox : NULL); 
     5158                } 
     5159 
     5160                if (1 && mExportRays) 
     5161                {        
     5162                        exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
     5163                } 
     5164 
     5165                mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, CLAMP_TO_BOX ? &bbox : NULL, false); 
     5166                ExportViewCellsForViz(exporter, CLAMP_TO_BOX ? &bbox : NULL, GetClipPlane()); 
     5167 
     5168                delete exporter; 
     5169                cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl; 
    51735170                mColorCode = savedColorCode; 
    51745171        } 
    51755172 
    5176         if (1) 
    5177         { 
    5178                 // export final object partition 
    5179                 Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 
    5180  
    5181                 if (exporter) 
    5182                 { 
    5183                         const long starttime = GetTime(); 
    5184                          
    5185                         // matt: hack for making visualization smaller in size 
    5186                         AxisAlignedBox3 bbox = mHierarchyManager->GetObjectSpaceBox(); 
    5187                         bbox.Scale(Vector3(0.5, 1, 0.5)); 
    5188  
    5189                         cout << "exporting object space hierarchy ... "; 
    5190                         mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, CLAMP_TO_BOX ? &bbox : NULL); 
    5191                  
    5192                         delete exporter; 
    5193                         cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl; 
    5194                 } 
    5195         } 
    5196          
     5173        // export final object partition 
     5174        exporter = Exporter::GetExporter("final_object_partition.wrl"); 
     5175 
     5176        if (exporter) 
     5177        { 
     5178                const long starttime = GetTime(); 
     5179 
     5180                // matt: hack for making visualization smaller in size 
     5181                AxisAlignedBox3 bbox = mHierarchyManager->GetObjectSpaceBox(); 
     5182                bbox.Scale(Vector3(0.5, 1, 0.5)); 
     5183 
     5184                cout << "exporting object space hierarchy ... "; 
     5185                mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, CLAMP_TO_BOX ? &bbox : NULL); 
     5186 
     5187                delete exporter; 
     5188                cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl; 
     5189        } 
     5190 
     5191         
     5192        //  visualization of the view cells 
     5193        if (0) ExportMergedViewCells(objects); 
     5194 
    51975195        // export some view cell 
    51985196        int leafOut; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1623 r1633  
    161161        { 
    162162                // for a spatial subdivision, it is not necessary to store 
    163                 // the objects with the leaves, they can be classified now 
     163                // the objects with the leaves, they can be classified 
     164                // geometrically 
    164165                mHierarchyManager->mOspTree->InsertObjects( 
    165166                        mHierarchyManager->mOspTree->mRoot, *mObjects); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1610 r1633  
    694694        if (!LocalTerminationCriteriaMet(tData) && !globalCriteriaMet) 
    695695        {        
     696                /////////// 
    696697                //-- continue subdivision 
     698 
    697699                VspTraversalData tFrontData; 
    698700                VspTraversalData tBackData; 
     
    714716                if (1) EvalSubdivisionStats(*sc); 
    715717                 
     718                ///////////// 
    716719                //-- evaluate new split candidates for global greedy cost heuristics 
    717720 
     
    728731                tQueue.Push(frontCandidate); 
    729732                tQueue.Push(backCandidate); 
    730                  
    731                 // delete old leaf node 
    732                 //DEL_PTR(tData.mNode); 
     733 
     734                // note: leaf is not destroyed because it is needed to collect  
     735                // dirty candidates in hierarchy manager 
    733736        } 
    734737 
     
    825828         
    826829        splitCandidate.SetPriority(priority); 
     830} 
     831 
     832 
     833float VspTree::EvalPriority(const VspSubdivisionCandidate &splitCandidate) const 
     834{ 
     835        // compute global decrease in render cost 
     836        float oldRenderCost; 
     837        const float renderCostDecr = EvalRenderCostDecrease(splitCandidate.mSplitPlane,  
     838                                                                                                                splitCandidate.mParentData, 
     839                                                                                                                oldRenderCost); 
     840     
     841#if 0 
     842        const float priority = (float)-splitCandidate.mParentData.mDepth; 
     843#else 
     844        // take render cost of node into account  
     845        // otherwise danger of being stuck in a local minimum!! 
     846        const float factor = mRenderCostDecreaseWeight; 
     847        const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost; 
     848#endif 
     849         
     850        return priority; 
    827851} 
    828852 
     
    28722896void VspTree::CollectDirtyCandidate(const VssRay &ray,  
    28732897                                                                        const bool isTermination, 
    2874                                                                         vector<SubdivisionCandidate *> &dirtyList) const 
     2898                                                                        vector<SubdivisionCandidate *> &dirtyList, 
     2899                                                                        const bool onlyUnmailed) const 
    28752900{ 
    28762901 
     
    28822907         
    28832908        if (!obj) return; 
    2884  
     2909         
     2910        SubdivisionCandidate *candidate = NULL; 
     2911                 
    28852912        switch (mHierarchyManager->GetObjectSpaceSubdivisionType()) 
    28862913        { 
     
    28922919                        { 
    28932920                                leaf->Mail(); 
    2894                                 dirtyList.push_back(leaf->mSubdivisionCandidate); 
     2921                                candidate = leaf->mSubdivisionCandidate; 
    28952922                        } 
    28962923                        break; 
     
    29032930                        { 
    29042931                                leaf->Mail(); 
    2905                                  // a candidate still attached to this node 
    2906                                 if (leaf->GetSubdivisionCandidate()) 
    2907                                 { 
    2908                                         dirtyList.push_back(leaf->GetSubdivisionCandidate()); 
    2909                                 } 
     2932                                candidate = leaf->GetSubdivisionCandidate(); 
    29102933                        } 
    29112934                        break; 
    29122935                } 
    29132936        default: 
     2937                cerr << "not implemented yet" << endl; 
     2938                candidate = NULL; 
    29142939                break; 
    29152940        } 
     2941 
     2942        // is this leaf still a split candidate? 
     2943        if (candidate && (!onlyUnmailed || !candidate->Mailed())) 
     2944        { 
     2945                candidate->Mail(); 
     2946                dirtyList.push_back(candidate); 
     2947        } 
    29162948} 
    29172949 
    29182950 
    29192951void VspTree::CollectDirtyCandidates(VspSubdivisionCandidate *sc,  
    2920                                                                          vector<SubdivisionCandidate *> &dirtyList) 
     2952                                                                         vector<SubdivisionCandidate *> &dirtyList, 
     2953                                                                         const bool onlyUnmailed) 
    29212954{ 
    29222955        VspTraversalData &tData = sc->mParentData; 
     
    29332966                VssRay *ray = (*rit).mRay; 
    29342967                 
    2935                 CollectDirtyCandidate(*ray, true, dirtyList); 
    2936                 CollectDirtyCandidate(*ray, false, dirtyList); 
     2968                CollectDirtyCandidate(*ray, true, dirtyList, onlyUnmailed); 
     2969        CollectDirtyCandidate(*ray, false, dirtyList, onlyUnmailed); 
    29372970        } 
    29382971} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1576 r1633  
    457457                int Type() const { return VIEW_SPACE; } 
    458458 
    459                 void EvalPriority() 
     459                void EvalPriority(bool computeSplitplane = true) 
    460460                { 
    461                         sVspTree->EvalSubdivisionCandidate(*this);       
     461                        if (computeSplitplane) 
     462                                sVspTree->EvalSubdivisionCandidate(*this);       
     463                        else 
     464                                mPriority = sVspTree->EvalPriority(*this); 
    462465                } 
    463466 
     
    467470                } 
    468471 
    469                 VspSubdivisionCandidate( 
    470                         const AxisAlignedPlane &plane,  
    471                         const VspTraversalData &tData):  
     472                bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet) 
     473                { 
     474                        VspNode *n = sVspTree->Subdivide(splitQueue, this, terminationCriteriaMet); 
     475                         
     476                        // local or global termination criteria failed 
     477                        return !n->IsLeaf();             
     478                } 
     479 
     480                void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList, 
     481                                                                        const bool onlyUnmailed) 
     482                { 
     483                        sVspTree->CollectDirtyCandidates(this, dirtyList, onlyUnmailed); 
     484                } 
     485 
     486        VspSubdivisionCandidate(const AxisAlignedPlane &plane, const VspTraversalData &tData):  
    472487                mSplitPlane(plane), mParentData(tData) 
    473488                {} 
     
    833848        int PrepareHeuristics(KdLeaf *leaf); 
    834849 
     850        /** Reevaluates the priority of this split candidate 
     851                @returns priority 
     852        */ 
     853        float EvalPriority(const VspSubdivisionCandidate &splitCandidate) const; 
     854 
    835855        ///////////////////////////////////////////////////////////////////////////// 
    836856 
     
    939959        */ 
    940960        void ProcessViewCellObjects(ViewCell *parent,  
    941                 ViewCell *front,  
    942                 ViewCell *back) const; 
     961                                                                ViewCell *front,  
     962                                                                ViewCell *back) const; 
    943963 
    944964        void CreateViewCell(VspTraversalData &tData, const bool updatePvs); 
     
    947967                and must be reevaluated. 
    948968        */ 
    949         void CollectDirtyCandidates(VspSubdivisionCandidate *sc, vector<SubdivisionCandidate *> &dirtyList); 
    950  
    951         void CollectDirtyCandidate( 
    952                 const VssRay &ray,  
    953                 const bool isTermination, 
    954                 vector<SubdivisionCandidate *> &dirtyList) const; 
     969        void CollectDirtyCandidates(VspSubdivisionCandidate *sc,  
     970                                                                vector<SubdivisionCandidate *> &dirtyList, 
     971                                                                const bool onlyUnmailed); 
     972 
     973        void CollectDirtyCandidate(const VssRay &ray,  
     974                                                           const bool isTermination, 
     975                                                           vector<SubdivisionCandidate *> &dirtyList, 
     976                                                           const bool onlyUnmailed) const; 
    955977 
    956978        /** Rays will be clipped to the bounding box. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1627 r1633  
    7676{ 
    7777        //Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree); 
    78          
     78        string suffix; 
     79 
     80        if (preprocessor->mLoadMeshes) 
     81        { 
     82                suffix = ".kdm";         
     83        } 
     84        else 
     85        { 
     86                suffix = ".kdt"; 
     87        } 
     88 
    7989        // hack! should take any extension 
    8090    if (strstr(filename.c_str(), ".x3d"))  
    8191        { 
    82                 return ReplaceSuffix(filename, ".x3d", ".kd"); 
     92                return ReplaceSuffix(filename, ".x3d", suffix); 
    8393        }  
    8494        else if (strstr(filename.c_str(), ".dat")) 
    8595        { 
    86                 return ReplaceSuffix(filename, ".dat", ".kd"); 
     96                return ReplaceSuffix(filename, ".dat", suffix); 
    8797        }  
    8898        else if (strstr(filename.c_str(), ".obj")) 
    8999        { 
    90                 return ReplaceSuffix(filename, ".dat", ".kd"); 
     100                return ReplaceSuffix(filename, ".dat", suffix); 
    91101        } 
    92102 
Note: See TracChangeset for help on using the changeset viewer.