Changeset 466 for trunk


Ignore:
Timestamp:
12/14/05 19:38:39 (19 years ago)
Author:
bittner
Message:

changed the viewcellsmanager interface to use vssrays - some functionality like the bsp merging is now restricted

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp

    r386 r466  
    131131  Vector3 target = xv + yv + mDirection; 
    132132 
    133   ray.intersections.clear(); 
    134   ray.kdLeaves.clear(); 
    135   ray.testedObjects.clear(); 
    136   ray.bspIntersections.clear(); 
    137  
     133  ray.Clear(); 
    138134  ray.Init(mPosition, target, Ray::LOCAL_RAY); 
    139135   
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r462 r466  
    7373  virtual bool 
    7474  ExportRays(const RayContainer &rays, 
    75                                                 const float length=1000, 
    76                                                 const RgbColor &color = RgbColor(1,1,1) 
    77                                                 ) = 0; 
    78  
    79         virtual bool 
     75                        const float length=1000, 
     76                        const RgbColor &color = RgbColor(1,1,1) 
     77                        ) = 0; 
     78   
     79  virtual bool 
    8080  ExportRays(const VssRayContainer &rays, 
    81                                                 const RgbColor &color = RgbColor(1,1,1) 
    82                                                 ) = 0; 
    83  
     81                        const RgbColor &color = RgbColor(1,1,1) 
     82                        ) = 0; 
     83   
    8484  virtual void  
    8585  ExportViewCells(const ViewCellContainer &viewCells) = 0; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp

    r462 r466  
    792792            // $$ JB TEMPORARY solution -> should add object PVS or explictly computed 
    793793            // kd tree PVS 
    794             if (leaf->mKdPvs.AddSample(node)) 
     794                float contribution; 
     795                if (leaf->mKdPvs.AddSample(node, contribution)) 
    795796              totalPvsSize++; 
    796797          } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h

    r406 r466  
    3131{ 
    3232public: 
    33         Pvs(): mSamples(0), mEntries() {} 
     33  Pvs(): mSamples(0), mEntries() {} 
     34   
     35  int mSamples; 
     36   
     37  int Compress() {return 0;} 
     38  int GetSize() const {return (int)mEntries.size();} 
     39  bool Empty() const {return mEntries.size() == 0;} 
     40  /** Merges pvs of a and pvs of b into this pvs. 
     41   */ 
     42  void Merge(const Pvs<T> &a, const Pvs<T> &b); 
     43  /** Difference of pvs to pvs b. 
     44          @returns number of different entries. 
     45  */ 
     46  int Diff(const Pvs<T> &b); 
     47   
     48  PvsData<T> *Find(T sample); 
     49  bool AddSample(T sample, float &contribution); 
     50  int AddSample(T sample); 
    3451 
    35         int mSamples; 
    36  
    37         int Compress() {return 0;} 
    38         int GetSize() const {return (int)mEntries.size();} 
    39         bool Empty() const {return mEntries.size() == 0;} 
    40         /** Merges pvs of a and pvs of b into this pvs. 
    41         */ 
    42         void Merge(const Pvs<T> &a, const Pvs<T> &b); 
    43     /** Difference of pvs to pvs b. 
    44                 @returns number of different entries. 
    45         */ 
    46         int Diff(const Pvs<T> &b); 
    47  
    48         PvsData<T> *Find(T sample); 
    49         int AddSample(T sample); 
    50  
    51         void GetData(const int index, T &entry, PvsData<T> &data); 
    52         std::map<T, PvsData<T>, LtSample<T> > mEntries; 
     52  void GetData(const int index, T &entry, PvsData<T> &data); 
     53  std::map<T, PvsData<T>, LtSample<T> > mEntries; 
    5354}; 
    5455 
     
    116117int Pvs<T>::AddSample(T sample) 
    117118{ 
    118         int result; 
    119         PvsData<T> *data = Find(sample); 
     119  float dummy; 
     120  return AddSample(sample, dummy) ? 1 : 0; 
     121} 
    120122 
    121         if (data)  
    122         { 
    123                 data->mVisibleSamples ++; 
    124                 result = 0; 
    125          
    126         }  
    127         else  
    128         { 
    129                 mEntries[sample] = PvsData<T>(1); 
    130                 result = 1; 
    131         } 
    132  
    133         return  result; 
     123template <typename T> 
     124bool Pvs<T>::AddSample(T sample, float &contribution) 
     125{ 
     126  PvsData<T> *data = Find(sample); 
     127   
     128  if (data)  { 
     129        data->mVisibleSamples++; 
     130        contribution = 1.0f/data->mVisibleSamples; 
     131        return false; 
     132  } 
     133  else { 
     134        mEntries[sample] = PvsData<T>(1); 
     135        contribution = 1.0f; 
     136        return true; 
     137  } 
    134138} 
    135139 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp

    r448 r466  
    220220} 
    221221 
    222 Ray::Ray(const VssRay &vssRay): 
    223 loc(vssRay.mOrigin), 
    224 sourceObject(0, vssRay.mOriginObject, 0), 
    225 mType(LOCAL_RAY) 
    226 { 
    227         float len = vssRay.Length(); 
    228  
    229         if (!len) 
    230                 len = Limits::Small; 
    231  
    232         dir = vssRay.GetDir() / len; 
    233  
    234         if (vssRay.mTerminationObject) 
    235                 intersections.push_back(Intersection(len, vssRay.mTerminationObject, 0)); 
    236  
    237         Precompute(); 
    238 } 
     222void 
     223Ray::Init(const VssRay &vssRay) 
     224{ 
     225  loc = vssRay.mOrigin; 
     226  sourceObject = Intersection(0, vssRay.mOriginObject, 0); 
     227  mType = LOCAL_RAY; 
     228   
     229  float len = vssRay.Length(); 
     230   
     231  if (!len) 
     232        len = Limits::Small; 
     233   
     234  dir = vssRay.GetDir() / len; 
     235   
     236  if (vssRay.mTerminationObject) 
     237        intersections.push_back(Intersection(len, vssRay.mTerminationObject, 0)); 
     238   
     239  Precompute(); 
     240} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h

    r448 r466  
    5959  }; 
    6060 
    61   struct BspIntersection { 
    62     // the point of intersection 
    63     float mT; 
    64  
    65     BspLeaf *mLeaf; 
    66  
    67     BspIntersection(const float t, BspLeaf *l): 
    68                         mT(t), mLeaf(l) {} 
    69                  
    70     BspIntersection() {} 
    71                  
    72     bool operator<(const BspIntersection &b) const { 
    73       return mT <b.mT; } 
    74   }; 
    7561 
    7662  // I should have some abstract cell data type !!! here 
     
    8066   
    8167  vector<Intersection> intersections; 
    82   vector<BspIntersection> bspIntersections; 
     68  //  vector<BspIntersection> bspIntersections; 
    8369  vector<KdLeaf *> kdLeaves; 
    8470  vector<Intersectable *> testedObjects; 
     
    10793  /** Construct ray from a vss ray. 
    10894  */ 
    109   Ray(const VssRay &vssRay);     
    110          
     95  Ray(const VssRay &vssRay) { 
     96        Init(vssRay); 
     97  } 
     98 
     99  void Clear() { 
     100        intersections.clear(); 
     101        kdLeaves.clear(); 
     102        testedObjects.clear(); 
     103        //      bspIntersections.clear(); 
     104  } 
     105 
     106  void Init(const VssRay &vssRay); 
     107 
    111108  Intersectable *GetIntersectionObject(const int i) const { 
    112109    return intersections[i].mObject; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp

    r464 r466  
    525525 
    526526  // viewcells->UpdatePVS(newVssRays); 
    527   // get viewcells as kd tree boxes 
    528   vector<AxisAlignedBox3> kdViewcells; 
    529  
    530   if (0) { 
    531         vector<KdLeaf *> leaves; 
    532         mKdTree->CollectLeaves(leaves); 
    533         vector<KdLeaf *>::const_iterator it; 
    534         int targetLeaves = 50; 
    535         float prob = targetLeaves/(float)leaves.size(); 
    536         for (it = leaves.begin(); it != leaves.end(); ++it) 
    537           if (RandomValue(0.0f,1.0f) < prob) 
    538                 kdViewcells.push_back(mKdTree->GetBox(*it)); 
    539                  
    540         float avgPvs = GetAvgPvsSize(rssTree, kdViewcells); 
    541         cout<<"Initial average PVS size = "<<avgPvs<<endl; 
    542   } 
    543  
    544          
     527   
    545528  int samples = 0; 
    546529  int pass = 0; 
     
    563546        for (int i=0; i < rays.size(); i++) 
    564547          CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 
    565                  
     548         
     549        if (mUseViewcells) { 
     550           
     551           
     552          /// compute view cell contribution of rays 
     553          mViewCellsManager->ComputeSampleContributions(vssRays 
     554                                                                                                        ); 
     555           
     556           
     557          float pvs = rssTree->GetAvgPvsSize(); 
     558          cout<<"*****************************\n"; 
     559          cout<<samples<<" avgPVS ="<<pvs<<endl; 
     560          cout<<"RssTree root PVS size = "<<rssTree->GetRootPvsSize()<<endl; 
     561          cout<<"*****************************\n"; 
     562        } 
     563 
     564 
     565 
    566566        rssTree->AddRays(vssRays); 
    567                  
     567         
    568568        if (mUpdateSubdivision) { 
    569569          int subdivided = rssTree->UpdateSubdivision(); 
    570570          cout<<"subdivided leafs = "<<subdivided<<endl; 
    571571          cout<<"#total leaves = "<<rssTree->stat.Leaves()<<endl; 
    572  
    573572        } 
    574573 
    575574        if (mUseViewcells) { 
    576           float avgPvs = GetAvgPvsSize(rssTree, kdViewcells); 
    577           cout<<"Average PVS size = "<<avgPvs<<endl; 
     575          //      float avgPvs = GetAvgPvsSize(rssTree, kdViewcells); 
     576          //      cout<<"Average PVS size = "<<avgPvs<<endl; 
    578577        } 
    579578 
     
    590589        samples+=num; 
    591590 
    592         if (mUseViewcells) { 
    593            
    594           //-- prepare traversal rays for view cell intersections 
    595           RayContainer passRays; 
    596            
    597           VssRayContainer::const_iterator it, it_end = vssRays.end(); 
    598            
    599           for (it = vssRays.begin(); it != it_end; ++ it) 
    600                 passRays.push_back(new Ray(*(*it))); 
    601            
    602           int sampleContributions = 0; 
    603           int contributingSamples = 0; 
    604            
    605           /// compute view cell contribution of rays 
    606           mViewCellsManager->ComputeSampleContributions(passRays, 
    607                                                                                                         sampleContributions,  
    608                                                                                                         contributingSamples); 
    609            
    610           //-- save rays for post processing 
    611           if (((int)storedRays.size() < mViewCellsManager->GetPostProcessSamples()) || 
    612                   ((int)storedRays.size() < mViewCellsManager->GetVisualizationSamples())) 
    613                 { 
    614                   RayContainer::const_iterator it, it_end = passRays.end(); 
    615                    
    616                   for (it = passRays.begin(); it != it_end; ++ it) 
    617                         storedRays.push_back(new Ray(*(*it))); 
    618                 } 
    619           else 
    620                 { 
    621                   CLEAR_CONTAINER(passRays); 
    622                 } 
    623            
    624           float pvs = rssTree->GetAvgPvsSize(); 
    625           cout<<"*****************************\n"; 
    626           cout<<samples<<" avgPVS ="<<pvs<<endl; 
    627           cout<<"sample contributions ="<<sampleContributions<<endl; 
    628           cout<<"contributing sample ="<<contributingSamples<<endl; 
    629           cout<<"RssTree root PVS size = "<<rssTree->GetRootPvsSize()<<endl; 
    630           cout<<"*****************************\n"; 
    631         } 
    632591         
    633592        if (mExportPvs) { 
     
    645604   
    646605  if (mUseViewcells) { 
     606 
     607        VssRayContainer storedRays; 
     608        rssTree->CollectRays(storedRays, Max( 
     609                                                                                 mViewCellsManager->GetPostProcessSamples(), 
     610                                                                                 mViewCellsManager->GetVisualizationSamples())); 
    647611         
    648612        //-- post process view cells 
     
    651615        //-- several visualizations and statistics 
    652616        mViewCellsManager->PrintStatistics(Debug); 
    653          
    654         //-- render simulation after merge 
    655         cout << "\nevaluating render time of final view cells ... "; 
    656          
    657         const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 
    658          
    659         cout << " finished" << endl; 
    660          
    661         cout << ss << endl; 
    662         Debug << ss << endl; 
    663          
     617 
    664618        mViewCellsManager->Visualize(mObjects, storedRays); 
    665   } 
    666    
     619 
     620        CLEAR_CONTAINER(storedRays); 
     621 
     622  //-- render simulation after merge 
     623  cout << "\nevaluating bsp view cells render time after merge ... "; 
     624   
     625  const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 
     626   
     627  cout << " finished" << endl; 
     628  cout << ss << endl; 
     629  Debug << ss << endl; 
     630 
     631  } 
     632 
    667633  delete rssTree; 
    668634   
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp

    r464 r466  
    20512051  return box; 
    20522052} 
     2053 
     2054 
     2055int 
     2056RssTree::CollectRays(VssRayContainer &rays, 
     2057                                         const int number) 
     2058{ 
     2059  VssRayContainer allRays; 
     2060  CollectRays(allRays); 
     2061   
     2062  int desired = min(number, (int)allRays.size()); 
     2063  float prob = desired/(float)allRays.size(); 
     2064  while (rays.size() < desired) { 
     2065        VssRayContainer::const_iterator it = allRays.begin(); 
     2066        for (; it != allRays.end() && rays.size() < desired; it++) { 
     2067          if (Random(1.0f) < prob) 
     2068                rays.push_back(*it); 
     2069        } 
     2070  } 
     2071  return rays.size(); 
     2072} 
     2073 
     2074 
     2075int 
     2076RssTree::CollectRays(VssRayContainer &rays 
     2077                                         ) 
     2078{ 
     2079  VssRay::NewMail(); 
     2080 
     2081  stack<RssTreeNode *> tstack; 
     2082  tstack.push(root); 
     2083   
     2084  while (!tstack.empty()) { 
     2085    RssTreeNode *node = tstack.top(); 
     2086    tstack.pop(); 
     2087         
     2088    if (node->IsLeaf()) { 
     2089          RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
     2090          // update pvs size 
     2091          RssTreeNode::RayInfoContainer::const_iterator it = leaf->rays.begin(); 
     2092          for (;it != leaf->rays.end(); ++it) 
     2093                if (!(*it).mRay->Mailed()) { 
     2094                  (*it).mRay->Mail(); 
     2095                  rays.push_back((*it).mRay); 
     2096                } 
     2097        } else { 
     2098          RssTreeInterior *in = (RssTreeInterior *)node; 
     2099          // both nodes for directional splits 
     2100          tstack.push(in->front); 
     2101          tstack.push(in->back); 
     2102        } 
     2103  } 
     2104   
     2105  return rays.size(); 
     2106} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h

    r464 r466  
    857857                           ); 
    858858 
     859    int 
     860  CollectRays(VssRayContainer &rays, 
     861                          const int number); 
     862 
     863  int 
     864  CollectRays(VssRayContainer &rays 
     865                          ); 
     866 
    859867}; 
    860868 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r462 r466  
    3232                                                           const Ray::Intersection &origin) 
    3333{ 
    34         ray.intersections.clear(); 
    35         ray.kdLeaves.clear(); 
    36         ray.testedObjects.clear(); 
    37         ray.bspIntersections.clear(); 
     34  ray.Clear(); 
    3835   
    3936        ray.mFlags |= Ray::STORE_KDLEAVES | Ray::STORE_BSP_INTERSECTIONS; 
     
    5956  
    6057void 
    61 SamplingPreprocessor::CastRays(const RayContainer &rays,  
    62                                                            int &sampleContributions,  
    63                                                            int &contributingSamples) 
     58SamplingPreprocessor::CastRays(const RayContainer &rays) 
    6459{        
    65         // cast ray to KD tree to find intersection with other objects 
    66         RayContainer::const_iterator it, it_end = rays.end(); 
    67   
    68         for (it = rays.begin(); it != it_end; ++it) 
    69         mKdTree->CastRay(*(*it)); 
    70  
    71         // for KD tree, intersecting view cells are already known, so no  
    72         // additional ray must be cast to them 
    73         const bool castRaysToViewCells =  
    74                 (mViewCellsManager->GetType() != ViewCellsManager::KD); 
    75  
    76         mViewCellsManager->ComputeSampleContributions(rays,  
    77                                                                                                   sampleContributions,  
    78                                                                                                   contributingSamples, 
    79                                                                                                   castRaysToViewCells); 
     60  // cast ray to KD tree to find intersection with other objects 
     61  RayContainer::const_iterator it, it_end = rays.end(); 
     62 
     63  VssRayContainer vssRays; 
     64  for (it = rays.begin(); it != it_end; ++it) { 
     65        mKdTree->CastRay(*(*it)); 
     66        vssRays.push_back(new VssRay(*(*it))); 
     67  } 
     68   
     69  mViewCellsManager->ComputeSampleContributions(vssRays); 
     70  CLEAR_CONTAINER(vssRays); 
    8071} 
    8172 
     
    8475{ 
    8576        // cast ray to KD tree to find intersection with other objects 
    86         mKdTree->CastRay(ray); 
    87  
    88         bool castRayToViewCells = mViewCellsManager->GetType() != ViewCellsManager::KD; 
    89  
    90         return mViewCellsManager->ComputeSampleContributions(ray, castRayToViewCells); 
     77  mKdTree->CastRay(ray); 
     78  VssRay vssRay(ray); 
     79  mViewCellsManager->ComputeSampleContributions(vssRay); 
     80  return vssRay.mPvsContribution; 
    9181} 
    9282 
     
    395385                mViewCellsManager->Construct(objects, mVssSampleRays); 
    396386 
    397         mViewCellsManager->PostProcess(objects, mSampleRays); 
     387        // $$JB temporary removed 
     388        //      mViewCellsManager->PostProcess(objects, mSampleRays); 
    398389         
    399390        //-- several visualizations and statistics 
     
    409400        Debug << ss << endl; 
    410401         
    411         mViewCellsManager->Visualize(objects, mSampleRays);      
     402        // $$JB temporary removed 
     403        //mViewCellsManager->Visualize(objects, mSampleRays);    
    412404    
    413405        return true; 
     
    419411                                                                                        int &contributingSamples) 
    420412{ 
    421         // cast rays to view cells 
    422         CastRays(newRays, sampleContributions, contributingSamples); 
    423  
    424         // save rays for view cells construction 
    425         if (!mViewCellsManager->ViewCellsConstructed()) 
     413  // cast rays to view cells 
     414  CastRays(newRays); 
     415 
     416  // save rays for view cells construction 
     417  if (!mViewCellsManager->ViewCellsConstructed()) 
    426418        { 
    427                 if ((int)mVssSampleRays.size() < mViewCellsManager->GetConstructionSamples()) 
     419          if ((int)mVssSampleRays.size() < mViewCellsManager->GetConstructionSamples()) 
    428420                { 
    429                         RayContainer::const_iterator it, it_end = newRays.end(); 
    430  
    431                         for (it = newRays.begin(); it != it_end; ++ it) 
    432                                 mVssSampleRays.push_back(new VssRay(*(*it))); 
    433                 } 
    434                 else 
     421                  RayContainer::const_iterator it, it_end = newRays.end(); 
     422                   
     423                  for (it = newRays.begin(); it != it_end; ++ it) 
     424                        mVssSampleRays.push_back(new VssRay(*(*it))); 
     425                } 
     426          else 
    435427                { 
    436                         // construct view cells 
    437                         mViewCellsManager->Construct(objects, mVssSampleRays); 
    438                  
    439                         // throw away samples  
    440                         //CLEAR_CONTAINER(mVssSampleRays); 
    441                 } 
    442         } 
    443         // Need rays (with ordered intersections) for post processing => collect new rays 
    444         if (((int)mSampleRays.size() < mViewCellsManager->GetPostProcessSamples()) || 
    445             ((int)mSampleRays.size() < mViewCellsManager->GetVisualizationSamples())) 
     428                  // construct view cells 
     429                  mViewCellsManager->Construct(objects, mVssSampleRays); 
     430                   
     431                  // throw away samples  
     432                  //CLEAR_CONTAINER(mVssSampleRays); 
     433                } 
     434        } 
     435  // Need rays (with ordered intersections) for post processing => collect new rays 
     436  if (((int)mSampleRays.size() < mViewCellsManager->GetPostProcessSamples()) || 
     437          ((int)mSampleRays.size() < mViewCellsManager->GetVisualizationSamples())) 
    446438        { 
    447                 RayContainer::const_iterator it, it_end = newRays.end(); 
    448  
    449                 for (it = newRays.begin(); it != it_end; ++ it) 
    450                                 mSampleRays.push_back(new Ray(*(*it))); 
    451         } 
    452 } 
     439          RayContainer::const_iterator it, it_end = newRays.end(); 
     440           
     441          for (it = newRays.begin(); it != it_end; ++ it) 
     442                mSampleRays.push_back(new Ray(*(*it))); 
     443        } 
     444} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r463 r466  
    2828                   const Vector3 &point,  
    2929                   const Vector3 &direction, 
    30                         const int type, 
    31                         const Ray::Intersection &source); 
    32  
    33         /** Refined sampling for finding "holes", i.e., difficult visibility. 
    34         */ 
     30                  const int type, 
     31                  const Ray::Intersection &source); 
     32   
     33  /** Refined sampling for finding "holes", i.e., difficult visibility. 
     34   */ 
    3535  void 
    3636  HoleSamplingPass(); 
    37  
    38         /** Casts a bundle of sample rays into the scene. 
     37   
     38  /** Casts a bundle of sample rays into the scene. 
    3939                @param sampleContributions the number of sample contributions 
    4040                @param contributingSamples the number of samples contributing 
    4141        */ 
    4242        void 
    43         CastRays(const RayContainer &rays, 
    44                          int &sampleContributions,  
    45                          int &contributingSamples); 
     43        CastRays(const RayContainer &rays); 
    4644         
    4745        /** Casts a single ray into the scene. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r463 r466  
    17641764} 
    17651765 
    1766 int BspTree::CastRay(Ray &ray) 
     1766int 
     1767BspTree::_CastRay(Ray &ray) 
    17671768{ 
    17681769        int hits = 0; 
     
    18331834                        if (!leaf->mViewCell->Mailed()) 
    18341835                        { 
    1835                                 ray.bspIntersections.push_back(Ray::BspIntersection(maxt, leaf)); 
     1836                          //                            ray.bspIntersections.push_back(Ray::BspIntersection(maxt, leaf)); 
    18361837                                leaf->mViewCell->Mail(); 
    18371838                                ++ hits; 
     
    18591860 
    18601861        return hits; 
     1862} 
     1863 
     1864 
     1865int 
     1866BspTree::CastLineSegment(const Vector3 &origin, 
     1867                                                 const Vector3 &termination, 
     1868                                                 vector<ViewCell *> &viewcells 
     1869                                                 ) 
     1870{ 
     1871  int hits = 0; 
     1872  stack<BspRayTraversalData> tStack; 
     1873   
     1874  float mint = 0.0f, maxt = 1.0f; 
     1875   
     1876  Intersectable::NewMail(); 
     1877   
     1878  Vector3 entp = origin; 
     1879  Vector3 extp = termination; 
     1880   
     1881  BspNode *node = mRoot; 
     1882  BspNode *farChild = NULL; 
     1883   
     1884  while (1) { 
     1885        if (!node->IsLeaf())  { 
     1886          BspInterior *in = dynamic_cast<BspInterior *>(node); 
     1887           
     1888          Plane3 splitPlane = in->GetPlane(); 
     1889          const int entSide = splitPlane.Side(entp); 
     1890          const int extSide = splitPlane.Side(extp); 
     1891           
     1892          if (entSide < 0) { 
     1893                node = in->GetBack(); 
     1894                 
     1895                if(extSide <= 0) // plane does not split ray => no far child 
     1896                  continue; 
     1897                 
     1898                farChild = in->GetFront(); // plane splits ray 
     1899                 
     1900          } else 
     1901                if (entSide > 0) { 
     1902                  node = in->GetFront(); 
     1903                   
     1904                  if (extSide >= 0) // plane does not split ray => no far child 
     1905                        continue; 
     1906                   
     1907                  farChild = in->GetBack(); // plane splits ray                  
     1908                } 
     1909                else // ray and plane are coincident 
     1910                  { 
     1911                        // WHAT TO DO IN THIS CASE ? 
     1912                        //break; 
     1913                        node = in->GetFront(); 
     1914                        continue; 
     1915                  } 
     1916           
     1917          // push data for far child 
     1918          tStack.push(BspRayTraversalData(farChild, extp, maxt)); 
     1919           
     1920          // find intersection of ray segment with plane 
     1921          float t; 
     1922          extp = splitPlane.FindIntersection(origin, extp, &t); 
     1923          maxt *= t; 
     1924           
     1925        } else { 
     1926          // reached leaf => intersection with view cell 
     1927          BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     1928           
     1929          if (!leaf->mViewCell->Mailed()) { 
     1930                viewcells.push_back(leaf->mViewCell); 
     1931                leaf->mViewCell->Mail(); 
     1932                hits++; 
     1933          } 
     1934           
     1935          //-- fetch the next far child from the stack 
     1936          if (tStack.empty()) 
     1937                break; 
     1938       
     1939          entp = extp; 
     1940          mint = maxt; // NOTE: need this? 
     1941           
     1942          BspRayTraversalData &s = tStack.top(); 
     1943           
     1944          node = s.mNode; 
     1945          extp = s.mExitPoint; 
     1946          maxt = s.mMaxT; 
     1947           
     1948          tStack.pop(); 
     1949        } 
     1950  } 
     1951  return hits; 
    18611952} 
    18621953 
     
    23552446                int contribution = 0; 
    23562447                Ray *ray = (*it)->mRay; 
    2357                          
     2448                float relContribution; 
    23582449                if (!ray->intersections.empty()) 
    2359                         contribution += vc->GetPvs().AddSample(ray->intersections[0].mObject); 
     2450                  contribution += vc->GetPvs().AddSample(ray->intersections[0].mObject, relContribution); 
    23602451                 
    23612452                if (ray->sourceObject.mObject) 
    2362                         contribution += vc->GetPvs().AddSample(ray->sourceObject.mObject); 
     2453                        contribution += vc->GetPvs().AddSample(ray->sourceObject.mObject, relContribution); 
    23632454 
    23642455                if (contribution) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r463 r466  
    407407                @returns the number of intersections with objects stored in the tree. 
    408408        */ 
    409         int CastRay(Ray &ray); 
     409  int 
     410  _CastRay(Ray &ray); 
     411 
     412 
     413  int 
     414  CastLineSegment(const Vector3 &origin, 
     415                                  const Vector3 &termination, 
     416                                  ViewCellContainer &viewcells 
     417                                  ); 
    410418 
    411419        /// bsp tree construction types 
     
    838846}; 
    839847 
     848struct BspIntersection { 
     849  // the point of intersection 
     850  float mT; 
     851   
     852  BspLeaf *mLeaf; 
     853   
     854  BspIntersection(const float t, BspLeaf *l): 
     855        mT(t), mLeaf(l) {} 
     856   
     857  BspIntersection() {} 
     858   
     859  bool operator<(const BspIntersection &b) const { 
     860        return mT       <b.mT; } 
     861}; 
     862 
    840863#endif 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r465 r466  
    6767} 
    6868 
    69 void ViewCellsManager::ComputeSampleContributions(const RayContainer &rays,  
    70                                                                                                   int &sampleContributions, 
    71                                                                                                   int &contributingSamples, 
    72                                                                                                   const bool castRays) 
    73 { 
    74         // view cells not yet constructed 
    75         if (!ViewCellsConstructed()) 
    76                 return; 
    77  
    78         RayContainer::const_iterator it, it_end = rays.end(); 
    79  
    80         sampleContributions = 0; 
    81         contributingSamples = 0; 
    82  
    83     for (it = rays.begin(); it != it_end; ++ it) 
    84         { 
    85                 sampleContributions += ComputeSampleContributions(*(*it), castRays); 
    86                 contributingSamples += sampleContributions > 0; 
    87         } 
     69void 
     70ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays 
     71                                                                                         ) 
     72{ 
     73  // view cells not yet constructed 
     74  if (!ViewCellsConstructed()) 
     75        return; 
     76   
     77  VssRayContainer::const_iterator it, it_end = rays.end(); 
     78  for (it = rays.begin(); it != it_end; ++ it) { 
     79        ComputeSampleContributions(*(*it)); 
     80  } 
    8881} 
    8982 
     
    277270} 
    278271 
    279 int BspViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 
    280 { 
    281         // view cells not yet constructed 
    282         if (!ViewCellsConstructed()) 
    283                 return 0; 
    284  
    285         int contributingSamples = 0; 
    286  
    287         if (castRay) 
    288                 mBspTree->CastRay(ray); 
    289          
    290         //if (mBspTree->bspIntersections.empty()) return 0; 
    291  
    292         Intersectable *tObject =  
    293                 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL; 
    294  
    295         Intersectable *sObject = ray.sourceObject.mObject; 
    296  
    297         if (sObject || tObject) 
    298         { 
    299                 // object can be seen from the view cell => add to view cell pvs 
    300                 for (int j = 0; j < (int)ray.bspIntersections.size(); ++ j) 
    301                 {        
    302                         BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    303                  
    304                         // if ray not outside of view space 
    305                         if (leaf->GetViewCell() != mBspTree->GetRootCell()) 
    306                         { 
    307                                 if (sObject) 
    308                                 { 
    309                                         contributingSamples +=  
    310                                                 leaf->GetViewCell()->GetPvs().AddSample(sObject); 
    311                                 } 
    312  
    313                                 if (tObject) 
    314                                 { 
    315                                         contributingSamples +=  
    316                                                 leaf->GetViewCell()->GetPvs().AddSample(tObject); 
    317                                 } 
    318                         } 
    319                 } 
    320         } 
    321  
    322         // rays passing through this viewcell 
    323         if (0) 
    324                 for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j)  
    325                 { 
    326                         BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    327  
    328                         if (leaf->GetViewCell() != mBspTree->GetRootCell()) 
    329                                 leaf->GetViewCell()-> 
    330                                         AddPassingRay(ray, contributingSamples ? 1 : 0); 
    331                 } 
    332  
    333         return contributingSamples; 
    334 } 
    335  
    336 int BspViewCellsManager::PostProcess(const ObjectContainer &objects,  
    337                                                                          const RayContainer &rays) 
    338 { 
    339         if (!ViewCellsConstructed()) 
     272void 
     273ViewCellsManager::ComputeSampleContributions(VssRay &ray) 
     274{ 
     275 
     276  ViewCellContainer viewcells; 
     277   
     278  CastLineSegment(ray.mOrigin, 
     279                                  ray.mTermination, 
     280                                  viewcells 
     281                                  ); 
     282   
     283  ViewCellContainer::const_iterator it = viewcells.begin(); 
     284  for (; it != viewcells.end(); ++it) {          
     285        ViewCell *viewcell = *it; 
     286         
     287        // if ray not outside of view space 
     288        float contribution; 
     289        bool added =  
     290          viewcell->GetPvs().AddSample(ray.mTerminationObject, 
     291                                                                   contribution 
     292                                                                   ); 
     293        if (added) 
     294          ray.mPvsContribution++; 
     295         
     296        ray.mRelativePvsContribution += contribution; 
     297  } 
     298   
     299} 
     300 
     301int 
     302BspViewCellsManager::CastLineSegment(const Vector3 &origin, 
     303                                                                         const Vector3 &termination, 
     304                                                                         ViewCellContainer &viewcells 
     305                                                                         ) 
     306{ 
     307  return mBspTree->CastLineSegment(origin, termination, viewcells); 
     308} 
     309 
     310int 
     311BspViewCellsManager::PostProcess(const ObjectContainer &objects,  
     312                                                                 const VssRayContainer &rays) 
     313{ 
     314  if (!ViewCellsConstructed()) 
    340315        { 
    341316                Debug << "view cells not constructed" << endl; 
     
    391366        long startTime = GetTime(); 
    392367 
     368        // $$JB we do not have connectivity information from the ray in the moment 
     369        // perhaps we could recast the rays or rember the cells traversed inside the 
     370        // vssray (which would on other hand create some overhead) 
    393371        //-- merge or subdivide view cells 
    394372        int merged = 0; 
     373#if 0 
    395374 
    396375        RayContainer::const_iterator rit, rit_end = rays.end(); 
     
    427406                } 
    428407        } 
    429  
     408#endif 
    430409        //-- stats and visualizations 
    431410        cout << "finished" << endl; 
     
    443422 
    444423void BspViewCellsManager::Visualize(const ObjectContainer &objects, 
    445                                                                         const RayContainer &sampleRays) 
    446 { 
    447         if (!ViewCellsConstructed()) 
    448                 return; 
    449  
    450         //-- recount pvs 
    451         ViewCellsStatistics vcStats; 
    452         mBspTree->EvaluateViewCellsStats(vcStats); 
    453  
    454         if (1) // export view cells 
    455         { 
    456                 cout << "exporting view cells after merge ... "; 
    457                 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
    458  
    459                 if (exporter) 
    460                 { 
    461                         exporter->ExportBspViewCellPartition(*mBspTree, vcStats.maxPvs); 
    462                         //exporter->ExportBspViewCellPartition(*mBspTree, 0); 
    463                         delete exporter; 
    464                 } 
    465  
    466                 cout << "finished" << endl; 
     424                                                                        const VssRayContainer &sampleRays) 
     425{ 
     426  if (!ViewCellsConstructed()) 
     427        return; 
     428   
     429  //-- recount pvs 
     430  ViewCellsStatistics vcStats; 
     431  mBspTree->EvaluateViewCellsStats(vcStats); 
     432   
     433  if (1) // export view cells 
     434        { 
     435          cout << "exporting view cells after merge ... "; 
     436          Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
     437           
     438          if (exporter) 
     439                { 
     440                  exporter->ExportBspViewCellPartition(*mBspTree, vcStats.maxPvs); 
     441                  //exporter->ExportBspViewCellPartition(*mBspTree, 0); 
     442                  delete exporter; 
     443                } 
     444           
     445          cout << "finished" << endl; 
    467446        }        
    468  
    469         //-- visualization of the BSP splits 
    470         bool exportSplits = false; 
    471                 environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 
    472          
    473         if (exportSplits) 
    474         { 
    475                 cout << "exporting splits ... "; 
    476                 ExportSplits(objects, sampleRays); 
    477                 cout << "finished" << endl; 
    478         } 
    479  
    480         ExportBspPvs(objects, sampleRays); 
     447   
     448  //-- visualization of the BSP splits 
     449  bool exportSplits = false; 
     450  environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 
     451   
     452  if (exportSplits) 
     453        { 
     454          cout << "exporting splits ... "; 
     455          ExportSplits(objects, sampleRays); 
     456          cout << "finished" << endl; 
     457        } 
     458   
     459  ExportBspPvs(objects, sampleRays); 
    481460} 
    482461 
     
    488467 
    489468void BspViewCellsManager::ExportSplits(const ObjectContainer &objects, 
    490                                                                            const RayContainer &sampleRays) 
     469                                                                           const VssRayContainer &sampleRays) 
    491470{ 
    492471        Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
     
    510489                if (0) 
    511490                { 
    512                         RayContainer outRays; 
    513                  
    514                         int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 
    515  
    516                         for (int i = 0; i < raysSize; ++ i) 
    517                         { 
    518                                 // only rays piercing geometry 
    519                                 if (!sampleRays[i]->intersections.empty()) 
    520                                         outRays.push_back(sampleRays[i]); 
    521                         } 
    522                          
    523                         // export rays  
    524                         exporter->ExportRays(outRays, 1000, RgbColor(1, 1, 0)); 
    525                 } 
    526  
     491                  VssRayContainer outRays; 
     492                   
     493                  int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 
     494                   
     495                  for (int i = 0; i < raysSize; ++ i) 
     496                        { 
     497                          // only rays piercing geometry 
     498                          outRays.push_back(sampleRays[i]); 
     499                        } 
     500                   
     501                  // export rays  
     502                  exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 
     503                } 
     504                 
    527505                if (0) 
    528                         exporter->ExportGeometry(objects); 
    529  
     506                  exporter->ExportGeometry(objects); 
     507                 
    530508                delete exporter; 
    531509        } 
     
    533511 
    534512void BspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 
    535                                                                            const RayContainer &sampleRays) 
    536 { 
    537         const int leafOut = 10; 
    538          
    539         ViewCell::NewMail(); 
    540  
    541         //-- some rays for output 
    542         const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 
    543         Debug << "visualization using " << raysOut << " samples" << endl; 
    544          
    545  
    546         if (1) 
    547         { 
    548                 //-- some random view cells and rays for output 
    549                 vector<BspLeaf *> bspLeaves; 
    550  
    551                 for (int i = 0; i < leafOut; ++ i) 
    552                         bspLeaves.push_back(mBspTree->GetRandomLeaf());  
    553                  
    554                 for (int i = 0; i < bspLeaves.size(); ++ i) 
    555                 { 
    556                         BspLeaf *leaf = bspLeaves[i]; 
    557  
    558                         RayContainer vcRays; 
    559                  
    560                         cout << "creating output for view cell " << i << " ... "; 
    561  
    562                         // check whether we can add the current ray to the output rays 
    563                         for (int k = 0; k < raysOut; ++ k)  
    564                         { 
    565                                 Ray *ray = sampleRays[k]; 
    566  
    567                                 for     (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
     513                                                                           const VssRayContainer &sampleRays) 
     514{ 
     515  const int leafOut = 10; 
     516   
     517  ViewCell::NewMail(); 
     518   
     519  //-- some rays for output 
     520  const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 
     521  Debug << "visualization using " << raysOut << " samples" << endl; 
     522 
     523  //$$ JB 
     524#if 0 
     525 
     526  if (1) 
     527        { 
     528          //-- some random view cells and rays for output 
     529          vector<BspLeaf *> bspLeaves; 
     530           
     531          for (int i = 0; i < leafOut; ++ i) 
     532                bspLeaves.push_back(mBspTree->GetRandomLeaf());  
     533 
     534           
     535          for (int i = 0; i < bspLeaves.size(); ++ i) 
     536                { 
     537                  BspLeaf *leaf = bspLeaves[i]; 
     538                   
     539                  RayContainer vcRays; 
     540                   
     541                  cout << "creating output for view cell " << i << " ... "; 
     542                   
     543                  // check whether we can add the current ray to the output rays 
     544                  for (int k = 0; k < raysOut; ++ k)  
     545                        { 
     546                          Ray *ray = sampleRays[k]; 
     547                           
     548                          for   (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
    568549                                { 
    569                                         BspLeaf *leaf2 = ray->bspIntersections[j].mLeaf; 
    570  
    571                                         if (leaf->GetViewCell() == leaf2->GetViewCell())  
     550                                  BspLeaf *leaf2 = ray->bspIntersections[j].mLeaf; 
     551                                   
     552                                  if (leaf->GetViewCell() == leaf2->GetViewCell())  
    572553                                        { 
    573                                                 vcRays.push_back(ray); 
     554                                          vcRays.push_back(ray); 
    574555                                        } 
    575556                                } 
    576557                        } 
    577  
    578             Intersectable::NewMail(); 
    579  
    580                         BspViewCell *vc = dynamic_cast<BspViewCell *>(leaf->GetViewCell()); 
    581  
    582                         //bspLeaves[j]->Mail(); 
    583                         char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
    584  
    585                         Exporter *exporter = Exporter::GetExporter(s); 
    586                         exporter->SetFilled(); 
    587  
    588                         exporter->SetWireframe(); 
    589                         //exporter->SetFilled(); 
    590  
    591                         Material m;//= RandomMaterial(); 
    592                         m.mDiffuseColor = RgbColor(1, 1, 0); 
    593                         exporter->SetForcedMaterial(m); 
    594  
    595                         if (vc->GetMesh()) 
    596                                 exporter->ExportViewCell(vc); 
    597                         else 
    598                         { 
    599                                 PolygonContainer vcGeom; 
    600                                 // export view cell geometry 
    601                                 mBspTree->ConstructGeometry(vc, vcGeom); 
    602                                 exporter->ExportPolygons(vcGeom); 
     558                   
     559                  Intersectable::NewMail(); 
     560                   
     561                  BspViewCell *vc = dynamic_cast<BspViewCell *>(leaf->GetViewCell()); 
     562                   
     563                  //bspLeaves[j]->Mail(); 
     564                  char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
     565                   
     566                  Exporter *exporter = Exporter::GetExporter(s); 
     567                  exporter->SetFilled(); 
     568 
     569                  exporter->SetWireframe(); 
     570                  //exporter->SetFilled(); 
     571                   
     572                  Material m;//= RandomMaterial(); 
     573                  m.mDiffuseColor = RgbColor(1, 1, 0); 
     574                  exporter->SetForcedMaterial(m); 
     575                   
     576                  if (vc->GetMesh()) 
     577                        exporter->ExportViewCell(vc); 
     578                  else 
     579                        { 
     580                          PolygonContainer vcGeom; 
     581                          // export view cell geometry 
     582                          mBspTree->ConstructGeometry(vc, vcGeom); 
     583                          exporter->ExportPolygons(vcGeom); 
    603584                                CLEAR_CONTAINER(vcGeom); 
    604585                        } 
    605  
    606                         Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    607                                   << ", piercing rays=" << (int)vcRays.size() << endl; 
    608  
    609                         // export rays piercing this view cell 
    610                         exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0));   
    611                          
    612                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    613                         exporter->SetForcedMaterial(m); 
    614  
    615                         // exporter->SetWireframe(); 
    616                         exporter->SetFilled(); 
    617  
    618                         ViewCellPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 
    619                         // output PVS of view cell 
    620                         for (it = vc->GetPvs().mEntries.begin(); it !=  it_end; ++ it)  
    621                         { 
    622                                 Intersectable *intersect = (*it).first; 
    623                                 if (!intersect->Mailed()) 
     586                   
     587                  Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
     588                                << ", piercing rays=" << (int)vcRays.size() << endl; 
     589                   
     590                  // export rays piercing this view cell 
     591                  exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0));         
     592                   
     593                  m.mDiffuseColor = RgbColor(1, 0, 0); 
     594                  exporter->SetForcedMaterial(m); 
     595                   
     596                  // exporter->SetWireframe(); 
     597                  exporter->SetFilled(); 
     598                   
     599                  ViewCellPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 
     600                  // output PVS of view cell 
     601                  for (it = vc->GetPvs().mEntries.begin(); it !=  it_end; ++ it)  
     602                        { 
     603                          Intersectable *intersect = (*it).first; 
     604                          if (!intersect->Mailed()) 
    624605                                { 
    625                                         exporter->ExportIntersectable(intersect); 
    626                                         intersect->Mail(); 
     606                                  exporter->ExportIntersectable(intersect); 
     607                                  intersect->Mail(); 
    627608                                }                        
    628609                        } 
    629  
    630                         DEL_PTR(exporter); 
    631                         cout << "finished" << endl; 
    632                 } 
    633         } 
    634         else 
    635         { 
    636                 ViewCellContainer viewCells; 
    637                 RayContainer vcRays; 
    638  
    639                 mBspTree->CollectViewCells(viewCells); 
    640                 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 
    641  
    642                 int limit = min(leafOut, (int)viewCells.size());  
    643                  
    644                 for (int i = 0; i < limit; ++ i) 
    645                 { 
    646                         cout << "creating output for view cell " << i << " ... "; 
     610                   
     611                  DEL_PTR(exporter); 
     612                  cout << "finished" << endl; 
     613                } 
     614        } 
     615  else 
     616        { 
     617          ViewCellContainer viewCells; 
     618          RayContainer vcRays; 
     619           
     620          mBspTree->CollectViewCells(viewCells); 
     621          stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 
     622           
     623          int limit = min(leafOut, (int)viewCells.size());  
     624           
     625          for (int i = 0; i < limit; ++ i) 
     626                { 
     627                  cout << "creating output for view cell " << i << " ... "; 
    647628                         
    648629            Intersectable::NewMail(); 
     
    721702                } 
    722703        } 
     704#endif 
    723705} 
    724706 
     
    822804 
    823805int KdViewCellsManager::PostProcess(const ObjectContainer &objects,  
    824                                                                         const RayContainer &rays) 
     806                                                                        const VssRayContainer &rays) 
    825807{ 
    826808        return 0; 
     
    828810 
    829811void KdViewCellsManager::Visualize(const ObjectContainer &objects, 
    830                                                                    const RayContainer &sampleRays) 
     812                                                                   const VssRayContainer &sampleRays) 
    831813{ 
    832814        if (!ViewCellsConstructed()) 
     
    837819        int limit = min(mVisualizationSamples, (int)sampleRays.size()); 
    838820 
    839         RayContainer *rays = new RayContainer[pvsOut]; 
     821        VssRayContainer *rays = new VssRayContainer[pvsOut]; 
    840822 
    841823        for  (int i = 0; i < limit; ++ i) 
    842824        { 
    843                 Ray *ray = sampleRays[i]; 
    844  
    845                 if (!ray->intersections.empty())  
    846                 { 
    847                         // check whether we can add this to the rays 
    848                         for (int j = 0; j < pvsOut; j++)  
    849                         { 
    850                                 if (objects[j] == ray->intersections[0].mObject)  
    851                                 { 
    852                                         rays[j].push_back(ray); 
    853                                 } 
    854                         } 
    855                 } 
    856         } 
     825          VssRay *ray = sampleRays[i]; 
     826           
     827          // check whether we can add this to the rays 
     828          for (int j = 0; j < pvsOut; j++)  
     829                { 
     830                  if (objects[j] == ray->mTerminationObject) 
     831                        { 
     832                          rays[j].push_back(ray); 
     833                        } 
     834                } 
     835        } 
     836         
    857837 
    858838        bool exportRays = false; 
    859839        if (exportRays) { 
    860                 Exporter *exporter = NULL; 
     840          Exporter *exporter = NULL; 
    861841                exporter = Exporter::GetExporter("sample-rays.x3d"); 
    862842                exporter->SetWireframe(); 
     
    864844                 
    865845                for (i=0; i < pvsOut; i++)  
    866                         exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0)); 
     846                        exporter->ExportRays(rays[i], RgbColor(1, 0, 0)); 
    867847                exporter->SetFilled(); 
    868848                 
     
    893873                } 
    894874 
    895                 exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 
     875                exporter->ExportRays(rays[k], RgbColor(0, 1, 0)); 
    896876                exporter->SetFilled(); 
    897877                  
     
    914894} 
    915895 
    916 int KdViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 
    917 { 
    918         // view cells not yet constructed 
    919         if (!ViewCellsConstructed()) 
    920                 return 0; 
    921  
    922         if (castRay) 
    923                 mKdTree->CastRay(ray); 
    924  
    925         if (ray.kdLeaves.empty()) 
    926                 return 0; 
    927  
    928         Intersectable *tObject = 
    929                 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL; 
    930  
    931         Intersectable *sObject = 
    932                 ray.sourceObject.mObject; 
    933  
    934         int contributingSamples = 0; 
    935          
    936         int objects = 0; 
    937  
    938         if (sObject) 
    939                 objects++; 
    940         if (tObject) 
    941                 objects++; 
    942  
    943         for (int j = 1; j < ((int)ray.kdLeaves.size() - 1); ++ j)  
    944         { 
    945                 ray.kdLeaves[j]->AddPassingRay2(ray, objects, 
    946                                                                                 (int)ray.kdLeaves.size()); 
    947         } 
    948  
    949         if (!objects) 
    950                 return 0; 
    951          
    952         for (int j=0; j < ray.kdLeaves.size(); j++)  
    953         { 
    954                 KdNode *node = GetNodeForPvs(ray.kdLeaves[j]); 
    955  
    956                 if (sObject) 
    957                         contributingSamples += sObject->mKdPvs.AddSample(node); 
    958                 if (tObject) 
    959                         contributingSamples += tObject->mKdPvs.AddSample(node); 
    960         } 
    961  
    962         return contributingSamples; 
    963 } 
    964896 
    965897 
     
    976908void KdViewCellsManager::PrintStatistics(ostream &s) const 
    977909{ 
     910} 
     911 
     912 
     913int 
     914KdViewCellsManager::CastLineSegment(const Vector3 &origin, 
     915                                                                        const Vector3 &termination, 
     916                                                                        ViewCellContainer &viewcells 
     917                                                                        ) 
     918{ 
     919 
     920  return 0; 
    978921} 
    979922 
     
    1031974} 
    1032975 
    1033 int VspKdViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 
    1034 { 
    1035         // view cells not yet constructed 
     976 
     977ViewCell *VspKdViewCellsManager::GenerateViewCell(Mesh *mesh) const 
     978{ 
     979        return new VspKdViewCell(mesh); 
     980} 
     981 
     982int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects,  
     983                                                                           const VssRayContainer &rays) 
     984{ 
    1036985        if (!ViewCellsConstructed()) 
    1037986                return 0; 
    1038987 
    1039 //      if (castRay) 
    1040 //              mVspKdTree->CastRay(ray); 
    1041  
    1042         int sampleContributions = 0; 
    1043  
    1044         return sampleContributions; 
    1045 } 
    1046  
    1047 ViewCell *VspKdViewCellsManager::GenerateViewCell(Mesh *mesh) const 
    1048 { 
    1049         return new VspKdViewCell(mesh); 
    1050 } 
    1051  
    1052 int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects,  
    1053                                                                            const RayContainer &rays) 
    1054 { 
    1055         if (!ViewCellsConstructed()) 
    1056                 return 0; 
    1057  
    1058988        return mVspKdTree->MergeLeaves(); 
    1059989} 
    1060990 
    1061991void VspKdViewCellsManager::Visualize(const ObjectContainer &objects, 
    1062                                                                           const RayContainer &sampleRays) 
     992                                                                          const VssRayContainer &sampleRays) 
    1063993{ 
    1064994        if (!ViewCellsConstructed()) 
     
    10791009 
    10801010                if (exportRays)  
    1081                 { 
     1011                  { 
    10821012                        int raysSize = 2000; 
    10831013                        float prob = raysSize / (float)sampleRays.size(); 
     
    10851015                        exporter->SetWireframe(); 
    10861016                         
    1087                         RayContainer rays; 
     1017                        VssRayContainer rays; 
    10881018                 
    10891019                        for (int i = 0; i < sampleRays.size(); ++ i) 
     
    10931023                        } 
    10941024 
    1095                         exporter->ExportRays(rays, 1000, RgbColor(1, 0, 0)); 
     1025                        exporter->ExportRays(rays, RgbColor(1, 0, 0)); 
    10961026                } 
    10971027 
     
    11651095                exporter->SetWireframe(); 
    11661096                         
    1167                 RayContainer rays; 
     1097                VssRayContainer rays; 
    11681098                 
    11691099                for (int i = 0; i < sampleRays.size(); ++ i) 
    11701100                { 
    1171                         if (RandomValue(0,1) < prob) 
    1172                                 rays.push_back(sampleRays[i]); 
    1173                 } 
    1174                 exporter->ExportRays(rays, 1000, RgbColor(1, 0, 0)); 
     1101                  if (RandomValue(0,1) < prob) 
     1102                        rays.push_back(sampleRays[i]); 
     1103                } 
     1104                exporter->ExportRays(rays, RgbColor(1, 0, 0)); 
    11751105        } 
    11761106 
     
    11911121} 
    11921122 
     1123 
     1124int 
     1125VspKdViewCellsManager::CastLineSegment(const Vector3 &origin, 
     1126                                                                           const Vector3 &termination, 
     1127                                                                           ViewCellContainer &viewcells 
     1128                                                                           ) 
     1129{ 
     1130   
     1131  return 0; 
     1132} 
    11931133 
    11941134/**********************************************************************/ 
     
    12521192} 
    12531193 
    1254 int VspBspViewCellsManager::ComputeSampleContributions(Ray &ray, const bool castRay) 
    1255 { 
    1256         // view cells not yet constructed 
    1257         if (!ViewCellsConstructed()) 
    1258                 return 0; 
    1259  
    1260         int contributingSamples = 0; 
    1261  
    1262         if (castRay) 
    1263                 mVspBspTree->CastRay(ray); 
    1264  
    1265         Intersectable *tObject =  
    1266                 !ray.intersections.empty() ? ray.intersections[0].mObject : NULL; 
    1267  
    1268         Intersectable *sObject = ray.sourceObject.mObject; 
    1269  
    1270         if (sObject || tObject) 
    1271         { 
    1272                 // object can be seen from the view cell => add to view cell pvs 
    1273                 for (int j = 0; j < (int)ray.bspIntersections.size(); ++ j) 
    1274                 {        
    1275                         BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    1276                  
    1277                         // if ray not in unbounded space 
    1278                         if (leaf->GetViewCell() != mVspBspTree->GetRootCell()) 
    1279                         { 
    1280                                 if (sObject) 
    1281                                 { 
    1282                                         contributingSamples +=  
    1283                                                 leaf->GetViewCell()->GetPvs().AddSample(sObject); 
    1284                                 } 
    1285  
    1286                                 if (tObject) 
    1287                                 { 
    1288                                         contributingSamples +=  
    1289                                                 leaf->GetViewCell()->GetPvs().AddSample(tObject); 
    1290                                 } 
    1291                         } 
    1292                 } 
    1293         } 
    1294  
    1295         // rays passing through this viewcell 
    1296         if (0) 
    1297                 for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j)  
    1298                 { 
    1299                         BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    1300  
    1301                         if (leaf->GetViewCell() != mVspBspTree->GetRootCell()) 
    1302                                 leaf->GetViewCell()-> 
    1303                                         AddPassingRay(ray, contributingSamples ? 1 : 0); 
    1304                 } 
    1305  
    1306         return contributingSamples; 
    1307 } 
    13081194 
    13091195int VspBspViewCellsManager::PostProcess(const ObjectContainer &objects,  
    1310                                                                                 const RayContainer &rays) 
     1196                                                                                const VssRayContainer &rays) 
    13111197{ 
    13121198        if (!ViewCellsConstructed()) 
     
    13561242 
    13571243 
     1244        // $$JB we do not have connectivity information from the ray in the moment 
     1245        // perhaps we could recast the rays or rember the cells traversed inside the 
     1246        // vssray (which would on other hand create some overhead) 
    13581247        //-- merge or subdivide view cells 
    13591248        int merged = 0; 
     1249#if 0 
    13601250 
    13611251        RayContainer::const_iterator rit, rit_end = rays.end(); 
     
    13661256        for (int i = 0; i < limit; ++ i) 
    13671257        {   
    1368                 Ray *ray = rays[i]; 
    1369  
    1370                 // traverse leaves stored in the rays and compare and merge consecutive 
    1371                 // leaves (i.e., the neighbors in the tree) 
    1372                 if (ray->bspIntersections.size() < 2) 
    1373                         continue; 
    1374  
    1375                 iit = ray->bspIntersections.begin(); 
     1258          VssRay *ray = rays[i]; 
     1259           
     1260          // traverse leaves stored in the rays and compare and merge consecutive 
     1261          // leaves (i.e., the neighbors in the tree) 
     1262          if (ray->bspIntersections.size() < 2) 
     1263                continue; 
     1264           
     1265          iit = ray->bspIntersections.begin(); 
    13761266 
    13771267                BspLeaf *previousLeaf = (*iit).mLeaf; 
     
    13921282                } 
    13931283        } 
    1394  
     1284#endif 
    13951285        //-- stats and visualizations 
    13961286        cout << "finished" << endl; 
     
    14091299 
    14101300void VspBspViewCellsManager::Visualize(const ObjectContainer &objects, 
    1411                                                                            const RayContainer &sampleRays) 
     1301                                                                           const VssRayContainer &sampleRays) 
    14121302{ 
    14131303        if (!ViewCellsConstructed()) 
     
    14481338 
    14491339void VspBspViewCellsManager::ExportSplits(const ObjectContainer &objects, 
    1450                                                                                   const RayContainer &sampleRays) 
     1340                                                                                  const VssRayContainer &sampleRays) 
    14511341{ 
    14521342        Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
     
    14711361                if (0) 
    14721362                { 
    1473                         RayContainer outRays; 
     1363                  VssRayContainer outRays; 
    14741364                 
    14751365                        int raysSize = min((int)sampleRays.size(), mVisualizationSamples); 
     
    14781368                        { 
    14791369                                // only rays piercing geometry 
    1480                                 if (!sampleRays[i]->intersections.empty()) 
    1481                                         outRays.push_back(sampleRays[i]); 
     1370                          outRays.push_back(sampleRays[i]); 
    14821371                        } 
    14831372                         
    14841373                        // export rays  
    1485                         exporter->ExportRays(outRays, 1000, RgbColor(1, 1, 0)); 
     1374                        exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 
    14861375                } 
    14871376 
     
    14941383 
    14951384void VspBspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 
    1496                                                                                   const RayContainer &sampleRays) 
     1385                                                                                  const VssRayContainer &sampleRays) 
    14971386{ 
    14981387        const int leafOut = 10; 
     
    15141403                for (int i = 0; i < (int)vspBspLeaves.size(); ++ i) 
    15151404                { 
    1516                         RayContainer vcRays; 
    1517                         cout << "creating output for view cell " << i << " ... "; 
    1518                          
     1405                  VssRayContainer vcRays; 
     1406                  cout << "creating output for view cell " << i << " ... "; 
     1407 
     1408                  //$$JB 
     1409#if 0 
    15191410                        // check whether we can add the current ray to the output rays 
    15201411                        for (int k = 0; k < raysOut; ++ k)  
    15211412                        { 
    1522                                 Ray *ray = sampleRays[k]; 
     1413                          VssRay *ray = sampleRays[k]; 
    15231414 
    15241415                                for     (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
     
    15321423                                } 
    15331424                        } 
    1534                          
     1425#endif 
    15351426 
    15361427                        Intersectable::NewMail(); 
     
    15701461 
    15711462                        // export rays piercing this view cell 
    1572                         exporter->ExportRays(vcRays, 1000, RgbColor(1, 0, 0)); 
     1463                        exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 
    15731464                        exporter->ExportRays(vspBspLeaves[i]->mVssRays, RgbColor(1, 1, 1)); 
    15741465                         
     
    16211512                { 
    16221513                        cout << "creating output for view cell " << i << " ... "; 
    1623                         RayContainer vcRays; 
     1514                        VssRayContainer vcRays; 
    16241515            Intersectable::NewMail(); 
    16251516                        BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 
    16261517 
    16271518                        cout << "creating output for view cell " << i << " ... "; 
     1519                        //$$ JB 
     1520#if 0 
    16281521                        // check whether we can add the current ray to the output rays 
    16291522                        for (int k = 0; k < raysOut; ++ k)  
    16301523                        { 
    1631                                 Ray *ray = sampleRays[k]; 
     1524                          Ray *ray = sampleRays[k]; 
    16321525 
    16331526                                for     (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
     
    16411534                                } 
    16421535                        } 
    1643  
     1536#endif 
    16441537                        //bspLeaves[j]->Mail(); 
    16451538                        char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
     
    16701563                         
    16711564                        // export rays piercing this view cell 
    1672                         exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 
     1565                        exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 
    16731566         
    16741567                        m.mDiffuseColor = RgbColor(1, 0, 0); 
     
    17711664} 
    17721665 
     1666 
     1667int 
     1668VspBspViewCellsManager::CastLineSegment(const Vector3 &origin, 
     1669                                                                                const Vector3 &termination, 
     1670                                                                                ViewCellContainer &viewcells 
     1671                                                                                ) 
     1672{ 
     1673  return mVspBspTree->CastLineSegment(origin, termination, viewcells); 
     1674} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r463 r466  
    2929 
    3030public: 
    31          
    32         /// view cell container types 
    33         enum {BSP, KD, VSP_KD, VSP_BSP}; 
    34  
     31   
     32  /// view cell container types 
     33  enum {BSP, KD, VSP_KD, VSP_BSP}; 
     34   
    3535        /** Constructor taking the maximal number of samples used for construction 
    3636        */ 
     
    5656                @param contributingSamples returns the number of contributingSamples 
    5757        */ 
    58         void  ComputeSampleContributions(const RayContainer &rays,  
    59                                                                          int &sampleContributions, 
    60                                                                          int &contributingSamples, 
    61                                                                          const bool castRays = true); 
    62  
    63  
    64         /** Computes sample contribution of a simgle ray to the view cells PVS. 
    65                 @param ray finds intersections with view cells and holds the contribution 
    66                 @param castRay true if ray should be cast to gain the information, false if ray 
    67                 is already holding the information and need not be recast. 
    68  
    69                 @returns number of sample contributions 
    70         */ 
    71         virtual int ComputeSampleContributions(Ray &ray, const bool castRay = true) = 0; 
    72  
     58  void  ComputeSampleContributions(const VssRayContainer &rays 
     59                                                                   ); 
     60 
     61 
     62  /** Computes sample contribution of a simgle ray to the view cells PVS. 
     63          @param ray finds intersections with view cells and holds the contribution 
     64          @param castRay true if ray should be cast to gain the information, false if ray 
     65          is already holding the information and need not be recast. 
     66           
     67          @returns number of sample contributions 
     68  */ 
     69  virtual void ComputeSampleContributions(VssRay &ray 
     70                                                                                  ); 
     71   
    7372        /** Prints out statistics of the view cells. 
    7473        */ 
     
    7776        /** Post processes view cells givemŽa number of rays. 
    7877        */ 
    79         virtual int PostProcess(const ObjectContainer &objects,  
    80                                                         const RayContainer &rays) = 0; 
     78  virtual int PostProcess(const ObjectContainer &objects,  
     79                                                  const VssRayContainer &rays) = 0; 
    8180 
    8281        /** Show visualization of the view cells. 
    8382        */ 
    8483        virtual void Visualize(const ObjectContainer &objects, 
    85                                                    const RayContainer &sampleRays) = 0; 
     84                                                   const VssRayContainer &sampleRays) = 0; 
    8685 
    8786        /** type of the view cell container. 
     
    157156        */ 
    158157        virtual bool ViewCellsConstructed() const = 0; 
    159                  
     158 
     159  /** cast line segment to get a list of unique viewcells which are intersected 
     160          by this line segment */ 
     161   
     162  virtual int CastLineSegment(const Vector3 &origin, 
     163                                                          const Vector3 &termination, 
     164                                                          ViewCellContainer &viewcells 
     165                                                          ) = 0; 
     166 
    160167 
    161168protected: 
     
    205212                                  AxisAlignedBox3 *sceneBbox); 
    206213 
    207         int ComputeSampleContributions(Ray &ray, const bool castRay = false); 
    208214 
    209215        int PostProcess(const ObjectContainer &objects,  
    210                                         const RayContainer &rays); 
     216                                        const VssRayContainer &rays); 
    211217 
    212218        void Visualize(const ObjectContainer &objects, 
    213                                    const RayContainer &sampleRays); 
     219                                   const VssRayContainer &sampleRays); 
    214220 
    215221        int GetType() const; 
     
    222228 
    223229        ~BspViewCellsManager(); 
     230 
     231  int CastLineSegment(const Vector3 &origin, 
     232                                          const Vector3 &termination, 
     233                                          ViewCellContainer &viewcells 
     234                                          ); 
     235 
    224236protected: 
    225237 
     
    241253        /** Exports visualization of the BSP splits. 
    242254        */ 
    243         void ExportSplits(const ObjectContainer &objects, const RayContainer &sampleRays); 
     255        void ExportSplits(const ObjectContainer &objects, const VssRayContainer &sampleRays); 
    244256 
    245257        /** Exports visualization of the BSP PVS. 
    246258        */ 
    247         void ExportBspPvs(const ObjectContainer &objects, const RayContainer &sampleRays); 
     259        void ExportBspPvs(const ObjectContainer &objects, const VssRayContainer &sampleRays); 
    248260 
    249261}; 
     
    263275                                  AxisAlignedBox3 *sceneBbox); 
    264276 
    265         int CastRay(const Ray &ray); 
     277  int CastLineSegment(const Vector3 &origin, 
     278                                          const Vector3 &termination, 
     279                                          ViewCellContainer &viewcells 
     280                                          ) ; 
    266281 
    267282        int PostProcess(const ObjectContainer &objects,  
    268                                         const RayContainer &rays); 
     283                                        const VssRayContainer &rays); 
    269284 
    270285        void Visualize(const ObjectContainer &objects, 
    271                                    const RayContainer &sampleRays); 
     286                                   const VssRayContainer &sampleRays); 
    272287 
    273288        int GetType() const; 
     
    284299         KdNode *GetNodeForPvs(KdLeaf *leaf); 
    285300 
    286          int ComputeSampleContributions(Ray &ray, const bool castRay = true); 
    287301 
    288302         /// the BSP tree. 
     
    310324                                  AxisAlignedBox3 *sceneBbox); 
    311325 
    312         int ComputeSampleContributions(Ray &ray, const bool castRay = true); 
    313326 
    314327        int PostProcess(const ObjectContainer &objects,  
    315                                         const RayContainer &rays); 
     328                                        const VssRayContainer &rays); 
    316329 
    317330        void Visualize(const ObjectContainer &objects, 
    318                                    const RayContainer &sampleRays); 
     331                                   const VssRayContainer &sampleRays); 
    319332 
    320333        int GetType() const; 
     
    325338 
    326339        ViewCell *GenerateViewCell(Mesh *mesh) const; 
     340 
     341 
     342    int CastLineSegment(const Vector3 &origin, 
     343                                                const Vector3 &termination, 
     344                                                ViewCellContainer &viewcells 
     345                                                ) ; 
    327346 
    328347protected: 
     
    350369                                  AxisAlignedBox3 *sceneBbox); 
    351370 
    352         int ComputeSampleContributions(Ray &ray, const bool castRay = false); 
    353371 
    354372        int PostProcess(const ObjectContainer &objects,  
    355                                         const RayContainer &rays); 
     373                                        const VssRayContainer &rays); 
    356374 
    357375        void Visualize(const ObjectContainer &objects, 
    358                                    const RayContainer &sampleRays); 
     376                                   const VssRayContainer &sampleRays); 
    359377 
    360378        int GetType() const; 
     
    365383 
    366384        void PrintStatistics(ostream &s) const; 
     385 
     386  int CastLineSegment(const Vector3 &origin, 
     387                                          const Vector3 &termination, 
     388                                          ViewCellContainer &viewcells 
     389                                          ) ; 
    367390 
    368391protected: 
     
    385408        /** Exports visualization of the BSP splits. 
    386409        */ 
    387         void ExportSplits(const ObjectContainer &objects, const RayContainer &sampleRays); 
     410        void ExportSplits(const ObjectContainer &objects, const VssRayContainer &sampleRays); 
    388411 
    389412        /** Exports visualization of the BSP PVS. 
    390413        */ 
    391         void ExportBspPvs(const ObjectContainer &objects, const RayContainer &sampleRays); 
     414        void ExportBspPvs(const ObjectContainer &objects, const VssRayContainer &sampleRays); 
    392415 
    393416}; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r463 r466  
    17101710        return splits; 
    17111711} 
     1712 
     1713 
     1714int 
     1715VspBspTree::CastLineSegment(const Vector3 &origin, 
     1716                                                 const Vector3 &termination, 
     1717                                                 vector<ViewCell *> &viewcells 
     1718                                                 ) 
     1719{ 
     1720  int hits = 0; 
     1721  stack<BspRayTraversalData> tStack; 
     1722   
     1723  float mint = 0.0f, maxt = 1.0f; 
     1724   
     1725  Intersectable::NewMail(); 
     1726   
     1727  Vector3 entp = origin; 
     1728  Vector3 extp = termination; 
     1729   
     1730  BspNode *node = mRoot; 
     1731  BspNode *farChild = NULL; 
     1732   
     1733  while (1) { 
     1734        if (!node->IsLeaf())  { 
     1735          BspInterior *in = dynamic_cast<BspInterior *>(node); 
     1736           
     1737          Plane3 splitPlane = in->GetPlane(); 
     1738          const int entSide = splitPlane.Side(entp); 
     1739          const int extSide = splitPlane.Side(extp); 
     1740           
     1741          if (entSide < 0) { 
     1742                node = in->GetBack(); 
     1743                 
     1744                if(extSide <= 0) // plane does not split ray => no far child 
     1745                  continue; 
     1746                 
     1747                farChild = in->GetFront(); // plane splits ray 
     1748                 
     1749          } else 
     1750                if (entSide > 0) { 
     1751                  node = in->GetFront(); 
     1752                   
     1753                  if (extSide >= 0) // plane does not split ray => no far child 
     1754                        continue; 
     1755                   
     1756                  farChild = in->GetBack(); // plane splits ray                  
     1757                } 
     1758                else // ray and plane are coincident 
     1759                  { 
     1760                        // WHAT TO DO IN THIS CASE ? 
     1761                        //break; 
     1762                        node = in->GetFront(); 
     1763                        continue; 
     1764                  } 
     1765           
     1766          // push data for far child 
     1767          tStack.push(BspRayTraversalData(farChild, extp, maxt)); 
     1768           
     1769          // find intersection of ray segment with plane 
     1770          float t; 
     1771          extp = splitPlane.FindIntersection(origin, extp, &t); 
     1772          maxt *= t; 
     1773           
     1774        } else { 
     1775          // reached leaf => intersection with view cell 
     1776          BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     1777           
     1778          if (!leaf->GetViewCell()->Mailed()) { 
     1779                viewcells.push_back(leaf->GetViewCell()); 
     1780                leaf->GetViewCell()->Mail(); 
     1781                hits++; 
     1782          } 
     1783           
     1784          //-- fetch the next far child from the stack 
     1785          if (tStack.empty()) 
     1786                break; 
     1787       
     1788          entp = extp; 
     1789          mint = maxt; // NOTE: need this? 
     1790           
     1791          BspRayTraversalData &s = tStack.top(); 
     1792           
     1793          node = s.mNode; 
     1794          extp = s.mExitPoint; 
     1795          maxt = s.mMaxT; 
     1796           
     1797          tStack.pop(); 
     1798        } 
     1799  } 
     1800  return hits; 
     1801} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r463 r466  
    208208        float GetEpsilon() const; 
    209209 
     210 
     211    int 
     212        CastLineSegment(const Vector3 &origin, 
     213                                        const Vector3 &termination, 
     214                                        ViewCellContainer &viewcells 
     215                                        ); 
     216 
    210217protected: 
    211218 
     
    427434                                  int &contributingSamples); 
    428435 
     436 
     437 
     438   
    429439        /// Pointer to the root of the tree 
    430440        BspNode *mRoot; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r465 r466  
    20352035 
    20362036                if (ray->mTerminationObject) 
    2037                         vc->GetPvs().AddSample(ray->mTerminationObject); 
     2037                  vc->GetPvs().AddSample(ray->mTerminationObject); 
    20382038 
    20392039                if (ray->mOriginObject) 
    2040                         vc->GetPvs().AddSample(ray->mOriginObject); 
     2040                  vc->GetPvs().AddSample(ray->mOriginObject); 
    20412041        } 
    20422042} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r465 r466  
    4242                                                  ) 
    4343{ 
    44   ray.intersections.clear(); 
     44  ray.Clear(); 
    4545  // do not store anything else then intersections at the ray 
    4646  ray.Init(point, direction, Ray::LOCAL_RAY); 
     
    450450  } 
    451451         
    452   ObjectContainer objects; 
    453   mSceneGraph->CollectObjects(&objects); 
     452  mSceneGraph->CollectObjects(&mObjects); 
    454453 
    455454  // construct view cells 
    456   mViewCellsManager->Construct(objects, mVssRays, mViewSpaceBox); 
     455  mViewCellsManager->Construct(mObjects, mVssRays, mViewSpaceBox); 
    457456 
    458457  vssTree = new VssTree; 
     
    509508          num = GenerateImportanceRays(vssTree, num, rays); 
    510509        } 
    511                          
     510         
    512511        for (int i=0; i < rays.size(); i++) 
    513512          CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 
     
    534533 
    535534        //-- prepare traversal rays for view cell intersections 
    536         RayContainer passRays; 
    537  
    538         VssRayContainer::const_iterator it, it_end = vssRays.end(); 
    539          
    540         for (it = vssRays.begin(); it != it_end; ++ it) 
    541                 passRays.push_back(new Ray(*(*it))); 
    542          
    543         int sampleContributions = 0; 
    544         int contributingSamples = 0; 
    545  
    546535        /// compute view cell contribution of rays 
    547 /*      mViewCellsManager->ComputeSampleContributions(passRays, 
    548                                                                                                   sampleContributions,  
    549                                                                                                   contributingSamples); 
    550          
    551         //-- save rays for post processing 
    552         if (((int)storedRays.size() < mViewCellsManager->GetPostProcessSamples()) || 
    553                 ((int)storedRays.size() < mViewCellsManager->GetVisualizationSamples())) 
    554         { 
    555                 RayContainer::const_iterator it, it_end = passRays.end(); 
    556  
    557                 for (it = passRays.begin(); it != it_end; ++ it) 
    558                         storedRays.push_back(new Ray(*(*it))); 
    559         } 
    560         else 
    561         { 
    562                 CLEAR_CONTAINER(passRays); 
    563         } 
    564 */ 
     536        mViewCellsManager->ComputeSampleContributions(vssRays); 
     537 
    565538        samples+=num; 
    566539        float pvs = vssTree->GetAvgPvsSize(); 
    567540        cout<<"*****************************\n"; 
    568541        cout<<samples<<" avgPVS ="<<pvs<<endl; 
    569         cout<<"sample contributions ="<<sampleContributions<<endl; 
    570         cout<<"contributing sample ="<<contributingSamples<<endl; 
    571542        cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 
    572543        cout<<"*****************************\n"; 
     
    576547  } 
    577548 
    578   cout << "here" << endl; 
    579   //-- post process view cells 
    580   mViewCellsManager->PostProcess(objects, storedRays); 
    581  
    582   //-- several visualizations and statistics 
    583   mViewCellsManager->PrintStatistics(Debug); 
     549  { 
     550        VssRayContainer storedRays; 
     551        vssTree->CollectRays(storedRays, Max( 
     552                                                                                 mViewCellsManager->GetPostProcessSamples(), 
     553                                                                                 mViewCellsManager->GetVisualizationSamples())); 
     554         
     555        //-- post process view cells 
     556        mViewCellsManager->PostProcess(mObjects, storedRays); 
     557         
     558        //-- several visualizations and statistics 
     559        mViewCellsManager->PrintStatistics(Debug); 
     560 
     561        mViewCellsManager->Visualize(mObjects, storedRays); 
     562 
     563        CLEAR_CONTAINER(storedRays); 
     564  } 
    584565 
    585566  //-- render simulation after merge 
    586567  cout << "\nevaluating bsp view cells render time after merge ... "; 
    587                  
     568   
    588569  const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 
    589                  
     570   
    590571  cout << " finished" << endl; 
    591572  cout << ss << endl; 
    592573  Debug << ss << endl; 
    593  
    594   mViewCellsManager->Visualize(objects, storedRays); 
    595  
    596   CLEAR_CONTAINER(storedRays); 
     574   
    597575   
    598576  delete vssTree; 
    599  
     577   
    600578  return true; 
    601579} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp

    r463 r466  
    19541954  //  cout<<"ei="<<mEntropyImportance<<" "; 
    19551955} 
     1956 
     1957 
     1958int 
     1959VssTree::CollectRays(VssRayContainer &rays, 
     1960                                         const int number) 
     1961{ 
     1962  VssRayContainer allRays; 
     1963  CollectRays(allRays); 
     1964   
     1965  int desired = min(number, (int)allRays.size()); 
     1966  float prob = desired/(float)allRays.size(); 
     1967  while (rays.size() < desired) { 
     1968        VssRayContainer::const_iterator it = allRays.begin(); 
     1969        for (; it != allRays.end() && rays.size() < desired; it++) { 
     1970          if (Random(1.0f) < prob) 
     1971                rays.push_back(*it); 
     1972        } 
     1973  } 
     1974  return rays.size(); 
     1975} 
     1976 
     1977 
     1978int 
     1979VssTree::CollectRays(VssRayContainer &rays 
     1980                                         ) 
     1981{ 
     1982  VssRay::NewMail(); 
     1983 
     1984  stack<VssTreeNode *> tstack; 
     1985  tstack.push(root); 
     1986   
     1987  while (!tstack.empty()) { 
     1988    VssTreeNode *node = tstack.top(); 
     1989    tstack.pop(); 
     1990         
     1991    if (node->IsLeaf()) { 
     1992          VssTreeLeaf *leaf = (VssTreeLeaf *)node; 
     1993          // update pvs size 
     1994          VssTreeNode::RayInfoContainer::const_iterator it = leaf->rays.begin(); 
     1995          for (;it != leaf->rays.end(); ++it) 
     1996                if (!(*it).mRay->Mailed()) { 
     1997                  (*it).mRay->Mail(); 
     1998                  rays.push_back((*it).mRay); 
     1999                } 
     2000        } else { 
     2001          VssTreeInterior *in = (VssTreeInterior *)node; 
     2002          // both nodes for directional splits 
     2003          tstack.push(in->front); 
     2004          tstack.push(in->back); 
     2005        } 
     2006  } 
     2007   
     2008  return rays.size(); 
     2009} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h

    r446 r466  
    918918                                   SimpleRayContainer &rays); 
    919919 
    920  
     920  int 
     921  CollectRays(VssRayContainer &rays, 
     922                          const int number); 
     923 
     924  int 
     925  CollectRays(VssRayContainer &rays 
     926                          ); 
     927   
    921928}; 
    922929 
Note: See TracChangeset for help on using the changeset viewer.