Changeset 1790


Ignore:
Timestamp:
11/25/06 04:07:13 (18 years ago)
Author:
mattausch
Message:

implemented dirty pvs and lazy update

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
4 edited

Legend:

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

    r1789 r1790  
    15541554 
    15551555                        // no good results for degenerate axis split 
    1556                         if (0 && tData.mNode->GetBoundingBox().Size(axis) < Limits::Small) 
     1556                        if (0 && 
     1557                                (tData.mNode->GetBoundingBox().Size(axis) < Limits::Small)) 
    15571558                                        nCostRatio[axis] += 9999; 
    15581559 
     
    25492550 
    25502551                if (!InitialTerminationCriteriaMet(bsc->mParentData)) 
    2551                 {cout << "here9"<<endl; 
     2552                { 
    25522553                        BvhNode *node = Subdivide(tempQueue, bsc, globalCriteriaMet); 
    25532554 
     
    25562557                } 
    25572558                else // initial preprocessing  finished for this candidate 
    2558                 {cout << "here19"<<endl; 
     2559                { 
    25592560                        // add to "real" traversal queue 
    25602561                        candidateContainer.push_back(bsc); 
     
    26082609                backObjects.push_back(*oit); 
    26092610        } 
    2610         TriangleIntersectable *tObj1 = (TriangleIntersectable *)frontObjects.back(); 
    2611         TriangleIntersectable *tObj2 = (TriangleIntersectable *)backObjects.front(); 
    2612  
    2613         cout << "here4 " << tObj1->GetItem().GetArea() << " " << tObj2->GetItem().GetArea() << endl; 
    2614  
    2615  
    2616 if (maxAreaDiff < 0.0001) 
    2617 cout << "big error!!!! " << maxAreaDiff << endl; 
    2618  
     2611         
    26192612        cout << "front: " << (int)frontObjects.size() << " back " << (int)backObjects.size() << " " << backObjects.front()->GetBox().SurfaceArea() - frontObjects.back()->GetBox().SurfaceArea() << endl; 
    26202613} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1789 r1790  
    206206                @returns iterator on the sample. 
    207207        */ 
    208         typename vector<PvsEntry<T, S> >::iterator Find(T sample, const bool checkDirty = true); 
     208        bool Find(T sample, 
     209                          typename vector<PvsEntry<T, S> >::iterator &it, 
     210                          const bool checkDirty = true); 
    209211 
    210212        bool GetSampleContribution(T sample, const float pdf, float &contribution); 
     
    391393                float aSumPdf = 0.0f; 
    392394 
    393                 vector<PvsEntry<T, S> >::iterator oit = Find((*it).mObject);             
    394  
    395                 const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject); 
     395                vector<PvsEntry<T, S> >::iterator oit; 
     396                const bool entryFound = Find((*it).mObject, oit);                
    396397 
    397398                if (entryFound) 
     
    427428                        (*it).mData.mSumPdf = -aSumPdf; 
    428429                } else { 
    429                         vector<PvsEntry<T, S> >::iterator oit = b.Find((*it).mObject); 
    430  
    431                         const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject); 
    432                          
     430                        vector<PvsEntry<T, S> >::iterator oit; 
     431                 
     432                        const bool entryFound = b.Find((*it).mObject, oit); 
     433                                                 
    433434                        if (entryFound) { 
    434435                                bSumPdf = (*oit).mData.mSumPdf; 
     
    461462        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
    462463        { 
    463                 std::vector<PvsEntry<T, S> >::const_iterator bit = Find((*it).first);            
    464                 if (bit == mEntries.end()) ++ dif; 
     464                vector<PvsEntry<T, S> >::iterator bit; 
     465                const bool entryFound = Find((*it).first, bit); 
     466 
     467                if (!entryFound) ++ dif; 
    465468        } 
    466469 
     
    586589 
    587590template <typename T, typename S>  
    588 typename std::vector<PvsEntry<T, S> >::iterator Pvs<T, S>::Find(T sample, const bool checkDirty) 
    589 { 
     591bool Pvs<T, S>::Find(T sample, 
     592                                         typename vector<PvsEntry<T, S> >::iterator &it, 
     593                                         const bool checkDirty) 
     594{ 
     595        bool found = false; 
     596 
    590597        PvsEntry<T, S> dummy(sample, PvsData()); 
    591598 
     
    593600        //mLastSorted = 0; 
    594601        vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 
    595 if (sorted_end != mEntries.end()) 
    596 cout << "not entries end!! " << endl; 
     602 
    597603        // binary search 
    598         vector<PvsEntry<T, S> >::iterator it = lower_bound(mEntries.begin(), sorted_end, dummy); 
     604        it = lower_bound(mEntries.begin(), sorted_end, dummy); 
     605 
     606        if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     607                found = true; 
    599608 
    600609        // sample not found yet => search further in the unsorted part 
    601         if (checkDirty && 
    602                 ((it == mEntries.end()) || ((*it).mObject != sample))) 
    603         { 
    604                 vector<PvsEntry<T, S> >::const_iterator it_end = mEntries.end(); 
    605                 for (it = sorted_end; (it != it_end) && ((*it).mObject != sample); ++ it); 
    606         } 
    607         else cout << "f "; 
    608         return it; 
     610        if (!found && checkDirty) 
     611        { 
     612                vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 
     613 
     614                for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit); 
     615 
     616                if ((dit != mEntries.end()) && ((*dit).mObject == sample)) 
     617                        found = true; 
     618        } 
     619         
     620        return found; 
    609621} 
    610622 
     
    625637{ 
    626638        ++ mSamples; 
    627         cout << "! "; 
    628         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    629  
    630         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
    631         {       cout << "g"; 
     639         
     640        vector<PvsEntry<T, S> >::iterator it; 
     641        const bool entryFound = Find(sample, it);                
     642 
     643        if (entryFound) 
     644        {        
    632645                S &data = (*it).mData; 
    633646                data.mSumPdf += pdf; 
     
    635648        } 
    636649        else  
    637         {cout << "t"; 
     650        { 
    638651                PvsEntry<T, S> entry(sample, pdf); 
    639652                mEntries.insert(it, entry); 
     
    641654                return pdf; 
    642655        } 
    643         cout << " $"; 
    644656} 
    645657 
     
    654666 
    655667template <typename T, typename S> 
    656 typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample, const float pdf) 
     668typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample,  
     669                                                                                                                                  const float pdf) 
    657670{ 
    658671        ++ mSamples; 
    659672         
    660         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    661  
    662         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     673        vector<PvsEntry<T, S> >::iterator it; 
     674        const bool entryFound == Find(sample, it); 
     675 
     676        if (entryFound) 
    663677        { 
    664678                S &data = (*it).second; 
     
    674688        return it; 
    675689} 
    676  
    677  
    678 /*template <typename T, typename S>  
    679 bool Pvs<T, S>::AddSample(T sample, 
    680                                                   const float pdf, 
    681                                                   float &contribution) 
    682 { 
    683         ++ mSamples; 
    684  
    685         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    686  
    687         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
    688         { 
    689                 S &data = (*it).mData; 
    690  
    691                 data.mSumPdf += pdf; 
    692                 contribution = pdf / data.mSumPdf; 
    693  
    694                 return false; 
    695         } 
    696         else  
    697         { 
    698                 PvsEntry<T, S> entry(sample, pdf); 
    699  
    700                 mEntries.insert(it, entry); 
    701                 contribution = 1.0f; 
    702                 ++ mLastSorted; 
    703  
    704                 return true; 
    705         } 
    706 }*/ 
    707690 
    708691 
     
    717700        ++ mSamples; 
    718701 
    719         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    720  
    721         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     702        vector<PvsEntry<T, S> >::iterator it; 
     703        const bool entryFound = Find(sample, it); 
     704 
     705        if (entryFound) 
    722706        { 
    723707                S &data = (*it).mData; 
     
    743727                                                                          float &contribution)  
    744728{ 
    745         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    746  
    747         if (it != mEntries.end() && ((*it).mObject == sample))   
     729        vector<PvsEntry<T, S> >::iterator it; 
     730        const bool entryFound = Find(sample, it); 
     731 
     732        if (entryFound)   
    748733        { 
    749734                S &data = (*it).mData; 
     
    764749        -- mSamples; 
    765750         
    766         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    767  
    768         if (it == mEntries.end()) 
     751        vector<PvsEntry<T, S> >::iterator it; 
     752        const bool entryFound = Find(sample, it); 
     753 
     754        if (!entryFound) 
    769755                return false; 
    770756 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r1789 r1790  
    26942694        for (it = rays.begin(); it != it_end; ++ it) 
    26952695        { 
    2696                 int contribution = 0; 
     2696                float contribution = 0; 
    26972697                Ray *ray = (*it)->mRay; 
    26982698                float relContribution; 
     
    27072707                                                                                                   //relContribution); 
    27082708                 
    2709                 if (contribution) 
    2710                 { 
    2711                         sampleContributions += contribution; 
     2709                if (contribution >  0) 
     2710                { 
     2711                        sampleContributions += (int)contribution; 
    27122712                        ++ contributingSamples; 
    27132713                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1789 r1790  
    19561956} 
    19571957 
    1958 /* 
    1959 void 
    1960 ViewCellsManager::AddSampleContributions(const VssRayContainer &rays) 
    1961 { 
    1962   if (!ViewCellsConstructed()) 
    1963         return; 
    1964  
    1965   VssRayContainer::const_iterator it, it_end = rays.end(); 
    1966 cout <<"here60"<<endl; 
    1967   for (it = rays.begin(); it != it_end; ++ it) { 
    1968         AddSampleContributions(*(*it)); 
    1969   } 
    1970 } 
    1971 */ 
    19721958 
    19731959int ViewCellsManager::GetMinPvsSize() const 
     
    19831969} 
    19841970 
    1985 /* 
    1986 void 
    1987 ViewCellsManager::AddSampleContributions(VssRay &ray) 
    1988 {cout << "here12" << endl; 
    1989         // assumes viewcells have been stored... 
    1990         ViewCellContainer *viewcells = &ray.mViewCells; 
    1991         ViewCellContainer::const_iterator it; 
    1992  
    1993         if (!ray.mTerminationObject) 
    1994                 return; 
    1995  
    1996         Intersectable *obj = GetIntersectable(ray, true); 
    1997  
    1998         for (it = viewcells->begin(); it != viewcells->end(); ++it)  
    1999         { 
    2000                 ViewCell *viewcell = *it; 
    2001                 if (viewcell->GetValid())  
    2002                 { 
    2003                         Intersectable *entry = GetIntersectable(ray, true); 
    2004                         if (entry)     
    2005                                 // if ray not outside of view space 
    2006                                 viewcell->GetPvs().AddSample(entry, ray.mPdf); 
    2007                 } 
    2008         } 
    2009 } 
    2010 */ 
    20111971 
    20121972float ViewCellsManager::ComputeSampleContribution(VssRay &ray, 
    20131973                                                                                                  const bool addRays, 
    20141974                                                                                                  const bool storeViewCells) 
    2015 {cout << "$$$$$$$$$$$$$4here10" << endl; 
     1975{ 
    20161976        ViewCellContainer viewcells; 
    20171977 
     
    60416001         
    60426002 
     6003#define PVS_ADD_DIRTY 1 
    60436004float VspOspViewCellsManager::ComputeSampleContribution(VssRay &ray, 
    60446005                                                                                                                const bool addRays, 
     
    60946055                        { 
    60956056                                // todo: maybe not correct for kd node pvs 
    6096                         /*      if (viewcell->GetPvs().GetSampleContribution( 
    6097                                         terminationObj, ray.mPdf, contribution)) 
     6057                                if (viewcell->GetPvs().GetSampleContribution( 
     6058                                                        terminationObj, ray.mPdf, contribution)) 
    60986059                                { 
    60996060                                        ++ ray.mPvsContribution; 
    61006061                                } 
    6101                                 ray.mRelativePvsContribution += contribution;*/ 
     6062 
     6063                                ray.mRelativePvsContribution += contribution; 
    61026064                        } 
    61036065 
     
    61096071#if SAMPLE_ORIGIN_OBJECTS 
    61106072 
    6111                 /*      if (originObj &&  
     6073                        if (originObj &&  
    61126074                                viewcell->GetPvs().GetSampleContribution(originObj, 
    61136075                                                                                                                 ray.mPdf, 
     
    61166078                                ++ ray.mPvsContribution; 
    61176079                                ray.mRelativePvsContribution += contribution; 
    6118                         }*/ 
     6080                        } 
    61196081#endif 
    61206082                } 
     
    61356097 
    61366098                //$$JB hack 
    6137                 float contrib; 
    6138                 //viewCell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf, contrib); 
    6139                 viewCell->GetPvs().AddSample(terminationObj, ray.mPdf);//, contrib); 
    6140  
    6141                 if (viewCell->GetPvs().GetSize() == 50) 
    6142                 //if (viewCell->GetPvs().RequiresResort()) 
    6143                 {Intersectable::NewMail(); 
    6144                 cout << "\nbefore sort: " << viewCell->GetPvs().GetLastSorted() << " \n"; 
    6145                         ObjectPvsIterator pit = viewCell->GetPvs().GetIterator(); int i = 0; 
    6146                         while (pit.HasMoreEntries()) 
    6147                         {                
    6148                                 ObjectPvsEntry entry = pit.Next(); 
    6149                 Intersectable *object = entry.mObject; 
    6150  
    6151                                 if ((i ++) == viewCell->GetPvs().GetLastSorted()) 
    6152                                         cout << "| "; 
    6153                                  
    6154                                 //if (object->Mailed()) cout << "error!!"<<endl; 
    6155                                 object->Mail(); 
    6156                                 cout << (int)object << " "; 
    6157                         } 
    6158  
    6159                         //viewCell->GetPvs().Sort(); 
    6160                          
    6161                         /*cout << "\nafter sort\n"; 
    6162                         pit = viewCell->GetPvs().GetIterator(); i = 0; 
    6163                         while (pit.HasMoreEntries()) 
    6164                         {                
    6165                                 ObjectPvsEntry entry = pit.Next(); 
    6166                 Intersectable *object = entry.mObject; 
    6167  
    6168                                 if ((i ++) == viewCell->GetPvs().GetLastSorted()) 
    6169                                         cout << "| ";    
    6170                                 cout << (int)object << " "; 
    6171                         }*/ 
    6172                 } 
    6173                 //else cout << "b"; 
     6099 
     6100#if PVS_ADD_DIRTY 
     6101                viewCell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 
     6102#else 
     6103                viewCell->GetPvs().AddSample(terminationObj, ray.mPdf); 
     6104#endif 
     6105 
    61746106#if SAMPLE_ORIGIN_OBJECTS 
    6175                 //viewCell->GetPvs().AddSample(originObj, ray.mPdf); 
     6107#if PVS_ADD_DIRTY 
     6108                viewCell->GetPvs().AddSampleDirtyCheck(originObj, ray.mPdf); 
     6109#else 
     6110                viewCell->GetPvs().AddSample(originObj, ray.mPdf); 
    61766111#endif 
     6112#endif 
     6113                if (viewCell->GetPvs().RequiresResort()) 
     6114                { 
     6115                        viewCell->GetPvs().Sort();                       
     6116                } 
    61776117        } 
    61786118 
     
    63106250                        ////////////// 
    63116251                        // filtered stats 
     6252 
    63126253                        sprintf(suffix, "-%09d-eval-filter.log", castSamples); 
    63136254                        const string filename2 = string(statsPrefix) + string(suffix); 
Note: See TracChangeset for help on using the changeset viewer.