Changeset 1738


Ignore:
Timestamp:
11/10/06 02:09:56 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
6 edited

Legend:

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

    r1736 r1738  
    266266{ 
    267267        SubdivisionCandidate *splitCandidate = splitQueue.Top(); 
     268 
     269        if (splitCandidate->IsDirty()) 
     270                splitCandidate->EvalCandidate(); 
     271 
    268272        splitQueue.Pop(); 
    269273 
     
    18371841 
    18381842                // hack: should not be done here 
    1839                 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
     1843                ObjectPvsEntries::const_iterator oit, oit_end = pvs.mEntries.end(); 
    18401844 
    18411845                for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
     
    19371941                { 
    19381942                        subStats.mTotalRenderCost -= subStats.mRenderCostDecrease; 
    1939                         subStats.mEntriesInPvs += entriesIncr; 
     1943                        //subStats.mEntriesInPvs += entriesIncr; 
    19401944 
    19411945                        // if (rcDecr <= 0) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp

    r1707 r1738  
    131131 
    132132 
    133  
    134133float ObjectPvs::EvalPvsCost() const 
    135134{ 
     
    140139        BvhLeaf::NewMail(); 
    141140 
    142         ObjectPvsMap::const_iterator it, it_end = mEntries.end(); 
     141        ObjectPvsEntries::const_iterator it, it_end = mEntries.end(); 
    143142 
    144143        for (it = mEntries.begin(); it != it_end; ++ it) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1737 r1738  
    8989}; 
    9090 
    91  
    9291/** Template class representing the Potentially Visible Set (PVS)  
    9392        mainly from a view cell, but also e.g., from objects. 
     
    9796{ 
    9897public: 
     98//vector<pair<T, S> >::iterator mItEnd; 
     99        template<typename T, typename S> 
     100        class Iterator 
     101        { 
     102                //template<typename T, typename S> friend Pvs<T, S>; 
     103        private: 
     104                //std::vector<std::pair<T, S> >::iterator mIt; 
     105                //vector<pair<T, S> >::iterator mItEnd; 
     106        }; 
     107 
     108        template<typename T, typename S> 
     109        class ConstIterator 
     110        { 
     111        //      template<typename T, typename S> friend Pvs<T, S>; 
     112        private: 
     113                //vector<pair<T, S> >::const_iterator mIt; 
     114                //vector<pair<T, S> >::const_iteator mItEnd; 
     115        }; 
     116 
    99117  Pvs(): mSamples(0), mEntries() {} 
    100118   
     
    185203        /** Compute continuous PVS difference */ 
    186204        float GetPvsHomogenity(Pvs<T, S> &pvs) { 
    187                 float  
    188                         pvsReduction, 
    189                         pvsEnlargement; 
     205                float pvsReduction, pvsEnlargement; 
    190206 
    191207                ComputeContinuousPvsDifference(pvs, 
     
    198214        int Size() { return mEntries.size(); } 
    199215 
    200         /// Map of PVS entries 
    201         std::map<T, S, LtSample<T> > mEntries; 
    202         //vector<pair<T, S> > mEntries;  
     216        //vector<pair<T, S> >::const_iterator &GetConstIterator() const { return mEntries.begin(); } 
     217        //vector<pair<T, S> >::iterator &GetIterator() { return mEntries.begin(); } 
     218 
     219//protected: 
     220 
     221        /// vector of PVS entries 
     222        vector<pair<T, S> > mEntries;  
    203223         
    204224        /// Number of samples used to create the PVS 
     
    221241        pvsReduction = 0.0f; 
    222242        pvsEnlargement = 0.0f; 
    223   // Uses sum of log differences, which corresponds to entropy 
    224   std::map<T, S, LtSample<T> >::iterator it; 
    225    
    226   for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)  
    227   { 
    228         float bSumPdf = (*it).second.mSumPdf; 
    229         float aSumPdf = 0.0f; 
    230         S *data = Find((*it).first);             
    231          
    232         if (data)  
    233         { 
    234                 aSumPdf = data->mSumPdf; 
    235                 // mark this entry as processed to avoid double counting 
    236                 data->mSumPdf = -aSumPdf; 
    237         } 
     243        // Uses sum of log differences, which corresponds to entropy 
     244        std::vector<pair<T, S> >::iterator it; 
     245 
     246        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)  
     247        { 
     248                float bSumPdf = (*it).second.mSumPdf; 
     249                float aSumPdf = 0.0f; 
     250                S *data = Find((*it).first);             
     251 
     252                if (data)  
     253                { 
     254                        aSumPdf = data->mSumPdf; 
     255                        // mark this entry as processed to avoid double counting 
     256                        data->mSumPdf = -aSumPdf; 
     257                } 
    238258 
    239259#if 0 
    240         float diff = bSumPdf - aSumPdf; 
    241          
    242         if (diff > 0.0f) { 
    243           pvsEnlargement += diff; 
    244         } else { 
    245           pvsReduction += -diff; 
    246         } 
     260                float diff = bSumPdf - aSumPdf; 
     261 
     262                if (diff > 0.0f) { 
     263                        pvsEnlargement += diff; 
     264                } else { 
     265                        pvsReduction += -diff; 
     266                } 
    247267#else 
    248         if (!data) 
    249           pvsEnlargement += 1.0f; 
    250 #endif 
    251   } 
    252    
    253   for (it = mEntries.begin(); it != mEntries.end(); ++ it) { 
    254         float aSumPdf = (*it).second.mSumPdf; 
    255         float bSumPdf = 0.0f; 
    256         if (aSumPdf < 0.0f) { 
    257           // this entry was already accounted for! 
    258           // just revert it back 
    259           (*it).second.mSumPdf = -aSumPdf; 
    260         } else { 
    261           S *data = b.Find((*it).first); 
    262           if (data) { 
    263                 bSumPdf = data->mSumPdf; 
    264           } 
     268                if (!data) 
     269                        pvsEnlargement += 1.0f; 
     270#endif 
     271        } 
     272 
     273        for (it = mEntries.begin(); it != mEntries.end(); ++ it) { 
     274                float aSumPdf = (*it).second.mSumPdf; 
     275                float bSumPdf = 0.0f; 
     276                if (aSumPdf < 0.0f) { 
     277                        // this entry was already accounted for! 
     278                        // just revert it back 
     279                        (*it).second.mSumPdf = -aSumPdf; 
     280                } else { 
     281                        S *data = b.Find((*it).first); 
     282                        if (data) { 
     283                                bSumPdf = data->mSumPdf; 
     284                        } 
    265285#if 0 
    266           float diff = bSumPdf - aSumPdf; 
    267            
    268           if (diff > 0.0f) { 
    269                 pvsEnlargement += diff; 
    270           } else { 
    271                 pvsReduction += -diff; 
    272           } 
     286                        float diff = bSumPdf - aSumPdf; 
     287 
     288                        if (diff > 0.0f) { 
     289                                pvsEnlargement += diff; 
     290                        } else { 
     291                                pvsReduction += -diff; 
     292                        } 
    273293 
    274294#else 
    275           if (!data)  
    276                 pvsReduction += 1.0f; 
    277 #endif 
    278         } 
    279   } 
    280 } 
     295                        if (!data)  
     296                                pvsReduction += 1.0f; 
     297#endif 
     298                } 
     299        } 
     300} 
     301 
    281302 
    282303template <typename T, typename S> 
     
    285306        int dif = 0; 
    286307 
    287         std::map<T, S, LtSample<T> >::const_iterator it; 
     308        std::vector<pair<T, S> >::const_iterator it; 
    288309 
    289310        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
     
    298319template <typename T, typename S> void Pvs<T, S>::Merge(const Pvs<T, S> &a) 
    299320{ 
    300    
    301   std::map<T, S, LtSample<T> >::const_iterator it; 
    302   int samples = mSamples + a.mSamples; 
    303  
    304   for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
    305         { 
    306           AddSample((*it).first, (*it).second.mSumPdf); 
    307         } 
    308   mSamples = samples; 
     321#if TODO 
     322        const int samples = mSamples + a.mSamples; 
     323 
     324        std::vector<pair<T, S>> >::const_iterator it; 
     325 
     326        for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
     327        { 
     328                AddSample((*it).first, (*it).second.mSumPdf); 
     329        } 
     330 
     331        mSamples = samples; 
     332#endif 
    309333} 
    310334 
     
    319343S *Pvs<T, S>::Find(T sample) 
    320344{ 
    321   std::map<T, S, LtSample<T> >::iterator i = mEntries.find(sample); 
     345#if TODO 
     346  std::vector<pair<T, S>, LtSample<T> >::iterator i = mEntries.find(sample); 
    322347 
    323348  if (i != mEntries.end())  
     
    329354          return NULL; 
    330355  } 
     356#else 
     357return NULL; 
     358#endif 
    331359} 
    332360 
     
    336364                                         S &data) 
    337365{ 
    338   std::map<T, S, LtSample<T> >::iterator i = mEntries.begin(); 
    339   for (int k = 0; k != index && i != mEntries.end(); i++, k++); 
    340  
    341   entry = (*i).first; 
    342   data = (*i).second; 
    343    
    344 } 
     366        std::vector<pair<T, S> >::iterator i = mEntries.begin(); 
     367        for (int k = 0; k != index && i != mEntries.end(); ++ i, ++ k); 
     368 
     369        entry = (*i).first; 
     370        data = (*i).second; 
     371} 
     372 
    345373 
    346374template <typename T, typename S> 
     
    348376Pvs<T, S>::AddSample(T sample, const float pdf) 
    349377{ 
    350   mSamples++; 
    351   S *data = Find(sample); 
    352    
    353   if (data)   
    354         { 
    355           data->mSumPdf += pdf; 
    356           return data->mSumPdf; 
    357         } 
    358   else  
    359         { 
    360           mEntries[sample] = S(pdf); 
    361           return pdf; 
    362         } 
     378#if TODO 
     379        ++ mSamples; 
     380        S *data = Find(sample); 
     381 
     382        if (data)   
     383        { 
     384                data->mSumPdf += pdf; 
     385                return data->mSumPdf; 
     386        } 
     387        else  
     388        { 
     389                mEntries[sample] = S(pdf); 
     390                return pdf; 
     391        } 
     392#else 
     393return 0; 
     394#endif 
    363395} 
    364396 
     
    388420                                  float &contribution) 
    389421{ 
    390   mSamples++; 
    391   S *data = Find(sample); 
    392    
    393   if (data)   
    394   { 
    395         data->mSumPdf += pdf; 
    396         contribution = pdf / data->mSumPdf; 
    397         return false; 
    398   } 
    399   else { 
    400         mEntries[sample] = S(pdf); 
    401         contribution = 1.0f; 
     422        ++ mSamples; 
     423    S *data = Find(sample); 
     424#if TODO 
     425        if (data)   
     426        { 
     427                data->mSumPdf += pdf; 
     428                contribution = pdf / data->mSumPdf; 
     429                return false; 
     430        } 
     431        else { 
     432                mEntries[sample] = S(pdf); 
     433                contribution = 1.0f; 
     434                return true; 
     435        } 
     436#else 
    402437        return true; 
    403   } 
     438#endif 
    404439} 
    405440 
     
    424459template <typename T, typename S> 
    425460bool Pvs<T, S>::RemoveSample(T sample, 
    426                                                   const float pdf) 
     461                                                        const float pdf) 
    427462{ 
    428463  -- mSamples; 
    429    
    430   std::map<T, S, LtSample<T> >:: 
    431         iterator it = mEntries.find(sample); 
     464#if TODO 
     465  std::vector<pair<T, S> >::iterator it = mEntries.find(sample); 
    432466   
    433467  if (it == mEntries.end()) 
     
    442476          mEntries.erase(it); 
    443477  } 
    444  
     478#endif 
    445479  return true; 
    446480} 
     
    450484{ 
    451485  int samples = mSamples + pvs.mSamples; 
    452   std::map<T, S, LtSample<T> >:: 
     486  std::vector<pair<T, S> >:: 
    453487        const_iterator it, it_end = pvs.mEntries.end(); 
    454488   
     
    468502int Pvs<T, S>::SubtractPvs(const Pvs<T, S> &pvs) 
    469503{ 
    470    
    471   int samples = mSamples - pvs.mSamples; 
    472   std::map<T, S, LtSample<T> >:: 
    473         const_iterator it, it_end = pvs.mEntries.end(); 
    474    
    475   // output PVS of view cell 
    476   for (it = pvs.mEntries.begin(); it != it_end; ++ it)  
    477         RemoveSample((*it).first, (*it).second.mSumPdf); 
    478  
    479   mSamples = samples; 
    480   return GetSize(); 
     504        const int samples = mSamples - pvs.mSamples; 
     505#if TODO 
     506        std::vector<pair<T, S> >:: 
     507                const_iterator it, it_end = pvs.mEntries.end(); 
     508 
     509        // output PVS of view cell 
     510        for (it = pvs.mEntries.begin(); it != it_end; ++ it)  
     511                RemoveSample((*it).first, (*it).second.mSumPdf); 
     512 
     513        mSamples = samples; 
     514#endif 
     515        return GetSize(); 
    481516} 
    482517 
     
    484519void Pvs<T, S>::CollectEntries(std::vector<T> &entries) 
    485520{ 
    486         std::map<T, S, LtSample<T> >:: 
     521        std::vector<pair<T, S> >:: 
    487522                const_iterator it, it_end = mEntries.end(); 
    488523 
     
    495530void Pvs<T, S>::NormalizeMaximum() 
    496531{ 
    497   std::map<T, S, LtSample<T> >:: 
     532  std::vector<pair<T, S> >:: 
    498533        const_iterator it, it_end = mEntries.end(); 
    499534 
     
    555590//-- typedefs 
    556591 
    557 typedef std::map<KdNode *, PvsData, LtSample<KdNode *> > KdPvsMap; 
    558 typedef std::map<Intersectable *, PvsData, LtSample<Intersectable *> > ObjectPvsMap; 
    559 typedef std::map<ViewCell *, MailablePvsData, LtSample<ViewCell *> > ViewCellPvsMap; 
    560  
     592//typedef std::map<KdNode *, PvsData, LtSample<KdNode *> > KdPvsMap; 
     593//typedef std::map<Intersectable *, PvsData, LtSample<Intersectable *> > ObjectPvsEntries; 
     594//typedef std::map<ViewCell *, MailablePvsData, LtSample<ViewCell *> > ViewCellPvsEntries; 
     595 
     596 
     597typedef std::vector<pair<Intersectable *, PvsData> > ObjectPvsEntries; 
    561598 
    562599typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1713 r1738  
    6161        int count = 0; 
    6262 
    63         ObjectPvsMap::const_iterator it, it_end = vc->GetPvs().mEntries.end(); 
     63        ObjectPvsEntries::const_iterator it, it_end = vc->GetPvs().mEntries.end(); 
    6464        for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    6565        { 
     
    8181        float pvs = (float)pvs1.GetSize(); 
    8282 
    83         ObjectPvsMap::const_iterator it, it_end = pvs1.mEntries.end(); 
     83        ObjectPvsEntries::const_iterator it, it_end = pvs1.mEntries.end(); 
    8484 
    8585        Intersectable::NewMail(); 
     
    830830 
    831831        // compute new pvs size 
    832         ObjectPvsMap::const_iterator it, it_end =  pvs1.mEntries.end(); 
     832        ObjectPvsEntries::const_iterator it, it_end =  pvs1.mEntries.end(); 
    833833 
    834834        Intersectable::NewMail(); 
     
    16381638        ViewCellContainer::const_iterator cit, cit_end = interior->mChildren.end(); 
    16391639 
    1640         ObjectPvsMap::const_iterator oit; 
     1640        ObjectPvsEntries::const_iterator oit; 
    16411641 
    16421642        // mail all objects in the leaf sets 
     
    16471647                ViewCell *vc = *cit; 
    16481648 
    1649                 ObjectPvsMap::const_iterator oit_end = vc->GetPvs().mEntries.end(); 
     1649                ObjectPvsEntries::const_iterator oit_end = vc->GetPvs().mEntries.end(); 
    16501650 
    16511651                for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     
    16691669                ViewCell *vc = *cit; 
    16701670 
    1671                 ObjectPvsMap::const_iterator oit_end = vc->GetPvs().mEntries.end(); 
     1671                ObjectPvsEntries::const_iterator oit_end = vc->GetPvs().mEntries.end(); 
    16721672 
    16731673                for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     
    16821682 
    16831683        // delete all the objects from the leaf sets which were moved to parent pvs 
    1684         ObjectPvsMap::const_iterator oit_end = interior->GetPvs().mEntries.end(); 
     1684        ObjectPvsEntries::const_iterator oit_end = interior->GetPvs().mEntries.end(); 
    16851685 
    16861686        for (oit = interior->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     
    17751775        for (it = leaves.begin(); it != it_end; ++ it) 
    17761776        { 
    1777                 ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 
     1777                ObjectPvsEntries::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 
    17781778 
    17791779                for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     
    18251825        for (it = leaves.begin(); it != it_end; ++ it) 
    18261826        { 
    1827                 ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 
     1827                ObjectPvsEntries::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 
    18281828 
    18291829                for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     
    23392339void ViewCellsTree::ExportPvs(ViewCell *viewCell, OUT_STREAM &stream) 
    23402340{ 
    2341         ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end(); 
     2341        ObjectPvsEntries::iterator it, it_end = viewCell->GetPvs().mEntries.end(); 
    23422342 
    23432343        for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1737 r1738  
    24752475  Intersectable::NewMail(); 
    24762476   
    2477   ObjectPvsMap::const_iterator oi; 
     2477  ObjectPvsEntries::const_iterator oi; 
    24782478   
    24792479  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++ oi)  
     
    25272527 
    25282528  Intersectable::NewMail(); 
    2529   ObjectPvsMap::const_iterator oi; 
     2529  ObjectPvsEntries::const_iterator oi; 
    25302530  // first mark all object from this pvs 
    25312531  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++ oi) { 
     
    25372537  int pvsSize = 0; 
    25382538  int nPvsSize = 0; 
    2539   float samples = pvs.mSamples; 
     2539  float samples = (float)pvs.mSamples; 
    25402540  cout<<"Samples = "<<samples<<endl; 
    25412541  //  cout<<"Filter size = "<<filterSize<<endl; 
     
    25952595 
    25962596        // update samples and globalC 
    2597         samples = pvs.mSamples; 
     2597        samples = (float)pvs.mSamples; 
    25982598        globalC = 2.0f*filterSize/sqrt(samples); 
    25992599        cout<<"neighboring viewcells = "<<i-1<<endl; 
     
    27802780        for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ oit) 
    27812781        { 
    2782             ObjectPvsMap::iterator pit, pit_end = (*oit).mEntries.end(); 
     2782            ObjectPvsEntries::iterator pit, pit_end = (*oit).mEntries.end(); 
    27832783         
    27842784                for (pit = (*oit).mEntries.begin(); pit != pit_end; ++ pit) 
     
    32683268                { 
    32693269                        Intersectable::NewMail(); 
    3270                         ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
     3270                        ObjectPvsEntries::const_iterator oit, oit_end = pvs.mEntries.end(); 
    32713271                         
    32723272                        // output PVS of view cell 
     
    37693769                        exporter->SetFilled(); 
    37703770 
    3771                         ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 
     3771                        ObjectPvsEntries::iterator it, it_end = vc->GetPvs().mEntries.end(); 
    37723772                        // -- output PVS of view cell 
    37733773                        for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 
     
    46174617                        Intersectable::NewMail(); 
    46184618 
    4619                         ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
     4619                        ObjectPvsEntries::const_iterator oit, oit_end = pvs.mEntries.end(); 
    46204620                        cout << endl; 
    46214621                        // output PVS of view cell 
     
    54485448 
    54495449                        Intersectable::NewMail(); 
    5450                         ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
     5450                        ObjectPvsEntries::const_iterator oit, oit_end = pvs.mEntries.end(); 
    54515451                         
    54525452                        // output PVS of view cell 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1737 r1738  
    8585 
    8686        // remove the parents from the object pvss 
    87         ObjectPvsMap::const_iterator oit, oit_end = parent->GetPvs().mEntries.end(); 
     87        ObjectPvsEntries::const_iterator oit, oit_end = parent->GetPvs().mEntries.end(); 
    8888 
    8989        for (oit = parent->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     
    104104 
    105105        // Add front view cell to the object pvsss 
    106         ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 
     106        ObjectPvsEntries::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 
    107107 
    108108        for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     
    29142914#if WORK_WITH_VIEWCELL_PVS 
    29152915        // add first view cell to all the objects view cell pvs 
    2916         ObjectPvsMap::const_iterator oit,  
     2916        ObjectPvsEntries::const_iterator oit,  
    29172917                oit_end = leaf->GetViewCell()->GetPvs().mEntries.end(); 
    29182918 
Note: See TracChangeset for help on using the changeset viewer.