Changeset 1189


Ignore:
Timestamp:
08/09/06 10:49:20 (18 years ago)
Author:
mattausch
Message:

changed osp partition to something taking mult references into account

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

Legend:

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

    r1184 r1189  
    99 
    1010namespace GtpVisibilityPreprocessor { 
     11 
     12int MailablePvsData::sMailId = 1; 
     13int MailablePvsData::sReservedMailboxes = 1; 
    1114 
    1215 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1184 r1189  
    44#include <map> 
    55#include <vector> 
     6#include "common.h" 
    67 
    78namespace GtpVisibilityPreprocessor { 
     
    1516 
    1617template<typename T> 
    17 struct LtSample { 
     18struct LtSample  
     19{ 
    1820    bool operator()(const T a, const T b) const 
    1921    { 
     
    2527        the object was seen from the view cell. 
    2628*/ 
    27  
    28 template<typename T>  
    29 struct PvsData { 
     29class PvsData { 
     30public: 
     31  // sum of probability density of visible sample rays 
     32  float mSumPdf; 
     33 
     34  PvsData() {} 
     35  PvsData(const float sumPdf): 
     36        mSumPdf(sumPdf) {} 
     37 
     38  // $$JB in order to return meaningfull values 
     39  // it assumes that the sum pdf has been normalized somehow!!! 
     40  float GetVisibility()  
     41  {  
     42          return mSumPdf;  
     43  } 
     44}; 
     45 
     46 
     47class MailablePvsData  
     48{ 
    3049//////////////////////////// 
    3150//  Mailing stuff 
     
    5675  // sum of probability density of visible sample rays 
    5776  float mSumPdf; 
    58  
    59   PvsData<T>() {} 
    60   PvsData<T>(const float sumPdf): 
     77  int mCounter; 
     78 
     79  MailablePvsData() {} 
     80  MailablePvsData(const float sumPdf): 
    6181        mSumPdf(sumPdf) {} 
    6282 
     
    6989}; 
    7090 
    71 template<typename T> int PvsData<T>::sMailId = 1; 
    72 template<typename T> int PvsData<T>::sReservedMailboxes = 1; 
    7391 
    7492/** Template class representing the Potentially Visible Set (PVS)  
    7593        mainly from a view cell, but also e.g., from objects. 
    7694*/ 
    77 template<typename T> 
     95template<typename T, typename S> 
    7896class Pvs 
    7997{ 
     
    8199  Pvs(): /*mSamples(0), */mEntries() {} 
    82100   
    83   //int mSamples; 
    84    
     101  //virtual ~Pvs(); 
     102     
    85103  /** Compresses PVS lossless or lossy. 
    86104  */ 
     
    96114  /** Merges pvs of a into this pvs. 
    97115   */ 
    98   void Merge(const Pvs<T> &a); 
     116  void Merge(const Pvs<T, S> &a); 
    99117   
    100118  /** Difference of pvs to pvs b. 
    101119          @returns number of different entries. 
    102120  */ 
    103   int Diff(const Pvs<T> &b); 
     121  int Diff(const Pvs<T, S> &b); 
    104122   
    105123  /** Finds sample in PVS. 
    106124          @returns sample if found, NULL otherwise. 
    107125  */ 
    108   PvsData<T> *Find(T sample); 
     126  S *Find(T sample); 
    109127 
    110128  bool GetSampleContribution(T sample, const float pdf, float &contribution); 
     
    124142          @returns PvsData 
    125143  */ 
    126   PvsData<T> *AddSample2(T sample, const float pdf); 
     144  S *AddSample2(T sample, const float pdf); 
    127145 
    128146  /** Adds one pvs to another one. 
    129147          @returns new pvs size 
    130148  */ 
    131   int AddPvs(const Pvs<T> &pvs); 
     149  int AddPvs(const Pvs<T, S> &pvs); 
    132150 
    133151  /** Subtracts one pvs from another one. 
     
    135153          @returns new pvs size 
    136154  */ 
    137   int SubtractPvs(const Pvs<T> &pvs); 
     155  int SubtractPvs(const Pvs<T, S> &pvs); 
    138156  /** Returns PVS data, i.e., how often it was seen from the view cell,  
    139157          and the object itsef. 
    140158  */ 
    141   void GetData(const int index, T &entry, PvsData<T> &data); 
     159  void GetData(const int index, T &entry, S &data); 
    142160 
    143161  /** Collects the PVS entries and returns them in the vector. 
     
    151169 
    152170  /** Compute continuous PVS difference */ 
    153   void ComputeContinuousPvsDifference(Pvs<T> &pvs, 
     171  void ComputeContinuousPvsDifference(Pvs<T, S> &pvs, 
    154172                                                                          float &pvsReduction, 
    155173                                                                          float &pvsEnlargement); 
     
    161179 
    162180  /** Compute continuous PVS difference */ 
    163   float GetPvsHomogenity(Pvs<T> &pvs) { 
     181  float GetPvsHomogenity(Pvs<T, S> &pvs) { 
    164182        float  
    165183          pvsReduction, 
     
    176194                                           
    177195  /// Map of PVS entries 
    178   std::map<T, PvsData<T>, LtSample<T> > mEntries; 
     196  std::map<T, S, LtSample<T> > mEntries; 
    179197}; 
    180198 
     
    186204 
    187205*/ 
    188 template <typename T> 
     206template <typename T, typename S> 
    189207void 
    190 Pvs<T>::ComputeContinuousPvsDifference(Pvs<T> &b, 
     208Pvs<T, S>::ComputeContinuousPvsDifference(Pvs<T, S> &b, 
    191209                                                                           float &pvsReduction, 
    192210                                                                           float &pvsEnlargement) 
     
    195213        pvsEnlargement = 0.0f; 
    196214  // Uses sum of log differences, which corresponds to entropy 
    197   std::map<T, PvsData<T>, LtSample<T> >::iterator it; 
    198    
    199   for (it = b.mEntries.begin();  
    200           it != b.mEntries.end(); ++ it) { 
     215  std::map<T, S, LtSample<T> >::iterator it; 
     216   
     217  for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)  
     218  { 
    201219        float bSumPdf = (*it).second.mSumPdf; 
    202220        float aSumPdf = 0.0f; 
    203         PvsData<T> *data = Find((*it).first);            
    204         if (data) { 
    205           aSumPdf = data->mSumPdf; 
    206           // mark this entry as processed to avoid double counting 
    207           data->mSumPdf = -aSumPdf; 
     221        S *data = Find((*it).first);             
     222         
     223        if (data)  
     224        { 
     225                aSumPdf = data->mSumPdf; 
     226                // mark this entry as processed to avoid double counting 
     227                data->mSumPdf = -aSumPdf; 
    208228        } 
    209229 
     
    230250          (*it).second.mSumPdf = -aSumPdf; 
    231251        } else { 
    232           PvsData<T> *data = b.Find((*it).first); 
     252          S *data = b.Find((*it).first); 
    233253          if (data) { 
    234254                bSumPdf = data->mSumPdf; 
     
    251271} 
    252272 
    253 template <typename T> 
    254 int Pvs<T>::Diff(const Pvs<T> &b) 
     273template <typename T, typename S> 
     274int Pvs<T, S>::Diff(const Pvs<T, S> &b) 
    255275{ 
    256276        int dif = 0; 
    257277 
    258         std::map<T, PvsData<T>, LtSample<T> >::const_iterator it; 
     278        std::map<T, S, LtSample<T> >::const_iterator it; 
    259279 
    260280        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
    261281        { 
    262                 PvsData<T> *data = Find((*it).first);            
     282                S data = Find((*it).first);              
    263283                if (!data) ++ dif; 
    264284        } 
     
    267287} 
    268288 
    269 template <typename T> 
    270 void Pvs<T>::Merge(const Pvs<T> &a) 
    271 { 
    272         std::map<T, PvsData<T>, LtSample<T> >::const_iterator it; 
     289template <typename T, typename S> void Pvs<T, S>::Merge(const Pvs<T, S> &a) 
     290{ 
     291        std::map<T, S, LtSample<T> >::const_iterator it; 
    273292 
    274293        for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
    275294        { 
    276                 PvsData<T> *data = Find((*it).first); 
    277                  
    278                 if (data) 
    279                         data->mSumPdf += (*it).second.mSumPdf; 
    280                 else 
    281                         mEntries.insert(*it); 
    282         } 
    283 } 
    284  
    285 template <typename T> void Pvs<T>::Clear() 
     295                AddSample((*it).first, (*it).second.mSumPdf); 
     296        } 
     297} 
     298 
     299 
     300template <typename T, typename S> void Pvs<T, S>::Clear() 
    286301{ 
    287302        mEntries.clear(); 
     
    289304 
    290305 
    291 template <typename T> 
    292 PvsData<T> *Pvs<T>::Find(T sample) 
    293 { 
    294   std::map<T, PvsData<T>, LtSample<T> >::iterator i = mEntries.find(sample); 
    295   if (i != mEntries.end()) { 
    296     return &(*i).second; 
    297   } else 
    298     return NULL; 
    299 } 
    300  
    301 template <typename T> 
    302 void Pvs<T>::GetData(const int index, 
     306template <typename T, typename S>  
     307S *Pvs<T, S>::Find(T sample) 
     308{ 
     309  std::map<T, S, LtSample<T> >::iterator i = mEntries.find(sample); 
     310 
     311  if (i != mEntries.end())  
     312  { 
     313          return &(*i).second; 
     314  }  
     315  else 
     316  { 
     317          return NULL; 
     318  } 
     319} 
     320 
     321template <typename T, typename S> 
     322void Pvs<T, S>::GetData(const int index, 
    303323                                         T &entry, 
    304                                          PvsData<T> &data) 
    305 { 
    306   std::map<T, PvsData<T>, LtSample<T> >::iterator i = mEntries.begin(); 
     324                                         S &data) 
     325{ 
     326  std::map<T, S, LtSample<T> >::iterator i = mEntries.begin(); 
    307327  for (int k = 0; k != index && i != mEntries.end(); i++, k++); 
    308328 
    309329  entry = (*i).first; 
    310330  data = (*i).second; 
    311 } 
    312  
    313 template <typename T> 
     331   
     332} 
     333 
     334template <typename T, typename S> 
    314335float 
    315 Pvs<T>::AddSample(T sample, const float pdf) 
    316 { 
    317   PvsData<T> *data = Find(sample); 
    318    
    319   if (data)  { 
    320         data->mSumPdf += pdf; 
    321         return data->mSumPdf; 
    322   } 
    323   else { 
    324         mEntries[sample] = PvsData<T>(pdf); 
    325         return pdf; 
    326   } 
    327 } 
    328  
    329 template <typename T> 
    330 PvsData<T> * 
    331 Pvs<T>::AddSample2(T sample, const float pdf) 
    332 { 
    333   PvsData<T> *data = Find(sample); 
    334    
    335   if (data)  { 
    336         data->mSumPdf += pdf; 
    337   } 
    338   else { 
    339         mEntries[sample] = PvsData<T>(pdf); 
    340         data = Find(sample); 
    341   } 
    342   return data; 
    343 } 
    344  
    345 template <typename T> 
    346 bool 
    347 Pvs<T>::AddSample(T sample, 
     336Pvs<T, S>::AddSample(T sample, const float pdf) 
     337{ 
     338        S *data = Find(sample); 
     339   
     340        if (data)   
     341        { 
     342                data->mSumPdf += pdf; 
     343                return data->mSumPdf; 
     344        } 
     345        else  
     346        { 
     347                mEntries[sample] = S(pdf); 
     348                return pdf; 
     349        } 
     350} 
     351 
     352 
     353template <typename T, typename S> 
     354S * Pvs<T, S>::AddSample2(T sample, const float pdf) 
     355{ 
     356        S *data = Find(sample); 
     357   
     358        if (data)   
     359        { 
     360                data->mSumPdf += pdf; 
     361        } 
     362        else  
     363        { 
     364                mEntries[sample] = S(pdf); 
     365                data = Find(sample); 
     366        } 
     367 
     368        return data; 
     369} 
     370 
     371template <typename T, typename S>  
     372bool Pvs<T, S>::AddSample(T sample, 
    348373                                  const float pdf, 
    349374                                  float &contribution) 
    350375{ 
    351   PvsData<T> *data = Find(sample); 
    352    
    353   if (data)  { 
     376  S *data = Find(sample); 
     377   
     378  if (data)   
     379  { 
    354380        data->mSumPdf += pdf; 
    355         contribution = pdf/data->mSumPdf; 
     381        contribution = pdf / data->mSumPdf; 
    356382        return false; 
    357383  } 
    358384  else { 
    359         mEntries[sample] = PvsData<T>(pdf); 
     385        mEntries[sample] = S(pdf); 
    360386        contribution = 1.0f; 
    361387        return true; 
     
    363389} 
    364390 
    365 template <typename T> 
     391template <typename T, typename S> 
    366392bool 
    367 Pvs<T>::GetSampleContribution(T sample, 
     393Pvs<T, S>::GetSampleContribution(T sample, 
    368394                                                          const float pdf, 
    369395                                                          float &contribution)  
    370396{ 
    371   PvsData<T> *data = Find(sample); 
     397  S *data = Find(sample); 
    372398   
    373399  if (data)  { 
    374         contribution = pdf/(data->mSumPdf + pdf); 
     400        contribution = pdf / (data->mSumPdf + pdf); 
    375401        return false; 
    376402  } 
     
    381407} 
    382408 
    383 template <typename T> 
    384 bool Pvs<T>::RemoveSample(T sample, 
     409template <typename T, typename S> 
     410bool Pvs<T, S>::RemoveSample(T sample, 
    385411                                                  const float pdf) 
    386412{ 
    387   std::map<T, PvsData<T>, LtSample<T> >:: 
     413  std::map<T, S, LtSample<T> >:: 
    388414        iterator it = mEntries.find(sample); 
    389415   
     
    391417        return false; 
    392418   
    393   PvsData<T> *data = &(*it).second; 
     419  S *data = &(*it).second; 
    394420   
    395421  data->mSumPdf -= pdf; 
     422 
    396423  if (data->mSumPdf <= 0.0f) 
    397         mEntries.erase(it); 
    398    
     424  { 
     425          mEntries.erase(it); 
     426  } 
     427 
    399428  return true; 
    400429} 
    401430 
    402 template <typename T> 
    403 int Pvs<T>::AddPvs(const Pvs<T> &pvs) 
    404 { 
    405   std::map<T, PvsData<T>, LtSample<T> >:: 
     431template <typename T, typename S> 
     432int Pvs<T, S>::AddPvs(const Pvs<T, S> &pvs) 
     433{ 
     434  std::map<T, S, LtSample<T> >:: 
    406435        const_iterator it, it_end = pvs.mEntries.end(); 
    407436   
    408437  float contri; 
    409438  // output PVS of view cell 
    410   for (it = pvs.mEntries.begin(); it != it_end; ++ it)  
    411         AddSample((*it).first, (*it).second.mSumPdf, contri); 
     439  for (it = pvs.mEntries.begin(); it != it_end; ++ it) 
     440  {      
     441          AddSample((*it).first, (*it).second.mSumPdf, contri); 
     442  } 
    412443   
    413444  return GetSize(); 
    414445} 
    415446  
    416 template <typename T> 
    417 int Pvs<T>::SubtractPvs(const Pvs<T> &pvs) 
    418 { 
    419   std::map<T, PvsData<T>, LtSample<T> >:: 
     447template <typename T, typename S> 
     448int Pvs<T, S>::SubtractPvs(const Pvs<T, S> &pvs) 
     449{ 
     450  std::map<T, S, LtSample<T> >:: 
    420451        const_iterator it, it_end = pvs.mEntries.end(); 
    421452   
     
    427458} 
    428459 
    429 template <typename T> 
    430 void Pvs<T>::CollectEntries(std::vector<T> &entries) 
    431 { 
    432         std::map<T, PvsData<T>, LtSample<T> >:: 
     460template <typename T, typename S> 
     461void Pvs<T, S>::CollectEntries(std::vector<T> &entries) 
     462{ 
     463        std::map<T, S, LtSample<T> >:: 
    433464                const_iterator it, it_end = mEntries.end(); 
    434465 
     
    438469} 
    439470 
    440 template <typename T> 
    441 void Pvs<T>::NormalizeMaximum() 
    442 { 
    443   std::map<T, PvsData<T>, LtSample<T> >:: 
     471template <typename T, typename S> 
     472void Pvs<T, S>::NormalizeMaximum() 
     473{ 
     474  std::map<T, S, LtSample<T> >:: 
    444475        const_iterator it, it_end = mEntries.end(); 
    445476 
     
    453484  } 
    454485 
    455   maxSum = 1.0f/maxSum; 
     486  maxSum = 1.0f / maxSum; 
    456487 
    457488  for (it = mEntries.begin(); it != it_end; ++ it) { 
     
    464495/** Class instantiating the Pvs template for kd tree nodes. 
    465496*/ 
    466 class KdPvs: public Pvs<KdNode *> 
     497class KdPvs: public Pvs<KdNode *, PvsData> 
    467498{ 
    468499public: 
     
    471502 
    472503 
    473 class ObjectPvs: public Pvs<Intersectable *> 
     504class ObjectPvs: public Pvs<Intersectable *, PvsData> 
    474505{ 
    475506public: 
     
    483514//-- typedefs 
    484515 
    485 typedef std::map<KdNode *, PvsData<KdNode *>, LtSample<KdNode *> > KdPvsMap; 
    486 typedef std::map<Intersectable *, PvsData<Intersectable *>, LtSample<Intersectable *> > ObjectPvsMap; 
    487 typedef std::map<ViewCell *, PvsData<ViewCell *>, LtSample<ViewCell *> > ViewCellPvsMap; 
    488  
    489 typedef PvsData<Intersectable *> ObjectPvsData; 
    490 typedef PvsData<KdNode *> KdPvsData; 
    491  
    492 typedef Pvs<ViewCell *> ViewCellPvs; 
    493 typedef PvsData<ViewCell *> ViewCellPvsData; 
     516typedef std::map<KdNode *, PvsData, LtSample<KdNode *> > KdPvsMap; 
     517typedef std::map<Intersectable *, PvsData, LtSample<Intersectable *> > ObjectPvsMap; 
     518typedef std::map<ViewCell *, MailablePvsData, LtSample<ViewCell *> > ViewCellPvsMap; 
     519 
     520 
     521typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs; 
    494522 
    495523} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r1145 r1189  
    648648        case 3: { 
    649649          float newCost = info.raysBack*info.pvsBack  + info.raysFront*info.pvsFront; 
    650           float oldCost = leaf->rays.size()*pvsSize; 
     650          float oldCost = (float)leaf->rays.size()*pvsSize; 
    651651          info.costRatio = newCost/oldCost; 
    652652        } 
     
    675675        case 3: { 
    676676          float newCost = abs(info.raysBack  - info.raysFront); 
    677           float oldCost = leaf->rays.size(); 
     677          float oldCost = (float)leaf->rays.size(); 
    678678          info.costRatio = newCost/oldCost; 
    679679          break; 
     
    17621762          RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
    17631763          float c = leaf->GetImportance(); 
    1764           int num = (c*ratioPerLeaf + 0.5); 
     1764          int num = int(c*ratioPerLeaf + 0.5f); 
    17651765          //                    cout<<num<<" "; 
    17661766 
     
    23232323           RssTreeLeaf::RayInfo::GreaterWeightedPvsContribution); 
    23242324 
    2325   int desired = ratio*leaf->rays.size(); 
    2326   int removed = leaf->rays.size() - desired; 
    2327    
    2328   for (i=desired; i < leaf->rays.size(); i++) { 
     2325  int desired = int(ratio*leaf->rays.size()); 
     2326  int removed = (int)leaf->rays.size() - desired; 
     2327   
     2328  for (i=desired; i < (int)leaf->rays.size(); i++) { 
    23292329        // delete the ray 
    23302330        leaf->rays[i].mRay->Unref(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp

    r1159 r1189  
    147147                for (int tries = 0; tries < 10; tries++) { 
    148148                        int index = (int)RandomValue(0, (Real)(pvsSize - 1)); 
    149                         KdPvsData data; 
     149                        PvsData data; 
    150150                        KdNode *node; 
    151151                        object->mKdPvs.GetData(index, node, data); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1179 r1189  
    9292        it_end = pvs2.mEntries.end(); 
    9393 
    94         // look if they are in second pvs 
     94        // look if the entries are also in second pvs 
    9595        for (it = pvs2.mEntries.begin(); it != it_end; ++ it) 
    9696        { 
     
    16261626        } 
    16271627 
    1628         interior->GetPvs().mEntries.clear(); 
     1628        interior->GetPvs().Clear(); 
    16291629         
    16301630         
     
    16561656                { 
    16571657                        if (!(*cit)->GetPvs().RemoveSample((*oit).first, Limits::Infinity)) 
     1658                        { 
    16581659                                Debug << "should not come here!" << endl; 
     1660                        } 
    16591661                } 
    16601662        } 
     
    19851987{ 
    19861988        const float entrySize =  
    1987                 sizeof(PvsData<Intersectable *>) + sizeof(Intersectable *); 
     1989                sizeof(PvsData) + sizeof(Intersectable *); 
    19881990 
    19891991        return (float)GetStoredPvsEntriesNum(vc) * entrySize; 
     
    22862288                tstack.pop(); 
    22872289 
    2288                 vc->GetPvs().mEntries.clear(); 
     2290                vc->GetPvs().Clear(); 
    22892291                 
    22902292                if (!vc->IsLeaf()) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1184 r1189  
    23402340  Intersectable::NewMail(); 
    23412341   
    2342   std::map<Intersectable *, 
    2343         PvsData<Intersectable *>, 
    2344         LtSample<Intersectable *> >::const_iterator oi; 
     2342 ObjectPvsMap::const_iterator oi; 
    23452343   
    2346   for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) { 
    2347         Intersectable *object = (*oi).first; 
    2348         object->Mail(); 
     2344  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++ oi)  
     2345  { 
     2346          Intersectable *object = (*oi).first; 
     2347      object->Mail(); 
    23492348  } 
    23502349 
    23512350  ObjectPvs nPvs; 
    2352   int nPvsSize=0; 
     2351  int nPvsSize = 0; 
    23532352  // now go through the pvs again 
    23542353  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) { 
     
    34183417                        ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 
    34193418                        // -- output PVS of view cell 
    3420                         for (it = vc->GetPvs().mEntries.begin(); it !=  it_end; ++ it) 
     3419                        for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    34213420                        { 
    34223421                                Intersectable *intersect = (*it).first; 
     
    53855384                {        
    53865385                        //-- export pvs 
     5386                         
     5387                        Intersectable::NewMail(); 
     5388                        KdLeaf::NewMail(); 
     5389 
     5390                        vector<KdLeaf *> kdLeaves; 
     5391 
    53875392                        ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
    53885393 
    5389                         Intersectable::NewMail(); 
    5390  
    5391                         vector<KdLeaf *> kdLeaves; 
    5392  
    5393                         KdLeaf::NewMail(); 
    5394  
    5395                         // export pvs entries 
    53965394                        for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
    53975395                        {        
     
    58035801        } 
    58045802         
    5805         Debug << "here295 " << rc / mVspTree->GetBoundingBox().GetVolume(); 
     5803        Debug << "\nhere295 " << rc / mVspTree->GetBoundingBox().GetVolume() << endl; 
    58065804 
    58075805        mViewCellsTree->ExportStats(fileName); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r1168 r1189  
    499499                  mBspStats.Leaves() * sizeof(BspLeaf) +  
    500500                  mCreatedViewCells * sizeof(BspViewCell) + 
    501                   mBspStats.pvs * sizeof(ObjectPvsData) + 
     501                  mBspStats.pvs * sizeof(PvsData) + 
    502502                  mBspStats.Interior() * sizeof(BspInterior) + 
    503503                  mBspStats.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1186 r1189  
    2222namespace GtpVisibilityPreprocessor { 
    2323 
     24 
    2425#define USE_FIXEDPOINT_T 0 
    2526 
     
    3233// variable for debugging volume contribution for heuristics 
    3334static float debugVol; 
     35 
     36int VspNode::sMailId = 1; 
    3437 
    3538// pvs penalty can be different from pvs size 
     
    4043        // clamp to minmax values 
    4144        if (pvs < lower) 
     45        { 
    4246                return (float)lower; 
     47        } 
    4348        else if (pvs > upper) 
     49        { 
    4450                return (float)upper; 
     51        } 
    4552 
    4653        return (float)pvs; 
     
    4855 
    4956 
    50 int VspNode::sMailId = 1; 
     57static bool ViewCellHasMultipleReferences(Intersectable *obj,  
     58                                                                                  ViewCell *vc,  
     59                                                                                  bool checkOnlyMailed) 
     60{ 
     61        MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
     62 
     63        if (vdata) 
     64        { 
     65                //Debug << "sumpdf: " << vdata->mSumPdf << endl; 
     66                // more than one view cell sees this object inside different kd cells 
     67                if (!checkOnlyMailed || !vdata->Mailed()) 
     68                { 
     69                        if (checkOnlyMailed) 
     70                                vdata->Mail(); 
     71 
     72                        if (vdata->mSumPdf > 1.5f)  
     73                                return true; 
     74                } 
     75        } 
     76 
     77        return false; 
     78} 
    5179 
    5280 
     
    548576                  mVspStats.Leaves() * sizeof(VspLeaf) +  
    549577                  mCreatedViewCells * sizeof(VspViewCell) + 
    550                   mVspStats.pvs * sizeof(ObjectPvsData) + 
     578                  mVspStats.pvs * sizeof(PvsData) + 
    551579                  mVspStats.Interior() * sizeof(VspInterior) + 
    552580                  mVspStats.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); 
     
    32033231        // This is important during the subdivision 
    32043232 
    3205 //ViewCellPvsData::NewMail(); 
     3233//MailablePvsData::NewMail(); 
    32063234        UpdateViewCellsPvs(front, *frontData.mRays); 
    32073235        UpdateViewCellsPvs(back, *backData.mRays); 
     
    34093437        Debug << "BSP stats: " 
    34103438                  << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " 
    3411                  // << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 
    3412                   << "Prob: " << data.mProbability << " (min: " << mTermMinProbability << "), " 
    3413                   << "#pvs: " << data.mPvs << ")\n"; 
     3439                  << "Prob: " << data.mProbability << " (min: " << mTermMinProbability << ")\n"; 
    34143440#endif 
    34153441} 
     
    34503476        SortSplitCandidates(tData, axis, minBand, maxBand); 
    34513477 
    3452         int numViewCells; 
    3453  
    3454         float totalVol = PrepareHeuristics(tData, numViewCells); 
     3478        float totalVol = 0;//PrepareHeuristics(tData); 
    34553479        float voll = 0; 
    34563480        float volr = totalVol; 
    34573481 
    3458         int vcl = 0; 
    3459         int vcr = numViewCells; 
    3460    
     3482        ViewCellContainer touchedViewCells; 
     3483        const float totalRenderCost = PrepareHeuristics(tData, touchedViewCells); 
     3484        float renderCost = totalRenderCost; 
     3485 
    34613486        /// this is kind of a reverse pvs 
    34623487        const int totalPvs = (int)tData.mNode->mObjects.size(); 
     
    34833508        int pvsFront = pvsr; 
    34843509         
    3485         float minSum = 1e20f; 
     3510        float minRenderCost = 1e20f; 
    34863511 
    34873512        debugVol = 0; 
    34883513        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
    34893514 
     3515 
    34903516        ///////////////////////////// 
    34913517        // the sweep heuristics 
    34923518 
    3493  
    34943519        Intersectable::NewMail(); 
    34953520        ViewCell::NewMail(); 
    3496          
    3497          
     3521                 
    34983522        //-- traverse through events and find best split plane 
    34993523         
     
    35063530                EvalHeuristicsContribution(tData.mNode,  
    35073531                                                                   *ci,  
    3508                                                                    voll, volr,  
    3509                                                                    pvsl, pvsr 
     3532                                                                   renderCost, 
     3533                                                                   touchedViewCells 
    35103534                                                                  ); 
    35113535 
     
    35143538                if (((*ci).mPos >= minBand) && ((*ci).mPos <= maxBand)) 
    35153539                { 
    3516                         // voll = view cells that see only left node (i.e., left pvs) 
    3517                         // volr = view cells that see only right node (i.e., right pvs) 
    3518                         // rest = view cells that see both nodes (i.e., total pvs) 
    3519             sum = voll * pvsl + volr * pvsr + (totalVol - voll - volr) * totalPvs; 
    3520  
    35213540                        float currentPos; 
    35223541                         
     
    35273546                                currentPos = (*ci).mPos;                         
    35283547 
    3529                         /*if ((totalVol - voll - volr - debugVol) / viewSpaceVol > 0.0001) 
    3530                                 Debug << "front and back volume: " << (totalVol - voll - volr) / viewSpaceVol << " error: " << (totalVol - voll - volr - debugVol) / viewSpaceVol << endl; 
    3531                                 Debug << "pos: " << currentPos  
    3532                                  << "\t (pvsl: " << pvsl << ", pvsr: " << pvsr << ")" 
    3533                                  << "\t (voll: " << voll << ", volr: " << volr << ")" 
    3534                                  << "\t (vcl: " << vcl << ", vcr: " << vcr << ", nvc: " << numViewCells << ")" 
    3535                                  << "\t sum: " << sum << endl; 
    3536                                  */ 
    3537  
    3538                         if (sum < minSum) 
     3548                        if (renderCost < minRenderCost) 
    35393549                        { 
    35403550                                splitPlaneFound = true; 
    3541  
    3542                                 minSum = sum; 
    3543  
    3544                                 pvsBack = pvsl; 
    3545                                 pvsFront = pvsr; 
    3546                                  
    3547                                 volBack = voll; 
    3548                                 volFront = volr; 
    3549  
     3551                                Debug << "pos: " << position << endl; 
     3552                                minRenderCost = renderCost; 
    35503553                                position = currentPos; 
    35513554                        } 
     
    35533556        } 
    35543557         
    3555         //-- compute cost 
    3556         const float frontAndBackVol = totalVol - volFront - volBack; 
    3557  
    3558         const float oldRenderCost = (float)totalPvs * totalVol + Limits::Small; 
    3559         const float newRenderCost = (float)pvsFront * volFront +  
    3560                                                                 (float)pvsBack * volBack + 
    3561                                                                 (float)totalPvs * frontAndBackVol; 
    3562  
    3563  
    35643558        if (splitPlaneFound) 
    35653559        { 
    3566                 ratio = newRenderCost / oldRenderCost; 
    3567         } 
    3568  
    3569         //Debug << "axis=" << axis << " costRatio=" << ratio << " pos="  
    3570         //        << position << " t=" << (position - minBox) / (maxBox - minBox) 
    3571         //      << "\t pb=(" << volBack << ")\t pf=(" << volFront << ")" << endl; 
    3572  
    3573 /*      Debug << "\n§§§§ eval local cost §§§§" << endl 
    3574                   << "back pvs: " << pvsBack << " front pvs: " << pvsFront << " total pvs: " << totalPvs << endl  
    3575                   << "back p: " << volBack / viewSpaceVol << " front p " << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl 
    3576                   << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 
    3577                   << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl; 
    3578 */ 
    3579         if (oldRenderCost < newRenderCost) 
    3580                 Debug << "\nwarning!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl; 
    3581          
     3560                ratio = totalRenderCost / minRenderCost; 
     3561        } 
     3562 
     3563        Debug << "\n§§§§ eval local cost §§§§" << endl 
     3564                  << "old rc: " << totalRenderCost / viewSpaceVol << " new rc: " << minRenderCost / viewSpaceVol << endl 
     3565                  << "render cost decrease: " << (totalRenderCost - minRenderCost) / viewSpaceVol  << endl; 
    35823566 
    35833567        return ratio; 
     
    36893673 
    36903674 
    3691 float OspTree::PrepareHeuristics(const VssRay &ray, int &numViewCells) 
    3692 { 
    3693         float vol = 0; 
    3694         numViewCells = 0; 
    3695  
     3675void OspTree::PrepareHeuristics(const VssRay &ray,  
     3676                                                                ViewCellContainer &touchedViewCells) 
     3677{ 
     3678 
     3679        // collect view cells and set mail + counter 
    36963680        ViewCellContainer viewCells; 
    3697  
    36983681        mVspTree->GetViewCells(VssRay(ray), viewCells); 
    36993682         
     
    37063689                if (!vc->Mailed()) 
    37073690                { 
    3708                         //Debug << "single vol: "<< vc->GetVolume() << endl; 
    3709                         vc->Mail(); 
     3691                        vc->Mail(); // set as belonging to front leaf 
    37103692                        vc->mCounter = 0; 
    3711                         vol += vc->GetVolume(); 
    3712                         ++ numViewCells; 
     3693                        touchedViewCells.push_back(vc); 
    37133694                } 
    37143695                 
     
    37163697                ++ vc->mCounter; 
    37173698        } 
    3718  
    3719         return vol; 
    3720 } 
    3721  
    3722  
    3723 float OspTree::PrepareHeuristics(const OspTraversalData &tData, int &numViewCells) 
     3699} 
     3700 
     3701 
     3702float OspTree::PrepareHeuristics(const OspTraversalData &tData, 
     3703                                                                 ViewCellContainer &touchedViewCells) 
    37243704{        
    3725         float vol = 0; 
    3726  
    3727         Intersectable::NewMail(); 
    3728         ViewCell::NewMail(); 
    3729         numViewCells = 0; 
     3705        float renderCost = 0; 
     3706 
     3707        Intersectable::NewMail(3); 
     3708        ViewCell::NewMail(3); 
     3709        MailablePvsData::NewMail(); 
    37303710 
    37313711        KdLeaf *leaf = tData.mNode; 
     
    37363716        { 
    37373717                VssRay *ray = (*rit).mRay; 
    3738  
    3739                 int newViewCells; 
    3740  
    3741                 // if hitpoint with one of the objects is inside this node, we 
    3742                 // evaluate the volume of the view cells seen by this ray 
    3743                 if (EndPointInsideNode(leaf, *ray, true)) 
    3744                 { 
    3745             vol += PrepareHeuristics(*ray, newViewCells); 
    3746                         numViewCells += newViewCells; 
    3747                 } 
    3748  
    3749                 // count double if both hit points are within the kd node 
    3750                 if (EndPointInsideNode(leaf, *ray, false)) 
    3751                 { 
    3752                         vol += PrepareHeuristics(*ray, newViewCells); 
    3753                         numViewCells += newViewCells; 
    3754                 } 
    3755         } 
    3756  
    3757          
    3758         return vol; 
    3759 } 
    3760  
    3761  
    3762 void OspTree::EvalHeuristicsContribution(KdLeaf *leaf, 
    3763                                                                                  const SortableEntry &ci, 
    3764                                                                                  float &volLeft, 
    3765                                                                                  float &volRight, 
    3766                                                                                  int &pvsLeft, 
    3767                                                                                  int &pvsRight 
    3768                                                                                  ) 
    3769 { 
    3770         Intersectable *obj = ci.mObject; 
    3771         VssRay *ray = ci.mRay; 
    3772  
    3773         // switch between different types of events 
    3774         switch (ci.mType)  
    3775         { 
    3776                 // add reverse pvs to left side of split plane 
    3777                 case SortableEntry::BOX_MIN: 
    3778                         ++ pvsLeft; 
    3779                         break; 
    3780                          
    3781                 case SortableEntry::BOX_MAX: 
    3782                         -- pvsRight; 
    3783                         break; 
    3784  
    3785                 // compute volume contribution from view cells 
    3786                 case SortableEntry::BOX_INTERSECT: 
    3787                                 // process ray if the hit point with termination / origin object  
    3788                                 // is inside this kd leaf 
    3789                                 if (EndPointInsideNode(leaf, *ray, true) || 
    3790                                         EndPointInsideNode(leaf, *ray, false)) 
    3791                                 { 
    3792                                         EvalVolumeContribution(*ray, volLeft, volRight); 
    3793                                 } 
    3794                         break; 
    3795                 default: 
    3796                         cout << "should not come here" << endl; 
    3797                         break; 
    3798         } 
    3799  
    3800         //cout << "vol left: " << volLeft << " vol right " << volRight << endl; 
    3801 } 
    3802  
    3803  
    3804 void OspTree::EvalVolumeContribution(const VssRay &ray,  
    3805                                                                          float &volLeft,  
    3806                                                                          float &volRight) 
     3718        PrepareHeuristics(*ray, touchedViewCells); 
     3719        } 
     3720 
     3721        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     3722 
     3723        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     3724        { 
     3725                Intersectable *obj = *oit; 
     3726                obj->Mail(); // set as belonging to front leaf 
     3727                 
     3728                ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     3729 
     3730                for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     3731                { 
     3732                        ViewCell *vc = *vit; 
     3733                        MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
     3734 
     3735                        if (!vdata) // should never happen 
     3736                                continue; 
     3737 
     3738                        if (!vdata->Mailed()) 
     3739                        { 
     3740                                vdata->Mail(); 
     3741                                renderCost += vc->GetVolume(); 
     3742                        } 
     3743                } 
     3744        } 
     3745 
     3746        Debug << "here32 " << touchedViewCells.size() << endl; 
     3747        return renderCost; 
     3748} 
     3749 
     3750 
     3751void OspTree::AddObjectContribution(KdLeaf *leaf, 
     3752                                                  Intersectable *obj, 
     3753                                                  ViewCellContainer &touchedViewCells, 
     3754                                                  float &renderCost) 
     3755{ 
     3756        obj->Mail(2); // set as belonging to both leafs 
     3757 
     3758        ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     3759         
     3760        for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     3761        { 
     3762                ViewCell *vc = *vit; 
     3763 
     3764                // if obj not previously associated with this view cell => increase render cost 
     3765                if (vc->Mailed(1) &&  
     3766                        !ViewCellHasMultipleReferences(obj, vc, false)) 
     3767                { 
     3768                        renderCost += vc->GetVolume(); 
     3769                } 
     3770        } 
     3771} 
     3772 
     3773 
     3774void OspTree::SubtractObjectContribution(KdLeaf *leaf, 
     3775                                                                Intersectable * obj, 
     3776                                                                ViewCellContainer &touchedViewCells, 
     3777                                                                float &renderCost) 
     3778{ 
     3779    obj->Mail(1); // set as belonging to back leaf 
     3780        ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     3781         
     3782        for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     3783        { 
     3784                ViewCell *vc = *vit; 
     3785 
     3786                // if obj was previously associated with this view cell but is not now  
     3787                // => decrease render cost 
     3788                if (vc->Mailed() &&  
     3789                        !ViewCellHasMultipleReferences(obj, vc, false)) 
     3790                { 
     3791                        renderCost -= vc->GetVolume(); 
     3792                } 
     3793        } 
     3794} 
     3795 
     3796 
     3797void OspTree::EvalRayContribution(KdLeaf *leaf, 
     3798                                                                  const VssRay &ray,  
     3799                                                                  float &renderCost) 
    38073800{ 
    38083801        ViewCellContainer viewCells; 
     
    38193812        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    38203813        { 
    3821                 // view cells can also be seen from left child node 
    3822                 ViewCell *viewCell = *vit; 
    3823  
    3824                 const float vol = viewCell->GetVolume(); 
    3825  
    3826                 if (!viewCell->Mailed()) 
    3827                 { 
    3828                         viewCell->Mail(); 
    3829  
    3830                         // we now see view cell from both nodes  
    3831                         // => remove ref to right child node 
    3832                         volRight -= vol; 
    3833  
    3834                         debugVol += vol; 
    3835                 } 
    3836  
    3837                 // last reference into the right node 
    3838                 if (-- viewCell->mCounter == 0) 
    3839                 { 
    3840 #if 0 
    3841                         // view cell was previousy seen from right node only 
    3842                         // => remove from right node (matt: need this?) 
    3843                         if (!viewCell->Mailed()) 
    3844                                 volRight -= vol; 
    3845                         else 
    3846 #endif 
    3847                         // view cell was previously seen from both nodes  => 
    3848                         // contributes only to left node now 
    3849                         volLeft += vol; 
    3850                         debugVol -= vol; 
    3851                 } 
    3852         } 
     3814                EvalViewCellContribution(leaf, *vit, renderCost); 
     3815        } 
     3816} 
     3817 
     3818 
     3819void OspTree::EvalViewCellContribution(KdLeaf *leaf,  
     3820                                                                           ViewCell *viewCell, 
     3821                                                                           float &renderCost) 
     3822{ 
     3823        // view cells can also be seen from left child node 
     3824        const float vol = viewCell->GetVolume(); 
     3825 
     3826        if (viewCell->Mailed()) 
     3827        { 
     3828                viewCell->NewMail(2); // view cell can be seen from both nodes 
     3829 
     3830        // we now see view cell from both nodes => add contri 
     3831                ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     3832 
     3833                for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     3834                { 
     3835                        Intersectable *obj = *oit; 
     3836 
     3837                        // was render cost already added? 
     3838                        if (!ViewCellHasMultipleReferences(obj, viewCell, false) || 
     3839                                obj->Mailed(1)) 
     3840                        { 
     3841                                renderCost += viewCell->GetVolume(); 
     3842                        } 
     3843                } 
     3844        } 
     3845 
     3846        if (-- viewCell->mCounter == 0) 
     3847        { 
     3848                ViewCell::NewMail(1); // view cell can be seen from back node only 
     3849 
     3850                //MailablePvsData::NewMail(); 
     3851                ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     3852 
     3853                for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     3854                { 
     3855                        Intersectable *obj = *oit; 
     3856 
     3857                        // can render cost be be reduced? 
     3858                        if (!ViewCellHasMultipleReferences(obj, viewCell, false) || 
     3859                                obj->Mailed()) 
     3860                        { 
     3861                                renderCost -= viewCell->GetVolume(); 
     3862                        } 
     3863                } 
     3864        } 
     3865} 
     3866 
     3867 
     3868void OspTree::EvalHeuristicsContribution(KdLeaf *leaf, 
     3869                                                                                 const SortableEntry &ci, 
     3870                                                                                 float &renderCost, 
     3871                                                                                 ViewCellContainer &touchedViewCells) 
     3872{ 
     3873        Intersectable *obj = ci.mObject; 
     3874        VssRay *ray = ci.mRay; 
     3875 
     3876        // switch between different types of events 
     3877        switch (ci.mType)  
     3878        { 
     3879                case SortableEntry::BOX_MIN: 
     3880                        cout << "<"; 
     3881                        AddObjectContribution(leaf, ci.mObject, touchedViewCells, renderCost);   
     3882                        break; 
     3883                         
     3884                case SortableEntry::BOX_MAX: 
     3885                        cout << ">"; 
     3886                        SubtractObjectContribution(leaf, ci.mObject, touchedViewCells, renderCost); 
     3887                        break; 
     3888 
     3889                // compute volume contribution from view cells 
     3890                case SortableEntry::BOX_INTERSECT: 
     3891                        cout << "i"; 
     3892                        // process ray if the hit point with termination / origin object  
     3893                        // is inside this kd leaf 
     3894                        EvalRayContribution(leaf, *ray, renderCost); 
     3895                        break; 
     3896 
     3897                default: 
     3898                        cout << "should not come here" << endl; 
     3899                        break; 
     3900        } 
     3901 
     3902        //cout << "vol left: " << volLeft << " vol right " << volRight << endl; 
    38533903} 
    38543904 
     
    39564006        else 
    39574007        { 
    3958                  return ray.mOriginObject && (GetLeaf(ray.mOrigin, ray.mOriginNode) == leaf); 
     4008                return false; // no origin object! 
     4009                return ray.mOriginObject && (GetLeaf(ray.mOrigin, ray.mOriginNode) == leaf); 
    39594010        } 
    39604011} 
     
    39704021                                                ); 
    39714022} 
    3972  
    39734023 
    39744024 
     
    39924042    const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
    39934043 
    3994         const bool originGt =  
    3995                 ray->mOrigin[plane.mAxis] > plane.mPosition; 
    3996                  
    3997         const bool terminationGt =  
    3998                 ray->mTermination[plane.mAxis] > plane.mPosition; 
     4044        const bool originGt = (ray->mOrigin[plane.mAxis] >= plane.mPosition); 
     4045        const bool originLt = (ray->mOrigin[plane.mAxis] <= plane.mPosition); 
     4046 
     4047        const bool terminationGt = (ray->mTermination[plane.mAxis] >= plane.mPosition); 
     4048        const bool terminationLt = (ray->mTermination[plane.mAxis] <= plane.mPosition); 
    39994049 
    40004050        // add view cell volume to front volume 
    4001         const bool addToFront = ((originInside && originGt) || (terminationInside && terminationGt)); 
     4051        const bool addToFront =  
     4052                ((originInside && originGt) || (terminationInside && terminationGt)); 
    40024053 
    40034054        // add view cell volume to back volume 
    4004         const bool addToBack = ((originInside && !originGt) || (terminationInside && !terminationGt)); 
     4055        const bool addToBack =  
     4056                ((originInside && originLt/*!originGt*/) || (terminationInside && terminationLt/*terminationGt*/)); 
    40054057 
    40064058        // classify ray with respect to the child nodes the view cells contribute 
     
    40164068 
    40174069 
    4018 static bool ViewCellHasMultipleReferences(Intersectable *obj,  
    4019                                                                                   ViewCell *vc,  
    4020                                                                                   bool checkOnlyMailed) 
    4021 { 
    4022         ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
    4023  
    4024         if (vdata) 
    4025         { 
    4026                 //Debug << "sumpdf: " << vdata->mSumPdf << endl; 
    4027                 // more than one view cell sees this object inside different kd cells 
    4028                 if (!checkOnlyMailed || !vdata->Mailed()) 
    4029                 { 
    4030                         vdata->Mail();//return true; 
    4031                         if (vdata->mSumPdf > 1.5f)  
    4032                                 return true; 
    4033                 } 
    4034         } 
    4035  
    4036         return false; 
    4037 } 
    4038  
    4039  
    40404070int OspTree::ClassifyRays(const RayInfoContainer &rays,  
    40414071                                                  KdLeaf *leaf,  
     
    40554085                Intersectable *obj = ray->mOriginObject; 
    40564086 
    4057                 if (obj) 
    4058                 { 
    4059                         originGt = ray->mOrigin[plane.mAxis] > plane.mPosition; 
     4087                if (0 && obj) 
     4088                { 
     4089                        originGt = ray->mOrigin[plane.mAxis] >= plane.mPosition; 
    40604090                } 
    40614091 
     
    40644094                if (obj) 
    40654095                { 
    4066                         terminationGt = ray->mTermination[plane.mAxis] > plane.mPosition; 
     4096                        terminationGt = ray->mTermination[plane.mAxis] >= plane.mPosition; 
    40674097                } 
    40684098 
     
    40844114 
    40854115 
    4086 #if 1 
     4116#if 0 
    40874117 
    40884118float OspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 
     
    41214151                VssRay *ray = (*rit).mRay; 
    41224152 
    4123                 // test if intersection point with one of the objects is inside this node 
    4124                 const bool originInside = EndPointInsideNode(leaf, *ray, false); 
    4125         const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
    4126  
    4127                 if (originInside || terminationInside) 
    4128                 { 
    4129                         // add volume to volumes of left and / or right children 
    4130                         // if one of the ray end points is inside 
    4131                         const int classification = ClassifyRay(ray, leaf, candidatePlane); 
    4132  
    4133                         ViewCellContainer viewCells; 
    4134                         mVspTree->GetViewCells(*ray, viewCells); 
     4153                // add volume to volumes of left and / or right children 
     4154                // if one of the ray end points is inside 
     4155                const int classification = ClassifyRay(ray, leaf, candidatePlane); 
     4156 
     4157                ViewCellContainer viewCells; 
     4158                mVspTree->GetViewCells(*ray, viewCells); 
    41354159                         
    4136                         ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    4137  
    4138                         // traverse through view cells and classify them according 
    4139                         // to them being seen from to back / front / front and back node 
    4140                         for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    4141                         { 
    4142                                 ViewCell *vc = *vit; 
    4143  
    4144                                 // if not previously mailed 
    4145                                 if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 
    4146                                 { 
    4147                                         touchedViewCells.push_back(vc); 
    4148                                 } 
    4149  
    4150                 // classify / mail the view cell 
    4151                                 MailViewCell(vc, classification);        
    4152                         } 
     4160                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     4161 
     4162                // traverse through view cells and classify them according 
     4163                // to them being seen from to back / front / front and back node 
     4164                for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     4165                { 
     4166                        ViewCell *vc = *vit; 
     4167 
     4168                        // if not previously mailed 
     4169                        if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 
     4170                        { 
     4171                                touchedViewCells.push_back(vc); 
     4172                        } 
     4173 
     4174                        // classify / mail the view cell 
     4175                        MailViewCell(vc, classification);        
    41534176                } 
    41544177        } 
     
    41734196        float additionalBackRenderCost = 0; 
    41744197         
    4175         ViewCellPvsData::NewMail(); 
     4198        MailablePvsData::NewMail(); 
    41764199 
    41774200        for (rit = tData.mRays->begin(); rit != tData.mRays->end(); ++ rit) 
     
    42964319        float pFrontAndBack = 0; 
    42974320 
     4321        Intersectable::NewMail(3); 
     4322        KdLeaf *leaf = tData.mNode; 
     4323 
    42984324        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
    4299  
    4300         Intersectable::NewMail(3); 
    4301          
    4302         KdLeaf *leaf = tData.mNode; 
    43034325        const int totalPvs = (int)leaf->mObjects.size(); 
    43044326         
     
    43304352                                obj->Mail(1); 
    43314353                } 
    4332                 //Debug << "here3 pt: " << obj << " mail: " << obj->mMailbox - Intersectable::sMailId << endl; 
    43334354        } 
    43344355 
     
    43694390 
    43704391                        // classify / mail the view cell 
    4371                         MailViewCell(vc, classification);        
    4372  
    4373                         /*if (terminationInside) 
    4374                                 objectsMap[ray->mTerminationObject].push_back(vc); 
    4375                         if (originInside) 
    4376                                 objectsMap[ray->mOriginObject].push_back(vc);*/ 
     4392                        MailViewCell(vc, classification); 
    43774393                } 
    43784394        } 
     
    43944410        // the object would still be part of the pvs 
    43954411 
    4396         float frontRc = 0; 
    4397         float backRc = 0; 
     4412        float newRc = 0; 
    43984413        float rc = 0; 
    43994414 
    4400         ViewCellPvsData::NewMail(); 
    4401         ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    4402  
    4403         //Debug << "here53 " << touchedViewCells.size() << endl; 
     4415        MailablePvsData::NewMail(); 
     4416        //ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     4417 
    44044418        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
    44054419        { 
     
    44104424                { 
    44114425                        ViewCell *vc = *vit; 
    4412                         /*ObjectPvsData *vdata = vc->GetPvs().Find(obj); 
     4426                         
     4427                        MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
    44134428 
    44144429                        if (!vdata) 
    44154430                        { 
    4416                                 vc->GetPvs().AddSample(obj, 1); 
    4417                                 newCost += vc->GetVolume(); 
    4418                                 //prop += vc->GetVolume(); 
    4419                         }*/ 
    4420  
    4421                         ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
    4422  
    4423                         if (!vdata || !vdata->Mailed()) 
    4424                         { 
    4425                                 newCost += vc->GetVolume(); 
    4426                                 if (!vdata) 
    4427                                         vdata = obj->mViewCellPvs.AddSample2(vc, 1); 
     4431                                Debug << "here86 error!!"<<endl; 
     4432                                continue; 
     4433                        } 
     4434 
     4435                        if (!vdata->Mailed()) 
     4436                        { 
    44284437                                vdata->Mail(); 
    4429                         } 
    4430                 } 
    4431         } 
    4432  
    4433  
    4434         } 
     4438                                rc += vc->GetVolume(); 
     4439 
     4440                                if ((vdata->mSumPdf > 1.5) ||  
     4441                                        vc->Mailed(2) ||  
     4442                                        obj->Mailed(2) || 
     4443                                        (obj->Mailed() && vc->Mailed()) || 
     4444                                        (obj->Mailed(1) && vc->Mailed(1)) 
     4445                                        ) 
     4446                                { 
     4447                                        newRc += vc->GetVolume(); 
     4448                                } 
     4449                        } 
     4450                } 
     4451        } 
     4452 
    44354453 
    44364454        ///////////////////////////// 
     
    44434461        //-- pvs rendering heuristics 
    44444462 
    4445         const float oldRenderCost = pOverall * totalPvs; 
     4463        const float oldRenderCost = rc;//pOverall * totalPvs; 
    44464464         
    44474465        // sum up the terms:  
     
    44504468        // b) the right node are weighted by the #right node objects 
    44514469        // c) both nodes are weighted by the #parent node objects 
    4452         const float newRenderCost = pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack 
    4453                 + additionalFrontRenderCost + additionalBackRenderCost; 
     4470        const float newRenderCost = newRc//pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack 
     4471;//             + additionalFrontRenderCost + additionalBackRenderCost; 
    44544472 
    44554473        // normalize volume with view space volume 
     
    44614479                  << " front and back p " << pFrontAndBack / viewSpaceVol << " p: " << tData.mProbability / viewSpaceVol << endl 
    44624480                  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 
    4463                   << "render cost decrease: " << renderCostDecrease << endl 
    4464                   << "additional front " << additionalFrontRenderCost / viewSpaceVol  
    4465                   << " additional back " << additionalBackRenderCost  / viewSpaceVol << endl; 
     4481                  << "render cost decrease: " << renderCostDecrease << endl; 
     4482                  //<< "additional front " << additionalFrontRenderCost / viewSpaceVol  
     4483                  //<< " additional back " << additionalBackRenderCost  / viewSpaceVol << endl; 
    44664484 
    44674485        if (oldRenderCost < newRenderCost * 0.99) 
     
    44774495} 
    44784496#endif 
     4497 
    44794498 
    44804499void OspTree::ComputeBoundingBox(const ObjectContainer &objects, 
     
    47244743                        // HACK: reset nodes for the case we have used object kd tree for 
    47254744                        // tree building. 
    4726                         ray->mOrigin = NULL; 
     4745                        ray->mOriginNode = NULL; 
    47274746                        ray->mTerminationNode = NULL; 
    47284747                } 
     
    48094828                                          
    48104829 
    4811 int OspTree::SplitViewCells(const AxisAlignedPlane &candidatePlane, 
    4812                                                         const RayInfoContainer &rays, 
    4813                                                         KdLeaf *leaf,                                                    
    4814                                                         ViewCellContainer &frontViewCells, 
    4815                                                         ViewCellContainer &backViewCells, 
    4816                                                         ViewCellContainer &frontAndBackViewCells) const  
    4817 { 
    4818         ViewCellContainer touchedViewCells; 
    4819         RayInfoContainer touchedRays; 
    4820  
    4821         // sum up volume seen from the objects of left and right children 
    4822         // => the volume is the weight for the render cost equation 
    4823         ViewCell::NewMail(3); 
    4824  
    4825         RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
    4826  
    4827         for (rit = rays.begin(); rit < rit_end; ++ rit) 
    4828         { 
    4829                 VssRay *ray = (*rit).mRay; 
    4830  
    4831                 // test if intersection point with one of the objects is inside this node 
    4832                 const bool originInside = EndPointInsideNode(leaf, *ray, false); 
    4833         const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
    4834  
    4835                 if (originInside || terminationInside) 
    4836                 { 
    4837                         touchedRays.push_back(*rit); 
    4838                         // add volume to volumes of left and / or right children 
    4839                         // if one of the ray end points is inside 
    4840                         const int classification = ClassifyRay(ray, leaf, candidatePlane); 
    4841  
    4842                         ViewCellContainer viewCells; 
    4843                         mVspTree->GetViewCells(*ray, viewCells); 
    4844                          
    4845                         ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    4846  
    4847                         // traverse through view cells and classify them according 
    4848                         // to them being seen from to back / front / front and back node 
    4849                         for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    4850                         { 
    4851                                 ViewCell *vc = *vit; 
    4852  
    4853                                 // if not previously mailed 
    4854                                 if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 
    4855                                 { 
    4856                                         touchedViewCells.push_back(vc); 
    4857                                 } 
    4858  
    4859                 // classify / mail the view cell 
    4860                                 MailViewCell(*vit, classification);      
    4861                         } 
    4862                 } 
    4863         } 
    4864          
    4865         // the important view cells 
    4866         ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
    4867  
    4868         for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
    4869         { 
    4870                 ViewCell *vc = *vit; 
    4871  
    4872                 if (vc->Mailed()) 
    4873                         frontViewCells.push_back(vc); 
    4874                 else if (vc->Mailed(1)) 
    4875                         backViewCells.push_back(vc); 
    4876                 else if (vc->Mailed(2)) 
    4877                         frontAndBackViewCells.push_back(vc); 
    4878         } 
    4879  
    4880         return 0; 
    4881 } 
    4882  
    4883  
    48844830int OspTree::CheckViewCellsPvs(KdLeaf *leaf,  
    48854831                                                           const RayInfoContainer &rays) const 
     
    48954841                VssRay *ray = (*rit).mRay; 
    48964842 
    4897                 // test if intersection point with one of the objects is inside this node 
    4898                 const bool originInside = EndPointInsideNode(leaf, *ray, false); 
    4899         const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
    4900  
    4901                 if (terminationInside) 
     4843                if (ray->mTerminationObject) 
    49024844                { 
    49034845                        Intersectable *obj = ray->mTerminationObject; 
     
    49104852                } 
    49114853 
    4912                 if (originInside) 
     4854                if (ray->mOriginObject) 
    49134855                { 
    49144856                        Intersectable *obj = ray->mOriginObject; 
     
    49384880 
    49394881 
    4940  
    4941  
    49424882KdIntersectable *OspTree::GetOrCreateKdIntersectable(KdNode *node) 
    49434883{ 
     
    49524892 
    49534893        // not in map => create new entry 
    4954         KdIntersectable *kdObj= new KdIntersectable(node); 
    4955  
     4894        KdIntersectable *kdObj = new KdIntersectable(node); 
    49564895        mKdIntersectables[node] = kdObj; 
    49574896 
     
    50144953        if (cf >= 0) // front volume 
    50154954        { 
    5016                  // already in back volume => in both volumes 
     4955                // already in back volume => in both volumes 
    50174956                if (vc->Mailed(1)) 
    50184957                { 
     
    50725011                VssRay *ray = (*rit).mRay; 
    50735012 
    5074                 // process ray if the hit point with termination / origin object  
    5075                 // is inside this kd leaf 
    5076                 if (!((EndPointInsideNode(leaf, *ray, true)) || 
    5077                           (EndPointInsideNode(leaf, *ray, false)))) 
    5078                         continue; 
    5079                  
    50805013                ViewCellContainer viewCells; 
    5081                 mVspTree->CastLineSegment(ray->mOrigin, ray->mTermination, viewCells); 
     5014                mVspTree->GetViewCells(*ray, viewCells); 
    50825015 
    50835016                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     
    51065039        contribution = 0; // todo 
    51075040 
    5108         ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
     5041        MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
    51095042 
    51105043        if (!vdata) 
     
    51205053 
    51215054        return true; 
     5055} 
     5056 
     5057 
     5058void OspTree::CollectTouchedViewCells(const RayInfoContainer &rays,  
     5059                                                                          ViewCellContainer &touchedViewCells) const 
     5060{ 
     5061        ViewCell::NewMail(); 
     5062         
     5063        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     5064 
     5065        for (rit = rays.begin(); rit != rit_end; ++ rit) 
     5066        { 
     5067                VssRay *ray = (*rit).mRay; 
     5068 
     5069                ViewCellContainer viewCells; 
     5070                mVspTree->GetViewCells(*ray, viewCells); 
     5071 
     5072                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     5073 
     5074                // traverse through view cells and classify them according 
     5075                // to them being seen from to back / front / front and back node 
     5076                for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     5077                { 
     5078                        ViewCell *vc = *vit; 
     5079                        if (!vc->Mailed()) 
     5080                        { 
     5081                                vc->Mail(); 
     5082                                touchedViewCells.push_back(vc); 
     5083                        } 
     5084                } 
     5085        } 
    51225086} 
    51235087 
     
    51275091 
    51285092{ 
    5129         RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
    5130  
    5131         //ViewCell::NewMail(); Intersectable::NewMail(); 
    5132         ViewCellPvsData::NewMail(); 
     5093        MailablePvsData::NewMail(); 
     5094         
     5095        /*RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
    51335096 
    51345097        for (rit = rays.begin(); rit < rit_end; ++ rit) 
     
    51365099                VssRay *ray = (*rit).mRay; 
    51375100 
    5138                 // test if intersection point with one of the objects is inside this node 
    5139                 const bool originInside = EndPointInsideNode(leaf, *ray, false); 
    5140         const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
    5141  
    5142                 if (originInside || terminationInside) 
    5143                 { 
    5144                         ViewCellContainer viewCells; 
    5145                         mVspTree->GetViewCells(*ray, viewCells); 
    5146  
    5147                         ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    5148  
    5149                         // traverse through view cells and classify them according 
    5150                         // to them being seen from to back / front / front and back node 
    5151                         for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    5152                         { 
    5153                                 ViewCell *vc = *vit; 
    5154  
    5155                                 Intersectable *obj = ray->mTerminationObject; 
    5156                          
    5157                                 if (obj) 
    5158                                 { 
    5159                                         float contri; 
    5160                                         AddViewCellToObjectPvs(obj, vc, contri, true); 
    5161                                 } 
    5162  
    5163                                 obj = ray->mOriginObject; 
    5164                          
    5165                                 if (obj) 
    5166                                 { 
    5167                                         float contri; 
    5168                                         AddViewCellToObjectPvs(obj, vc, contri, true); 
    5169                                 } 
    5170                         } 
     5101                ViewCellContainer viewCells; 
     5102                mVspTree->GetViewCells(*ray, viewCells); 
     5103 
     5104                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     5105 
     5106                // traverse through view cells and classify them according 
     5107                // to them being seen from to back / front / front and back node 
     5108                for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     5109                { 
     5110                        ViewCell *vc = *vit; 
     5111 
     5112                        Intersectable *obj = ray->mTerminationObject; 
     5113                        if (obj) 
     5114                        { 
     5115                                float contri; 
     5116                                AddViewCellToObjectPvs(obj, vc, contri, true); 
     5117                        } 
     5118 
     5119                        obj = ray->mOriginObject; 
     5120                        if (obj) 
     5121                        { 
     5122                                float contri; 
     5123                                AddViewCellToObjectPvs(obj, vc, contri, true); 
     5124                        } 
     5125                } 
     5126        }*/ 
     5127         
     5128        ViewCellContainer touchedViewCells; 
     5129        CollectTouchedViewCells(rays, touchedViewCells); 
     5130 
     5131        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     5132 
     5133        for (oit = leaf->mObjects.begin(); oit < oit_end; ++ oit) 
     5134        { 
     5135                Intersectable *obj = *oit; 
     5136                ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     5137 
     5138                // traverse through view cells and classify them according 
     5139                // to them being seen from to back / front / front and back node 
     5140                for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     5141                { 
     5142                        ViewCell *vc = *vit; 
     5143                        float contri; 
     5144                        AddViewCellToObjectPvs(obj, vc, contri, true); 
    51715145                } 
    51725146        } 
     
    51815155 
    51825156{ 
    5183         RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
    5184         //ViewCell::NewMail(); Intersectable::NewMail(); 
    5185         ViewCellPvsData::NewMail(); 
    5186  
     5157        MailablePvsData::NewMail(); 
     5158 
     5159        /*RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
    51875160        for (rit = rays.begin(); rit < rit_end; ++ rit) 
    51885161        { 
     
    51905163 
    51915164                // test if intersection point with one of the objects is inside this node 
    5192                 const bool originInside = EndPointInsideNode(leaf, *ray, false); 
    5193         const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
    5194  
    5195                 if (originInside || terminationInside) 
    5196                 { 
    5197                         ViewCellContainer viewCells; 
    5198                         mVspTree->GetViewCells(*ray, viewCells); 
    5199  
    5200                         ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    5201  
    5202                         // traverse through view cells and classify them according 
    5203                         // to them being seen from to back / front / front and back node 
    5204                         for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    5205                         { 
    5206                                 ViewCell *vc = *vit; 
    5207  
    5208                                 Intersectable *obj = ray->mTerminationObject; 
    5209                                 if (obj) 
     5165                ViewCellContainer viewCells; 
     5166                mVspTree->GetViewCells(*ray, viewCells); 
     5167 
     5168                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     5169 
     5170                // traverse through view cells and classify them according 
     5171                // to them being seen from to back / front / front and back node 
     5172                for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     5173                { 
     5174                        ViewCell *vc = *vit; 
     5175                        Intersectable *obj = ray->mTerminationObject; 
     5176 
     5177                        if (obj) 
     5178                        { 
     5179                                MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
     5180 
     5181                                if (vdata && !vdata->Mailed()) 
    52105182                                { 
    5211                                         ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
    5212  
    5213                                         if (vdata && !vdata->Mailed()) 
    5214                                         { 
    5215                                                 vdata->Mail(); 
    5216                                                 obj->mViewCellPvs.RemoveSample(vc, 1); 
    5217                                         } 
    5218                                          
     5183                                        vdata->Mail(); 
     5184                                        obj->mViewCellPvs.RemoveSample(vc, 1); 
    52195185                                } 
    5220  
    5221                                 obj = ray->mOriginObject; 
    5222                                 if (obj) 
     5186                        } 
     5187 
     5188                        obj = ray->mOriginObject; 
     5189 
     5190                        if (obj) 
     5191                        { 
     5192                                MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
     5193 
     5194                                if (vdata && !vdata->Mailed()) 
    52235195                                { 
    5224                                         ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
    5225  
    5226                                         if (vdata && !vdata->Mailed()) 
    5227                                         { 
    5228                                                 vdata->Mail(); 
    5229                                                 obj->mViewCellPvs.RemoveSample(vc, 1); 
    5230                                         } 
     5196                                        vdata->Mail(); 
     5197                                        obj->mViewCellPvs.RemoveSample(vc, 1); 
    52315198                                } 
     5199                        } 
     5200                } 
     5201        }*/ 
     5202 
     5203        ViewCellContainer touchedViewCells; 
     5204        CollectTouchedViewCells(rays, touchedViewCells); 
     5205 
     5206        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     5207 
     5208        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     5209        { 
     5210                Intersectable *obj = *oit; 
     5211 
     5212                // traverse through view cells and classify them according 
     5213                // to them being seen from to back / front / front and back node 
     5214        ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     5215 
     5216                for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     5217                { 
     5218                        ViewCell *vc = *vit; 
     5219                         
     5220                        MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
     5221 
     5222                        if (vdata && !vdata->Mailed()) 
     5223                        { 
     5224                                vdata->Mail(); 
     5225                                obj->mViewCellPvs.RemoveSample(vc, 1); 
    52325226                        } 
    52335227                } 
     
    52605254        KdLeafContainer::const_iterator kit, kit_end = leaves.end(); 
    52615255 
    5262         ViewCellPvsData::NewMail(); 
     5256        MailablePvsData::NewMail(); 
    52635257 
    52645258        for (kit = leaves.begin(); kit != kit_end; ++ kit) 
     
    52775271                         
    52785272                        // test if intersection point with one of the objects is inside this node 
    5279  
    52805273                        const bool originInside = EndPointInsideNode(leaf, *ray, false); 
    52815274                        const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
     
    53055298                ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    53065299 
    5307                 //Debug << "here53 " << touchedViewCells.size() << endl; 
    53085300                for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
    53095301                { 
     
    53145306                        { 
    53155307                                ViewCell *vc = *vit; 
    5316                                 /*ObjectPvsData *vdata = vc->GetPvs().Find(obj); 
     5308                                PvsData *vdata = vc->GetPvs().Find(obj); 
    53175309 
    53185310                                if (!vdata) 
     
    53205312                                        vc->GetPvs().AddSample(obj, 1); 
    53215313                                        newCost += vc->GetVolume(); 
    5322                                         //prop += vc->GetVolume(); 
    5323                                 }*/ 
    5324  
    5325                                 ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
     5314                                } 
     5315 
     5316/*                              MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 
    53265317 
    53275318                                if (!vdata || !vdata->Mailed()) 
     
    53315322                                                vdata = obj->mViewCellPvs.AddSample2(vc, 1); 
    53325323                                        vdata->Mail(); 
    5333                                 } 
     5324                                }*/ 
    53345325                        } 
    53355326                } 
     
    53975388                { 
    53985389                        ViewCell *vc = *vit; 
    5399                         ObjectPvsData *vdata = vc->GetPvs().Find(obj); 
     5390                        PvsData *vdata = vc->GetPvs().Find(obj); 
    54005391 
    54015392                        if (!vdata) 
     
    54265417 
    54275418        char subdivisionStatsLog[100]; 
    5428         Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats", subdivisionStatsLog); 
     5419        Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats",  
     5420                subdivisionStatsLog); 
    54295421        mSubdivisionStats.open(subdivisionStatsLog); 
    54305422} 
     
    55335525 
    55345526        // probabilty is voume of all "seen" view cells 
    5535 #if 0 
     5527#if 1 
    55365528        const float prop = mOspTree.EvalViewCellsVolume(kdleaf, rays); 
    55375529#else 
     
    55455537                                                                        0, 
    55465538                                                                        &rays, 
    5547                                                                         (int)objects.size(), 
     5539                                                                        0,//(int)objects.size(), 
    55485540                                                                        prop, 
    55495541                                                                        mOspTree.mBoundingBox); 
     
    55535545        OspTree::OspSplitCandidate *oSplitCandidate =  
    55545546                new OspTree::OspSplitCandidate(oData); 
     5547 
     5548        mOspTree.UpdateViewCellsPvs(kdleaf, rays); 
    55555549 
    55565550        mOspTree.EvalSplitCandidate(*oSplitCandidate); 
     
    57555749        ///////////////////////////////////////////////////////////// 
    57565750 
     5751 
    57575752        Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 
    57585753        cout << "starting osp contruction ... " << endl; 
     
    57845779        float rc = mOspTree.EvalRenderCost(sampleRays); 
    57855780 
    5786         Debug << "My render cost evalulation: " << rc << endl; 
     5781        Debug << "here47 My render cost evalulation: " << rc << endl; 
    57875782 
    57885783#if 0 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1186 r1189  
    15871587        int FilterRays(KdLeaf *leaf, const RayInfoContainer &rays, RayInfoContainer &filteredRays); 
    15881588 
    1589         int SplitViewCells( 
    1590                 const AxisAlignedPlane &candidatePlane, 
    1591                 const RayInfoContainer &rays, 
    1592                 KdLeaf *leaf, 
    1593                 ViewCellContainer &frontViewCells, 
    1594                 ViewCellContainer &backViewCells, 
    1595                 ViewCellContainer &frontAndBackViewCells) const; 
    1596  
    15971589        /** Adds the object to the pvs of the front and back leaf with a given classification. 
    15981590 
     
    16411633        /** Evaluate the contributions of view cell volume of the left and the right view cell. 
    16421634        */ 
    1643         void EvalVolumeContribution(const VssRay &ray,  
    1644                                                                         float &volLeft,  
    1645                                                                         float &volRight); 
    1646  
     1635        void EvalRayContribution(KdLeaf *leaf, 
     1636                                                                         const VssRay &ray,  
     1637                                                                         float &renderCost); 
     1638void EvalViewCellContribution(KdLeaf *leaf,  
     1639                                                                           ViewCell *viewCell, 
     1640                                                                           float &renderCost); 
    16471641        /** Evaluates the influence on the pvs of the event. 
    16481642                @param ve the visibility event 
     
    16521646        void EvalHeuristicsContribution(KdLeaf *leaf, 
    16531647                const SortableEntry &ci, 
    1654                 float &volLeft, 
    1655                 float &volRight, 
    1656                 int &pvsLeft, 
    1657                 int &pvsRight); 
     1648                float &renderCost, 
     1649                ViewCellContainer &touchedViewCells); 
    16581650 
    16591651        /** Prepares objects for the cost heuristics. 
    16601652                @returns pvs size of the node 
    16611653        */ 
    1662         float PrepareHeuristics(const OspTraversalData &tData, int &numViewCells); 
     1654        float PrepareHeuristics(const OspTraversalData &tData, ViewCellContainer &touchedViewCells); 
    16631655 
    16641656        /** Prepares heuristics for a particular ray. 
    16651657        */ 
    1666         float PrepareHeuristics(const VssRay &ray, int &numViewCells); 
     1658        void PrepareHeuristics(const VssRay &ray, ViewCellContainer &touchedViewCells); 
    16671659 
    16681660        /** Prepares construction for vsp and osp trees. 
     
    17261718 
    17271719        int UpdateViewCellsPvs(KdLeaf *leaf, const RayInfoContainer &rays) const; 
    1728 int OspTree::CheckViewCellsPvs(KdLeaf *leaf,  
     1720int CheckViewCellsPvs(KdLeaf *leaf,  
    17291721                                                           const RayInfoContainer &rays) const; 
    17301722        bool AddViewCellToObjectPvs( 
     
    17411733                RayInfoContainer &backRays) const; 
    17421734 
     1735        void CollectTouchedViewCells( 
     1736                const RayInfoContainer &rays,  
     1737                ViewCellContainer &touchedViewCells) const; 
     1738 
     1739        void AddObjectContribution(KdLeaf *leaf, 
     1740                                                  Intersectable * obj, 
     1741                                                  ViewCellContainer &touchedViewCells, 
     1742                                                  float &renderCost); 
     1743        void SubtractObjectContribution(KdLeaf *leaf, 
     1744                                                  Intersectable * obj, 
     1745                                                  ViewCellContainer &touchedViewCells, 
     1746                                                  float &renderCost); 
    17431747protected: 
    17441748 
  • GTP/trunk/Lib/Vis/QtRenderer/QtGlRenderer.cpp

    r1171 r1189  
    277277         
    278278        // Render PVS 
    279         std::map<Intersectable *, 
    280           PvsData<Intersectable *>, 
    281           LtSample<Intersectable *> >::const_iterator it = viewcell->GetPvs().mEntries.begin(); 
     279        ObjectPvsMap::const_iterator it = viewcell->GetPvs().mEntries.begin(); 
    282280 
    283281        pvsSize = viewcell->GetPvs().mEntries.size(); 
     
    341339           
    342340          // Render PVS 
    343           std::map<Intersectable *, 
    344                 PvsData<Intersectable *>, 
    345                 LtSample<Intersectable *> >::const_iterator it = viewcell->GetPvs().mEntries.begin(); 
     341          ObjectPvsMap::const_iterator it = viewcell->GetPvs().mEntries.begin(); 
    346342           
    347343          for (; it != viewcell->GetPvs().mEntries.end(); ++ it) { 
     
    954950         
    955951        // read back the texture 
    956         std::map<Intersectable *, 
    957           PvsData<Intersectable *>, 
    958           LtSample<Intersectable *> >::const_iterator it = pvs.mEntries.begin(); 
     952        ObjectPvsMap::const_iterator it = pvs.mEntries.begin(); 
    959953 
    960954        mPvsSize = pvs.mEntries.size(); 
Note: See TracChangeset for help on using the changeset viewer.