Changeset 1580


Ignore:
Timestamp:
10/06/06 21:37:00 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
11 edited

Legend:

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

    r1577 r1580  
    174174        ReadEnvironment(); 
    175175        mSubdivisionCandidates = new SortableEntryContainer; 
     176        for (int i = 0; i < 3; ++ i) 
     177                mSortedObjects[i] = NULL; 
    176178} 
    177179 
     
    189191        DEL_PTR(mSubdivisionCandidates); 
    190192 
     193        for (int i = 0; i < 3; ++ i) 
     194        { 
     195                DEL_PTR(mSortedObjects[i]); 
     196        } 
    191197        mSubdivisionStats.close(); 
    192198} 
     
    10041010{ 
    10051011        //-- insert object queries 
    1006         ObjectContainer *objects = mUseGlobalSorting ? tData.mSortedObjects[axis] : &tData.mNode->mObjects; 
     1012        ObjectContainer *objects =  
     1013                mUseGlobalSorting ? tData.mSortedObjects[axis] : &tData.mNode->mObjects; 
    10071014 
    10081015        CreateLocalSubdivisionCandidates(*objects, &mSubdivisionCandidates, !mUseGlobalSorting, axis); 
     
    10421049 
    10431050        if (sort) 
    1044         { 
     1051        {       // no presorted candidate list 
    10451052                stable_sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 
    10461053        } 
     
    11541161        } 
    11551162         
    1156         //////////////////////////////////////////// 
     1163        //////////////////////////////////// 
    11571164        //-- evaluate split cost for all three axis 
    11581165         
     
    11791186                                else 
    11801187                                { 
    1181                                         //-- use surface area heuristic because view cells not constructed yet                           
     1188                                        ////////////////// 
     1189                                        //-- view cells not constructed yet     => use surface area heuristic                    
    11821190                                        nCostRatio[axis] = 
    11831191                                                EvalSah( 
     
    12101218        } 
    12111219 
    1212         ///////////////////////////////////// 
     1220    //////////////// 
    12131221        //-- assign values 
    12141222 
     
    12421250                } 
    12431251 
    1244                 if (1 && ray->mOriginObject) 
     1252                if (COUNT_ORIGIN_OBJECTS && ray->mOriginObject) 
    12451253                { 
    12461254                        ray->mOriginObject->mVssRays.push_back(ray); 
     
    12981306 
    12991307float BvHierarchy::EvalRenderCost(const ObjectContainer &objects) const 
    1300 { 
    1301         if (mHierarchyManager->GetViewSpaceSubdivisionType() == HierarchyManager::NO_VIEWSPACE_SUBDIV) 
    1302         { 
     1308{        
     1309        if (mHierarchyManager->GetViewSpaceSubdivisionType() ==  
     1310                HierarchyManager::NO_VIEWSPACE_SUBDIV) 
     1311        { 
     1312                //////////////// 
     1313                //-- surface area heuristics 
     1314 
    13031315                if (objects.empty()) 
    13041316                        return 0.0f; 
    13051317 
    1306                 //////////////// 
    1307                 //-- surface area heuristics 
    1308  
    13091318                const AxisAlignedBox3 box = EvalBoundingBox(objects); 
    13101319                const float area = box.SurfaceArea(); 
    1311  
    1312                 return (float)objects.size() * area / mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 
     1320                const float viewSpaceArea = mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 
     1321 
     1322                return (float)objects.size() * area / viewSpaceArea; 
    13131323        } 
    13141324        else 
     
    17711781        if (mUseGlobalSorting) 
    17721782        { 
    1773                 CreateInitialSortedObjectList(oData); 
     1783                AssignInitialSortedObjectList(oData); 
    17741784        } 
    17751785         
     
    17931803 
    17941804 
    1795 void BvHierarchy::CreateInitialSortedObjectList(BvhTraversalData &tData) 
    1796 { 
    1797         SortableEntryContainer *sortedObjects = new SortableEntryContainer(); 
    1798  
     1805void BvHierarchy::AssignInitialSortedObjectList(BvhTraversalData &tData) 
     1806{ 
    17991807        // we sort the objects as a preprocess so they don't have 
    18001808        // to be sorted for each split 
    18011809        for (int i = 0; i < 3; ++ i) 
    18021810        { 
    1803                 CreateLocalSubdivisionCandidates(tData.mNode->mObjects, &sortedObjects, true, i); 
    1804                          
     1811                // create new objects 
     1812                if (!mSortedObjects[i]) 
     1813                { 
     1814                        mSortedObjects[i] = new SortableEntryContainer(); 
     1815                        CreateLocalSubdivisionCandidates(tData.mNode->mObjects, &mSortedObjects[i], true, i); 
     1816                } 
     1817 
     1818                // copy list into traversal data list 
    18051819                tData.mSortedObjects[i] = new ObjectContainer(); 
    1806                 tData.mSortedObjects[i]->reserve((int)sortedObjects->size()); 
    1807  
    1808                 SortableEntryContainer::const_iterator oit, oit_end = sortedObjects->end(); 
    1809                 for (oit = sortedObjects->begin(); oit != oit_end; ++ oit) 
     1820                tData.mSortedObjects[i]->reserve((int)mSortedObjects[i]->size()); 
     1821 
     1822                SortableEntryContainer::const_iterator oit, oit_end = mSortedObjects[i]->end(); 
     1823 
     1824                for (oit = mSortedObjects[i]->begin(); oit != oit_end; ++ oit) 
    18101825                { 
    18111826                        tData.mSortedObjects[i]->push_back((*oit).mObject); 
    18121827                } 
    18131828        } 
    1814  
    1815         delete sortedObjects; 
    18161829} 
    18171830 
     
    18851898        BvhTraversalData oData(bvhLeaf, 0, prop, nRays); 
    18861899 
     1900        AssignInitialSortedObjectList(oData); 
     1901         
     1902 
    18871903        /////////////////// 
    18881904        //-- add first candidate for object space partition      
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1576 r1580  
    1313#include "AxisAlignedBox3.h" 
    1414#include "IntersectableWrapper.h" 
     15 
    1516 
    1617 
     
    789790        float EvalViewCellsVolume(const ObjectContainer &objects) const; 
    790791 
    791         /** Creates initial list of sorted objects. 
    792         */ 
    793         void CreateInitialSortedObjectList(BvhTraversalData &tData); 
     792        /** Assigns or newly creates initial list of sorted objects. 
     793        */ 
     794        void AssignInitialSortedObjectList(BvhTraversalData &tData); 
    794795 
    795796        /** Assigns sorted objects to front and back data. 
     
    844845        //-- global termination criteria 
    845846 
     847        /// the minimal accepted global cost ratio 
    846848        float mTermMinGlobalCostRatio; 
     849        //// number of accepted misses of the global cost ratio 
    847850        int mTermGlobalCostMissTolerance; 
    848          
    849  
    850851        /// maximal number of view cells 
    851852        int mTermMaxLeaves; 
     
    882883        /// stores the kd node intersectables used for pvs 
    883884        BvhIntersectableMap mBvhIntersectables; 
    884  
     885        /// if the objects should be sorted in one global step 
    885886        bool mUseGlobalSorting; 
     887 
     888        SortableEntryContainer *mSortedObjects[3]; 
    886889}; 
    887890 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r1576 r1580  
    6767                // set flag for visualization 
    6868                newRay->mFlags |= VssRay::ReverseSample; 
    69                 cout << "here9444 " << (int) newRay->mFlags << " " << newRay << endl; 
     69                 
    7070                // ray is not pushed into the queue => can delete ray 
    7171                if (!HandleRay(newRay)) 
     
    8181bool GvsPreprocessor::HandleRay(VssRay *vssRay) 
    8282{ 
    83         cout << "x " << (int)vssRay->mFlags; 
    8483        const bool storeRaysForViz = true; 
    8584        mViewCellsManager->ComputeSampleContribution(*vssRay, true, storeRaysForViz); 
     
    8887        if (vssRay->mPvsContribution > 0) 
    8988        { 
     89                // add new ray to ray queue 
    9090                mRayQueue.push(vssRay); 
    9191 
     
    9696                        { 
    9797                                VssRay *nray = new VssRay(*vssRay); 
    98                                 nray->mFlags = vssRay->mFlags; 
    99                                 (*vit)->mVssRays.push_back(nray); 
    100 nray->mFlags = 10; 
    101                                 cout << "\nhere58 " << (int)nray->mFlags << "  " << (int)vssRay->mFlags << endl; 
     98                                (*vit)->mVssRays.push_back(nray);                                
    10299                        } 
    103100                } 
     
    205202                 
    206203                if (!newRay) return 0; 
    207 newRay->mFlags |= VssRay::BorderSample; 
     204 
     205                newRay->mFlags |= VssRay::BorderSample; 
     206 
     207                // add new ray to queue 
    208208                const bool enqueued = HandleRay(newRay); 
    209209                 
     
    267267        CastRays(simpleRays, vssRays, false, false); 
    268268 
     269        // set flags 
     270        VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 
     271        for (rit = vssRays.begin(); rit != rit_end; ++ rit) 
     272        {cout << "z"; 
     273                (*rit)->mFlags |= VssRay::BorderSample; 
     274                //(*rit)->mOriginObject = currentRay.mTerminationObject; 
     275        } 
    269276        // add to ray queue 
    270277        EnqueueRays(vssRays); 
     
    273280        int castRays = (int)vssRays.size(); 
    274281 
    275         VssRayContainer::const_iterator rit, rit_end = vssRays.end(); 
    276         for (rit = vssRays.begin(); rit != rit_end; ++ rit) 
    277         { 
    278                 (*rit)->mFlags |= VssRay::BorderSample; 
    279                 cout << "here390 " << (int) (*rit)->mFlags << endl; 
    280         } 
    281  
    282 #if 1 
     282 
     283#if 0 
    283284    // recursivly subdivide each edge 
    284285        for (int i = 0; i < n; ++ i) 
     
    347348{        
    348349        const long startTime = GetTime(); 
    349  
     350//cout << "here8"<<endl; 
    350351        // generate simple rays 
    351352        SimpleRayContainer simpleRays; 
     
    433434                /// construct the view cells from the scratch 
    434435                ConstructViewCells(); 
     436                // reset pvs already gathered during view cells construction 
     437                mViewCellsManager->ResetPvs(); 
    435438                cout << "finished view cell construction" << endl; 
    436439        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1577 r1580  
    5858        mVspTree->mHierarchyManager = this; 
    5959         
     60        mViewSpaceSubdivisionType = KD_BASED_VIEWSPACE_SUBDIV; 
    6061        ParseEnvironment(); 
    6162} 
     
    7273        mVspTree->mHierarchyManager = this; 
    7374 
     75        mViewSpaceSubdivisionType = KD_BASED_VIEWSPACE_SUBDIV; 
    7476        ParseEnvironment(); 
    7577} 
     
    7880void HierarchyManager::ParseEnvironment() 
    7981{ 
    80         char subdivisionStatsLog[100]; 
    81         Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats",  
    82                 subdivisionStatsLog); 
    83         mSubdivisionStats.open(subdivisionStatsLog); 
    84  
    8582        Environment::GetSingleton()->GetFloatValue( 
    8683                "Hierarchy.Termination.minGlobalCostRatio", mTermMinGlobalCostRatio); 
     
    109106                "Hierarchy.Construction.useMultiLevel", mUseMultiLevelConstruction); 
    110107 
    111          mUseMultiLevelConstruction; 
     108        Environment::GetSingleton()->GetIntValue( 
     109                "Hierarchy.Construction.levels", mNumMultiLevels); 
     110 
    112111        Debug << "******** Hierachy Manager Parameters ***********" << endl; 
    113112        Debug << "max leaves: " << mTermMaxLeaves << endl; 
     
    117116        Debug << "min depth for object space subdivision: " << mMinDepthForObjectSpaceSubdivion << endl; 
    118117        Debug << "repair queue: " << mRepairQueue << endl; 
     118        Debug << "number of multilevels: " << mNumMultiLevels << endl; 
    119119        Debug << endl; 
    120120} 
     
    198198 
    199199 
    200 void HierarchyManager::EvalSubdivisionStats(const SubdivisionCandidate &tData) 
    201 { 
    202         const float costDecr = tData.GetRenderCostDecrease(); 
    203 cout << "here44 " << mHierarchyStats.pvsEntries << endl; 
     200void HierarchyManager::EvalSubdivisionStats(const float renderCostDecr) 
     201{ 
     202        //cout << "pvs entries " << mHierarchyStats.pvsEntries << endl; 
    204203        AddSubdivisionStats(mHierarchyStats.Leaves(), 
    205                                                 costDecr, 
     204                                                renderCostDecr, 
    206205                                                mTotalCost, 
    207                                                 //mPvsEntries 
    208206                                                mHierarchyStats.pvsEntries 
    209207                                                ); 
     
    253251        else 
    254252        { 
     253                char subdivisionStatsLog[100]; 
     254                Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats",  
     255                subdivisionStatsLog); 
     256                mSubdivisionStats.open(subdivisionStatsLog); 
     257 
    255258                ConstructInterleaved(sampleRays, objects, forcedViewSpace); 
    256259        } 
     
    267270 
    268271        mTotalCost = (float)objects.size(); 
     272        EvalSubdivisionStats(0); 
    269273        Debug << "setting total cost to " << mTotalCost << endl; 
    270274 
     
    315319{ 
    316320        cout << "\nstarting view space hierarchy construction ... " << endl; 
    317          // hack: reset global cost misses 
     321        // hack: reset global cost misses 
    318322        mHierarchyStats.mGlobalCostMisses = 0; 
    319  
     323         
    320324        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
    321325        SubdivisionCandidate *vsc =  
     
    346350 
    347351void HierarchyManager::PrepareBvHierarchy(const VssRayContainer &sampleRays, 
    348                                                                                   const ObjectContainer &objects)  
    349  
     352                                                                                  const ObjectContainer &objects) 
    350353{ 
    351354        const long startTime = GetTime(); 
     
    387390 
    388391 
    389 bool HierarchyManager::ApplySubdivisionCandidate(SubdivisionCandidate *sc) 
     392bool HierarchyManager::ApplySubdivisionCandidate(SubdivisionCandidate *sc, const bool repairQueue) 
    390393{ 
    391394        const bool globalTerminationCriteriaMet = GlobalTerminationCriteriaMet(sc); 
     
    406409        } 
    407410 
    408         if (vspSplit) 
    409         { 
    410                 VspNode *n = mVspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
    411  
    412                 if (n->IsLeaf()) // local or global termination criteria failed 
    413                         return false; 
    414         } 
    415         else 
    416         { 
    417                 if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV) 
    418                 { 
    419                         KdNode *n = mOspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
    420                         // local or global termination criteria failed 
    421                         if (n->IsLeaf())  
    422                                 return false; 
    423                 } 
    424                 else if (mObjectSpaceSubdivisionType == BV_BASED_OBJ_SUBDIV) 
    425                 { 
    426                         BvhNode *n = mBvHierarchy->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
    427                         // local or global termination criteria failed 
    428                         if (n->IsLeaf()) 
    429                                 return false; 
    430                 } 
     411        bool success; 
     412        switch (sc->Type()) 
     413        { 
     414        case SubdivisionCandidate::VIEW_SPACE: 
     415                { 
     416                        VspNode *n = mVspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
     417                        success = !n->IsLeaf(); // local or global termination criteria failed? 
     418                } 
     419                break; 
     420        case SubdivisionCandidate::OBJECT_SPACE: 
     421                { 
     422                        if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV) 
     423                        { 
     424                                KdNode *n = mOspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
     425                                // local or global termination criteria failed 
     426                                success = !n->IsLeaf(); 
     427                        } 
     428                        else if (mObjectSpaceSubdivisionType == BV_BASED_OBJ_SUBDIV) 
     429                        { 
     430                                BvhNode *n = mBvHierarchy->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
     431                                // local or global termination criteria failed 
     432                                success = !n->IsLeaf();                                  
     433                        } 
     434                } 
     435                break; 
     436        default: 
     437                break; 
     438        } 
     439 
     440        cout << sc->Type() << " "; 
     441                 
     442        // update stats 
     443        mHierarchyStats.nodes += 2; 
     444         
     445        const int pvsEntries = sc->GetPvsEntriesIncr(); 
     446        mHierarchyStats.pvsEntries += pvsEntries; 
     447         
     448        //cout << "pvs entries: " << pvsEntries << " " << mHierarchyStats.pvsEntries << endl; 
     449        mHierarchyStats.memory += 0; // TODO 
     450         
     451        // subdivision successful 
     452        EvalSubdivisionStats(sc->GetRenderCostDecrease()); 
     453                 
     454        // reevaluate candidates affected by the split for view space splits,  
     455        // this would be object space splits and other way round 
     456        if (repairQueue)  
     457        {        
     458                RepairQueue(); 
    431459        } 
    432460 
     
    507535                //-- subdivide leaf node 
    508536 
    509                 if (ApplySubdivisionCandidate(mCurrentCandidate)) 
    510                 { 
    511                         cout << mCurrentCandidate->Type() << " "; 
    512                  
    513                         // update stats 
    514                         mHierarchyStats.nodes += 2; 
    515                         const int pvsEntries = mCurrentCandidate->GetPvsEntriesIncr(); 
    516                         mHierarchyStats.pvsEntries += pvsEntries; 
    517                         cout << "pvs entries: " << pvsEntries << " " << mHierarchyStats.pvsEntries << endl; 
    518                         mHierarchyStats.memory += 0; // TODO 
    519                         // subdivision successful 
    520                         EvalSubdivisionStats(*mCurrentCandidate); 
    521                  
    522                         // reevaluate candidates affected by the split for view space splits,  
    523                         // this would be object space splits and other way round 
    524                         if (repairQueue)  
    525                         {        
    526                                 RepairQueue(); 
    527                         } 
    528                 } 
    529  
     537                ApplySubdivisionCandidate(mCurrentCandidate, repairQueue); 
     538                                 
    530539                // we use objects for evaluating vsp tree construction until  
    531540                // a certain depth once a certain depth existiert ... 
     
    569578{ 
    570579        int i = 0; 
     580        // main loop 
    571581        while (!FinishedConstruction()) 
    572582        { 
    573583                mCurrentCandidate = NextSubdivisionCandidate();     
    574584                         
    575                 /////////////////// 
     585                /////// 
    576586                //-- subdivide leaf node 
    577587 
    578                 if (ApplySubdivisionCandidate(mCurrentCandidate)) 
    579                 { 
    580                         cout << mCurrentCandidate->Type() << " "; 
    581                         if (0) cout << "subdividing candidate " << ++ i << " of type "  
    582                                                 << mCurrentCandidate->Type() << endl; 
    583                         mHierarchyStats.nodes += 2; 
    584  
    585                         // subdivision successful 
    586                         EvalSubdivisionStats(*mCurrentCandidate); 
    587                  
    588                         // reevaluate candidates affected by the split for view space splits,  
    589                         // this would be object space splits and other way round 
    590                         if (repairQueue)  
    591                         { 
    592                                 RepairQueue(); 
    593                         } 
    594                 } 
    595  
     588                ApplySubdivisionCandidate(mCurrentCandidate, repairQueue); 
    596589                DEL_PTR(mCurrentCandidate); 
    597590        } 
     
    601594void HierarchyManager::ResetObjectSpaceSubdivision(const VssRayContainer &sampleRays,  
    602595                                                                                                   const ObjectContainer &objects) 
    603 { 
     596{        
    604597#if 0    
    605598                DEL_PTR(mBvHierarchy); 
     
    609602                PrepareObjectSpaceSubdivision(sampleRays, objects); 
    610603                return; 
    611 #endif 
    612  
     604#else 
     605         
     606        // no object space subdivision yet 
    613607        if (!ObjectSpaceSubdivisionConstructed()) 
    614608        { 
     
    616610        } 
    617611 
     612        // object space partition constructed => reconstruct 
    618613        switch (mObjectSpaceSubdivisionType) 
    619614        { 
    620615        case BV_BASED_OBJ_SUBDIV: 
    621                 cout << "\nreseting bv hierarchy" << endl; 
    622         Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl; 
    623          
    624                 mHierarchyStats.nodes -= mBvHierarchy->mBvhStats.nodes; 
    625                 mTQueue.Push(mBvHierarchy->Reset(sampleRays, objects)); 
    626                 mTotalCost = mBvHierarchy->mTotalCost; 
     616                { 
     617                        cout << "\nreseting bv hierarchy" << endl; 
     618                        Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl; 
     619         
     620                        SubdivisionCandidate *firstCandidate =  
     621                                mBvHierarchy->Reset(sampleRays, objects); 
     622 
     623                        mTQueue.Push(firstCandidate); 
     624                        mTotalCost = mBvHierarchy->mTotalCost; 
     625 
     626                        mHierarchyStats.nodes = 2; 
     627                        mHierarchyStats.pvsEntries = 0; 
     628                        EvalSubdivisionStats(0); 
     629                } 
    627630                break; 
    628631 
     
    633636                break; 
    634637        } 
     638#endif 
    635639} 
    636640 
     
    639643                                                                                                 const ObjectContainer &objects) 
    640644{ 
    641         DEL_PTR(mBvHierarchy); 
    642         mBvHierarchy = new BvHierarchy(); 
    643         mBvHierarchy->mHierarchyManager = this; 
     645        ViewCellsManager *vc = mVspTree->mViewCellsManager; 
     646 
     647        DEL_PTR(mVspTree); 
     648        mVspTree = new VspTree(); 
     649        mVspTree->mHierarchyManager = this; 
     650        mVspTree->mViewCellsManager = vc; 
    644651 
    645652        PrepareViewSpaceSubdivision(sampleRays, objects); 
    646         return; 
     653         
     654        mHierarchyStats.nodes = 2; 
     655        mHierarchyStats.pvsEntries = 0; 
     656        EvalSubdivisionStats(0); 
     657 
    647658} 
    648659 
     
    665676        mVspTree->ComputeBoundingBox(sampleRays, forcedViewSpace); 
    666677 
    667         // use sah for evaluating object space construction for the first run 
     678        // use sah for evaluating osp tree construction  
     679        // in the first iteration of the subdivision 
     680         
    668681        mSavedViewSpaceSubdivisionType = mViewSpaceSubdivisionType; 
    669682        mViewSpaceSubdivisionType = NO_VIEWSPACE_SUBDIV; 
    670          
    671         const int limit = 4; 
     683 
     684        mSavedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType; 
     685        //mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV; 
     686 
     687        const int limit = mNumMultiLevels; 
    672688        int i = 0; 
    673689 
     
    678694        while (1) 
    679695        { 
    680         // first run object space subdivision 
     696                char subdivisionStatsLog[100]; 
     697                sprintf(subdivisionStatsLog, "tests/i3d/subdivision-%04d.log", i); 
     698                mSubdivisionStats.open(subdivisionStatsLog); 
     699 
     700                // fsubdivide object space first 
    681701                ResetObjectSpaceSubdivision(sampleRays, objects); 
    682  
    683702                // process object space candidates 
    684703                RunConstruction(false); 
    685704 
    686                 if ((++ i) >= limit) 
     705                // object space subdivision constructed 
     706                mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
     707 
     708                cout << "iteration " << i << " of " << limit << " finished" << endl; 
     709 
     710                mSubdivisionStats.close(); 
     711                if ((i ++) >= limit) 
    687712                        break; 
    688713 
     714                sprintf(subdivisionStatsLog, "tests/i3d/subdivision-%04d.log", i); 
     715                mSubdivisionStats.open(subdivisionStatsLog); 
     716 
    689717                ///////////////// 
    690                 // do view space subdivison with respect to the object space partition 
     718                // subdivide view space with respect to the objects 
     719 
    691720                ResetViewSpaceSubdivision(sampleRays, objects); 
    692  
    693721                // process view space candidates 
    694722                RunConstruction(false); 
     723                // view space subdivision constructed 
    695724                mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 
    696                  
    697                 if ((++ i) >= limit) 
     725         
     726                cout << "iteration " << i << " of " << limit << " finished" << endl; 
     727 
     728                mSubdivisionStats.close(); 
     729 
     730                if ((i ++) >= limit) 
    698731                        break; 
    699  
    700                 cout << "iteration " << i << " of " << limit << " finished" << endl; 
    701732        } 
    702733         
     
    729760                return mBvHierarchy && mBvHierarchy->GetRoot(); 
    730761        default: 
    731         return false; 
     762                return false; 
    732763        } 
    733764} 
     
    808839 
    809840        // collect list of "dirty" candidates 
    810         long startTime = GetTime(); 
     841        const long startTime = GetTime(); 
    811842    
    812843        vector<SubdivisionCandidate *> dirtyList; 
     
    827858                sc->EvalPriority(); // reevaluate 
    828859                 
    829                 /* 
     860#ifdef _DEBUG 
    830861                Debug << "candidate " << sc << " reevaluated\n"  
    831862                          << "render cost decrease diff " <<  rcd - sc->GetRenderCostDecrease() 
    832                           << " old: " << rcd << " new " << sc->GetRenderCostDecrease() << endl;*/ 
    833                 if (0) 
    834                 { 
    835                         const float rcDiff =  rcd - sc->GetRenderCostDecrease(); 
    836                         mTotalCost += rcDiff; 
    837                 } 
     863                          << " old: " << rcd << " new " << sc->GetRenderCostDecrease() << endl; 
     864#endif   
    838865                mTQueue.Push(sc); // reinsert 
     866                cout << "."; 
    839867        } 
    840868 
    841869        long endTime = GetTime(); 
    842870        Real timeDiff = TimeDiff(startTime, endTime); 
    843  
    844871        mHierarchyStats.repairTime += timeDiff; 
    845872 
    846         if (0) cout << "finished in " << timeDiff * 1e-3f << " secs" << endl; 
     873        if (1) cout << "repaired in " << timeDiff * 1e-3f << " secs" << endl; 
    847874} 
    848875 
     
    864891        SubdivisionCandidateContainer::const_iterator sit, sit_end = mCandidateBuffer.end(); 
    865892    for (sit = mCandidateBuffer.begin(); sit != sit_end; ++ sit) 
    866         {cout << ":"; 
     893        { 
    867894                mTQueue.Push(*sit); 
    868895        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1576 r1580  
    245245        void RunConstruction(const bool repairQueue); 
    246246                 
    247         bool ApplySubdivisionCandidate(SubdivisionCandidate *sc); 
     247        /** Evaluates the subdivision candidate and executes the split. 
     248        */ 
     249        bool ApplySubdivisionCandidate(SubdivisionCandidate *sc, const bool repairQueue); 
    248250 
    249251        bool FinishedConstruction() const; 
     
    251253        SubdivisionCandidate *NextSubdivisionCandidate(); 
    252254 
     255        /** Repairs the dirty entries of the candidate queue. 
     256        */ 
    253257        void RepairQueue(); 
    254258 
     259        /** Collect the list of dirty candidates after the current subdivision candidate 
     260                split. 
     261        */ 
    255262        void CollectDirtyCandidates(vector<SubdivisionCandidate *> &dirtyList); 
    256263 
    257         void EvalSubdivisionStats(const SubdivisionCandidate &tData); 
     264        /** Evaluate subdivision stats for log. 
     265        */ 
     266        void EvalSubdivisionStats(const float renderCostDecr); 
    258267 
    259268        void AddSubdivisionStats( 
     
    328337 
    329338        enum {SEQUENTIAL, INTERLEAVED}; 
    330          
     339        /// type of hierarchy construction 
     340        int mConstructionType; 
     341 
     342        /// Type of object space partition 
    331343        int mObjectSpaceSubdivisionType; 
     344        /// Type of view space partition 
    332345    int mViewSpaceSubdivisionType; 
    333346 
    334         /// the original osp type 
     347        //////////// 
     348        //-- helper variables 
     349         
     350        // the original osp type 
    335351        int mSavedObjectSpaceSubdivisionType; 
     352        // the original vsp type 
    336353        int mSavedViewSpaceSubdivisionType; 
    337  
    338         int mConstructionType; 
    339  
     354        /// the current subdivision candidate 
     355        SubdivisionCandidate *mCurrentCandidate; 
     356 
     357        /////////////////// 
     358 
     359 
     360        /////////////////// 
     361        // Hierarchies 
     362 
     363        /// view space hierarchy 
    340364        VspTree *mVspTree; 
     365        /// object space partition kd tree 
    341366        OspTree *mOspTree; 
     367        /// bounding volume hierarchy 
    342368        BvHierarchy *mBvHierarchy; 
    343369 
    344         AxisAlignedBox3 mBoundingBox; 
    345  
     370        ////////////////////// 
     371         
     372 
     373        /// the traversal queue 
    346374        SplitQueue mTQueue; 
    347  
    348         SubdivisionCandidate *mCurrentCandidate; 
    349  
    350         //////// 
     375         
     376 
     377        ////////// 
    351378        //-- global termination criteria 
    352379 
     380        /// the mininal acceptable cost ratio for a split 
    353381        float mTermMinGlobalCostRatio; 
     382        /// the threshold for global cost miss tolerance 
    354383        int mTermGlobalCostMissTolerance; 
    355          
     384        /// maximum number of leaves 
     385        int mTermMaxLeaves; 
     386 
    356387        //////////////////// 
    357388 
    358389        /// keeps track of cost during subdivision 
    359390        float mTotalCost; 
    360  
    361         int mTotalPvsEntries; 
     391        /// statistics about the hierarchy 
    362392        HierarchyStatistics mHierarchyStats; 
    363393 
    364394        int mMinDepthForObjectSpaceSubdivion; 
    365395        int mMinDepthForViewSpaceSubdivion; 
    366  
    367         int mTermMaxLeaves; 
     396         
    368397        ofstream mSubdivisionStats; 
    369398 
     399        /// if the queue should be repaired after a subdivision steps 
    370400        bool mRepairQueue; 
    371401 
    372402        bool mStartWithObjectSpace; 
    373  
     403        /** if multi level construction method should be used 
     404                where we iterate over both hierarchies until we 
     405                converge to the optimum. 
     406        */ 
    374407        bool mUseMultiLevelConstruction; 
     408        /// number of iteration steps for multilevel approach    
     409        int mNumMultiLevels; 
    375410}; 
    376411 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1576 r1580  
    3535// HACK 
    3636const static bool SAMPLE_AFTER_SUBDIVISION = true; 
    37 const static bool CLAMP_TO_BOX = false; 
     37const static bool CLAMP_TO_BOX = true; 
    3838 
    3939template <typename T> class myless 
     
    814814        // potentially visible objects 
    815815        return vc->AddPvsSample(obj, pdf, contribution); 
     816} 
     817 
     818 
     819void ViewCellsManager::ResetPvs() 
     820{ 
     821        if (ViewCellsTreeConstructed()) 
     822        { 
     823                mViewCellsTree->ResetPvs(); 
     824        } 
     825        else 
     826        { 
     827                cout << "view cells tree not constructed" << endl; 
     828        } 
    816829} 
    817830 
     
    18411854 
    18421855                        if (ray.mTerminationObject)  
    1843                         { 
     1856                        {                        
    18441857                                if (viewcell->GetPvs().GetSampleContribution( 
    18451858                                                        ray.mTerminationObject, 
     
    29322945                                if (p < raysOut) 
    29332946                                { 
    2934                                         cout << "here42 " << (int)(*rit)->mFlags << endl; 
    29352947                                        if ((*rit)->mFlags & VssRay::BorderSample) 
     2948                                        { 
    29362949                                                vcRays.push_back(*rit); 
     2950                                        } 
    29372951                                        else if ((*rit)->mFlags & VssRay::ReverseSample) 
    29382952                                                vcRays2.push_back(*rit); 
     
    53095323        stream << "<VisibilitySolution>" << endl; 
    53105324 
    5311  
    5312         /////////////// 
    5313         //-- export bounding boxes 
    5314         //-- The bounding boxes are used to identify  
    5315         //-- the objects in the rendering engine 
    5316  
    5317         stream << "<BoundingBoxes>" << endl; 
    5318         ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    5319  
    5320         for (oit = objects.begin(); oit != oit_end; ++ oit) 
    5321         { 
     5325        if (exportPvs)  
     5326        { 
     5327        /////////////// 
     5328                //-- export bounding boxes 
     5329                //-- The bounding boxes are used to identify  
     5330                //-- the objects in the rendering engine 
     5331 
     5332                stream << "<BoundingBoxes>" << endl; 
     5333                ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     5334         
     5335                for (oit = objects.begin(); oit != oit_end; ++ oit) 
     5336                { 
    53225337                        const AxisAlignedBox3 box = (*oit)->GetBox(); 
    53235338                        stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 
    5324                                    << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
    5325                                    << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
    5326         } 
    5327         stream << "</BoundingBoxes>" << endl; 
    5328  
     5339                                << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
     5340                                 
     5341                                << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
     5342                } 
     5343                 
     5344                stream << "</BoundingBoxes>" << endl; 
     5345        } 
    53295346 
    53305347        ////////////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1576 r1580  
    517517                @param exportPvs if the pvs should also be exported 
    518518                @param exportRays if sample rays should be exported as well 
     519                @param maxRays maximum number of rays to export 
     520                @param prefix the prefix for the output file 
    519521                @param visRays additional rays 
    520522        */ 
     
    530532                VssRayContainer *visRays = NULL) = NULL; 
    531533 
     534         
     535        void ViewCellsManager::ResetPvs(); 
     536 
     537 
    532538protected: 
    533539 
     
    577583        void EvaluateViewCellsStats(); 
    578584 
    579  
     585         
    580586        /////////////////////// 
    581587        //-- helper functions for view cell visualization 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r1577 r1580  
    2626#define COUNT_ORIGIN_OBJECTS 1 
    2727 
    28 /////////// 
     28 
     29////////////// 
    2930//-- static members 
    3031 
     
    383384 
    384385        cout << "Extracting polygons from rays ... "; 
    385  
    386                 long startTime = GetTime(); 
     386                const long startTime = GetTime(); 
    387387 
    388388        VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     
    422422                                                { 
    423423                                                        // TODO 
    424                                                         cout << "here5" << endl; 
     424                                                        cout << "not implemented yet" << endl; 
    425425                                                } 
    426426                                        default: 
     
    13841384        SortSubdivisionCandidates(usedRays, axis, minBand, maxBand); 
    13851385 
     1386        ////////////////// 
    13861387        // go through the lists, count the number of objects left and right 
    13871388        // and evaluate the following cost funcion: 
     
    13961397        float sum = (float)pvsSize * sizeBox; 
    13971398        float minSum = 1e20f; 
    1398  
    13991399         
    14001400        // if no border can be found, take mid split 
     
    14061406 
    14071407        Intersectable::NewMail(); 
    1408  
    14091408        RayInfoContainer::const_iterator ri, ri_end = usedRays.end(); 
    14101409 
     
    14431442 
    14441443        Intersectable::NewMail(); 
    1445  
    14461444        vector<SortableEntry>::const_iterator ci, ci_end = mLocalSubdivisionCandidates->end(); 
    14471445 
     
    14541452                Intersectable *tObject = ray->mTerminationObject; 
    14551453                 
    1456  
    14571454                switch ((*ci).type) 
    14581455                { 
     
    21152112                AddObjToPvs(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 
    21162113 
    2117                 if (COUNT_ORIGIN_OBJECTS)  
     2114                if (COUNT_ORIGIN_OBJECTS) 
     2115                { 
    21182116                        AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 
     2117                } 
    21192118        } 
    21202119 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1577 r1580  
    829829         
    830830        AxisAlignedPlane candidatePlane = splitCandidate.mSplitPlane; 
    831         RayInfoContainer::const_iterator rit,  
    832                 rit_end = splitCandidate.mParentData.mRays->end(); 
    833  
    834         // this is the main ray classification loop! 
     831         
     832        Intersectable::NewMail(3); 
     833        KdLeaf::NewMail(3); 
     834        BvhLeaf::NewMail(3); 
     835 
     836        RayInfoContainer::const_iterator rit, rit_end = splitCandidate.mParentData.mRays->end(); 
     837 
     838    // this is the main ray classification loop! 
    835839        for(rit = splitCandidate.mParentData.mRays->begin(); rit != rit_end; ++ rit) 
    836840        { 
     
    849853#endif 
    850854        } 
    851          
     855        //cout << "pvs entries: " << fPvsSize << " " << bPvsSize << " " << oldPvsSize << endl; 
     856 
    852857        return (int)(fPvsSize + bPvsSize - oldPvsSize); 
    853858} 
     
    14951500                                                                                  candidatePlane.mPosition, t); 
    14961501 
    1497                 // evaluate contribution of ray endpoint to front and back pvs 
    1498                 // with respect to the classification 
     1502                // evaluate contribution of ray endpoint to front  
     1503                // and back pvs with respect to the classification 
    14991504                UpdateContributionsToPvs(*ray, true, cf, pvsFront, pvsBack, totalPvs);   
    15001505#if COUNT_ORIGIN_OBJECTS 
     
    16571662        if (!leaf) return; 
    16581663        const int renderCost = countEntries ? 1 : (int)leaf->mObjects.size(); 
    1659  
     1664         
    16601665        // leaf in no pvs => new 
    16611666        if (!leaf->Mailed() && !leaf->Mailed(1) && !leaf->Mailed(2)) 
     
    31243129                { 
    31253130                        BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
    3126                         UpdateContributionsToPvs(leaf, cf, pvsFront, pvsBack, totalPvs, true);           
     3131                        UpdateContributionsToPvs(leaf, cf, pvsFront, pvsBack, totalPvs, true); 
    31273132                        break; 
    31283133                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp

    r1528 r1580  
    7373        mFlags = 0; 
    7474        Vector3 dir = GetDir(); 
    75  
     75//mFlags |= BorderSample; 
    7676#define BIDIRECTIONAL_RAY 0 
    7777#if BIDIRECTIONAL_RAY 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1579 r1580  
    129129        char internKdTree[100]; 
    130130        Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree); 
     131        //string internKdTree = ReplaceSuffic(filename, ".x3d", ".kd"); 
    131132 
    132133        //-- initialize external ray casters 
Note: See TracChangeset for help on using the changeset viewer.