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

improved performance of osp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        /////////////////// 
Note: See TracChangeset for help on using the changeset viewer.