Changeset 2210


Ignore:
Timestamp:
03/08/07 13:23:13 (17 years ago)
Author:
mattausch
Message:

improved performance of osp

Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility.env

    r2075 r2210  
    2424        useGlDebugger false 
    2525# 0 = INTERNAL          1 = MLRT 
    26         rayCastMethod 0 
     26        rayCastMethod 1 
    2727         
    2828        type combined 
     
    128128        importRandomViewCells false 
    129129 
    130         useKdPvs true 
     130        useKdPvs false 
    131131        useKdPvsAfterFiltering true 
    132132        # samples used for view cell construction 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r2206 r2210  
    237237mRoot(NULL), 
    238238mTimeStamp(1), 
    239 mIsInitialSubdivision(false), 
    240 mCachedObjects(NULL) 
     239mIsInitialSubdivision(false) 
    241240{ 
    242241        ReadEnvironment(); 
     
    394393        mNodeTimer.Entry(); 
    395394 
     395/* 
    396396#if STORE_VIEWCELLS_WITH_BVH 
    397         AssociateViewCellsWithObjects(sc.mFrontObjects); 
    398         AssociateViewCellsWithObjects(sc.mBackObjects); 
     397        AssociateViewCellsWithObjects(sc.mSampledFrontObjects); 
     398        AssociateViewCellsWithObjects(sc.mSampledBackObjects); 
    399399#endif   
     400*/ 
    400401        const BvhTraversalData &tData = sc.mParentData; 
    401402        BvhLeaf *leaf = tData.mNode; 
     
    451452        backData.mNode = back; 
    452453 
     454        backData.mSampledObjects = new ObjectContainer(); 
     455        frontData.mSampledObjects = new ObjectContainer(); 
     456 
     457        *backData.mSampledObjects = sc.mSampledBackObjects; 
     458        *frontData.mSampledObjects = sc.mSampledFrontObjects; 
     459 
    453460        back->mObjects = sc.mBackObjects; 
    454461        front->mObjects = sc.mFrontObjects; 
     
    456463        // if the number of rays is too low, no assumptions can be made 
    457464        // (=> switch to surface area heuristics?) 
    458         frontData.mNumRays = CountRays(sc.mFrontObjects); 
    459         backData.mNumRays = CountRays(sc.mBackObjects); 
     465        frontData.mNumRays = CountRays(sc.mSampledFrontObjects); 
     466        backData.mNumRays = CountRays(sc.mSampledBackObjects); 
    460467 
    461468        AssociateObjectsWithLeaf(back); 
     
    465472        //-- compute pvs correction to cope with undersampling 
    466473 
    467         frontData.mPvs = (float)CountViewCells(front->mObjects); 
    468         backData.mPvs = (float)CountViewCells(back->mObjects); 
     474        frontData.mPvs = (float)sc.mNumFrontViewCells;//(float)CountViewCells(sc.mSampledFrontObjects); 
     475        backData.mPvs = (float)sc.mNumBackViewCells;//(float)CountViewCells(sc.mSampledBackObjects); 
    469476 
    470477        frontData.mCorrectedPvs = sc.mCorrectedFrontPvs; 
     
    474481        // compute probability of this node being visible,  
    475482        // i.e., volume of the view cells that can see this node 
    476         frontData.mVolume = EvalViewCellsVolume(sc.mFrontObjects) / GetViewSpaceVolume(); 
    477         backData.mVolume = EvalViewCellsVolume(sc.mBackObjects) / GetViewSpaceVolume(); 
     483        frontData.mVolume = sc.mVolumeFrontViewCells;//EvalViewCellsVolume(sc.mSampledFrontObjects) / GetViewSpaceVolume(); 
     484        backData.mVolume = sc.mVolumeBackViewCells;//EvalViewCellsVolume(sc.mSampledBackObjects) / GetViewSpaceVolume(); 
    478485 
    479486        frontData.mCorrectedVolume = sc.mCorrectedFrontVolume; 
     
    493500                AssignSortedObjects(sc, frontData, backData); 
    494501        } 
    495  
     502/* 
    496503#if STORE_VIEWCELLS_WITH_BVH 
    497         ReleaseViewCells(sc.mFrontObjects); 
    498         ReleaseViewCells(sc.mBackObjects); 
     504        ReleaseViewCells(sc.mSampledFrontObjects); 
     505        ReleaseViewCells(sc.mSampledBackObjects); 
    499506#endif 
    500  
     507*/ 
    501508        mNodeTimer.Exit(); 
    502509 
     
    637644#if STORE_VIEWCELLS_WITH_BVH 
    638645        // fill view cells cache 
    639         AssociateViewCellsWithObjects(*splitCandidate.mParentData.mSortedObjects[3]); 
     646        AssociateViewCellsWithObjects(*splitCandidate.mParentData.mSampledObjects); 
    640647#endif 
    641648 
    642649        if (computeSplitPlane) 
    643650        { 
     651                splitCandidate.mFrontObjects.clear(); 
     652                splitCandidate.mBackObjects.clear(); 
     653                splitCandidate.mSampledFrontObjects.clear(); 
     654                splitCandidate.mSampledBackObjects.clear(); 
     655 
    644656                const bool sufficientSamples =  
    645657                        splitCandidate.mParentData.mNumRays > mMinRaysForVisibility; 
     
    663675                splitCandidate.SetMaxCostMisses(maxCostRatioViolated ?  
    664676                                                                                previousMisses + 1 : previousMisses); 
    665         } 
     677 
     678                StoreSampledObjects(splitCandidate.mSampledFrontObjects, splitCandidate.mFrontObjects); 
     679                StoreSampledObjects(splitCandidate.mSampledBackObjects, splitCandidate.mBackObjects); 
     680        } 
     681 
    666682        mPlaneTimer.Exit(); 
    667683 
     
    672688 
    673689        // avg contribution of a ray to a pvs 
    674         const float pvs = (float)CountViewCells(leaf->mObjects); 
     690        const float pvs = (float)CountViewCells(*tData.mSampledObjects); 
    675691        const float avgRayContri = AvgRayContribution((int)pvs, tData.mNumRays); 
    676692 
     
    679695        const float viewSpaceVol = GetViewSpaceVolume(); 
    680696 
    681         const float oldVolume = EvalViewCellsVolume(leaf->mObjects) / viewSpaceVol; 
     697        const float oldVolume = EvalViewCellsVolume(*tData.mSampledObjects) / viewSpaceVol; 
    682698        const float oldRatio = (tData.mVolume) > 0 ? oldVolume / tData.mVolume : 1; 
    683699        const float parentVol = tData.mCorrectedVolume * oldRatio; 
     
    685701        // this leaf is a pvs entry in all the view cells 
    686702        // that see one of the objects. 
    687         const float frontVol = EvalViewCellsVolume(splitCandidate.mFrontObjects) / viewSpaceVol; 
    688         const float backVol = EvalViewCellsVolume(splitCandidate.mBackObjects) / viewSpaceVol; 
     703        splitCandidate.mVolumeFrontViewCells = EvalViewCellsVolume(splitCandidate.mSampledFrontObjects) / viewSpaceVol; 
     704        splitCandidate.mVolumeBackViewCells = EvalViewCellsVolume(splitCandidate.mSampledBackObjects) / viewSpaceVol; 
     705 
     706        splitCandidate.mNumFrontViewCells = CountViewCells(splitCandidate.mSampledFrontObjects); 
     707        splitCandidate.mNumBackViewCells = CountViewCells(splitCandidate.mSampledBackObjects); 
    689708 
    690709        splitCandidate.mCorrectedFrontVolume =  
    691                 mHierarchyManager->EvalCorrectedPvs(frontVol, parentVol, avgRayContri); 
     710                mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells, parentVol, avgRayContri); 
    692711         
    693712        splitCandidate.mCorrectedBackVolume =  
    694                 mHierarchyManager->EvalCorrectedPvs(backVol, parentVol, avgRayContri); 
     713                mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeBackViewCells, parentVol, avgRayContri); 
    695714         
    696715        const float relfrontCost = splitCandidate.mCorrectedFrontVolume *  
     
    707726 
    708727        // increase in pvs entries 
    709         const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, avgRayContri); 
     728        const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate,  
     729                                                                                                  avgRayContri,  
     730                                                                                                  (int)pvs,  
     731                                                                                                  splitCandidate.mNumFrontViewCells,  
     732                                                                                                  splitCandidate.mNumBackViewCells); 
     733 
    710734        splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 
    711735 
     
    715739                 << " avg ray contri: " << avgRayContri << " ratio: " << oldRatio  
    716740                 << " parent: " << parentVol << " old vol: " << oldVolume  
    717                  << " frontvol: " << frontVol << " corr. " << splitCandidate.mCorrectedFrontVolume  
    718                  << " backvol: " << backVol << " corr. " << splitCandidate.mCorrectedBackVolume << endl; 
     741                 << " frontvol: " << splitCandidate.mVolumeFrontViewCells << " corr. " << splitCandidate.mCorrectedFrontVolume  
     742                 << " backvol: " << splitCandidate.mVolumeBackViewCells << " corr. " << splitCandidate.mCorrectedBackVolume << endl; 
    719743        } 
    720744 
     
    733757 
    734758#if STORE_VIEWCELLS_WITH_BVH 
    735         ReleaseViewCells(*splitCandidate.mParentData.mSortedObjects[3]); 
     759        ReleaseViewCells(*splitCandidate.mParentData.mSampledObjects); 
    736760#endif 
    737761 
     
    741765 
    742766int BvHierarchy::EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate,  
    743                                                                         const float avgRayContri) //const 
    744 { 
    745         const float oldPvsSize = (float)CountViewCells(splitCandidate.mParentData.mNode->mObjects); 
     767                                                                        const float avgRayContri, 
     768                                                                        const int numParentViewCells, 
     769                                                                        const int numFrontViewCells, 
     770                                                                        const int numBackViewCells) //const 
     771{ 
     772        const float oldPvsSize = (float)numParentViewCells;//CountViewCells(*splitCandidate.mParentData.mSampledObjects); 
    746773        const float oldPvsRatio = (splitCandidate.mParentData.mPvs > 0) ? oldPvsSize / splitCandidate.mParentData.mPvs : 1; 
    747774 
    748775        const float parentPvs = splitCandidate.mParentData.mCorrectedPvs * oldPvsRatio; 
    749776 
    750         const int frontViewCells = CountViewCells(splitCandidate.mFrontObjects); 
    751         const int backViewCells = CountViewCells(splitCandidate.mBackObjects); 
     777        const int frontViewCells = numFrontViewCells;//CountViewCells(splitCandidate.mSampledFrontObjects); 
     778        const int backViewCells = numBackViewCells;//CountViewCells(splitCandidate.mSampledBackObjects); 
    752779         
    753780        splitCandidate.mCorrectedFrontPvs =  
     
    9761003        const float cost = (tData.mNode->GetBoundingBox().Size().DrivingAxis() == axis) ? -1.0f : 0.0f; 
    9771004#else 
    978         const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 
     1005        const float oldRenderCost = EvalAbsCost(tData.mLeaf->mObjects) / EvalProbability(tData.mSampledObjects); 
    9791006        const float newRenderCost = EvalRenderCost(objectsFront) + EvalRenderCost(objectsBack); 
    9801007 
     
    11961223                Intersectable *obj = (*cit).mObject; 
    11971224 
    1198                 const float renderCost = mViewCellsManager->EvalRenderCost(obj); 
     1225                const float renderCost = ViewCellsManager::EvalRenderCost(obj); 
    11991226                 
    12001227                objectsLeft += renderCost; 
     
    13291356        float volRight = totalVol; 
    13301357         
    1331 #if USE_BETTER_RENDERCOST_EST 
     1358#if 1//USE_BETTER_RENDERCOST_EST 
    13321359        const float nTotalObjects = EvalAbsCost(tData.mNode->mObjects); 
    13331360        float nObjectsLeft = 0; 
     
    13861413                nObjectsLeft += rc; 
    13871414                nObjectsRight -= rc; 
    1388                  
    1389                 // split is only valid if #objects on left and right is not zero 
    1390                 const bool noValidSplit = ((nObjectsLeft <= Limits::Small) ||  
    1391                                                                    (nObjectsRight <= Limits::Small)); 
     1415         
    13921416#else 
    13931417                ++ nObjectsLeft; 
    13941418                -- nObjectsRight; 
    1395  
     1419#endif 
     1420         
    13961421                // split is only valid if #objects on left and right is not zero 
    1397                 const bool noValidSplit = !nObjectsLeft || !nObjectsRight; 
    1398  
    1399 #endif 
    1400                  
     1422                const bool noValidSplit = (nObjectsRight <= Limits::Small); 
     1423 
    14011424                // the heuristics 
    14021425            const float sum = noValidSplit ?  
     
    15311554 
    15321555         
    1533         CollectViewCells(tData.mNode->mObjects,  
     1556        CollectViewCells(*tData.mSampledObjects,  
    15341557                                         viewCells,  
    15351558                                         setCounter,  
     
    18511874        /////////////// 
    18521875        //-- render cost heuristics 
     1876        const float objRenderCost = EvalAbsCost(objects); 
    18531877 
    18541878        const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 
     
    18561880        // probability that view point lies in a view cell which sees this node 
    18571881        const float p = EvalViewCellsVolume(objects) / viewSpaceVol; 
    1858     const float objRenderCost = EvalAbsCost(objects); 
    18591882         
    18601883        return objRenderCost * p; 
     1884} 
     1885 
     1886 
     1887float BvHierarchy::EvalProbability(const ObjectContainer &objects)// const 
     1888{        
     1889        const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 
     1890         
     1891        // probability that view point lies in a view cell which sees this node 
     1892        return EvalViewCellsVolume(objects) / viewSpaceVol; 
    18611893} 
    18621894 
     
    19411973 
    19421974 
     1975int BvHierarchy::CollectViewCells(const ObjectContainer &objects,  
     1976                                                                  ViewCellContainer &viewCells, 
     1977                                                                  const bool setCounter, 
     1978                                                                  const bool onlyUnmailedRays)// const 
     1979{ 
     1980        ViewCell::NewMail(); 
     1981 
     1982        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     1983 
     1984        // use mailing to avoid dublicates 
     1985        const bool useMailBoxing = true; 
     1986 
     1987        int numRays = 0; 
     1988        // loop through all object and collect view cell pvs of this node 
     1989        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     1990        { 
     1991                // use mailing to avoid duplicates 
     1992                numRays += CollectViewCells(*oit, viewCells, useMailBoxing, setCounter, onlyUnmailedRays); 
     1993        } 
     1994 
     1995        return numRays; 
     1996} 
     1997 
    19431998 
    19441999#if STORE_VIEWCELLS_WITH_BVH 
     
    19532008                (*oit)->DelViewCells(); 
    19542009        } 
    1955  
    1956         DEL_PTR(mCachedObjects); 
    1957 } 
    1958  
    1959  
    1960 void BvHierarchy::AssociateViewCellsWithObjects(const ObjectContainer &objects)// const 
     2010} 
     2011 
     2012 
     2013void BvHierarchy::AssociateViewCellsWithObjects(const ObjectContainer &objects) const 
    19612014{ 
    19622015        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    19632016 
    19642017        const bool useMailBoxing = true; 
    1965  
    1966         mCachedObjects = new ObjectContainer(); 
     2018        VssRay::NewMail(); 
    19672019         
    19682020        for (oit = objects.begin(); oit != oit_end; ++ oit) 
    19692021        { 
    1970                 if (!(*oit)->GetOrCreateRays()->empty()) 
    1971                 { 
    19722022                        ViewCell::NewMail(); 
    19732023                        // use mailing to avoid duplicates 
    19742024                        AssociateViewCellsWithObject(*oit, useMailBoxing); 
    1975                          
    1976                         mCachedObjects->push_back(*oit); 
    1977                 } 
    19782025        } 
    19792026} 
     
    19822029int BvHierarchy::AssociateViewCellsWithObject(Intersectable *obj, const bool useMailBoxing) const 
    19832030{ 
     2031        int nRays = 0; 
     2032 
    19842033        if (!obj->GetOrCreateViewCells()->empty()) 
    19852034        { 
    1986                 cerr << "AssociateViewCellsWithObject: view cells cache error" << endl; 
    1987                 exit(0); 
     2035                cerr << "AssociateViewCellsWithObject: view cells cache not working" << endl; 
    19882036        } 
    19892037 
     
    20012049                //              continue; 
    20022050                mHierarchyManager->mVspTree->GetViewCells(*ray, *objViewCells); 
    2003         } 
    2004  
    2005         return (int)vssRays->size(); 
     2051                 
     2052                if (!useMailBoxing || !ray->Mailed()) 
     2053                { 
     2054                        if (useMailBoxing) 
     2055                                ray->Mail(); 
     2056 
     2057                        ++ nRays; 
     2058                } 
     2059        } 
     2060 
     2061        return nRays; 
    20062062} 
    20072063 
     
    20142070        if (obj->GetOrCreateViewCells()->empty()) 
    20152071        { 
    2016                 cerr << "h";//CountViewCells: view cells empty, view cells cache not working" << endl; 
     2072                //cerr << "h";//CountViewCells: view cells empty, view cells cache not working" << endl; 
    20172073                return CountViewCellsFromRays(obj); 
    20182074        } 
     
    21772233} 
    21782234 
    2179  
    2180 int BvHierarchy::CollectViewCells(const ObjectContainer &objects,  
    2181                                                                   ViewCellContainer &viewCells, 
    2182                                                                   const bool setCounter, 
    2183                                                                   const bool onlyUnmailedRays)// const 
    2184 { 
    2185         ViewCell::NewMail(); 
    2186  
    2187         // use mailing to avoid dublicates 
    2188         const bool useMailBoxing = true; 
    2189  
    2190         int numRays = 0; 
    2191  
    2192         if (mCachedObjects) 
    2193         { 
    2194                 ObjectContainer::const_iterator oit, oit_end = mCachedObjects->end(); 
    2195  
    2196                 // loop through all object and collect view cell pvs of this node 
    2197                 for (oit = mCachedObjects->begin(); oit != oit_end; ++ oit) 
    2198                 { 
    2199                         // use mailing to avoid duplicates 
    2200                         numRays += CollectViewCells(*oit, viewCells, useMailBoxing, setCounter, onlyUnmailedRays); 
    2201                 } 
    2202         } 
    2203         else 
    2204         { 
    2205                 ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    2206  
    2207                 // loop through all object and collect view cell pvs of this node 
    2208                 for (oit = objects.begin(); oit != oit_end; ++ oit) 
    2209                 { 
    2210                         // use mailing to avoid duplicates 
    2211                         numRays += CollectViewCellsFromRays(*oit, viewCells, useMailBoxing, setCounter, onlyUnmailedRays); 
    2212                 } 
    2213         } 
    2214  
    2215         return numRays; 
    2216 } 
    2217  
    2218  
    2219 int BvHierarchy::CountViewCells(const ObjectContainer &objects)// const 
    2220 { 
    2221         int nViewCells = 0; 
    2222  
    2223         ViewCell::NewMail(); 
    2224          
    2225         if (mCachedObjects) 
    2226         { 
    2227                 ObjectContainer::const_iterator oit, oit_end = mCachedObjects->end(); 
    2228  
    2229                 // loop through all object and collect view cell pvs of this node 
    2230                 for (oit = mCachedObjects->begin(); oit != oit_end; ++ oit) 
    2231                 { 
    2232                         // use mailing to avoid duplicates 
    2233                         nViewCells += CountViewCells(*oit); 
    2234                 } 
    2235         } 
    2236         else 
    2237         { 
    2238                 ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    2239  
    2240                 // loop through all object and collect view cell pvs of this node 
    2241                 for (oit = objects.begin(); oit != oit_end; ++ oit) 
    2242                 { 
    2243                         nViewCells += CountViewCellsFromRays(*oit); 
    2244                 } 
    2245         } 
    2246  
    2247         return nViewCells; 
    2248 } 
    2249  
    2250  
    22512235#else 
    2252  
    2253 int BvHierarchy::CollectViewCells(const ObjectContainer &objects,  
    2254                                                                   ViewCellContainer &viewCells, 
    2255                                                                   const bool setCounter, 
    2256                                                                   const bool onlyUnmailedRays)// const 
    2257 { 
    2258         ViewCell::NewMail(); 
    2259  
    2260         ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    2261  
    2262         // use mailing to avoid dublicates 
    2263         const bool useMailBoxing = true; 
    2264  
    2265         int numRays = 0; 
    2266         // loop through all object and collect view cell pvs of this node 
    2267         for (oit = objects.begin(); oit != oit_end; ++ oit) 
    2268         { 
    2269                 // use mailing to avoid duplicates 
    2270                 numRays += CollectViewCells(*oit, viewCells, useMailBoxing, setCounter, onlyUnmailedRays); 
    2271         } 
    2272  
    2273         return numRays; 
    2274 } 
    2275  
    2276  
    2277 int BvHierarchy::CountViewCells(const ObjectContainer &objects)// const 
    2278 { 
    2279         int nViewCells = 0; 
    2280  
    2281         ViewCell::NewMail(); 
    2282         ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    2283  
    2284         // loop through all object and collect view cell pvs of this node 
    2285         for (oit = objects.begin(); oit != oit_end; ++ oit) 
    2286         { 
    2287                 nViewCells += CountViewCells(*oit); 
    2288         } 
    2289  
    2290         return nViewCells; 
    2291 } 
    2292  
    22932236 
    22942237int BvHierarchy::CountViewCells(Intersectable *obj) //const 
     
    23772320 
    23782321 
     2322int BvHierarchy::CountViewCells(const ObjectContainer &objects)// const 
     2323{ 
     2324        int nViewCells = 0; 
     2325 
     2326        ViewCell::NewMail(); 
     2327        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     2328 
     2329        // loop through all object and collect view cell pvs of this node 
     2330        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     2331        { 
     2332                nViewCells += CountViewCells(*oit); 
     2333        } 
     2334 
     2335        return nViewCells; 
     2336} 
     2337 
    23792338 
    23802339void BvHierarchy::CollectDirtyCandidates(BvhSubdivisionCandidate *sc,  
     
    23872346        ViewCellContainer viewCells; 
    23882347        //ViewCell::NewMail(); 
    2389         int numRays = CollectViewCells(node->mObjects, viewCells, false, false); 
     2348        int numRays = CollectViewCells(*tData.mSampledObjects, viewCells, false, false); 
    23902349 
    23912350        if (0) cout << "collected " << (int)viewCells.size() << " dirty candidates" << endl; 
     
    24352394} 
    24362395 
    2437  
     2396#if 0 
    24382397BvhLeaf *BvHierarchy::GetLeaf(Intersectable *object, BvhNode *node) const 
    24392398{ 
    2440         // rather use the simple version 
     2399        // hack: we use the simpler but faster version 
    24412400        if (!object)  
    24422401                return NULL; 
     2402 
    24432403        return object->mBvhLeaf; 
    24442404         
    24452405        /////////////////////////////////////// 
    24462406        // start from root of tree 
    2447          
     2407        /* 
    24482408        if (node == NULL) 
    24492409                node = mRoot; 
     
    24892449   
    24902450        return leaf; 
    2491 } 
    2492  
     2451        */ 
     2452} 
     2453#endif 
    24932454 
    24942455bool BvHierarchy::Export(OUT_STREAM &stream) 
     
    25862547 
    25872548 
    2588 /* 
    2589 Mesh *BvHierarchy::MergeLeafToMesh() 
    2590 { 
    2591         vector<BvhLeaf *> leaves; 
    2592         CollectLeaves(leaves); 
    2593  
    2594         vector<BvhLeaf *>::const_iterator lit, lit_end = leaves.end(); 
    2595  
    2596         for (lit = leaves.begin(); lit != lit_end; ++ lit) 
    2597         { 
    2598                 Mesh *mesh = MergeLeafToMesh(*lit); 
    2599         } 
    2600 }*/ 
     2549void BvHierarchy::StoreSampledObjects(ObjectContainer &sampledObjects, const ObjectContainer &objects) 
     2550{ 
     2551        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     2552 
     2553        for (oit = objects.begin(); oit != objects.end(); ++ oit) 
     2554        { 
     2555                Intersectable *obj = *oit; 
     2556 
     2557                if (!obj->GetOrCreateRays()->empty()) 
     2558        { 
     2559                        sampledObjects.push_back(obj); 
     2560                } 
     2561        } 
     2562        } 
    26012563 
    26022564 
     
    26242586        //cout << "using " << nRays << " of " << (int)sampleRays.size() << " rays" << endl; 
    26252587         
     2588        ObjectContainer *sampledObjects = new ObjectContainer(); 
     2589        StoreSampledObjects(*sampledObjects, objects); 
     2590 
    26262591#if STORE_VIEWCELLS_WITH_BVH 
    2627         AssociateViewCellsWithObjects(objects); 
     2592        AssociateViewCellsWithObjects(*sampledObjects); 
    26282593#endif 
    26292594 
    26302595        // probability that volume is "seen" from the view cells 
    2631         const float prop = EvalViewCellsVolume(objects) / GetViewSpaceVolume(); 
     2596        const float prop = EvalViewCellsVolume(*sampledObjects) / GetViewSpaceVolume(); 
    26322597 
    26332598        // create bvh traversal data 
     
    26402605        } 
    26412606         
     2607        oData.mSampledObjects = sampledObjects; 
     2608         
    26422609        /////////////////// 
    26432610        //-- add first candidate for object space partition      
    26442611 
    26452612        mTotalCost = EvalRenderCost(objects); 
    2646         mPvsEntries = CountViewCells(objects); 
     2613        mPvsEntries = CountViewCells(*sampledObjects); 
    26472614 
    26482615        oData.mCorrectedPvs = oData.mPvs = (float)mPvsEntries; 
     
    26552622 
    26562623#if STORE_VIEWCELLS_WITH_BVH 
    2657         ReleaseViewCells(objects); 
     2624        ReleaseViewCells(*sampledObjects); 
    26582625#endif 
    26592626 
     
    27272694        } 
    27282695 
    2729         // last sorted list: by size 
     2696        // next sorted list: by size (for initial criteria) 
    27302697        tData.mSortedObjects[3] = new ObjectContainer(); 
    27312698        tData.mSortedObjects[3]->reserve((int)objects.size()); 
     
    27342701         
    27352702        stable_sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 
    2736         //sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 
    27372703} 
    27382704 
     
    27962762        mRoot = bvhleaf; 
    27972763         
     2764        ObjectContainer *sampledObjects = new ObjectContainer(); 
     2765        StoreSampledObjects(*sampledObjects, objects); 
     2766 
    27982767#if STORE_VIEWCELLS_WITH_BVH 
    2799         AssociateViewCellsWithObjects(objects); 
     2768        AssociateViewCellsWithObjects(*sampledObjects); 
    28002769#endif 
    28012770 
     
    28032772        // probability that volume is "seen" from the view cells 
    28042773        const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 
    2805         const float prop = EvalViewCellsVolume(objects); 
    2806  
    2807         const int nRays = CountRays(objects); 
     2774        const float prop = EvalViewCellsVolume(*sampledObjects); 
     2775 
     2776        const int nRays = CountRays(*sampledObjects); 
    28082777        BvhLeaf *bvhLeaf = static_cast<BvhLeaf *>(mRoot); 
    28092778 
     
    28112780        BvhTraversalData oData(bvhLeaf, 0, prop, nRays); 
    28122781 
     2782        oData.mSampledObjects = sampledObjects; 
     2783 
    28132784        if (mUseGlobalSorting) 
    28142785                AssignInitialSortedObjectList(oData, objects); 
    28152786         
    28162787#if STORE_VIEWCELLS_WITH_BVH 
    2817         ReleaseViewCells(objects); 
     2788        ReleaseViewCells(*sampledObjects); 
    28182789#endif 
    28192790        /////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r2206 r2210  
    407407                mPvs(0), 
    408408                mCorrectedVolume(0), 
    409                 mVolume(v) 
     409                mVolume(v), 
     410                mSampledObjects(NULL) 
    410411                { 
    411412                        for (int i = 0; i < 4; ++ i) 
     
    420421                        for (int i = 0; i < 4; ++ i) 
    421422                                DEL_PTR(mSortedObjects[i]); 
     423 
     424                        DEL_PTR(mSampledObjects); 
    422425                } 
    423426 
     
    441444                float mCorrectedPvs; 
    442445 
    443                 /// the sorted objects for the three dimensions 
     446                /** the sorted objects for the three dimensions + one for the original 
     447                        order + one for the objects which have been sampled at least once 
     448                */ 
    444449                ObjectContainer *mSortedObjects[4];              
     450                ObjectContainer *mSampledObjects;        
    445451    }; 
    446452 
     
    511517                ObjectContainer mBackObjects; 
    512518                         
     519                /// the sampled objects on the front of the potential split 
     520                ObjectContainer mSampledFrontObjects; 
     521                /// the sampled objects on the back of the potential split 
     522                ObjectContainer mSampledBackObjects; 
     523 
    513524                float mCorrectedFrontPvs; 
    514525                float mCorrectedBackPvs; 
     
    516527                float mCorrectedFrontVolume; 
    517528                float mCorrectedBackVolume; 
     529 
     530                //int mNumFrontRays; 
     531                //int mNumBackRays; 
     532                 
     533                int mNumFrontViewCells; 
     534                int mNumBackViewCells; 
     535 
     536                float mVolumeFrontViewCells; 
     537                float mVolumeBackViewCells; 
    518538        }; 
    519539 
     
    620640        /** Returns leaf the point pt lies in, starting from root. 
    621641        */ 
    622         BvhLeaf *GetLeaf(Intersectable *obj, BvhNode *root = NULL) const; 
     642        inline BvhLeaf *GetLeaf(Intersectable *object, BvhNode *root = NULL) const 
     643        { 
     644                // hack: we use the simpler but faster version 
     645                if (!object)  
     646                        return NULL; 
     647 
     648                return object->mBvhLeaf; 
     649        } 
    623650 
    624651        /** Sets a pointer to the view cells tree. 
     
    638665        void SetActive(BvhNode *node) const; 
    639666 
     667 
     668        void StoreSampledObjects(ObjectContainer &sampledObjects, const ObjectContainer &objects); 
    640669 
    641670        /////////////////////////// 
     
    711740        float EvalRenderCost(const ObjectContainer &objects);// const; 
    712741 
     742        float EvalProbability(const ObjectContainer &objects); 
     743 
    713744        /** Evaluates tree stats in the BSP tree leafs. 
    714745        */ 
     
    860891        int AssociateViewCellsWithObject(Intersectable *obj, const bool useMailBoxing) const; 
    861892 
    862         void AssociateViewCellsWithObjects(const ObjectContainer &objects);// const; 
     893        void AssociateViewCellsWithObjects(const ObjectContainer &objects) const; 
    863894 
    864895        void ReleaseViewCells(const ObjectContainer &objects); 
     
    876907        */ 
    877908        int EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate,  
    878                                                    const float avgRayContri);// const; 
     909                                                   const float avgRayContri, 
     910                                                   const int numParentViewCells, 
     911                                                   const int numFrontViewCells, 
     912                                                   const int numBackViewCells);// const; 
    879913 
    880914        /** Rays will be clipped to the bounding box. 
     
    9751009        HierarchyManager *mHierarchyManager; 
    9761010 
    977  
    978         ObjectContainer *mCachedObjects; 
    9791011 
    9801012        //////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r2206 r2210  
    25242524        // delete old "base" view cells: only pvss in the leaves are allowed 
    25252525        ViewCellContainer::const_iterator oit, oit_end = mOldViewCells.end(); 
     2526 
    25262527        for (oit = mOldViewCells.begin(); oit != oit_end; ++ oit) 
    25272528        { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp

    r2172 r2210  
    9292                Intersectable *newObject = vssRays[i]->mTerminationObject; 
    9393 
    94                 Intersectable *oldObject =mRays[vssRays[i]->mGeneratorId].mRay->mTerminationObject; 
     94                Intersectable *oldObject = mRays[vssRays[i]->mGeneratorId].mRay->mTerminationObject; 
    9595                 
    9696                if (oldObject == newObject) 
     
    600600  //rr[0] = RandomValue(0,1); 
    601601  // use binary search to find index with this cdf 
    602   int l=0, r=mRays.size()-1; 
     602  int l=0, r=(int)mRays.size()-1; 
    603603  while(l<r) { 
    604604        int i = (l+r)/2; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r2205 r2210  
    438438 
    439439 
    440   // has to called before first usage 
     440/******************************************************************/ 
     441/*           class MixtureDistribution implementation             */ 
     442/******************************************************************/ 
     443 
     444 
     445// has to be called before first usage 
    441446void 
    442447MixtureDistribution::Init() 
     
    683688} 
    684689 
     690 
    685691bool HwGlobalLinesDistribution::GenerateSample(SimpleRay &ray)  
    686692{ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r2205 r2210  
    238238{  
    239239        const bool result = mPvs.AddSample(sample, pdf); 
    240         // have to recompute pvs size 
     240        // we have to recompute pvs size 
    241241        mPvsSizeValid = false; 
    242242 
     
    515515        ///////////// 
    516516        //-- fill merge queue 
     517 
    517518        vector<MergeCandidate> candidates; 
    518519 
     
    527528        } 
    528529 
    529         Debug << "************************* merge ***********************************" << endl;   
     530        Debug << "********************** merge ******************************" << endl;   
    530531        Debug << "deviation: " << mDeviation << endl; 
    531532        Debug << "avg render cost: " << mAvgRenderCost << endl; 
     
    648649                        totalRenderCost += renderCostIncr; 
    649650                        mDeviation += mc.GetDeviationIncr(); 
    650  
    651                                                  
     651                         
     652                        /////////// 
    652653                        //-- merge the view cells of leaf1 and leaf2 
     654 
    653655                        float pvsDiff; 
    654656                        ViewCellInterior *mergedVc =  
     
    834836                if (!obj->Mailed()) 
    835837                { 
    836                         renderCost += mViewCellsManager->EvalRenderCost(obj); 
     838                        renderCost += ViewCellsManager::EvalRenderCost(obj); 
    837839                } 
    838840        } 
     
    10281030                // set scalars 
    10291031                mViewCellsManager->UpdateScalarPvsSize(right,  
    1030                         right->GetPvs().EvalPvsCost(),  
    1031                         right->GetPvs().GetSize()); 
     1032                                                                                           right->GetPvs().EvalPvsCost(),  
     1033                                                                                           right->GetPvs().GetSize()); 
    10321034 
    10331035                right->mPvsSizeValid = true; 
     
    18041806                return vc->GetPvs().GetSize(); 
    18051807        } 
    1806          
    1807         // interior node 
    18081808 
    18091809        // interior nodes: pvs is either stored as a scalar or 
     
    19871987        Intersectable::NewMail(); 
    19881988 
    1989         //////////////////////////////////////////////// 
    1990         // for interiors, pvs can be stored using different methods 
     1989        ///////////////////////// 
     1990        //-- different storage methods for interiors 
    19911991         
    19921992        switch (mViewCellsStorage) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r2206 r2210  
    881881                                                                                        splitCandidate.GetAvgRayContribution()); 
    882882         
     883        splitCandidate.mFrontPvs = fPvsSize; 
     884        splitCandidate.mBackPvs = bPvsSize; 
     885 
    883886        if (0) 
    884887        cout << "vsp pvs" 
     
    902905 
    903906        const VspTraversalData &tData = sc.mParentData; 
    904         const AxisAlignedPlane splitPlane = sc.mSplitPlane; 
     907        const AxisAlignedPlane &splitPlane = sc.mSplitPlane; 
    905908 
    906909        /////////////// 
     
    917920 
    918921        //-- compute pvs 
    919         frontData.mPvs = (float)EvalPvsEntriesSize(*frontData.mRays); 
    920         backData.mPvs = (float)EvalPvsEntriesSize(*backData.mRays); 
     922        frontData.mPvs = sc.mFrontPvs;//(float)EvalPvsEntriesSize(*frontData.mRays); 
     923        backData.mPvs = sc.mBackPvs;//(float)EvalPvsEntriesSize(*backData.mRays); 
    921924         
    922925        //-- compute pvs correction for coping with undersampling 
     
    934937 
    935938        //-- compute render cost 
    936         frontData.mRenderCost = (float)EvalPvsCost(*frontData.mRays); 
    937         backData.mRenderCost = (float)EvalPvsCost(*backData.mRays); 
     939        frontData.mRenderCost = sc.mFrontRenderCost;//(float)EvalPvsCost(*frontData.mRays); 
     940        backData.mRenderCost = sc.mBackRenderCost;//(float)EvalPvsCost(*backData.mRays); 
    938941         
    939942        frontData.mCorrectedRenderCost = sc.mCorrectedFrontRenderCost; 
     
    12751278        const float maxBand = minBox + mMaxBand * sizeBox; 
    12761279 
     1280        // sort by the current dimension 
    12771281        SortSubdivisionCandidates(usedRays, axis, minBand, maxBand); 
    12781282 
     
    15891593        sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs(pvsBack, penaltyOld, avgRayContri); 
    15901594 
     1595        sc.mFrontRenderCost = pvsFront; 
     1596        sc.mBackRenderCost = pvsBack; 
     1597 
    15911598        const float oldRenderCost = pOverall * penaltyOld; 
    15921599        const float newRenderCost = sc.mCorrectedFrontRenderCost * pFront +  
     
    17271734 
    17281735        const float renderCost = countEntries ? 1 :  
    1729                 mHierarchyManager->mBvHierarchy->EvalAbsCost(leaf->mObjects); 
     1736                mBvHierarchy->EvalAbsCost(leaf->mObjects); 
    17301737         
    17311738        // leaf in no pvs => new 
     
    22862293        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
    22872294                { 
    2288                         BvhLeaf *bvhleaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     2295                        BvhLeaf *bvhleaf = mBvHierarchy->GetLeaf(obj); 
    22892296 
    22902297                        if (!bvhleaf->Mailed()) 
     
    29012908        VspSubdivisionCandidate::sVspTree = this; 
    29022909         
     2910        mBvHierarchy = mHierarchyManager->mBvHierarchy; 
     2911 
    29032912        // initialise termination criteria 
    29042913        mTermMinProbability *= mBoundingBox.GetVolume(); 
     
    29692978        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
    29702979                { 
    2971                         BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     2980                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    29722981 
    29732982                        if (!leaf->Mailed()) 
     
    30493058        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
    30503059                { 
    3051                         BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     3060                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    30523061 
    30533062                        if (-- leaf->mCounter == 0) 
     
    30983107        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
    30993108                { 
    3100                         BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     3109                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    31013110 
    31023111                        if (!leaf->Mailed()) 
     
    31513160        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
    31523161                { 
    3153                         BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     3162                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    31543163                        if (!leaf->Mailed()) 
    31553164                        { 
     
    31983207                case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
    31993208                { 
    3200                         BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     3209                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    32013210                        UpdateContributionsToPvs(leaf, cf, frontPvs, backPvs, totalPvs, false); 
    32023211                        break; 
     
    32273236        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
    32283237                { 
    3229                         BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     3238                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    32303239                        UpdateContributionsToPvs(leaf, cf, pvsFront, pvsBack, totalPvs, true); 
    32313240                        break; 
     
    32693278        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
    32703279                { 
    3271                         BvhLeaf *bvhleaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     3280                        BvhLeaf *bvhleaf = mBvHierarchy->GetLeaf(obj); 
    32723281 
    32733282                        if (!bvhleaf->Mailed()) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r2199 r2210  
    551551                float mCorrectedBackPvs; 
    552552 
     553                float mFrontPvs; 
     554                float mBackPvs; 
     555 
    553556                float mCorrectedFrontRenderCost; 
    554557                float mCorrectedBackRenderCost; 
    555                 float mCorrectedFrontVolume; 
    556                 float mCorrectedBackVolume; 
     558                //float mCorrectedFrontVolume; 
     559                //float mCorrectedBackVolume; 
     560 
     561                float mFrontRenderCost; 
     562                float mBackRenderCost; 
    557563        }; 
    558564 
     
    10921098 
    10931099        HierarchyManager *mHierarchyManager; 
     1100        BvHierarchy *mBvHierarchy; 
     1101 
    10941102        //OspTree *mOspTree; 
    10951103        //bool mUseKdPvsForHeuristics; 
Note: See TracChangeset for help on using the changeset viewer.