Changeset 1174


Ignore:
Timestamp:
07/31/06 18:27:06 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
6 edited

Legend:

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

    r1161 r1174  
    23202320 
    23212321 
     2322        RegisterOption("Hierarchy.subdivisionStats", 
     2323                                        optString, 
     2324                                        "hierarchy_subdivision_stats=", 
     2325                                        "hierarchySubdivisionStats.log"); 
     2326 
    23222327        ////////////////////////////////////////////////////////////////////////////////// 
    23232328} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1166 r1174  
    2828  KdPvs mKdPvs; 
    2929   
     30  /// view cell based pvs per object 
    3031  ViewCellPvs mViewCellPvs; 
    3132 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1145 r1174  
    444444                mVspTree = new VspTree(); 
    445445                mOspTree = new OspTree(); 
    446                 // HACK 
    447                 //mOspTree = new OspTree(*mKdTree); 
     446                 
     447                // HACK for testing if per kd evaluation works!! 
     448                mOspTree = new OspTree(*mKdTree); 
    448449 
    449450                mViewCellsManager = new VspOspViewCellsManager(mVspTree, mOspTree); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1168 r1174  
    11301130struct SortableViewCellEntry { 
    11311131 
    1132   SortableViewCellEntry() {} 
    1133   SortableViewCellEntry(const float v, ViewCell *cell):mValue(v), mViewCell(cell) {} 
    1134    
    1135   float mValue; 
    1136   ViewCell *mViewCell; 
    1137  
    1138   friend bool operator<(const SortableViewCellEntry &a, const SortableViewCellEntry &b) { 
    1139         return a.mValue < b.mValue; 
    1140   } 
     1132        SortableViewCellEntry() {} 
     1133        SortableViewCellEntry(const float v, ViewCell *cell):mValue(v), mViewCell(cell) {} 
     1134 
     1135        float mValue; 
     1136        ViewCell *mViewCell; 
     1137 
     1138        friend bool operator<(const SortableViewCellEntry &a, const SortableViewCellEntry &b) { 
     1139                return a.mValue < b.mValue; 
     1140        } 
    11411141}; 
    11421142 
    1143 ViewCell * 
    1144 ViewCellsManager::ConstructLocalMergeTree2(ViewCell *currentViewCell,  
    1145                                                                                    const ViewCellContainer &viewCells) 
     1143 
     1144ViewCell * ViewCellsManager::ConstructLocalMergeTree2(ViewCell *currentViewCell,  
     1145                                                                                                          const ViewCellContainer &viewCells) 
    11461146{ 
    11471147   
     
    25422542} 
    25432543 
     2544 
     2545 
     2546 
    25442547/*******************************************************************/ 
    25452548/*               BspViewCellsManager implementation                */ 
     
    48854888        if (!mOspTree->GetRoot()) 
    48864889        { 
    4887                 cout << "constructing vsp and osp tree" << endl; 
     4890                Debug << "constructing vsp and osp tree" << endl; 
    48884891                //mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 
    48894892                mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox); 
     
    48914894        else // just build view space partition tree 
    48924895        { 
    4893                 cout << "constructing only vsp tree" << endl; 
     4896                Debug << "constructing only vsp tree" << endl; 
    48944897                mHierarchyManager->Construct3(constructionRays, objects, &mViewSpaceBox); 
    48954898        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1168 r1174  
    637637 
    638638 
    639 void VspTree::EvalSubdivisionStats(const VspTraversalData &tData, 
    640                                                                    const VspTraversalData &tFrontData, 
    641                                                                    const VspTraversalData &tBackData 
    642                                                                    ) 
    643 { 
    644         const float cFront = (float)tFrontData.mPvs * tFrontData.mProbability; 
    645         const float cBack = (float)tBackData.mPvs * tBackData.mProbability; 
    646         const float cData = (float)tData.mPvs * tData.mProbability; 
    647          
    648         const float costDecr =  
    649                 (cFront + cBack - cData) / mBoundingBox.GetVolume(); 
    650  
    651         mTotalCost += costDecr; 
    652         mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 
    653  
     639void VspTree::EvalSubdivisionStats(const SplitCandidate &sc) 
     640{ 
     641        const float costDecr = sc.GetRenderCostDecrease(); 
     642         
    654643        AddSubdivisionStats(mVspStats.Leaves(), 
    655644                                                -costDecr, 
     
    663652                                                        const bool globalCriteriaMet) 
    664653{ 
    665         // doto remove dynamic cast 
     654        // todo remove dynamic cast 
    666655        VspSplitCandidate *sc = dynamic_cast<VspSplitCandidate *>(splitCandidate); 
    667656        VspTraversalData &tData = sc->mParentData; 
    668657 
    669658        VspNode *newNode = tData.mNode; 
     659 
    670660 
    671661        if (!LocalTerminationCriteriaMet(tData) && !globalCriteriaMet) 
     
    687677                tBackData.mMaxCostMisses = maxCostMisses; 
    688678                         
    689          
    690                 if (1) //-- subdivision statistics 
    691                         EvalSubdivisionStats(tData, tFrontData, tBackData); 
     679                mTotalCost -= sc->GetRenderCostDecrease(); 
     680                mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 
     681 
     682                // subdivision statistics 
     683                if (1) EvalSubdivisionStats(*sc); 
    692684                 
    693685                //-- evaluate new split candidates for global greedy cost heuristics 
     
    882874        CreateViewCell(backData, false); 
    883875 
    884          
     876 
     877#if WORK_WITH_VIEWCELL_PVS 
    885878        // create front and back view cell 
    886879        // add front and back view cell to "Potentially Visbilie View Cells"  
    887880        // of the objects in front and back pvs 
    888881 
    889         //AddViewCellReferences(frontLeaf->GetViewCell()); 
    890         //AddViewCellReferences(backLeaf->GetViewCell()); 
     882        AddViewCellReferences(frontLeaf->GetViewCell()); 
     883        AddViewCellReferences(backLeaf->GetViewCell()); 
     884#endif 
    891885 
    892886        interior->mTimeStamp = mTimeStamp ++; 
     
    28232817{ 
    28242818        ReadEnvironment(); 
    2825  
    28262819        mSplitCandidates = new vector<SortableEntry>; 
    28272820} 
     
    29942987                 
    29952988        // TODO matt: compute pvs 
    2996         frontData.mPvs = 999; // ComputePvsSize(*frontData.mRays); 
    2997         backData.mPvs = 999; //ComputePvsSize(*backData.mRays); 
     2989        frontData.mPvs = 999999; // ComputePvsSize(*frontData.mRays); 
     2990        backData.mPvs = 9999999; //ComputePvsSize(*backData.mRays); 
    29982991 
    29992992        frontData.mProbability = frontData.mBoundingBox.GetVolume(); 
     
    30893082                const int maxCostMisses = sc->mMaxCostMisses; 
    30903083 
    3091                 // how often was max cost ratio missed in this branch? 
     3084        // how often was max cost ratio missed in this branch? 
    30923085                tFrontData.mMaxCostMisses = maxCostMisses; 
    30933086                tBackData.mMaxCostMisses = maxCostMisses; 
    3094                          
     3087                 
     3088                mTotalCost -= sc->GetRenderCostDecrease(); 
     3089 
     3090                // subdivision statistics 
     3091                if (1) EvalSubdivisionStats(*sc); 
     3092 
    30953093                //-- push the new split candidates on the queue 
     3094                 
    30963095                OspSplitCandidate *frontCandidate = new OspSplitCandidate(tFrontData); 
    30973096                OspSplitCandidate *backCandidate = new OspSplitCandidate(tBackData); 
     
    32313230{ 
    32323231        RayInfoContainer usedRays; 
    3233 int mMaxTests = 5000; 
     3232int mMaxTests = 5000; // HACK 
    32343233        if (mMaxTests < (int)tData.mRays->size()) 
    32353234        { 
     
    33843383                  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 
    33853384                  << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl; 
     3385 
     3386        if (oldRenderCost < newRenderCost) 
     3387                Debug << "\nwarning!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 
     3388         
    33863389 
    33873390        return ratio; 
     
    37473750 
    37483751 
    3749 #if TODO 
    3750 void OspTree::EvalSubdivisionStats(const VspTraversalData &tData, 
    3751                                                                    const VspTraversalData &tFrontData, 
    3752                                                                    const VspTraversalData &tBackData 
    3753                                                                    ) 
    3754 { 
    3755         const float cFront = (float)tFrontData.mPvs * tFrontData.mProbability; 
    3756         const float cBack = (float)tBackData.mPvs * tBackData.mProbability; 
    3757         const float cData = (float)tData.mPvs * tData.mProbability; 
    3758          
    3759         const float costDecr =  
    3760                 (cFront + cBack - cData) / mBoundingBox.GetVolume(); 
    3761  
    3762         mTotalCost += costDecr; 
    3763         mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 
    3764  
    3765         AddSubdivisionStats(mVspStats.Leaves(), 
    3766                                                 -costDecr, 
    3767                                                 sc->GetPriority(), 
    3768                                                 mTotalCost, 
    3769                                                 (float)mTotalPvsSize / (float)mVspStats.Leaves()); 
    3770 } 
    3771 #endif 
     3752void OspTree::EvalSubdivisionStats(const SplitCandidate &sc) 
     3753{ 
     3754        const float costDecr = sc.GetRenderCostDecrease(); 
     3755        Debug << "**********************$$$$$$$$$$$$$$"<< endl; 
     3756Debug << "here78 " << mOspStats.Leaves() << " " << mTotalCost << endl; 
     3757        AddSubdivisionStats(mOspStats.Leaves(), 
     3758                                                costDecr, 
     3759                                                mTotalCost 
     3760                                                ); 
     3761} 
     3762 
     3763 
     3764 
     3765void OspTree::AddSubdivisionStats(const int leaves, 
     3766                                                                  const float renderCostDecr, 
     3767                                                                  const float totalRenderCost) 
     3768                                                                  //const float avgRenderCost) 
     3769{Debug << "here64 " << totalRenderCost << " " << renderCostDecr << endl; 
     3770        mSubdivisionStats  
     3771                        << "#Leaves\n" << leaves << endl 
     3772                        << "#RenderCostDecrease\n" << renderCostDecr << endl  
     3773                        << "#TotalRenderCost\n" << totalRenderCost << endl; 
     3774                        //<< "#AvgRenderCost\n" << avgRenderCost << endl; 
     3775} 
    37723776 
    37733777 
     
    38093813        float pvsFront = 0; 
    38103814        float pvsBack = 0; 
    3811         float totalPvs = 0; 
    38123815 
    38133816        // probability that view point lies in back / front node 
     
    38233826 
    38243827        KdLeaf *leaf = tData.mNode; 
     3828        int totalPvs = (int)leaf->mObjects.size(); 
     3829 
    38253830        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    38263831 
     
    38293834        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
    38303835        { 
     3836                int pvsContri = 0; 
     3837 
    38313838                Intersectable *obj = *oit; 
    38323839                const AxisAlignedBox3 box = obj->GetBox(); 
    3833                  
    3834                 ++ totalPvs; 
    38353840 
    38363841                //cout << "totalpvs " << totalPvs << endl; 
    38373842 
    38383843                // test if box falls in left / right child node 
    3839                 if (box.Max(candidatePlane.mAxis) > candidatePlane.mPosition) 
     3844                if (box.Max(candidatePlane.mAxis) >= candidatePlane.mPosition) 
    38403845                { 
    38413846                        ++ pvsFront; 
    38423847                } 
     3848 
    38433849                if (box.Min(candidatePlane.mAxis) < candidatePlane.mPosition) 
    38443850                { 
     
    38463852                } 
    38473853        } 
    3848  
    38493854 
    38503855        // sum up volume seen from the objects of left and right children 
     
    38893894        const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 
    38903895 
    3891         Debug << "\n==== eval render cost decrease ===" << endl 
     3896        Debug << "\n==== eval render cost decrease ====" << endl 
    38923897                  << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl  
    38933898                  << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl 
     
    38963901 
    38973902        normalizedOldRenderCost = oldRenderCost / viewSpaceVol; 
     3903 
     3904        if (oldRenderCost < newRenderCost) 
     3905                Debug << "\nwarning2!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 
     3906        else 
     3907                Debug << "here4" << endl; 
     3908 
     3909        if (pBack + pFront < pOverall * 0.9) 
     3910                Debug << "\nwarning3!!:\n" << "p new: " << pBack + pFront << " p old: " << pOverall << endl; 
     3911        else 
     3912                Debug << "here55" << endl; 
     3913 
     3914        if (pvsBack + pvsFront < totalPvs) 
     3915                Debug << "\nwarning4!!:\n" << "pvs new: " << pvsBack + pvsFront << " pvs old: " << totalPvs << endl; 
     3916        else 
     3917                Debug << "here25" << endl; 
    38983918 
    38993919        return renderCostDecrease; 
     
    42904310        mVspTree.mOspTree = &ospTree; 
    42914311        mOspTree.mVspTree = &vspTree; 
     4312 
     4313        char subdivisionStatsLog[100]; 
     4314        Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats", subdivisionStatsLog); 
     4315        mSubdivisionStats.open(subdivisionStatsLog); 
    42924316} 
    42934317 
     
    43454369                                                                        mVspTree.mBoundingBox); 
    43464370 
    4347  
     4371#if WORK_WITH_VIEWCELL_PVS 
     4372         
    43484373        // create first view cell 
    43494374        mVspTree.CreateViewCell(vData, false); 
     
    43594384                obj->mViewCellPvs.AddSample(leaf->GetViewCell(), 1); 
    43604385        } 
     4386#endif 
    43614387 
    43624388        // compute first split candidate 
     
    43654391    mVspTree.EvalSplitCandidate(*splitCandidate); 
    43664392 
     4393        mVspTree.mTotalCost = (float)pvsSize; 
     4394        mVspTree.EvalSubdivisionStats(*splitCandidate); 
     4395 
    43674396        return splitCandidate; 
    43684397} 
     
    43704399 
    43714400OspTree::OspSplitCandidate * HierarchyManager::PrepareOsp(const VssRayContainer &sampleRays, 
    4372                                                                                           const ObjectContainer &objects, 
    4373                                                                                           AxisAlignedBox3 *forcedObjectSpace, 
    4374                                                                                           RayInfoContainer &rays) 
     4401                                                                                                                  const ObjectContainer &objects, 
     4402                                                                                                                  AxisAlignedBox3 *forcedObjectSpace, 
     4403                                                                                                                  RayInfoContainer &rays) 
    43754404{ 
    43764405        // store pointer to this tree 
     
    44104439                new OspTree::OspSplitCandidate(oData); 
    44114440 
    4412     mOspTree.EvalSplitCandidate(*oSplitCandidate); 
     4441        mOspTree.EvalSplitCandidate(*oSplitCandidate); 
     4442 
     4443        mOspTree.mTotalCost = (float)objects.size(); 
     4444        Debug << "total cost here553: " << mOspTree.mTotalCost << endl; 
     4445        mOspTree.EvalSubdivisionStats(*oSplitCandidate); 
    44134446 
    44144447        return oSplitCandidate; 
     
    44334466 
    44344467 
     4468void HierarchyManager::EvalSubdivisionStats(const SplitCandidate &tData) 
     4469{ 
     4470        const float costDecr = tData.GetRenderCostDecrease(); 
     4471 
     4472        //mTotalCost -= costDecr; 
     4473        // mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 
     4474 
     4475        AddSubdivisionStats(mOspTree.mOspStats.Leaves() + mVspTree.mVspStats.Leaves(), 
     4476                                                costDecr, 
     4477                                                mTotalCost 
     4478                                                ); 
     4479} 
     4480 
     4481 
     4482void HierarchyManager::AddSubdivisionStats(const int splits, 
     4483                                                                                   const float renderCostDecr, 
     4484                                                                                   const float totalRenderCost) 
     4485{ 
     4486        mSubdivisionStats  
     4487                        << "#Splits\n" << splits << endl 
     4488                        << "#RenderCostDecrease\n" << renderCostDecr << endl  
     4489                        << "#TotalRenderCost\n" << totalRenderCost << endl; 
     4490                        //<< "#AvgRenderCost\n" << avgRenderCost << endl; 
     4491} 
     4492 
     4493 
    44354494bool HierarchyManager::GlobalTerminationCriteriaMet(SplitCandidate *candidate) const 
    44364495{ 
     
    44734532        if (vspSplit) 
    44744533        { 
    4475                 mVspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
    4476                 return true; 
     4534                VspNode *n = mVspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
    44774535        } 
    44784536        else 
    44794537        { 
    4480                 mOspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
    4481                 return false; 
    4482         } 
     4538                KdNode *n = mOspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
     4539        } 
     4540         
     4541        return !globalTerminationCriteriaMet; 
    44834542} 
    44844543 
     
    44924551                SplitCandidate *splitCandidate = NextSplitCandidate(); 
    44934552             
    4494                 cout << "nodes: " << ++ numNodes << endl; 
    4495  
    44964553                mTotalCost -= splitCandidate->GetRenderCostDecrease(); 
    4497  
    44984554                // cost ratio of cost decrease / totalCost 
    44994555                const float costRatio = splitCandidate->GetRenderCostDecrease() / mTotalCost; 
    4500                  
     4556 
     4557                if (costRatio < mTermMinGlobalCostRatio) 
     4558                        ++ mGlobalCostMisses; 
     4559 
     4560                /*              cout << "nodes: " << ++ numNodes << endl; 
    45014561                Debug << "\n**********" << endl 
    45024562                          << "total cost: " << mTotalCost << " render cost decr: "  
    45034563                          << splitCandidate->GetRenderCostDecrease()  
    45044564                          << " cost ratio: " << costRatio << endl << endl; 
    4505  
     4565*/ 
    45064566                //-- subdivide leaf node 
    4507                 SubdivideSplitCandidate(splitCandidate); 
    4508  
    4509                 if (costRatio < mTermMinGlobalCostRatio) 
    4510                         ++ mGlobalCostMisses; 
    4511  
    4512                 // reevaluate candidates affected by the split 
    4513                 // for view space splits, this would be object space splits 
    4514                 // and other way round 
    4515                 if (repair) 
    4516                         RepairQueue(); 
     4567                if (SubdivideSplitCandidate(splitCandidate)) 
     4568                { 
     4569                        EvalSubdivisionStats(*splitCandidate); 
     4570                 
     4571                        // reevaluate candidates affected by the split 
     4572                        // for view space splits, this would be object space splits 
     4573                        // and other way round 
     4574                        if (repair) 
     4575                                RepairQueue(); 
     4576                } 
    45174577 
    45184578                DEL_PTR(splitCandidate); 
     
    45444604        VspTree::VspSplitCandidate *vsc =  
    45454605                PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays); 
     4606 
    45464607        // add to queue 
    45474608        mTQueue.Push(vsc); 
     
    45904651        // note: only true for view space = object space 
    45914652        mTotalCost = (float)osc->mParentData.mNode->mObjects.size();//(float)sc->mParentData.mPvs; 
    4592  
     4653         
    45934654        Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
    45944655 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1159 r1174  
    6666        int mMaxCostMisses; 
    6767 
    68         SplitCandidate() 
     68        SplitCandidate(): mRenderCostDecrease(0) 
    6969        {}; 
    7070 
    71         SplitCandidate(const AxisAlignedPlane &plane): mSplitPlane(plane) 
     71        SplitCandidate(const AxisAlignedPlane &plane): mSplitPlane(plane), mRenderCostDecrease(0) 
    7272        {} 
    7373 
     
    10391039                RayInfoContainer &rays); 
    10401040 
    1041         void EvalSubdivisionStats(const VspTraversalData &tData, 
    1042                                                           const VspTraversalData &tFrontData, 
    1043                                                           const VspTraversalData &tBackData); 
     1041        void EvalSubdivisionStats(const SplitCandidate &tData); 
    10441042protected: 
    10451043 
     
    16681666        int ClassifyRay(VssRay *ray, KdLeaf *leaf, const AxisAlignedPlane &plane) const; 
    16691667 
     1668        void EvalSubdivisionStats(const SplitCandidate &tData); 
     1669 
     1670        void AddSubdivisionStats(const int viewCells, 
     1671                const float renderCostDecr, 
     1672                const float totalRenderCost); 
     1673 
    16701674protected: 
    16711675 
     
    18441848                RayInfoContainer &rays); 
    18451849 
     1850        void EvalSubdivisionStats(const SplitCandidate &tData); 
     1851 
     1852        void AddSubdivisionStats(const int splits, 
     1853                const float renderCostDecr, 
     1854                const float totalRenderCost); 
     1855 
    18461856 
    18471857protected: 
     
    18601870        /// keeps track of cost during subdivision 
    18611871        float mTotalCost; 
     1872 
     1873        ofstream mSubdivisionStats; 
    18621874}; 
    18631875 
Note: See TracChangeset for help on using the changeset viewer.