Changeset 1176


Ignore:
Timestamp:
08/02/06 09:09:03 (18 years ago)
Author:
mattausch
Message:

corrected errors in the object space partition, but still buggy!

Location:
GTP/trunk/Lib/Vis
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1174 r1176  
    4545                }; 
    4646   
    47   Intersectable():mMailbox(0), mReferences(0) {} 
     47  Intersectable(): mMailbox(0), mReferences(0) {} 
    4848 
    4949        void SetId(const int id) { mId = id; } 
     
    6262        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
    6363 
    64         int IncMail() { return ++mMailbox - sMailId; } 
     64        int IncMail() { return ++ mMailbox - sMailId; } 
    6565 
    6666 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1144 r1176  
    1212namespace GtpVisibilityPreprocessor { 
    1313 
    14 int KdNode::mailID = 1; 
    15  
    16 KdNode::KdNode(KdInterior *parent):mParent(parent), mailbox(0) 
     14int KdNode::sMailId = 1; 
     15int KdNode::sReservedMailboxes = 1; 
     16 
     17KdNode::KdNode(KdInterior *parent):mParent(parent), mMailbox(0) 
    1718{ 
    1819  if (parent) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r1144 r1176  
    6464 
    6565  int Nodes() const {return nodes;} 
    66   int Interior() const { return nodes/2; } 
    67   int Leaves() const { return (nodes/2) + 1; } 
     66  int Interior() const { return nodes / 2; } 
     67  int Leaves() const { return (nodes / 2) + 1; } 
    6868 
    6969  void Reset() { 
     
    9595class KdNode { 
    9696public: 
    97   static int mailID; 
    98   int mailbox; 
    99    
    100   void Mail() { mailbox = mailID; } 
    101   static void NewMail() { mailID++; } 
    102   bool Mailed() const { return mailbox == mailID; } 
     97   
     98        static int sMailId; 
     99        static int sReservedMailboxes; 
     100  int mMailbox; 
     101   
     102  void Mail() { mMailbox = sMailId; } 
     103  //static void NewMail() { sMailId ++; } 
     104  bool Mailed() const { return mMailbox == sMailId; } 
     105  
     106  static void NewMail(const int reserve = 1) { 
     107                sMailId += sReservedMailboxes; 
     108                sReservedMailboxes = reserve; 
     109        } 
     110        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
     111        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
    103112 
    104113  virtual ~KdNode(){}; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp

    r1168 r1176  
    2222 
    2323        Intersectable::NewMail(); 
    24         KdNode::NewMail(); 
     24        KdLeaf::NewMail(); 
    2525 
    2626        ObjectPvsMap::const_iterator it, it_end = mEntries.end(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1174 r1176  
    35473547        while (node->mParent && node->mDepth > mKdPvsDepth) 
    35483548                node = node->mParent; 
     3549 
    35493550        return node; 
    35503551} 
     
    38103811        } 
    38113812 
    3812         if (0) // export merged view cells using pvs coding 
    3813         { 
    3814                 mColorCode = 1; 
    3815  
     3813        if (0)  
     3814        { 
     3815                mColorCode = 1; // export merged view cells using pvs coding 
    38163816                Exporter *exporter = Exporter::GetExporter("merged_view_cells_pvs.wrl"); 
    3817          
     3817 
    38183818                cout << "exporting view cells after merge (pvs size) ... ";      
    38193819 
     
    48864886        long startTime; 
    48874887 
    4888         if (!mOspTree->GetRoot()) 
    4889         { 
    4890                 Debug << "constructing vsp and osp tree" << endl; 
    4891                 //mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 
    4892                 mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox); 
    4893         } 
    4894         else // just build view space partition tree 
    4895         { 
    4896                 Debug << "constructing only vsp tree" << endl; 
    4897                 mHierarchyManager->Construct3(constructionRays, objects, &mViewSpaceBox); 
    4898         } 
     4888        //mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 
     4889        mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox); 
     4890 
    48994891 
    49004892        // print subdivision statistics 
     
    56895681                                        if (!mStoreKdPvs) 
    56905682                                        { 
    5691                                                 viewcell->AddPvsSample(ray.mTerminationObject, ray.mPdf, ray.mRelativePvsContribution); 
     5683                                                viewcell->AddPvsSample(ray.mTerminationObject,  
     5684                                                        ray.mPdf, ray.mRelativePvsContribution); 
    56925685                                        } 
    56935686                                        else 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1174 r1176  
    370370 
    371371 
    372 /******************************************************************************/ 
    373 /*                       class VspTree implementation                      */ 
    374 /******************************************************************************/ 
     372/*************************************************************************/ 
     373/*                       class VspTree implementation                    */ 
     374/*************************************************************************/ 
    375375 
    376376 
     
    642642         
    643643        AddSubdivisionStats(mVspStats.Leaves(), 
    644                                                 -costDecr, 
     644                                                costDecr, 
    645645                                                mTotalCost, 
    646646                                                (float)mTotalPvsSize / (float)mVspStats.Leaves()); 
     
    887887         
    888888        return interior; 
    889 } 
    890  
    891  
    892 KdNode *VspTree::GetKdNode(VssRay &ray, const bool termination) const 
    893 { 
    894         if (termination) 
    895         { 
    896                 if (!ray.mTerminationNode) 
    897                 { 
    898                         ray.mTerminationNode = mOspTree->GetRoot(); 
    899                 } 
    900  
    901                 ray.mTerminationNode =  
    902                         mOspTree->GetLeaf(ray.mTermination, ray.mTerminationNode); 
    903  
    904                 return ray.mTerminationNode; 
    905         } 
    906         else 
    907         { 
    908                 if (!ray.mOriginNode) 
    909                 { 
    910                         ray.mOriginNode = mOspTree->GetRoot(); 
    911                 } 
    912  
    913                 ray.mOriginNode =  
    914                         mOspTree->GetLeaf(ray.mOrigin, ray.mOriginNode); 
    915  
    916                 return ray.mOriginNode; 
    917         } 
    918889} 
    919890 
     
    10451016                { 
    10461017                        // potentially visible kd cells 
    1047                         if (mUseKdPvsForHeuristics) 
    1048                         { 
    1049                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode);        
    1050                                 AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 
    1051                         } 
    1052                         else 
     1018                        if (!mUseKdPvsForHeuristics) // matt TODo: remove storekdpvs!! 
    10531019                        { 
    10541020                                if (vc->AddPvsSample(obj, ray->mPdf, contribution)) 
     
    10571023                                } 
    10581024                        } 
     1025                        else 
     1026                        { 
     1027                                KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode);        
     1028                                AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 
     1029                        } 
     1030                         
     1031                         
    10591032 
    10601033                        sc += contribution; 
     
    12081181                                        oObject->Mail(); 
    12091182                                        oObject->mCounter = 1; 
     1183 
    12101184                                        ++ pvsSize; 
    12111185                                } 
     
    13421316                        } 
    13431317                } 
    1344                          
    1345  
    13461318        } 
    13471319         
     
    16151587        // create unique ids for pvs heuristics 
    16161588        Intersectable::NewMail(3); 
    1617          
     1589        KdLeaf::NewMail(3); 
     1590 
    16181591        RayInfoContainer::const_iterator rit, rit_end = data.mRays->end(); 
    16191592 
     
    16291602                                                                                  candidatePlane.mPosition, t); 
    16301603 
    1631                 // find front and back pvs for origing and termination object 
    1632                 AddObjToPvs(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 
    1633                 AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 
     1604                if (!mUseKdPvsForHeuristics) 
     1605                { 
     1606                        // find front and back pvs for origing and termination object 
     1607                        UpdateObjPvsContri(ray->mTerminationObject, cf, pvsFront, pvsBack, totalPvs); 
     1608                        UpdateObjPvsContri(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 
     1609                } 
     1610                else 
     1611                { 
     1612                        if (ray->mTerminationObject) 
     1613                        { 
     1614                                KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
     1615                                UpdateKdLeafPvsContri(leaf, cf, pvsFront, pvsBack, totalPvs); 
     1616                        } 
     1617 
     1618                        if (ray->mOriginObject) 
     1619                        { 
     1620                                KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
     1621                                UpdateKdLeafPvsContri(leaf, cf, pvsFront, pvsBack, totalPvs); 
     1622                        } 
     1623                } 
    16341624        } 
    16351625 
     
    16611651        const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 
    16621652         
    1663          
    16641653        Debug << "\n==== eval render cost decrease ===" << endl 
    16651654                  << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl  
     
    16971686                const int side = (*rit).ComputeRayIntersection(axis, position, t); 
    16981687         
    1699                 AddObjToPvs((*rit).mRay->mTerminationObject, side, pvsFront, pvsBack, pvsTotal); 
    1700                 AddObjToPvs((*rit).mRay->mOriginObject, side, pvsFront, pvsBack, pvsTotal); 
     1688                UpdateObjPvsContri((*rit).mRay->mTerminationObject, side, pvsFront, pvsBack, pvsTotal); 
     1689                UpdateObjPvsContri((*rit).mRay->mOriginObject, side, pvsFront, pvsBack, pvsTotal); 
    17011690        } 
    17021691 
     
    17211710 
    17221711 
    1723 void VspTree::AddObjToPvs(Intersectable *obj, 
     1712void VspTree::UpdateObjPvsContri(Intersectable *obj, 
    17241713                                                  const int cf, 
    17251714                                                  float &frontPvs, 
     
    17271716                                                  float &totalPvs) const 
    17281717{ 
    1729         if (!obj) 
    1730                 return; 
     1718        if (!obj) return; 
    17311719 
    17321720        //const float renderCost = mViewCellsManager->SimpleRay &raynderCost(obj); 
     
    17731761 
    17741762 
     1763void VspTree::UpdateKdLeafPvsContri(KdLeaf *leaf, 
     1764                                                                        const int cf, 
     1765                                                                        float &frontPvs, 
     1766                                                                        float &backPvs, 
     1767                                                                        float &totalPvs) const 
     1768{ 
     1769        if (!leaf) return; 
     1770 
     1771        // the objects which are referenced in this and only this leaf 
     1772        const int contri = (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
     1773         
     1774        // newly found leaf 
     1775        if (!leaf->Mailed() && !leaf->Mailed(1) && !leaf->Mailed(2)) 
     1776        { 
     1777                totalPvs += contri; 
     1778        } 
     1779 
     1780        // compute contribution of yet unclassified objects 
     1781        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
     1782 
     1783        for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
     1784        {        
     1785                UpdateObjPvsContri(*oit, cf, frontPvs, backPvs, totalPvs); 
     1786    }    
     1787         
     1788        // QUESTION matt: is it safe to assume that  
     1789        // the object belongs to no pvs in this case? 
     1790        //if (cf == Ray::COINCIDENT) return; 
     1791 
     1792        if (cf >= 0) // front pvs 
     1793        { 
     1794                if (!leaf->Mailed() && !leaf->Mailed(2)) 
     1795                { 
     1796                        frontPvs += contri; 
     1797                 
     1798                        // already in back pvs => in both pvss 
     1799                        if (leaf->Mailed(1)) 
     1800                                leaf->Mail(2); 
     1801                        else 
     1802                                leaf->Mail(); 
     1803                } 
     1804        } 
     1805 
     1806        if (cf <= 0) // back pvs 
     1807        { 
     1808                if (!leaf->Mailed(1) && !leaf->Mailed(2)) 
     1809                { 
     1810                        backPvs += contri; 
     1811                 
     1812                        // already in front pvs => in both pvss 
     1813                        if (leaf->Mailed()) 
     1814                                leaf->Mail(2); 
     1815                        else 
     1816                                leaf->Mail(1); 
     1817                } 
     1818        } 
     1819} 
     1820 
     1821 
    17751822void VspTree::CollectLeaves(vector<VspLeaf *> &leaves,  
    1776                                                            const bool onlyUnmailed, 
    1777                                                            const int maxPvsSize) const 
     1823                                                        const bool onlyUnmailed, 
     1824                                                        const int maxPvsSize) const 
    17781825{ 
    17791826        stack<VspNode *> nodeStack; 
     
    22192266{ 
    22202267        int pvsSize = 0; 
     2268        Intersectable::NewMail(); 
    22212269 
    22222270        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
    22232271 
    2224         Intersectable::NewMail(); 
    2225  
    2226         for (rit = rays.begin(); rit != rays.end(); ++ rit) 
    2227         { 
    2228                 VssRay *ray = (*rit).mRay; 
    2229  
    2230                 if (ray->mOriginObject) 
    2231                 { 
    2232                         if (!ray->mOriginObject->Mailed()) 
    2233                         { 
    2234                                 ray->mOriginObject->Mail(); 
    2235                                 ++ pvsSize; 
    2236                         } 
    2237                 } 
    2238                 if (ray->mTerminationObject) 
    2239                 { 
    2240                         if (!ray->mTerminationObject->Mailed()) 
    2241                         { 
    2242                                 ray->mTerminationObject->Mail(); 
    2243                                 ++ pvsSize; 
     2272        if (!mUseKdPvsForHeuristics) 
     2273        { 
     2274                for (rit = rays.begin(); rit != rays.end(); ++ rit) 
     2275                { 
     2276                        VssRay *ray = (*rit).mRay; 
     2277 
     2278                        if (ray->mOriginObject) 
     2279                        { 
     2280                                if (!ray->mOriginObject->Mailed()) 
     2281                                { 
     2282                                        ray->mOriginObject->Mail(); 
     2283                                        ++ pvsSize; 
     2284                                } 
     2285                        } 
     2286                        if (ray->mTerminationObject) 
     2287                        { 
     2288                                if (!ray->mTerminationObject->Mailed()) 
     2289                                { 
     2290                                        ray->mTerminationObject->Mail(); 
     2291                                        ++ pvsSize; 
     2292                                } 
     2293                        } 
     2294                } 
     2295        } 
     2296        else 
     2297        { 
     2298                KdNode::NewMail(); 
     2299 
     2300                for (rit = rays.begin(); rit != rays.end(); ++ rit) 
     2301                { 
     2302                        VssRay *ray = (*rit).mRay; 
     2303 
     2304                        if (ray->mTerminationObject) 
     2305                        { 
     2306                                KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
     2307 
     2308                                if (!leaf->Mailed()) 
     2309                                { 
     2310                                        leaf->Mail(); 
     2311                                        pvsSize += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
     2312                                 
     2313                                        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
     2314                                        for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
     2315                                        { 
     2316                                                Intersectable *obj = *oit; 
     2317 
     2318                                                if (!obj->Mailed()) 
     2319                                                { 
     2320                                                        obj->Mail(); 
     2321                                                        ++ pvsSize; 
     2322                                                } 
     2323                                        } 
     2324                                } 
     2325                        } 
     2326 
     2327                        if (ray->mOriginObject) 
     2328                        { 
     2329                                KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
     2330 
     2331                                if (!leaf->Mailed()) 
     2332                                { 
     2333                                        leaf->Mail(); 
     2334                                        pvsSize += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
     2335                                 
     2336                                        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
     2337                                        for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
     2338                                        { 
     2339                                                Intersectable *obj = *oit; 
     2340 
     2341                                                if (!obj->Mailed()) 
     2342                                                { 
     2343                                                        obj->Mail(); 
     2344                                                        ++ pvsSize; 
     2345                                                } 
     2346                                        } 
     2347                                } 
    22442348                        } 
    22452349                } 
     
    27632867 
    27642868 
    2765 void VspTree::ProcessRays(const VssRayContainer &sampleRays, 
    2766                                                   RayInfoContainer &rays) 
     2869void VspTree::PreprocessRays(const VssRayContainer &sampleRays, 
     2870                                                        RayInfoContainer &rays) 
    27672871{ 
    27682872        VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     
    28412945        } 
    28422946 
    2843         // if not using kd tree root 
     2947        // if not using kd tree root, delete tree (otherwise mKdTree has to do the job) 
    28442948        if (!mCopyFromKdTree) 
    28452949                DEL_PTR(mRoot); 
     2950 
     2951        mSubdivisionStats.close(); 
    28462952} 
    28472953 
     
    29273033                Intersectable *object = *oit; 
    29283034                 
    2929                 // initialise 
     3035                // initialise leaf references of objects 
    29303036                if (parent->IsRoot()) 
    29313037                        object->mReferences = 1; 
     
    32963402 
    32973403        //-- traverse through events and find best split plane 
    3298  
    32993404        vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 
    33003405 
     
    33063411                                                                   *ci,  
    33073412                                                                   voll, volr,  
    3308                                                                    pvsl, pvsr, 
    3309                                                                    vcl, vcr); 
     3413                                                                   pvsl, pvsr 
     3414                                                                  ); 
    33103415 
    33113416                // Note: sufficient to compare size of bounding boxes of front and back side? 
     
    33133418                if (((*ci).mPos >= minBand) && ((*ci).mPos <= maxBand)) 
    33143419                { 
    3315                         sum = voll * pvsl + volr * pvsr; 
     3420                        // voll = view cells that see only left node (i.e., left pvs) 
     3421                        // volr = view cells that see only right node (i.e., right pvs) 
     3422                        // rest = view cells that see both nodes (i.e., total pvs) 
     3423            sum = voll * pvsl + volr * pvsr + (totalVol - voll - volr) * totalPvs; 
    33163424 
    33173425                        float currentPos; 
    33183426                         
    33193427                        // HACK: current positition is BETWEEN visibility events 
    3320                         if (0 && ((ci + 1) != ci_end)) 
     3428                        if (1 && ((ci + 1) != ci_end)) 
    33213429                                currentPos = ((*ci).mPos + (*(ci + 1)).mPos) * 0.5f; 
    33223430                        else 
     
    33493457        } 
    33503458         
    3351  
    33523459        //-- compute cost 
    3353  
    3354         const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 
    3355         const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 
    3356  
    3357         const float pOverall = totalVol; 
    3358         const float pBack = volBack; 
    3359         const float pFront = volFront; 
    3360  
    3361         const float penaltyOld = (float)totalPvs; 
    3362     const float penaltyFront = (float)pvsFront; 
    3363         const float penaltyBack = (float)pvsBack; 
    3364          
    3365         const float oldRenderCost = penaltyOld * pOverall + Limits::Small; 
    3366         const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 
     3460        const float frontAndBackVol = totalVol - volFront - volBack; 
     3461 
     3462        const float oldRenderCost = (float)totalPvs * totalVol + Limits::Small; 
     3463        const float newRenderCost =  
     3464                (float)pvsFront * volFront +  
     3465                (float)pvsBack * volBack + 
     3466                (float)totalPvs * frontAndBackVol; 
    33673467 
    33683468 
     
    33803480        Debug << "\n§§§§ eval local cost §§§§" << endl 
    33813481                  << "back pvs: " << pvsBack << " front pvs: " << pvsFront << " total pvs: " << totalPvs << endl  
    3382                   << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl 
     3482                  << "back p: " << volBack / viewSpaceVol << " front p " << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl 
    33833483                  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 
    33843484                  << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl; 
     
    34433543                                                          ); 
    34443544                } 
     3545 
     3546 
     3547 
    34453548 
    34463549                if (ray->mTerminationObject && (GetLeaf(ray->mTermination, ray->mTerminationNode) == leaf)) 
     
    35723675                                                                                 float &volRight, 
    35733676                                                                                 int &pvsLeft, 
    3574                                                                                  int &pvsRight, 
    3575                                                                                  int &viewCellsLeft, 
    3576                                                                                  int &viewCellsRight) 
     3677                                                                                 int &pvsRight 
     3678                                                                                 ) 
    35773679{ 
    35783680        Intersectable *obj = ci.mObject; 
    35793681        VssRay *ray = ci.mRay; 
    3580          
     3682 
     3683        // switch between different types of events 
    35813684        switch (ci.mType)  
    35823685        { 
     
    35923695                // compute volume contribution from view cells 
    35933696                case SortableEntry::BOX_INTERSECT: 
     3697                                // process ray if the hit point with termination / origin object  
     3698                                // is inside this kd leaf 
    35943699                                if ((ray->mOriginObject && (GetLeaf(ray->mOrigin, ray->mOriginNode) == leaf)) || 
    35953700                                        (ray->mTerminationObject && (GetLeaf(ray->mTermination, ray->mTerminationNode) == leaf))) 
    35963701                                { 
    3597                                         EvalVolumeContribution(*ray, volLeft, volRight, viewCellsLeft, viewCellsRight); 
     3702                                        EvalVolumeContribution(*ray, volLeft, volRight); 
    35983703                                } 
    35993704                        break; 
     
    36093714void OspTree::EvalVolumeContribution(const VssRay &ray,  
    36103715                                                                         float &volLeft,  
    3611                                                                          float &volRight, 
    3612                                                                          int &viewCellsLeft, 
    3613                                                                          int &viewCellsRight) 
     3716                                                                         float &volRight) 
    36143717{ 
    36153718        ViewCellContainer viewCells; 
     
    36173720        mVspTree->GetViewCells(ray, viewCells); 
    36183721 
     3722        /// classify view cells and compute volume contri accordingly 
     3723        /// possible view cell classifications: 
     3724        /// view cell mailed => view cell can be seen from left child node 
     3725        /// view cell counter > 0 view cell can be seen from right child node 
     3726        /// combined: view cell volume belongs to both nodes 
    36193727        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    36203728         
    36213729        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    36223730        { 
    3623                 // add view cells volume to left child node 
     3731                // view cells can also be seen from left child node 
    36243732                ViewCell *viewCell = *vit; 
    36253733 
     3734                const float vol = viewCell->GetVolume(); 
     3735 
    36263736                if (!viewCell->Mailed()) 
    36273737                { 
    36283738                        viewCell->Mail(); 
    3629                          
    3630                         volLeft += viewCell->GetVolume(); 
    3631  
    3632                         ++ viewCellsLeft; 
    3633                 } 
    3634  
    3635                 // remove from right child node 
     3739 
     3740                        // we now see view cell from both nodes  
     3741                        // => remove ref to right child node 
     3742                        volRight -= vol; 
     3743                } 
     3744 
     3745                // last reference into the right node 
    36363746                if (-- viewCell->mCounter == 0) 
    36373747                { 
    3638                         volRight -= viewCell->GetVolume(); 
    3639  
    3640                         -- viewCellsRight; 
     3748#if 0 
     3749                        // view cell was previousy seen from right node only 
     3750                        // => remove from right node (matt: need this?) 
     3751                        if (!viewCell->Mailed()) 
     3752                                volRight -= vol; 
     3753                        else 
     3754#endif 
     3755                        // view cell was previously seen from both nodes  => 
     3756                        // contributes only to left node now 
     3757                        volLeft += vol; 
    36413758                } 
    36423759        } 
     
    37533870{ 
    37543871        const float costDecr = sc.GetRenderCostDecrease(); 
    3755         Debug << "**********************$$$$$$$$$$$$$$"<< endl; 
    3756 Debug << "here78 " << mOspStats.Leaves() << " " << mTotalCost << endl; 
     3872 
    37573873        AddSubdivisionStats(mOspStats.Leaves(), 
    37583874                                                costDecr, 
     
    37663882                                                                  const float renderCostDecr, 
    37673883                                                                  const float totalRenderCost) 
    3768                                                                   //const float avgRenderCost) 
    3769 {Debug << "here64 " << totalRenderCost << " " << renderCostDecr << endl; 
     3884{ 
    37703885        mSubdivisionStats  
    37713886                        << "#Leaves\n" << leaves << endl 
     
    38183933        float pFront = 0; 
    38193934        float pBack = 0; 
     3935        float pFrontAndBack = 0; 
     3936 
    38203937 
    38213938        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     
    38563973        // => the volume is the weight for the render cost equation 
    38573974        ViewCell::NewMail(3); 
    3858          
     3975 
    38593976        RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
     3977 
     3978        ViewCellContainer collectedViewCells; 
    38603979 
    38613980        for (rit = tData.mRays->begin(); rit < rit_end; ++ rit) 
     
    38733992                        const int classification = ClassifyRay(ray, leaf, candidatePlane); 
    38743993 
    3875                         ViewCellContainer viewCells;             
     3994                        ViewCellContainer viewCells; 
    38763995                        mVspTree->GetViewCells(*ray, viewCells); 
    38773996                         
    38783997                        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    38793998 
    3880                         // evaluate view cells volume contribution 
     3999                        // mail view cell 
    38814000                        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    38824001                        { 
    3883                                 AddViewCellVolume(*vit, classification, pFront, pBack, pOverall); 
    3884                         } 
    3885                 } 
     4002                                ViewCell *vc = *vit; 
     4003 
     4004                                // if not previously mailed 
     4005                                if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 
     4006                                        collectedViewCells.push_back(vc); 
     4007 
     4008                                MailViewCell(*vit, classification);      
     4009                        } 
     4010                } 
     4011        } 
     4012 
     4013        // these are non-overlapping sets 
     4014        pOverall = pFront + pBack + pFrontAndBack; 
     4015 
     4016        ViewCellContainer::const_iterator vit, vit_end = collectedViewCells.end(); 
     4017 
     4018        // evaluate view cells volume contribution with respect to mail box 
     4019        for (vit = collectedViewCells.begin(); vit != vit_end; ++ vit) 
     4020        { 
     4021                AddViewCellVolumeContri(*vit, pFront, pBack, pFrontAndBack); 
    38864022        } 
    38874023 
     
    38894025        //-- pvs rendering heuristics 
    38904026        const float oldRenderCost = pOverall * totalPvs; 
    3891         const float newRenderCost = pvsFront * pFront + pvsBack * pBack; 
     4027        const float newRenderCost = pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack; 
    38924028 
    38934029        // normalize volume with view space volume 
    38944030        const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 
    38954031 
    3896         Debug << "\n==== eval render cost decrease ====" << endl 
     4032        Debug << "\n(((( eval render cost decrease ))))" << endl 
    38974033                  << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl  
    3898                   << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl 
     4034                  << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol  
     4035                  << " front and back p " << pFrontAndBack / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl 
    38994036                  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 
    39004037                  << "render cost decrease: " << renderCostDecrease << endl; 
     
    39024039        normalizedOldRenderCost = oldRenderCost / viewSpaceVol; 
    39034040 
    3904         if (oldRenderCost < newRenderCost) 
     4041        if (oldRenderCost < newRenderCost * 0.99) 
    39054042                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; 
    3918  
     4043         
    39194044        return renderCostDecrease; 
    39204045} 
     
    41484273 
    41494274 
    4150 void OspTree::ProcessRays(const VssRayContainer &sampleRays, 
    4151                                                   RayInfoContainer &rays) 
     4275void OspTree::PreprocessRays(const VssRayContainer &sampleRays, 
     4276                                                        RayInfoContainer &rays) 
    41524277{ 
    41534278        VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     
    41774302 
    41784303                        rays.push_back(RayInfo(ray, minT / len, maxT / len)); 
     4304 
     4305                        // HACK: reset nodes for the case we have used object kd tree for 
     4306                        // tree building. 
     4307                        ray->mOrigin = NULL; 
     4308                        ray->mTerminationNode = NULL; 
    41794309                } 
    41804310        } 
     
    42544384 
    42554385 
     4386/* 
    42564387void OspTree::AddViewCellVolume(ViewCell *vc, 
    42574388                                                                const int cf, 
     
    42974428        } 
    42984429} 
     4430*/ 
     4431void OspTree::MailViewCell(ViewCell *vc, const int cf) const 
     4432{ 
     4433        if (vc->Mailed(2)) // already classified 
     4434                return; 
     4435 
     4436        if (cf >= 0) // front volume 
     4437        { 
     4438                 // already in back volume => in both volumes 
     4439                if (vc->Mailed(1)) 
     4440                { 
     4441                        vc->Mail(2); 
     4442                } 
     4443                else 
     4444                { 
     4445                        vc->Mail(); 
     4446                } 
     4447        } 
     4448 
     4449        if (cf <= 0) // back volume 
     4450        { 
     4451                // already in front volume => in both volume 
     4452                if (vc->Mailed()) 
     4453                { 
     4454                        vc->Mail(2); 
     4455                } 
     4456                else 
     4457                { 
     4458                        vc->Mail(1); 
     4459                } 
     4460        } 
     4461} 
     4462 
     4463 
     4464void OspTree::AddViewCellVolumeContri(ViewCell *vc, 
     4465                                                                          float &frontVol, 
     4466                                                                          float &backVol, 
     4467                                                                          float &frontAndBackVol) const 
     4468{ 
     4469        if (vc->Mailed()) 
     4470                frontVol += vc->GetVolume(); 
     4471        else if (vc->Mailed(1)) 
     4472                backVol += vc->GetVolume(); 
     4473        else if (vc->Mailed(2)) 
     4474                frontAndBackVol += vc->GetVolume(); 
     4475} 
     4476 
    42994477 
    43004478 
     
    43464524 
    43474525        // get clipped rays 
    4348         mVspTree.ProcessRays(sampleRays, rays); 
     4526        mVspTree.PreprocessRays(sampleRays, rays); 
    43494527 
    43504528        const int pvsSize = mVspTree.ComputePvsSize(rays); 
     
    44144592 
    44154593        // get clipped rays 
    4416         mOspTree.ProcessRays(sampleRays, rays); 
     4594        mOspTree.PreprocessRays(sampleRays, rays); 
    44174595 
    44184596        // add first candidate for view space partition 
     
    45934771        ///////////////////////////////////////////////////////////// 
    45944772 
    4595  
     4773#if 0 
    45964774        // makes no sense otherwise because only one kd cell available 
    45974775        // during view space partition 
     
    46014779        mVspTree.mUseKdPvsForHeuristics = false; 
    46024780        mVspTree.mStoreKdPvs = false; 
     4781#endif 
    46034782 
    46044783        VspTree::VspSplitCandidate *vsc =  
     
    46614840        mOspTree.mOspStats.Stop(); 
    46624841 
     4842#if 0 
    46634843        // reset parameters 
    46644844        mVspTree.mUseKdPvsForHeuristics = savedCountMethod; 
    46654845        mVspTree.mStoreKdPvs = savedStoreMethod; 
     4846#endif 
    46664847} 
    46674848 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1174 r1176  
    965965                                  RayInfoContainer &backRays) const; 
    966966 
    967         /** Adds the object to the pvs of the front and back leaf with a given classification. 
     967        /** Classfifies the object with respect to the  
     968                pvs of the front and back leaf and updates pvs size 
     969                accordingly. 
    968970 
    969971                @param obj the object to be added 
     
    973975         
    974976        */ 
    975         void AddObjToPvs(Intersectable *obj,  
     977        void UpdateObjPvsContri(Intersectable *obj,  
    976978                                         const int cf,  
    977979                                         float &frontPvs,  
     
    979981                                         float &totalPvs) const; 
    980982         
     983        /** See UpdateObjPvsContri.  
     984        */ 
     985        void UpdateKdLeafPvsContri(KdLeaf *leaf, 
     986                const int cf, 
     987                float &frontPvs, 
     988                float &backPvs, 
     989                float &totalPvs) const; 
     990 
     991 
    981992        /** Computes PVS size induced by the rays. 
    982993        */ 
     
    10021013        */ 
    10031014        void AddSamplesToPvs(VspLeaf *leaf, 
    1004                                   const RayInfoContainer &rays,  
    1005                                   float &sampleContributions, 
    1006                                   int &contributingSamples); 
    1007  
    1008         bool AddKdLeafToPvs(KdLeaf *leaf, ViewCell *vc, float &pvs, float &contribution); 
     1015                                                 const RayInfoContainer &rays,  
     1016                                                 float &sampleContributions, 
     1017                                                 int &contributingSamples); 
     1018 
     1019        bool AddKdLeafToPvs(KdLeaf *leaf,  
     1020                                                ViewCell *vc,  
     1021                                                float &pvs,  
     1022                                                float &contribution); 
    10091023 
    10101024        /** Propagates valid flag up the tree. 
     
    10251039        float GetMemUsage() const; 
    10261040 
     1041        /** Updates view cell pvs of objects. 
     1042        */ 
    10271043        void ProcessViewCellObjects(ViewCell *parent,  
    10281044                ViewCell *front,  
     
    10311047        void CreateViewCell(VspTraversalData &tData, const bool updatePvs); 
    10321048 
     1049        /** Collect split candidates which are affected by the last split 
     1050                and must be reevaluated. 
     1051        */ 
    10331052        void CollectDirtyCandidates(VspSplitCandidate *sc,  
    10341053                vector<SplitCandidate *> &dirtyList); 
    10351054 
    1036         KdNode *GetKdNode(VssRay &ray, const bool termination) const; 
    1037  
    1038         void ProcessRays(const VssRayContainer &sampleRays, 
     1055        /** Rays will be clipped to the bounding box. 
     1056        */ 
     1057        void PreprocessRays(const VssRayContainer &sampleRays, 
    10391058                RayInfoContainer &rays); 
    10401059 
     1060        /** Evaluate subdivision statistics. 
     1061        */ 
    10411062        void EvalSubdivisionStats(const SplitCandidate &tData); 
     1063 
     1064 
    10421065protected: 
    10431066 
     
    15661589         
    15671590        */ 
    1568         void AddObjToPvs(Intersectable *obj,  
     1591        void UpdateObjPvsContri(Intersectable *obj,  
    15691592                                         const int cf,  
    15701593                                         float &frontPvs,  
     
    16021625        float GetMemUsage() const; 
    16031626 
    1604         /** Evaluates the influence on the pvs of the event. 
     1627        /** Evaluate the contributions of view cell volume of the left and the right view cell. 
     1628        */ 
     1629        void EvalVolumeContribution(const VssRay &ray,  
     1630                                                                        float &volLeft,  
     1631                                                                        float &volRight); 
     1632 
     1633/** Evaluates the influence on the pvs of the event. 
    16051634                @param ve the visibility event 
    16061635                @param pvsLeft updates the left pvs 
     
    16121641                float &volRight, 
    16131642                int &pvsLeft, 
    1614                 int &pvsRight, 
    1615                 int &viewCellsLeft, 
    1616                 int &viewCellsRight); 
    1617  
    1618         /** Evaluate the contributions of view cell volume of the left and the right view cell. 
    1619         */ 
    1620         void EvalVolumeContribution(const VssRay &ray,  
    1621                                                                 float &volLeft,  
    1622                                                                 float &volRight, 
    1623                                                                 int &viewCellsLeft, 
    1624                                                                 int &viewCellsRight); 
     1643                int &pvsRight); 
    16251644 
    16261645        /** Prepares objects for the cost heuristics. 
     
    16461665                ViewCellContainer &viewCells); 
    16471666 
    1648         void ProcessRays(const VssRayContainer &sampleRays, 
     1667        /** Rays will be clipped to the bounding box. 
     1668        */ 
     1669        void PreprocessRays(const VssRayContainer &sampleRays, 
    16491670                RayInfoContainer &rays); 
    16501671 
     
    16581679        bool EndPointInsideNode(KdLeaf *leaf, VssRay &ray, bool isTermination) const; 
    16591680 
    1660         void AddViewCellVolume(ViewCell *vc, 
    1661                                                    const int cf, 
    1662                                                    float &frontPvs, 
    1663                                                    float &backPvs, 
    1664                                                    float &totalPvs) const; 
     1681        void AddViewCellVolumeContri( 
     1682                ViewCell *vc,  
     1683                float &frontVol,  
     1684                float &backVol, 
     1685                float &frontAndBackVol) const; 
     1686 
     1687        /** Classifies and mail view cell with respect to the heuristics contribution. 
     1688                Set view cell mail box according to it's influence on  
     1689                front (0), back (1) and front / back node (2). 
     1690        */ 
     1691        void  MailViewCell(ViewCell *vc, const int cf) const; 
    16651692 
    16661693        int ClassifyRay(VssRay *ray, KdLeaf *leaf, const AxisAlignedPlane &plane) const; 
     
    16711698                const float renderCostDecr, 
    16721699                const float totalRenderCost); 
     1700 
     1701        void EvalViewCellsForHeuristics(const VssRay &ray,  
     1702                float &volLeft,  
     1703                float &volRight); 
    16731704 
    16741705protected: 
Note: See TracChangeset for help on using the changeset viewer.